Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js |
— | — | @@ -27,29 +27,26 @@ |
28 | 28 | .addClass( 'editSurface-' + typeName ) |
29 | 29 | .data( typeName, this ); |
30 | 30 | var container = this; |
31 | | - function cleanupItemView( itemModel ) { |
| 31 | + function recycleItemView( itemModel, autoCreate ) { |
32 | 32 | var itemView = container.lookupItemView( itemModel ); |
33 | 33 | if ( itemView ) { |
34 | 34 | container.views.splice( container.views.indexOf( itemView ), 1 ); |
35 | 35 | itemView.$.detach(); |
36 | 36 | } |
| 37 | + if ( autoCreate && itemView === null ) { |
| 38 | + itemView = itemModel.createView(); |
| 39 | + } |
37 | 40 | return itemView; |
38 | 41 | } |
39 | 42 | this.containerModel.on( 'prepend', function( itemModel ) { |
40 | | - var itemView = cleanupItemView( itemModel ); |
41 | | - if ( itemView === null ) { |
42 | | - itemView = itemModel.createView(); |
43 | | - } |
| 43 | + var itemView = recycleItemView( itemModel, true ); |
44 | 44 | container.views.unshift( itemView ); |
45 | 45 | container.$.prepend( itemView.$ ); |
46 | 46 | container.emit( 'prepend', itemView ); |
47 | 47 | container.emit( 'update' ); |
48 | 48 | } ); |
49 | 49 | this.containerModel.on( 'append', function( itemModel ) { |
50 | | - var itemView = cleanupItemView( itemModel ); |
51 | | - if ( itemView === null ) { |
52 | | - itemView = itemModel.createView(); |
53 | | - } |
| 50 | + var itemView = recycleItemView( itemModel, true ); |
54 | 51 | container.views.push( itemView ); |
55 | 52 | container.$.append( itemView.$ ); |
56 | 53 | container.emit( 'append', itemView ); |
— | — | @@ -57,10 +54,7 @@ |
58 | 55 | } ); |
59 | 56 | this.containerModel.on( 'insertBefore', function( itemModel, beforeModel ) { |
60 | 57 | var beforeView = container.lookupItemView( beforeModel ), |
61 | | - itemView = cleanupItemView( itemModel ); |
62 | | - if ( itemView === null ) { |
63 | | - itemView = itemModel.createView(); |
64 | | - } |
| 58 | + itemView = recycleItemView( itemModel, true ); |
65 | 59 | if ( beforeView ) { |
66 | 60 | container.views.splice( container.views.indexOf( beforeView ), 0, itemView ); |
67 | 61 | itemView.$.insertBefore( beforeView.$ ); |
— | — | @@ -73,10 +67,7 @@ |
74 | 68 | } ); |
75 | 69 | this.containerModel.on( 'insertAfter', function( itemModel, afterModel ) { |
76 | 70 | var afterView = container.lookupItemView( afterModel ), |
77 | | - itemView = cleanupItemView( itemModel ); |
78 | | - if ( itemView === null ) { |
79 | | - itemView = itemModel.createView(); |
80 | | - } |
| 71 | + itemView = recycleItemView( itemModel, true ); |
81 | 72 | if ( afterView ) { |
82 | 73 | container.views.splice( container.views.indexOf( afterView ) + 1, 0, itemView ); |
83 | 74 | itemView.$.insertAfter( afterView.$ ); |
— | — | @@ -88,7 +79,7 @@ |
89 | 80 | container.emit( 'update' ); |
90 | 81 | } ); |
91 | 82 | this.containerModel.on( 'remove', function( itemModel ) { |
92 | | - var itemView = cleanupItemView( itemModel ); |
| 83 | + var itemView = recycleItemView( itemModel ); |
93 | 84 | container.emit( 'remove', itemView ); |
94 | 85 | container.emit( 'update' ); |
95 | 86 | } ); |