Fix "Add Time Period" button
Don't clone the whole set of time periods, just add one more list item to the end.
Showing
1 changed file
with
15 additions
and
20 deletions
... | @@ -10,9 +10,6 @@ | ... | @@ -10,9 +10,6 @@ |
10 | player, | 10 | player, |
11 | runButton, | 11 | runButton, |
12 | parameters, | 12 | parameters, |
13 | addTimePeriod, | ||
14 | networkTimeline, | ||
15 | timePeriod, | ||
16 | timeline, | 13 | timeline, |
17 | 14 | ||
18 | displayTimeline; | 15 | displayTimeline; |
... | @@ -31,23 +28,21 @@ | ... | @@ -31,23 +28,21 @@ |
31 | }; | 28 | }; |
32 | 29 | ||
33 | // a dynamic number of time-bandwidth pairs may be defined to drive the simulation | 30 | // a dynamic number of time-bandwidth pairs may be defined to drive the simulation |
34 | addTimePeriod = document.querySelector('.add-time-period'); | 31 | (function() { |
35 | networkTimeline = document.querySelector('.network-timeline'); | 32 | var addTimePeriod = document.querySelector('.add-time-period'), |
36 | timePeriod = networkTimeline.cloneNode(true); | 33 | networkTimeline = document.querySelector('.network-timeline'), |
37 | addTimePeriod.addEventListener('click', function() { | 34 | timePeriod = networkTimeline.querySelector('li:last-child').cloneNode(true); |
38 | var clone = timePeriod.cloneNode(true), | 35 | addTimePeriod.addEventListener('click', function() { |
39 | fragment = document.createDocumentFragment(), | 36 | var clone = timePeriod.cloneNode(true), |
40 | count = networkTimeline.querySelectorAll('input.bandwidth').length, | 37 | count = networkTimeline.querySelectorAll('input.bandwidth').length, |
41 | time = clone.querySelector('.time'), | 38 | time = clone.querySelector('.time'), |
42 | bandwidth = clone.querySelector('input.bandwidth'); | 39 | bandwidth = clone.querySelector('input.bandwidth'); |
43 | 40 | ||
44 | time.name = 'time' + count; | 41 | time.name = 'time' + count; |
45 | bandwidth.name = 'bandwidth' + count; | 42 | bandwidth.name = 'bandwidth' + count; |
46 | while (clone.childNodes.length) { | 43 | networkTimeline.appendChild(clone); |
47 | fragment.appendChild(clone.childNodes[0]); | 44 | }); |
48 | } | 45 | })(); |
49 | networkTimeline.appendChild(fragment); | ||
50 | }); | ||
51 | 46 | ||
52 | // collect the simulation parameters | 47 | // collect the simulation parameters |
53 | parameters = function() { | 48 | parameters = function() { | ... | ... |
-
Please register or sign in to post a comment