Index: trunk/parsers/wikidom/lib/es/es.Document.js |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | * @property width {Integer} |
11 | 11 | */ |
12 | 12 | es.Document = function( blocks ) { |
13 | | - es.Container.call( this, 'document', 'blocks', blocks ); |
| 13 | + es.DomContainer.call( this, 'document', 'blocks', blocks ); |
14 | 14 | this.width = null; |
15 | 15 | }; |
16 | 16 | |
— | — | @@ -79,4 +79,4 @@ |
80 | 80 | |
81 | 81 | /* Inheritance */ |
82 | 82 | |
83 | | -es.extend( es.Document, es.Container ); |
| 83 | +es.extend( es.Document, es.DomContainer ); |
Index: trunk/parsers/wikidom/lib/es/es.DomContainer.js |
— | — | @@ -0,0 +1,58 @@ |
| 2 | +/** |
| 3 | + * Generic synchronized Object/Element container. |
| 4 | + * |
| 5 | + * Child objects must extend es.EventEmitter. |
| 6 | + * |
| 7 | + * @class |
| 8 | + * @constructor |
| 9 | + * @extends {es.EventEmitter} |
| 10 | + * @param typeName {String} Property name to set references to this object to in child objects |
| 11 | + * @param listName {String} Property name for list of child objects |
| 12 | + * @param items {Array} List of initial items |
| 13 | + * @emits "update" when items argument causes items to be appended |
| 14 | + * @emits "append" when items argument causes items to be appended |
| 15 | + * @property $ {jQuery} Container element |
| 16 | + */ |
| 17 | +es.DomContainer = function( typeName, listName, items, tagName ) { |
| 18 | + if ( typeof tagName !== 'string' ) { |
| 19 | + tagName = 'div'; |
| 20 | + } |
| 21 | + this.$ = $( '<' + tagName + '/>' ) |
| 22 | + .addClass( 'editSurface-' + typeName ) |
| 23 | + .data( typeName, this ); |
| 24 | + es.Container.call( this, typeName, listName ); |
| 25 | + this.on( 'prepend', function( item ) { |
| 26 | + this.$.prepend( item.$ ); |
| 27 | + } ); |
| 28 | + this.on( 'append', function( item ) { |
| 29 | + this.$.append( item.$ ); |
| 30 | + } ); |
| 31 | + this.on( 'insertBefore', function( item, before ) { |
| 32 | + if ( before ) { |
| 33 | + item.$.insertBefore( before.$ ); |
| 34 | + } else { |
| 35 | + this.$.append( item.$ ); |
| 36 | + } |
| 37 | + } ); |
| 38 | + this.on( 'insertAfter', function( item, after ) { |
| 39 | + if ( after ) { |
| 40 | + item.$.insertAfter( after.$ ); |
| 41 | + } else { |
| 42 | + this.$.append( item.$ ); |
| 43 | + } |
| 44 | + } ); |
| 45 | + this.on( 'remove', function( item ) { |
| 46 | + item.$.detach(); |
| 47 | + } ); |
| 48 | + // Auto-append - must do our own, not use the one es.Content() give us, so that the events will |
| 49 | + // be called when items are appended |
| 50 | + if ( $.isArray( items ) ) { |
| 51 | + for ( var i = 0; i < items.length; i++ ) { |
| 52 | + this.append( items[i] ); |
| 53 | + } |
| 54 | + } |
| 55 | +}; |
| 56 | + |
| 57 | +/* Inheritance */ |
| 58 | + |
| 59 | +es.extend( es.DomContainer, es.Container ); |
Property changes on: trunk/parsers/wikidom/lib/es/es.DomContainer.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 60 | + native |
Added: svn:mime-type |
2 | 61 | + text/plain |
Index: trunk/parsers/wikidom/lib/es/es.Container.js |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | /** |
3 | | - * Generic synchronized Object/Element container. |
| 3 | + * Generic Object container. |
4 | 4 | * |
5 | 5 | * Child objects must extend es.EventEmitter. |
6 | 6 | * |
— | — | @@ -9,10 +9,10 @@ |
10 | 10 | * @param typeName {String} Property name to set references to this object to in child objects |
11 | 11 | * @param listName {String} Property name for list of child objects |
12 | 12 | * @param items {Array} List of initial items |
| 13 | + * @emits "append" when items argument causes items to be appended |
13 | 14 | * @emits "update" when items argument causes items to be appended |
14 | | - * @property $ {jQuery} Container element |
15 | 15 | */ |
16 | | -es.Container = function( typeName, listName, items, tagName ) { |
| 16 | +es.Container = function( typeName, listName, items ) { |
17 | 17 | es.EventEmitter.call( this ); |
18 | 18 | if ( typeof typeName !== 'string' ) { |
19 | 19 | typeName = 'container'; |
— | — | @@ -20,15 +20,9 @@ |
21 | 21 | if ( typeof listName !== 'string' ) { |
22 | 22 | listName = 'items'; |
23 | 23 | } |
24 | | - if ( typeof tagName !== 'string' ) { |
25 | | - tagName = 'div'; |
26 | | - } |
27 | 24 | this._typeName = typeName; |
28 | 25 | this._listName = listName; |
29 | 26 | this._list = this[listName] = []; |
30 | | - this.$ = $( '<' + tagName + '/>' ) |
31 | | - .addClass( 'editSurface-' + typeName ) |
32 | | - .data( typeName, this ); |
33 | 27 | // Auto-append |
34 | 28 | if ( $.isArray( items ) ) { |
35 | 29 | for ( var i = 0; i < items.length; i++ ) { |
— | — | @@ -92,7 +86,7 @@ |
93 | 87 | container.emit( 'update' ); |
94 | 88 | } ); |
95 | 89 | this._list.push( item ); |
96 | | - this.$.append( item.$ ); |
| 90 | + this.emit( 'append', item ); |
97 | 91 | this.emit( 'update' ); |
98 | 92 | }; |
99 | 93 | |
— | — | @@ -112,7 +106,7 @@ |
113 | 107 | container.emit( 'update' ); |
114 | 108 | } ); |
115 | 109 | this._list.unshift( item ); |
116 | | - this.$.prepend( item.$ ); |
| 110 | + this.emit( 'prepend', item ); |
117 | 111 | this.emit( 'update' ); |
118 | 112 | }; |
119 | 113 | |
— | — | @@ -134,11 +128,10 @@ |
135 | 129 | } ); |
136 | 130 | if ( before ) { |
137 | 131 | this._list.splice( before.getIndex(), 0, item ); |
138 | | - item.$.insertBefore( before.$ ); |
139 | 132 | } else { |
140 | 133 | this._list.push( item ); |
141 | | - this.$.append( item.$ ); |
142 | 134 | } |
| 135 | + this.emit( 'insertBefore', item, before ); |
143 | 136 | this.emit( 'update' ); |
144 | 137 | }; |
145 | 138 | /** |
— | — | @@ -159,11 +152,10 @@ |
160 | 153 | } ); |
161 | 154 | if ( after ) { |
162 | 155 | this._list.splice( after.getIndex() + 1, 0, item ); |
163 | | - item.$.insertAfter( after.$ ); |
164 | 156 | } else { |
165 | 157 | this._list.push( item ); |
166 | | - this.$.append( item.$ ); |
167 | 158 | } |
| 159 | + this.emit( 'insertAfter', item, after ); |
168 | 160 | this.emit( 'update' ); |
169 | 161 | }; |
170 | 162 | |
— | — | @@ -180,7 +172,7 @@ |
181 | 173 | item.removeAllListeners( 'update' ); |
182 | 174 | this._list.splice( item.getIndex(), 1 ); |
183 | 175 | item[this._typeName] = null; |
184 | | - item.$.detach(); |
| 176 | + this.emit( 'remove', item ); |
185 | 177 | this.emit( 'update' ); |
186 | 178 | }; |
187 | 179 | |
Index: trunk/parsers/wikidom/lib/es/es.ListBlockList.js |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | es.ListBlockList = function( items ) { |
3 | | - es.Container.call( this, 'list', 'items', items ); |
| 3 | + es.DomContainer.call( this, 'list', 'items', items ); |
4 | 4 | }; |
5 | 5 | |
6 | 6 | es.ListBlockList.newFromWikiDomList = function( wikidomList ) { |
— | — | @@ -41,4 +41,4 @@ |
42 | 42 | } |
43 | 43 | }; |
44 | 44 | |
45 | | -es.extend( es.ListBlockList, es.Container ); |
| 45 | +es.extend( es.ListBlockList, es.DomContainer ); |
Index: trunk/parsers/wikidom/demos/es/index.html |
— | — | @@ -60,6 +60,7 @@ |
61 | 61 | <script src="../../lib/es/es.Selection.js"></script> |
62 | 62 | <script src="../../lib/es/es.Content.js"></script> |
63 | 63 | <script src="../../lib/es/es.Container.js"></script> |
| 64 | + <script src="../../lib/es/es.DomContainer.js"></script> |
64 | 65 | <script src="../../lib/es/es.Block.js"></script> |
65 | 66 | <script src="../../lib/es/es.Document.js"></script> |
66 | 67 | <script src="../../lib/es/es.AnnotationSerializer.js"></script> |
Index: trunk/parsers/wikidom/demos/es/index2.html |
— | — | @@ -87,6 +87,7 @@ |
88 | 88 | <script src="../../lib/es/es.Selection.js"></script>
|
89 | 89 | <script src="../../lib/es/es.Content.js"></script>
|
90 | 90 | <script src="../../lib/es/es.Container.js"></script>
|
| 91 | + <script src="../../lib/es/es.DomContainer.js"></script>
|
91 | 92 | <script src="../../lib/es/es.Block.js"></script>
|
92 | 93 | <script src="../../lib/es/es.Document.js"></script>
|
93 | 94 | <script src="../../lib/es/es.AnnotationSerializer.js"></script>
|