Index: trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js |
— | — | @@ -8,7 +8,11 @@ |
9 | 9 | */ |
10 | 10 | es.ParagraphBlockModel = function( content ) { |
11 | 11 | es.BlockModel.call( this, ['hasContent', 'isAnnotatable'] ); |
12 | | - this.content = content || null; |
| 12 | + this.content = content || new es.ContentModel(); |
| 13 | + var model = this; |
| 14 | + this.content.on( 'change', function() { |
| 15 | + model.emit( 'update' ); |
| 16 | + } ); |
13 | 17 | }; |
14 | 18 | |
15 | 19 | /* Static Methods */ |
Index: trunk/parsers/wikidom/lib/synth/models/es.ListBlockModel.js |
— | — | @@ -9,7 +9,11 @@ |
10 | 10 | es.ListBlockModel = function( items ) { |
11 | 11 | es.BlockModel.call( this, ['hasContent', 'isAnnotatable', 'isAggregate'] ); |
12 | 12 | es.ModelContainer.call( this ); |
13 | | - this.items = new es.AggregateArray( items || [] ); |
| 13 | + if ( $.isArray( items ) ) { |
| 14 | + for ( var i = 0; i < items.length; i++ ) { |
| 15 | + this.append( items[i] ); |
| 16 | + } |
| 17 | + } |
14 | 18 | }; |
15 | 19 | |
16 | 20 | /* Static Methods */ |
Index: trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js |
— | — | @@ -433,7 +433,7 @@ |
434 | 434 | 'offset': offset, |
435 | 435 | 'content': content |
436 | 436 | } ); |
437 | | - this.emit( 'change', { 'type': 'insert' } ); |
| 437 | + this.emit( 'update', { 'type': 'insert' } ); |
438 | 438 | }; |
439 | 439 | |
440 | 440 | /** |
— | — | @@ -450,7 +450,7 @@ |
451 | 451 | this.emit( 'remove', { |
452 | 452 | 'range': range |
453 | 453 | } ); |
454 | | - this.emit( 'change', { 'type': 'remove' } ); |
| 454 | + this.emit( 'update', { 'type': 'remove' } ); |
455 | 455 | }; |
456 | 456 | |
457 | 457 | /** |
— | — | @@ -463,7 +463,7 @@ |
464 | 464 | es.ContentModel.prototype.clear = function() { |
465 | 465 | this.data = []; |
466 | 466 | this.emit( 'clear' ); |
467 | | - this.emit( 'change', { 'type': 'clear' } ); |
| 467 | + this.emit( 'update', { 'type': 'clear' } ); |
468 | 468 | }; |
469 | 469 | |
470 | 470 | /** |
— | — | @@ -568,7 +568,7 @@ |
569 | 569 | 'annotation': annotation, |
570 | 570 | 'range': range |
571 | 571 | } ); |
572 | | - this.emit( 'change', { 'type': 'annotate' } ); |
| 572 | + this.emit( 'update', { 'type': 'annotate' } ); |
573 | 573 | }; |
574 | 574 | |
575 | 575 | es.extend( es.ContentModel, es.EventEmitter ); |
Index: trunk/parsers/wikidom/lib/synth/bases/es.ModelContainer.js |
— | — | @@ -114,16 +114,12 @@ |
115 | 115 | var parent = item.parent(); |
116 | 116 | if ( parent === this ) { |
117 | 117 | this[this._listName].splice( this.indexOf( item ), 1 ); |
118 | | - this[this._listName].push( item ); |
119 | | - } else { |
120 | | - if ( parent ) { |
121 | | - parent.remove( item ); |
122 | | - } |
123 | | - this[this._listName].push( item ); |
124 | | - var container = this; |
125 | | - item.on( 'update', this.relayUpdate ); |
126 | | - item.attach( this ); |
| 118 | + } else if ( parent ) { |
| 119 | + parent.remove( item ); |
127 | 120 | } |
| 121 | + this[this._listName].push( item ); |
| 122 | + item.on( 'update', this.relayUpdate ); |
| 123 | + item.attach( this ); |
128 | 124 | this.emit( 'append', item ); |
129 | 125 | this.emit( 'update' ); |
130 | 126 | }; |
— | — | @@ -141,16 +137,12 @@ |
142 | 138 | var parent = item.parent(); |
143 | 139 | if ( parent === this ) { |
144 | 140 | this[this._listName].splice( this.indexOf( item ), 1 ); |
145 | | - this[this._listName].unshift( item ); |
146 | | - } else { |
147 | | - if ( parent ) { |
148 | | - parent.remove( item ); |
149 | | - } |
150 | | - this[this._listName].unshift( item ); |
151 | | - var container = this; |
152 | | - item.on( 'update', this.relayUpdate ); |
153 | | - item.attach( this ); |
| 141 | + } else if ( parent ) { |
| 142 | + parent.remove( item ); |
154 | 143 | } |
| 144 | + this[this._listName].unshift( item ); |
| 145 | + item.on( 'update', this.relayUpdate ); |
| 146 | + item.attach( this ); |
155 | 147 | this.emit( 'prepend', item ); |
156 | 148 | this.emit( 'update' ); |
157 | 149 | }; |
— | — | @@ -169,24 +161,16 @@ |
170 | 162 | var parent = item.parent(); |
171 | 163 | if ( parent === this ) { |
172 | 164 | this[this._listName].splice( this.indexOf( item ), 1 ); |
173 | | - if ( before ) { |
174 | | - this[this._listName].splice( this[this._listName].indexOf( before ), 0, item ); |
175 | | - } else { |
176 | | - this[this._listName].unshift( item ); |
177 | | - } |
| 165 | + } else if ( parent ) { |
| 166 | + parent.remove( item ); |
| 167 | + } |
| 168 | + if ( before ) { |
| 169 | + this[this._listName].splice( this[this._listName].indexOf( before ), 0, item ); |
178 | 170 | } else { |
179 | | - if ( parent ) { |
180 | | - parent.remove( item ); |
181 | | - } |
182 | | - if ( before ) { |
183 | | - this[this._listName].splice( this[this._listName].indexOf( before ), 0, item ); |
184 | | - } else { |
185 | | - this[this._listName].unshift( item ); |
186 | | - } |
187 | | - var container = this; |
188 | | - item.on( 'update', this.relayUpdate ); |
189 | | - item.attach( this ); |
| 171 | + this[this._listName].unshift( item ); |
190 | 172 | } |
| 173 | + item.on( 'update', this.relayUpdate ); |
| 174 | + item.attach( this ); |
191 | 175 | this.emit( 'insertBefore', item, before ); |
192 | 176 | this.emit( 'update' ); |
193 | 177 | }; |
— | — | @@ -205,24 +189,16 @@ |
206 | 190 | var parent = item.parent(); |
207 | 191 | if ( parent === this ) { |
208 | 192 | this[this._listName].splice( this.indexOf( item ), 1 ); |
209 | | - if ( after ) { |
210 | | - this[this._listName].splice( this[this._listName].indexOf( after ) + 1, 0, item ); |
211 | | - } else { |
212 | | - this[this._listName].push( item ); |
213 | | - } |
| 193 | + } else if ( parent ) { |
| 194 | + parent.remove( item ); |
| 195 | + } |
| 196 | + if ( after ) { |
| 197 | + this[this._listName].splice( this[this._listName].indexOf( after ) + 1, 0, item ); |
214 | 198 | } else { |
215 | | - if ( parent ) { |
216 | | - parent.remove( item ); |
217 | | - } |
218 | | - if ( after ) { |
219 | | - this[this._listName].splice( this[this._listName].indexOf( after ) + 1, 0, item ); |
220 | | - } else { |
221 | | - this[this._listName].push( item ); |
222 | | - } |
223 | | - var container = this; |
224 | | - item.on( 'update', this.relayUpdate ); |
225 | | - item.attach( this ); |
| 199 | + this[this._listName].push( item ); |
226 | 200 | } |
| 201 | + item.on( 'update', this.relayUpdate ); |
| 202 | + item.attach( this ); |
227 | 203 | this.emit( 'insertAfter', item, after ); |
228 | 204 | this.emit( 'update' ); |
229 | 205 | }; |
Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js |
— | — | @@ -31,6 +31,9 @@ |
32 | 32 | } |
33 | 33 | this.$.addClass( 'editSurface-' + typeName ).data( typeName, this ); |
34 | 34 | var container = this; |
| 35 | + this.relayUpdate = function() { |
| 36 | + container.emit( 'update' ); |
| 37 | + }; |
35 | 38 | function recycleItemView( itemModel, autoCreate ) { |
36 | 39 | var itemView = container.lookupItemView( itemModel ); |
37 | 40 | if ( itemView ) { |
— | — | @@ -44,6 +47,7 @@ |
45 | 48 | } |
46 | 49 | this.containerModel.on( 'prepend', function( itemModel ) { |
47 | 50 | var itemView = recycleItemView( itemModel, true ); |
| 51 | + itemView.on( 'update', container.relayUpdate ); |
48 | 52 | container.views.unshift( itemView ); |
49 | 53 | container.$.prepend( itemView.$ ); |
50 | 54 | container.emit( 'prepend', itemView ); |
— | — | @@ -51,6 +55,7 @@ |
52 | 56 | } ); |
53 | 57 | this.containerModel.on( 'append', function( itemModel ) { |
54 | 58 | var itemView = recycleItemView( itemModel, true ); |
| 59 | + itemView.on( 'update', container.relayUpdate ); |
55 | 60 | container.views.push( itemView ); |
56 | 61 | container.$.append( itemView.$ ); |
57 | 62 | container.emit( 'append', itemView ); |
— | — | @@ -59,6 +64,7 @@ |
60 | 65 | this.containerModel.on( 'insertBefore', function( itemModel, beforeModel ) { |
61 | 66 | var beforeView = container.lookupItemView( beforeModel ), |
62 | 67 | itemView = recycleItemView( itemModel, true ); |
| 68 | + itemView.on( 'update', container.relayUpdate ); |
63 | 69 | if ( beforeView ) { |
64 | 70 | container.views.splice( container.views.indexOf( beforeView ), 0, itemView ); |
65 | 71 | itemView.$.insertBefore( beforeView.$ ); |
— | — | @@ -72,6 +78,7 @@ |
73 | 79 | this.containerModel.on( 'insertAfter', function( itemModel, afterModel ) { |
74 | 80 | var afterView = container.lookupItemView( afterModel ), |
75 | 81 | itemView = recycleItemView( itemModel, true ); |
| 82 | + itemView.on( 'update', container.relayUpdate ); |
76 | 83 | if ( afterView ) { |
77 | 84 | container.views.splice( container.views.indexOf( afterView ) + 1, 0, itemView ); |
78 | 85 | itemView.$.insertAfter( afterView.$ ); |
— | — | @@ -84,6 +91,7 @@ |
85 | 92 | } ); |
86 | 93 | this.containerModel.on( 'remove', function( itemModel ) { |
87 | 94 | var itemView = recycleItemView( itemModel ); |
| 95 | + itemView.removeListener( 'update', container.relayUpdate ); |
88 | 96 | container.emit( 'remove', itemView ); |
89 | 97 | container.emit( 'update' ); |
90 | 98 | } ); |
Index: trunk/parsers/wikidom/lib/synth/views/es.ContentView.js |
— | — | @@ -447,7 +447,7 @@ |
448 | 448 | .nextAll() |
449 | 449 | .remove(); |
450 | 450 | rs.timeout = undefined; |
451 | | - this.emit( 'render' ); |
| 451 | + this.emit( 'update' ); |
452 | 452 | } else { |
453 | 453 | rs.ruler.innerHTML = ''; |
454 | 454 | var that = this; |
— | — | @@ -494,7 +494,7 @@ |
495 | 495 | 'wordOffset': 0, |
496 | 496 | 'fractional': false |
497 | 497 | }]; |
498 | | - this.emit( 'render' ); |
| 498 | + this.emit( 'update' ); |
499 | 499 | return; |
500 | 500 | } |
501 | 501 | /* |
Index: trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js |
— | — | @@ -4,6 +4,10 @@ |
5 | 5 | es.ParagraphBlockView = function( model ) { |
6 | 6 | es.BlockView.call( this, model, 'paragraph' ); |
7 | 7 | this.contentView = new es.ContentView( this.$, this.model.content ); |
| 8 | + var view = this; |
| 9 | + this.contentView.on( 'update', function() { |
| 10 | + view.emit('update'); |
| 11 | + } ); |
8 | 12 | }; |
9 | 13 | |
10 | 14 | /** |