Index: trunk/parsers/wikidom/tests/synth/index.html |
— | — | @@ -14,6 +14,8 @@ |
15 | 15 | <script src="../../lib/synth/bases/es.EventEmitter.js"></script> |
16 | 16 | <script src="../../lib/synth/bases/es.ModelContainer.js"></script> |
17 | 17 | <script src="../../lib/synth/bases/es.ModelContainerItem.js"></script> |
| 18 | + <script src="../../lib/synth/bases/es.ViewContainer.js"></script> |
| 19 | + <script src="../../lib/synth/bases/es.ViewContainerItem.js"></script> |
18 | 20 | <script src="../../lib/synth/bases/es.AggregateArray.js"></script> |
19 | 21 | <script src="../../lib/synth/es.Range.js"></script> |
20 | 22 | <script src="../../lib/jquery.js"></script> |
Index: trunk/parsers/wikidom/tests/synth/test.js |
— | — | @@ -157,6 +157,25 @@ |
158 | 158 | // TODO: Events for appending, prepending, inserting and removing |
159 | 159 | } ); |
160 | 160 | |
| 161 | + |
| 162 | +test( 'es.ViewContainer', function() { |
| 163 | + var modelContainer = new es.ModelContainer(), |
| 164 | + modelItem1 = new es.ModelContainerItem(), |
| 165 | + modelItem2 = new es.ModelContainerItem(), |
| 166 | + modelItem3 = new es.ModelContainerItem(); |
| 167 | + var viewContainer = new es.ViewContainer( modelContainer ); |
| 168 | + viewContainer.createItemView = function( itemModel ) { |
| 169 | + return new es.ViewContainerItem( itemModel ); |
| 170 | + }; |
| 171 | + |
| 172 | + // |
| 173 | + modelContainer.append( modelItem1 ); |
| 174 | + modelContainer.append( modelItem2 ); |
| 175 | + modelContainer.append( modelItem2 ); |
| 176 | + |
| 177 | + equals( viewContainer.views, 3, 'es.ViewContainer' ); |
| 178 | +} ); |
| 179 | + |
161 | 180 | function ContentStub( name, size ) { |
162 | 181 | this.name = name; |
163 | 182 | this.size = size; |
Index: trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js |
— | — | @@ -45,6 +45,13 @@ |
46 | 46 | /* Methods */ |
47 | 47 | |
48 | 48 | /** |
| 49 | + * Creates a view for this model |
| 50 | + */ |
| 51 | +es.BlockModel.prototype.createView = function() { |
| 52 | + return new es.BlockView( this ); |
| 53 | +}; |
| 54 | + |
| 55 | +/** |
49 | 56 | * Checks for a trait. |
50 | 57 | * |
51 | 58 | * Traits are boolean flags that indicate supported behavior |
Index: trunk/parsers/wikidom/lib/synth/models/es.CommentBlockModel.js |
— | — | @@ -27,6 +27,13 @@ |
28 | 28 | /* Methods */ |
29 | 29 | |
30 | 30 | /** |
| 31 | + * Creates a view for this model |
| 32 | + */ |
| 33 | +es.BlockModel.prototype.createView = function() { |
| 34 | + return new es.BlockView( this ); |
| 35 | +}; |
| 36 | + |
| 37 | +/** |
31 | 38 | * Gets the length of all content. |
32 | 39 | * |
33 | 40 | * @method |
Index: trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js |
— | — | @@ -27,6 +27,13 @@ |
28 | 28 | /* Methods */ |
29 | 29 | |
30 | 30 | /** |
| 31 | + * Creates a view for this model |
| 32 | + */ |
| 33 | +es.ParagraphBlockModel.prototype.createView = function() { |
| 34 | + return new es.ParagraphBlockView( this ); |
| 35 | +}; |
| 36 | + |
| 37 | +/** |
31 | 38 | * Gets the length of all content. |
32 | 39 | * |
33 | 40 | * @method |
Index: trunk/parsers/wikidom/lib/synth/models/es.TableBlockModel.js |
— | — | @@ -37,6 +37,13 @@ |
38 | 38 | /* Methods */ |
39 | 39 | |
40 | 40 | /** |
| 41 | + * Creates a view for this model |
| 42 | + */ |
| 43 | +es.TableBlockModel.prototype.createView = function() { |
| 44 | + return new es.TableBlockView( this ); |
| 45 | +}; |
| 46 | + |
| 47 | +/** |
41 | 48 | * Gets the length of all content. |
42 | 49 | * |
43 | 50 | * @method |
Index: trunk/parsers/wikidom/lib/synth/bases/es.ModelContainerItem.js |
— | — | @@ -23,6 +23,13 @@ |
24 | 24 | }; |
25 | 25 | |
26 | 26 | /** |
| 27 | + * Creates a view for this model |
| 28 | + */ |
| 29 | +es.ModelContainerItem.prototype.createView = function() { |
| 30 | + return new es.ViewContainerItem( this ); |
| 31 | +}; |
| 32 | + |
| 33 | +/** |
27 | 34 | * Attaches item to a container. |
28 | 35 | * |
29 | 36 | * @method |
Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainerItem.js |
— | — | @@ -11,6 +11,9 @@ |
12 | 12 | es.ViewContainerItem = function( model, typeName, tagName ) { |
13 | 13 | es.EventEmitter.call( this ); |
14 | 14 | this.model = model; |
| 15 | + if ( typeof typeName !== 'string' ) { |
| 16 | + typeName = 'viewContainerItem'; |
| 17 | + } |
15 | 18 | if ( typeof tagName !== 'string' ) { |
16 | 19 | tagName = 'div'; |
17 | 20 | } |
Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js |
— | — | @@ -17,6 +17,9 @@ |
18 | 18 | es.EventEmitter.call( this ); |
19 | 19 | this.containerModel = containerModel; |
20 | 20 | this.views = []; |
| 21 | + if ( typeof typeName !== 'string' ) { |
| 22 | + typeName = 'viewContainer'; |
| 23 | + } |
21 | 24 | if ( typeof tagName !== 'string' ) { |
22 | 25 | tagName = 'div'; |
23 | 26 | } |
— | — | @@ -25,14 +28,14 @@ |
26 | 29 | .data( typeName, this ); |
27 | 30 | var container = this; |
28 | 31 | this.containerModel.on( 'prepend', function( itemModel ) { |
29 | | - var itemView = container.createItem( itemModel ); |
| 32 | + var itemView = container.createItemView( itemModel ); |
30 | 33 | container.views.unshift( itemView ); |
31 | 34 | container.$.prepend( itemView.$ ); |
32 | 35 | container.emit( 'prepend', itemView ); |
33 | 36 | container.emit( 'update' ); |
34 | 37 | } ); |
35 | 38 | this.containerModel.on( 'append', function( itemModel ) { |
36 | | - var itemView = container.createItem( itemModel ); |
| 39 | + var itemView = container.createItemView( itemModel ); |
37 | 40 | container.views.push( itemView ); |
38 | 41 | container.$.append( itemView.$ ); |
39 | 42 | container.emit( 'append', itemView ); |
— | — | @@ -83,7 +86,7 @@ |
84 | 87 | }; |
85 | 88 | |
86 | 89 | es.ViewContainer.prototype.createItemView = function( itemModel ) { |
87 | | - throw 'es.ViewContainer.createItem not implemented in this subclass'; |
| 90 | + throw 'es.ViewContainer.createItemView not implemented in this subclass'; |
88 | 91 | }; |
89 | 92 | |
90 | 93 | /* Inheritance */ |
Index: trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js |
— | — | @@ -1,7 +1,11 @@ |
2 | | -es.DocumentView = function( blockViews ) { |
3 | | - es.DomContainer.call( this, 'blocks' ); |
| 2 | +es.DocumentView = function( documentModel ) { |
| 3 | + es.ViewContainer.call( this, documentModel, 'blocks' ); |
4 | 4 | }; |
5 | 5 | |
| 6 | +es.DocumentView.prototype.createItemView = function( itemModel ) { |
| 7 | + return itemModel.createView(); |
| 8 | +}; |
| 9 | + |
6 | 10 | /* Inheritance */ |
7 | 11 | |
8 | | -es.extend( es.DocumentView, es.DomContainer ); |
| 12 | +es.extend( es.DocumentView, es.ViewContainer ); |