Implement a comment marker and use the original element as the reference.
Showing
1 changed file
with
10 additions
and
9 deletions
... | @@ -48,7 +48,6 @@ class Rivets.Binding | ... | @@ -48,7 +48,6 @@ class Rivets.Binding |
48 | @routine @el, value, @currentListener | 48 | @routine @el, value, @currentListener |
49 | @currentListener = value | 49 | @currentListener = value |
50 | else if @options.special is "iteration" | 50 | else if @options.special is "iteration" |
51 | @iterated or= [] | ||
52 | @routine @el, value, @ | 51 | @routine @el, value, @ |
53 | else | 52 | else |
54 | value = value() if value instanceof Function | 53 | value = value() if value instanceof Function |
... | @@ -192,21 +191,23 @@ eventBinding = (event) -> (el, bind, unbind) -> | ... | @@ -192,21 +191,23 @@ eventBinding = (event) -> (el, bind, unbind) -> |
192 | 191 | ||
193 | # Returns an iteration binding routine for the specified collection. | 192 | # Returns an iteration binding routine for the specified collection. |
194 | iterationBinding = (name) -> (el, collection, binding) -> | 193 | iterationBinding = (name) -> (el, collection, binding) -> |
195 | Rivets.routines.hide el, true | 194 | if binding.iterated? |
196 | 195 | for iteration in binding.iterated | |
197 | for iteration in binding.iterated | 196 | iteration.view.unbind() |
198 | iteration.view.unbind() | 197 | iteration.el.parentNode.removeChild iteration.el |
199 | iteration.el.parentNode.removeChild iteration.el | 198 | else |
199 | binding.marker = document.createComment " rivets: each-#{name} " | ||
200 | el.parentNode.insertBefore binding.marker, el | ||
201 | el.parentNode.removeChild el | ||
200 | 202 | ||
201 | binding.iterated = [] | 203 | binding.iterated = [] |
202 | 204 | ||
203 | for item in collection | 205 | for item in collection |
204 | data = {} | 206 | data = {} |
205 | data[name] = item | 207 | data[name] = item |
206 | |||
207 | itemEl = el.cloneNode true | 208 | itemEl = el.cloneNode true |
208 | Rivets.routines.show itemEl, true | 209 | previous = binding.iterated[binding.iterated.length - 1] or binding.marker |
209 | el.parentNode.insertBefore itemEl, el | 210 | binding.marker.parentNode.insertBefore itemEl, previous.nextSibling |
210 | 211 | ||
211 | binding.iterated.push | 212 | binding.iterated.push |
212 | el: itemEl | 213 | el: itemEl | ... | ... |
-
Please register or sign in to post a comment