| Index: trunk/parsers/wikidom/lib/synth/models/es.DocumentModel.js |
| — | — | @@ -9,7 +9,7 @@ |
| 10 | 10 | * @property attributes {Object} |
| 11 | 11 | */ |
| 12 | 12 | es.DocumentModel = function( blocks, attributes ) { |
| 13 | | - es.ModelContainer.call( this ); |
| | 13 | + es.ModelList.call( this ); |
| 14 | 14 | this.items = new es.AggregateArray( blocks || [] ); |
| 15 | 15 | this.attributes = attributes || {}; |
| 16 | 16 | }; |
| — | — | @@ -60,4 +60,4 @@ |
| 61 | 61 | return this.items.getContentLength(); |
| 62 | 62 | }; |
| 63 | 63 | |
| 64 | | -es.extend( es.DocumentModel, es.ModelContainer ); |
| | 64 | +es.extend( es.DocumentModel, es.ModelList ); |
| Index: trunk/parsers/wikidom/lib/synth/models/es.TableBlockCellModel.js |
| — | — | @@ -9,7 +9,7 @@ |
| 10 | 10 | * @property attributes {Object} |
| 11 | 11 | */ |
| 12 | 12 | es.TableBlockCellModel = function( documentModel, attributes ) { |
| 13 | | - es.ModelContainerItem.call( this ); |
| | 13 | + es.ModelListItem.call( this ); |
| 14 | 14 | this.documentModel = documentModel || null; |
| 15 | 15 | this.attributes = attributes || {}; |
| 16 | 16 | }; |
| — | — | @@ -70,4 +70,4 @@ |
| 71 | 71 | |
| 72 | 72 | /* Inheritance */ |
| 73 | 73 | |
| 74 | | -es.extend( es.TableBlockCellModel, es.ModelContainerItem ); |
| \ No newline at end of file |
| | 74 | +es.extend( es.TableBlockCellModel, es.ModelListItem ); |
| \ No newline at end of file |
| Index: trunk/parsers/wikidom/lib/synth/models/es.TableBlockModel.js |
| — | — | @@ -10,7 +10,7 @@ |
| 11 | 11 | */ |
| 12 | 12 | es.TableBlockModel = function( rows, attributes ) { |
| 13 | 13 | es.BlockModel.call( this, ['isDocumentContainer', 'isAggregate'] ); |
| 14 | | - es.ModelContainer.call( this ); |
| | 14 | + es.ModelList.call( this ); |
| 15 | 15 | |
| 16 | 16 | if ( $.isArray( rows ) ) { |
| 17 | 17 | for ( var i = 0; i < rows.length; i++ ) { |
| — | — | @@ -87,4 +87,4 @@ |
| 88 | 88 | /* Inheritance */ |
| 89 | 89 | |
| 90 | 90 | es.extend( es.TableBlockModel, es.BlockModel ); |
| 91 | | -es.extend( es.TableBlockModel, es.ModelContainer ); |
| | 91 | +es.extend( es.TableBlockModel, es.ModelList ); |
| Index: trunk/parsers/wikidom/lib/synth/models/es.ListBlockItemModel.js |
| — | — | @@ -9,7 +9,7 @@ |
| 10 | 10 | * @property styles {Array} |
| 11 | 11 | */ |
| 12 | 12 | es.ListBlockItemModel = function( content, styles ) { |
| 13 | | - es.ModelContainerItem.call( this ); |
| | 13 | + es.ModelListItem.call( this ); |
| 14 | 14 | this.content = content || null; |
| 15 | 15 | this.styles = styles || ['bullet']; |
| 16 | 16 | }; |
| — | — | @@ -57,4 +57,4 @@ |
| 58 | 58 | |
| 59 | 59 | /* Inheritance */ |
| 60 | 60 | |
| 61 | | -es.extend( es.ListBlockItemModel, es.ModelContainerItem ); |
| \ No newline at end of file |
| | 61 | +es.extend( es.ListBlockItemModel, es.ModelListItem ); |
| \ No newline at end of file |
| Index: trunk/parsers/wikidom/lib/synth/models/es.ListBlockModel.js |
| — | — | @@ -8,7 +8,7 @@ |
| 9 | 9 | */ |
| 10 | 10 | es.ListBlockModel = function( items ) { |
| 11 | 11 | es.BlockModel.call( this, ['hasContent', 'isAnnotatable', 'isAggregate'] ); |
| 12 | | - es.ModelContainer.call( this ); |
| | 12 | + es.ModelList.call( this ); |
| 13 | 13 | if ( $.isArray( items ) ) { |
| 14 | 14 | for ( var i = 0; i < items.length; i++ ) { |
| 15 | 15 | this.append( items[i] ); |
| — | — | @@ -116,4 +116,4 @@ |
| 117 | 117 | /* Inheritance */ |
| 118 | 118 | |
| 119 | 119 | es.extend( es.ListBlockModel, es.BlockModel ); |
| 120 | | -es.extend( es.ListBlockModel, es.ModelContainer ); |
| | 120 | +es.extend( es.ListBlockModel, es.ModelList ); |
| Index: trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js |
| — | — | @@ -2,14 +2,14 @@ |
| 3 | 3 | * Creates an es.BlockModel object. |
| 4 | 4 | * |
| 5 | 5 | * @class |
| 6 | | - * @extends {es.ModelContainerItem} |
| | 6 | + * @extends {es.ModelListItem} |
| 7 | 7 | * @abstract |
| 8 | 8 | * @constructor |
| 9 | 9 | * @param traits {Array} List of trait names |
| 10 | 10 | * @property traits {Array} List of trait names |
| 11 | 11 | */ |
| 12 | 12 | es.BlockModel = function( traits ) { |
| 13 | | - es.ModelContainerItem.call( this, 'document' ); |
| | 13 | + es.ModelListItem.call( this, 'document' ); |
| 14 | 14 | this.traits = traits || []; |
| 15 | 15 | }; |
| 16 | 16 | |
| — | — | @@ -173,4 +173,4 @@ |
| 174 | 174 | throw 'BlockModel.getPlainObject not implemented in this subclass.'; |
| 175 | 175 | }; |
| 176 | 176 | |
| 177 | | -es.extend( es.BlockModel, es.ModelContainerItem ); |
| | 177 | +es.extend( es.BlockModel, es.ModelListItem ); |
| Index: trunk/parsers/wikidom/lib/synth/models/es.TableBlockRowModel.js |
| — | — | @@ -9,8 +9,8 @@ |
| 10 | 10 | * @property attributes {Object} |
| 11 | 11 | */ |
| 12 | 12 | es.TableBlockRowModel = function( items, attributes ) { |
| 13 | | - es.ModelContainerItem.call( this ); |
| 14 | | - es.ModelContainer.call( this ); |
| | 13 | + es.ModelListItem.call( this ); |
| | 14 | + es.ModelList.call( this ); |
| 15 | 15 | |
| 16 | 16 | if ( $.isArray( items ) ) { |
| 17 | 17 | for ( var i = 0; i < items.length; i++ ) { |
| — | — | @@ -82,5 +82,5 @@ |
| 83 | 83 | |
| 84 | 84 | /* Inheritance */ |
| 85 | 85 | |
| 86 | | -es.extend( es.TableBlockRowModel, es.ModelContainerItem ); |
| 87 | | -es.extend( es.TableBlockRowModel, es.ModelContainer ); |
| | 86 | +es.extend( es.TableBlockRowModel, es.ModelListItem ); |
| | 87 | +es.extend( es.TableBlockRowModel, es.ModelList ); |
| Index: trunk/parsers/wikidom/lib/synth/bases/es.ModelContainerItem.js |
| — | — | @@ -1,133 +0,0 @@ |
| 2 | | -/** |
| 3 | | - * Creates an es.ModelContainerItem object. |
| 4 | | - * |
| 5 | | - * @class |
| 6 | | - * @constructor |
| 7 | | - * @extends {es.EventEmitter} |
| 8 | | - * @property container {Object} Reference to container, if attached |
| 9 | | - */ |
| 10 | | -es.ModelContainerItem = function() { |
| 11 | | - es.EventEmitter.call( this ); |
| 12 | | - this.container = null; |
| 13 | | -}; |
| 14 | | - |
| 15 | | -/* Methods */ |
| 16 | | - |
| 17 | | -es.ModelContainerItem.prototype.parent = function() { |
| 18 | | - return this.container; |
| 19 | | -}; |
| 20 | | - |
| 21 | | -/** |
| 22 | | - * Creates a view for this model |
| 23 | | - */ |
| 24 | | -es.ModelContainerItem.prototype.createView = function() { |
| 25 | | - throw 'ModelContainerItem.createView not implemented in this subclass.'; |
| 26 | | -}; |
| 27 | | - |
| 28 | | -/** |
| 29 | | - * Attaches item to a container. |
| 30 | | - * |
| 31 | | - * @method |
| 32 | | - * @param container {es.Container} Container to attach to |
| 33 | | - * @emits "attach" with container argument |
| 34 | | - */ |
| 35 | | -es.ModelContainerItem.prototype.attach = function( container ) { |
| 36 | | - this.container = container; |
| 37 | | - this.emit( 'attach', container ); |
| 38 | | -}; |
| 39 | | - |
| 40 | | -/** |
| 41 | | - * Detaches item from a container. |
| 42 | | - * |
| 43 | | - * @method |
| 44 | | - * @emits "detach" with container argument |
| 45 | | - */ |
| 46 | | -es.ModelContainerItem.prototype.detach = function() { |
| 47 | | - var container = this.container; |
| 48 | | - this.container = null; |
| 49 | | - this.emit( 'detach', container ); |
| 50 | | -}; |
| 51 | | - |
| 52 | | -/** |
| 53 | | - * Gets the index of this item within it's container. |
| 54 | | - * |
| 55 | | - * @method |
| 56 | | - * @returns {Integer} Index of item in it's container |
| 57 | | - * @throws Unknown item error if this item is not in it's container |
| 58 | | - * @throws Missing container error if this container can't be accessed. |
| 59 | | - */ |
| 60 | | -es.ModelContainerItem.prototype.getIndex = function() { |
| 61 | | - try { |
| 62 | | - var index = this.container.indexOf( this ); |
| 63 | | - if ( index === -1 ) { |
| 64 | | - throw 'Unknown item error. Can not get index of item that is not in a container. ' + e; |
| 65 | | - } |
| 66 | | - return index; |
| 67 | | - } catch ( e ) { |
| 68 | | - throw 'Missing container error. Can not get index of item in missing container. ' + e; |
| 69 | | - } |
| 70 | | -}; |
| 71 | | - |
| 72 | | -/** |
| 73 | | - * Gets the previous item in container. |
| 74 | | - * |
| 75 | | - * @method |
| 76 | | - * @returns {Object} Previous item, or null if none exists |
| 77 | | - * @throws Missing container error if getting the previous item item failed |
| 78 | | - */ |
| 79 | | -es.ModelContainerItem.prototype.previous = function() { |
| 80 | | - try { |
| 81 | | - return this.container.get( this.container.indexOf( this ) - 1 ); |
| 82 | | - } catch ( e ) { |
| 83 | | - throw 'Missing container error. Can not get previous item in missing container. ' + e; |
| 84 | | - } |
| 85 | | -}; |
| 86 | | - |
| 87 | | -/** |
| 88 | | - * Gets the next item in container. |
| 89 | | - * |
| 90 | | - * @method |
| 91 | | - * @returns {Object} Next item, or null if none exists |
| 92 | | - * @throws Missing container error if getting the next item item failed |
| 93 | | - */ |
| 94 | | -es.ModelContainerItem.prototype.next = function() { |
| 95 | | - try { |
| 96 | | - return this.container.get( this.container.indexOf( this ) + 1 ); |
| 97 | | - } catch ( e ) { |
| 98 | | - throw 'Missing container error. Can not get next item in missing container. ' + e; |
| 99 | | - } |
| 100 | | -}; |
| 101 | | - |
| 102 | | -/** |
| 103 | | - * Checks if this item is the first in it's container. |
| 104 | | - * |
| 105 | | - * @method |
| 106 | | - * @returns {Boolean} If item is the first in it's container |
| 107 | | - * @throws Missing container error if getting the index of this item failed |
| 108 | | - */ |
| 109 | | -es.ModelContainerItem.prototype.isFirst = function() { |
| 110 | | - try { |
| 111 | | - return this.container.indexOf( this ) === 0; |
| 112 | | - } catch ( e ) { |
| 113 | | - throw 'Missing container error. Can not get index of item in missing container. ' + e; |
| 114 | | - } |
| 115 | | -}; |
| 116 | | - |
| 117 | | -/** |
| 118 | | - * Checks if this item is the last in it's container. |
| 119 | | - * |
| 120 | | - * @method |
| 121 | | - * @returns {Boolean} If item is the last in it's container |
| 122 | | - * @throws Missing container error if getting the index of this item failed |
| 123 | | - */ |
| 124 | | -es.ModelContainerItem.prototype.isLast = function() { |
| 125 | | - try { |
| 126 | | - return this.container.indexOf( this ) === this.container.getLength() - 1; |
| 127 | | - } catch ( e ) { |
| 128 | | - throw 'Missing container error. Can not get index of item in missing container. ' + e; |
| 129 | | - } |
| 130 | | -}; |
| 131 | | - |
| 132 | | -/* Inheritance */ |
| 133 | | - |
| 134 | | -es.extend( es.ModelContainerItem, es.EventEmitter ); |
| Index: trunk/parsers/wikidom/lib/synth/bases/es.ModelContainer.js |
| — | — | @@ -1,220 +0,0 @@ |
| 2 | | -/** |
| 3 | | - * Creates an es.ModelContainer object. |
| 4 | | - * |
| 5 | | - * Child objects must extend es.ModelContainerItem. |
| 6 | | - * |
| 7 | | - * @class |
| 8 | | - * @constructor |
| 9 | | - * @extends {es.EventEmitter} |
| 10 | | - * @property items {Array} list of items |
| 11 | | - */ |
| 12 | | -es.ModelContainer = function() { |
| 13 | | - es.EventEmitter.call( this ); |
| 14 | | - this.items = new es.AggregateArray(); |
| 15 | | - var container = this; |
| 16 | | - this.relayUpdate = function() { |
| 17 | | - container.emit( 'update' ); |
| 18 | | - }; |
| 19 | | -}; |
| 20 | | - |
| 21 | | -/* Methods */ |
| 22 | | - |
| 23 | | -/** |
| 24 | | - * Gets an item at a specific index. |
| 25 | | - * |
| 26 | | - * @method |
| 27 | | - * @returns {Object} Child object at index |
| 28 | | - */ |
| 29 | | -es.ModelContainer.prototype.get = function( index ) { |
| 30 | | - return this.items[index] || null; |
| 31 | | -}; |
| 32 | | - |
| 33 | | -/** |
| 34 | | - * Gets all items. |
| 35 | | - * |
| 36 | | - * @method |
| 37 | | - * @returns {Array} List of all items. |
| 38 | | - */ |
| 39 | | -es.ModelContainer.prototype.all = function() { |
| 40 | | - return this.items; |
| 41 | | -}; |
| 42 | | - |
| 43 | | -/** |
| 44 | | - * Gets the number of items in container. |
| 45 | | - * |
| 46 | | - * @method |
| 47 | | - * @returns {Integer} Number of items in container |
| 48 | | - */ |
| 49 | | -es.ModelContainer.prototype.getLength = function() { |
| 50 | | - return this.items.length |
| 51 | | -}; |
| 52 | | - |
| 53 | | -/** |
| 54 | | - * Gets the index of an item. |
| 55 | | - * |
| 56 | | - * @method |
| 57 | | - * @returns {Integer} Index of item, -1 if item is not in container |
| 58 | | - */ |
| 59 | | -es.ModelContainer.prototype.indexOf = function( item ) { |
| 60 | | - return this.items.indexOf( item ); |
| 61 | | -}; |
| 62 | | - |
| 63 | | -/** |
| 64 | | - * Gets the first item in the container. |
| 65 | | - * |
| 66 | | - * @method |
| 67 | | - * @returns {Object} First item |
| 68 | | - */ |
| 69 | | -es.ModelContainer.prototype.first = function() { |
| 70 | | - return this.items.length ? this.items[0] : null; |
| 71 | | -}; |
| 72 | | - |
| 73 | | -/** |
| 74 | | - * Gets the last item in the container. |
| 75 | | - * |
| 76 | | - * @method |
| 77 | | - * @returns {Object} Last item |
| 78 | | - */ |
| 79 | | -es.ModelContainer.prototype.last = function() { |
| 80 | | - return this.items.length |
| 81 | | - ? this.items[this.items.length - 1] : null; |
| 82 | | -}; |
| 83 | | - |
| 84 | | -/** |
| 85 | | - * Iterates over items, executing a callback for each. |
| 86 | | - * |
| 87 | | - * Returning false in the callback will stop iteration. |
| 88 | | - * |
| 89 | | - * @method |
| 90 | | - * @param callback {Function} Function to call on each item which takes item and index arguments |
| 91 | | - */ |
| 92 | | -es.ModelContainer.prototype.each = function( callback ) { |
| 93 | | - for ( var i = 0; i < this.items.length; i++ ) { |
| 94 | | - if ( callback( this.items[i], i ) === false ) { |
| 95 | | - break; |
| 96 | | - } |
| 97 | | - } |
| 98 | | -}; |
| 99 | | - |
| 100 | | -/** |
| 101 | | - * Adds an item to the end of the container. |
| 102 | | - * |
| 103 | | - * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
| 104 | | - * |
| 105 | | - * @method |
| 106 | | - * @param item {Object} Item to append |
| 107 | | - * @emits "update" |
| 108 | | - */ |
| 109 | | -es.ModelContainer.prototype.append = function( item ) { |
| 110 | | - var parent = item.parent(); |
| 111 | | - if ( parent === this ) { |
| 112 | | - this.items.splice( this.indexOf( item ), 1 ); |
| 113 | | - } else if ( parent ) { |
| 114 | | - parent.remove( item ); |
| 115 | | - } |
| 116 | | - this.items.push( item ); |
| 117 | | - item.on( 'update', this.relayUpdate ); |
| 118 | | - item.attach( this ); |
| 119 | | - this.emit( 'append', item ); |
| 120 | | - this.emit( 'update' ); |
| 121 | | -}; |
| 122 | | - |
| 123 | | -/** |
| 124 | | - * Adds an item to the beginning of the container. |
| 125 | | - * |
| 126 | | - * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
| 127 | | - * |
| 128 | | - * @method |
| 129 | | - * @param item {Object} Item to prepend |
| 130 | | - * @emits "update" |
| 131 | | - */ |
| 132 | | -es.ModelContainer.prototype.prepend = function( item ) { |
| 133 | | - var parent = item.parent(); |
| 134 | | - if ( parent === this ) { |
| 135 | | - this.items.splice( this.indexOf( item ), 1 ); |
| 136 | | - } else if ( parent ) { |
| 137 | | - parent.remove( item ); |
| 138 | | - } |
| 139 | | - this.items.unshift( item ); |
| 140 | | - item.on( 'update', this.relayUpdate ); |
| 141 | | - item.attach( this ); |
| 142 | | - this.emit( 'prepend', item ); |
| 143 | | - this.emit( 'update' ); |
| 144 | | -}; |
| 145 | | - |
| 146 | | -/** |
| 147 | | - * Adds an item to the container after an existing item. |
| 148 | | - * |
| 149 | | - * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
| 150 | | - * |
| 151 | | - * @method |
| 152 | | - * @param item {Object} Item to insert |
| 153 | | - * @param before {Object} Item to insert before, if null then item will be inserted at the end |
| 154 | | - * @emits "update" |
| 155 | | - */ |
| 156 | | -es.ModelContainer.prototype.insertBefore = function( item, before ) { |
| 157 | | - var parent = item.parent(); |
| 158 | | - if ( parent === this ) { |
| 159 | | - this.items.splice( this.indexOf( item ), 1 ); |
| 160 | | - } else if ( parent ) { |
| 161 | | - parent.remove( item ); |
| 162 | | - } |
| 163 | | - if ( before ) { |
| 164 | | - this.items.splice( this.items.indexOf( before ), 0, item ); |
| 165 | | - } else { |
| 166 | | - this.items.unshift( item ); |
| 167 | | - } |
| 168 | | - item.on( 'update', this.relayUpdate ); |
| 169 | | - item.attach( this ); |
| 170 | | - this.emit( 'insertBefore', item, before ); |
| 171 | | - this.emit( 'update' ); |
| 172 | | -}; |
| 173 | | - |
| 174 | | -/** |
| 175 | | - * Adds an item to the container after an existing item. |
| 176 | | - * |
| 177 | | - * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
| 178 | | - * |
| 179 | | - * @method |
| 180 | | - * @param item {Object} Item to insert |
| 181 | | - * @param after {Object} Item to insert after, if null item will be inserted at the end |
| 182 | | - * @emits "update" |
| 183 | | - */ |
| 184 | | -es.ModelContainer.prototype.insertAfter = function( item, after ) { |
| 185 | | - var parent = item.parent(); |
| 186 | | - if ( parent === this ) { |
| 187 | | - this.items.splice( this.indexOf( item ), 1 ); |
| 188 | | - } else if ( parent ) { |
| 189 | | - parent.remove( item ); |
| 190 | | - } |
| 191 | | - if ( after ) { |
| 192 | | - this.items.splice( this.items.indexOf( after ) + 1, 0, item ); |
| 193 | | - } else { |
| 194 | | - this.items.push( item ); |
| 195 | | - } |
| 196 | | - item.on( 'update', this.relayUpdate ); |
| 197 | | - item.attach( this ); |
| 198 | | - this.emit( 'insertAfter', item, after ); |
| 199 | | - this.emit( 'update' ); |
| 200 | | -}; |
| 201 | | - |
| 202 | | -/** |
| 203 | | - * Removes an item from the container. |
| 204 | | - * |
| 205 | | - * Also detaches item's Element object to the DOM and removes all listeners its "update" events. |
| 206 | | - * |
| 207 | | - * @method |
| 208 | | - * @param item {Object} Item to remove |
| 209 | | - * @emits "update" |
| 210 | | - */ |
| 211 | | -es.ModelContainer.prototype.remove = function( item ) { |
| 212 | | - item.removeListener( 'update', this.relayUpdate ); |
| 213 | | - this.items.splice( this.indexOf( item ), 1 ); |
| 214 | | - item.detach(); |
| 215 | | - this.emit( 'remove', item ); |
| 216 | | - this.emit( 'update' ); |
| 217 | | -}; |
| 218 | | - |
| 219 | | -/* Inheritance */ |
| 220 | | - |
| 221 | | -es.extend( es.ModelContainer, es.EventEmitter ); |
| Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainerItem.js |
| — | — | @@ -1,45 +0,0 @@ |
| 2 | | -/** |
| 3 | | - * Generic synchronized Object/Element container item. |
| 4 | | - * |
| 5 | | - * @class |
| 6 | | - * @constructor |
| 7 | | - * @extends {es.EventEmitter} |
| 8 | | - * @param typeName {String} Name to use in CSS classes and HTML element data |
| 9 | | - * @param tagName {String} HTML element name to use (optional, default: "div") |
| 10 | | - * @property $ {jQuery} Container element |
| 11 | | - */ |
| 12 | | -es.ViewContainerItem = function( model, typeName, tagName ) { |
| 13 | | - es.EventEmitter.call( this ); |
| 14 | | - this.model = model; |
| 15 | | - if ( typeof typeName !== 'string' ) { |
| 16 | | - typeName = 'viewContainerItem'; |
| 17 | | - } |
| 18 | | - if ( typeof tagName !== 'string' ) { |
| 19 | | - tagName = 'div'; |
| 20 | | - } |
| 21 | | - |
| 22 | | - if ( !this.$ ) { |
| 23 | | - this.$ = $( '<' + tagName + '/>' ); |
| 24 | | - } |
| 25 | | - this.$.addClass( 'editSurface-' + typeName ).data( typeName, this ); |
| 26 | | -}; |
| 27 | | - |
| 28 | | -es.ViewContainerItem.prototype.getModel = function() { |
| 29 | | - return this.model; |
| 30 | | -}; |
| 31 | | - |
| 32 | | -/** |
| 33 | | - * Gets the index of this item within it's container. |
| 34 | | - * |
| 35 | | - * This method simply delegates to the model. |
| 36 | | - * |
| 37 | | - * @method |
| 38 | | - * @returns {Integer} Index of item in it's container |
| 39 | | - */ |
| 40 | | -es.ViewContainerItem.prototype.getIndex = function() { |
| 41 | | - return this.model.getIndex(); |
| 42 | | -}; |
| 43 | | - |
| 44 | | -/* Inheritance */ |
| 45 | | - |
| 46 | | -es.extend( es.ViewContainerItem, es.EventEmitter ); |
| Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js |
| — | — | @@ -1,119 +0,0 @@ |
| 2 | | -/** |
| 3 | | - * Creates an es.ViewContainer object. |
| 4 | | - * |
| 5 | | - * View containers follow the operations performed on a model container and keep a list of views, |
| 6 | | - * each correlating to a model in the model container. |
| 7 | | - * |
| 8 | | - * @class |
| 9 | | - * @constructor |
| 10 | | - * @extends {es.EventEmitter} |
| 11 | | - * @param model {es.ModelContainer} Model to follow |
| 12 | | - * @param typeName {String} Name to use in CSS classes and HTML element data |
| 13 | | - * @param tagName {String} HTML element name to use (optional, default: "div") |
| 14 | | - * @property $ {jQuery} Container element |
| 15 | | - * @property items {Array} List of views, correlating to models in the model container |
| 16 | | - */ |
| 17 | | -es.ViewContainer = function( model, typeName, tagName ) { |
| 18 | | - es.EventEmitter.call( this ); |
| 19 | | - this.model = model; |
| 20 | | - if ( !this.model ) { |
| 21 | | - return; |
| 22 | | - } |
| 23 | | - this.items = new es.AggregateArray(); |
| 24 | | - if ( typeof typeName !== 'string' ) { |
| 25 | | - typeName = 'viewContainer'; |
| 26 | | - } |
| 27 | | - if ( typeof tagName !== 'string' ) { |
| 28 | | - tagName = 'div'; |
| 29 | | - } |
| 30 | | - if ( !this.$ ) { |
| 31 | | - this.$ = $( '<' + tagName + '/>' ); |
| 32 | | - } |
| 33 | | - this.$.addClass( 'editSurface-' + typeName ).data( typeName, this ); |
| 34 | | - var container = this; |
| 35 | | - this.relayUpdate = function() { |
| 36 | | - container.emit( 'update' ); |
| 37 | | - }; |
| 38 | | - function recycleItemView( itemModel, autoCreate ) { |
| 39 | | - var itemView = container.lookupItemView( itemModel ); |
| 40 | | - if ( itemView ) { |
| 41 | | - container.views.splice( container.views.indexOf( itemView ), 1 ); |
| 42 | | - itemView.$.detach(); |
| 43 | | - } |
| 44 | | - if ( autoCreate && itemView === null ) { |
| 45 | | - itemView = itemModel.createView(); |
| 46 | | - } |
| 47 | | - return itemView; |
| 48 | | - } |
| 49 | | - this.model.on( 'prepend', function( itemModel ) { |
| 50 | | - var itemView = recycleItemView( itemModel, true ); |
| 51 | | - itemView.on( 'update', container.relayUpdate ); |
| 52 | | - container.views.unshift( itemView ); |
| 53 | | - container.$.prepend( itemView.$ ); |
| 54 | | - container.emit( 'prepend', itemView ); |
| 55 | | - container.emit( 'update' ); |
| 56 | | - } ); |
| 57 | | - this.model.on( 'append', function( itemModel ) { |
| 58 | | - var itemView = recycleItemView( itemModel, true ); |
| 59 | | - itemView.on( 'update', container.relayUpdate ); |
| 60 | | - container.views.push( itemView ); |
| 61 | | - container.$.append( itemView.$ ); |
| 62 | | - container.emit( 'append', itemView ); |
| 63 | | - container.emit( 'update' ); |
| 64 | | - } ); |
| 65 | | - this.model.on( 'insertBefore', function( itemModel, beforeModel ) { |
| 66 | | - var beforeView = container.lookupItemView( beforeModel ), |
| 67 | | - itemView = recycleItemView( itemModel, true ); |
| 68 | | - itemView.on( 'update', container.relayUpdate ); |
| 69 | | - if ( beforeView ) { |
| 70 | | - container.views.splice( container.views.indexOf( beforeView ), 0, itemView ); |
| 71 | | - itemView.$.insertBefore( beforeView.$ ); |
| 72 | | - } else { |
| 73 | | - container.views.unshift( itemView ); |
| 74 | | - container.$.prepend( itemView.$ ); |
| 75 | | - } |
| 76 | | - container.emit( 'insertBefore', itemView, beforeView ); |
| 77 | | - container.emit( 'update' ); |
| 78 | | - } ); |
| 79 | | - this.model.on( 'insertAfter', function( itemModel, afterModel ) { |
| 80 | | - var afterView = container.lookupItemView( afterModel ), |
| 81 | | - itemView = recycleItemView( itemModel, true ); |
| 82 | | - itemView.on( 'update', container.relayUpdate ); |
| 83 | | - if ( afterView ) { |
| 84 | | - container.views.splice( container.views.indexOf( afterView ) + 1, 0, itemView ); |
| 85 | | - itemView.$.insertAfter( afterView.$ ); |
| 86 | | - } else { |
| 87 | | - container.views.push( itemView ); |
| 88 | | - container.$.append( itemView.$ ); |
| 89 | | - } |
| 90 | | - container.emit( 'insertAfter', itemView, afterView ); |
| 91 | | - container.emit( 'update' ); |
| 92 | | - } ); |
| 93 | | - this.model.on( 'remove', function( itemModel ) { |
| 94 | | - var itemView = recycleItemView( itemModel ); |
| 95 | | - itemView.removeListener( 'update', container.relayUpdate ); |
| 96 | | - container.emit( 'remove', itemView ); |
| 97 | | - container.emit( 'update' ); |
| 98 | | - } ); |
| 99 | | - // Auto-add views for existing items |
| 100 | | - var itemModels = this.model.all(); |
| 101 | | - for ( var i = 0; i < itemModels.length; i++ ) { |
| 102 | | - var itemView = itemModels[i].createView(); |
| 103 | | - itemView.on( 'update', container.relayUpdate ); |
| 104 | | - this.items.push( itemView ); |
| 105 | | - this.$.append( itemView.$ ); |
| 106 | | - } |
| 107 | | -}; |
| 108 | | - |
| 109 | | -es.ViewContainer.prototype.lookupItemView = function( itemModel ) { |
| 110 | | - for ( var i = 0; i < this.items.length; i++ ) { |
| 111 | | - if ( this.items[i].getModel() === itemModel ) { |
| 112 | | - return this.items[i]; |
| 113 | | - } |
| 114 | | - } |
| 115 | | - return null; |
| 116 | | -}; |
| 117 | | - |
| 118 | | -/* Inheritance */ |
| 119 | | - |
| 120 | | -es.extend( es.ViewContainer, es.EventEmitter ); |
| Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewListItem.js |
| — | — | @@ -0,0 +1,45 @@ |
| | 2 | +/** |
| | 3 | + * Generic synchronized Object/Element container item. |
| | 4 | + * |
| | 5 | + * @class |
| | 6 | + * @constructor |
| | 7 | + * @extends {es.EventEmitter} |
| | 8 | + * @param typeName {String} Name to use in CSS classes and HTML element data |
| | 9 | + * @param tagName {String} HTML element name to use (optional, default: "div") |
| | 10 | + * @property $ {jQuery} Container element |
| | 11 | + */ |
| | 12 | +es.ViewListItem = function( model, typeName, tagName ) { |
| | 13 | + es.EventEmitter.call( this ); |
| | 14 | + this.model = model; |
| | 15 | + if ( typeof typeName !== 'string' ) { |
| | 16 | + typeName = 'viewListItem'; |
| | 17 | + } |
| | 18 | + if ( typeof tagName !== 'string' ) { |
| | 19 | + tagName = 'div'; |
| | 20 | + } |
| | 21 | + |
| | 22 | + if ( !this.$ ) { |
| | 23 | + this.$ = $( '<' + tagName + '/>' ); |
| | 24 | + } |
| | 25 | + this.$.addClass( 'editSurface-' + typeName ).data( typeName, this ); |
| | 26 | +}; |
| | 27 | + |
| | 28 | +es.ViewListItem.prototype.getModel = function() { |
| | 29 | + return this.model; |
| | 30 | +}; |
| | 31 | + |
| | 32 | +/** |
| | 33 | + * Gets the index of this item within it's container. |
| | 34 | + * |
| | 35 | + * This method simply delegates to the model. |
| | 36 | + * |
| | 37 | + * @method |
| | 38 | + * @returns {Integer} Index of item in it's container |
| | 39 | + */ |
| | 40 | +es.ViewListItem.prototype.getIndex = function() { |
| | 41 | + return this.model.getIndex(); |
| | 42 | +}; |
| | 43 | + |
| | 44 | +/* Inheritance */ |
| | 45 | + |
| | 46 | +es.extend( es.ViewListItem, es.EventEmitter ); |
| Property changes on: trunk/parsers/wikidom/lib/synth/bases/es.ViewListItem.js |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| 1 | 47 | + native |
| Added: svn:mime-type |
| 2 | 48 | + text/plain |
| Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewList.js |
| — | — | @@ -0,0 +1,119 @@ |
| | 2 | +/** |
| | 3 | + * Creates an es.ViewList object. |
| | 4 | + * |
| | 5 | + * View containers follow the operations performed on a model container and keep a list of views, |
| | 6 | + * each correlating to a model in the model container. |
| | 7 | + * |
| | 8 | + * @class |
| | 9 | + * @constructor |
| | 10 | + * @extends {es.EventEmitter} |
| | 11 | + * @param model {es.ModelList} Model to follow |
| | 12 | + * @param typeName {String} Name to use in CSS classes and HTML element data |
| | 13 | + * @param tagName {String} HTML element name to use (optional, default: "div") |
| | 14 | + * @property $ {jQuery} Container element |
| | 15 | + * @property items {Array} List of views, correlating to models in the model container |
| | 16 | + */ |
| | 17 | +es.ViewList = function( model, typeName, tagName ) { |
| | 18 | + es.EventEmitter.call( this ); |
| | 19 | + this.model = model; |
| | 20 | + if ( !this.model ) { |
| | 21 | + return; |
| | 22 | + } |
| | 23 | + this.items = new es.AggregateArray(); |
| | 24 | + if ( typeof typeName !== 'string' ) { |
| | 25 | + typeName = 'viewList'; |
| | 26 | + } |
| | 27 | + if ( typeof tagName !== 'string' ) { |
| | 28 | + tagName = 'div'; |
| | 29 | + } |
| | 30 | + if ( !this.$ ) { |
| | 31 | + this.$ = $( '<' + tagName + '/>' ); |
| | 32 | + } |
| | 33 | + this.$.addClass( 'editSurface-' + typeName ).data( typeName, this ); |
| | 34 | + var container = this; |
| | 35 | + this.relayUpdate = function() { |
| | 36 | + container.emit( 'update' ); |
| | 37 | + }; |
| | 38 | + function recycleItemView( itemModel, autoCreate ) { |
| | 39 | + var itemView = container.lookupItemView( itemModel ); |
| | 40 | + if ( itemView ) { |
| | 41 | + container.views.splice( container.views.indexOf( itemView ), 1 ); |
| | 42 | + itemView.$.detach(); |
| | 43 | + } |
| | 44 | + if ( autoCreate && itemView === null ) { |
| | 45 | + itemView = itemModel.createView(); |
| | 46 | + } |
| | 47 | + return itemView; |
| | 48 | + } |
| | 49 | + this.model.on( 'prepend', function( itemModel ) { |
| | 50 | + var itemView = recycleItemView( itemModel, true ); |
| | 51 | + itemView.on( 'update', container.relayUpdate ); |
| | 52 | + container.views.unshift( itemView ); |
| | 53 | + container.$.prepend( itemView.$ ); |
| | 54 | + container.emit( 'prepend', itemView ); |
| | 55 | + container.emit( 'update' ); |
| | 56 | + } ); |
| | 57 | + this.model.on( 'append', function( itemModel ) { |
| | 58 | + var itemView = recycleItemView( itemModel, true ); |
| | 59 | + itemView.on( 'update', container.relayUpdate ); |
| | 60 | + container.views.push( itemView ); |
| | 61 | + container.$.append( itemView.$ ); |
| | 62 | + container.emit( 'append', itemView ); |
| | 63 | + container.emit( 'update' ); |
| | 64 | + } ); |
| | 65 | + this.model.on( 'insertBefore', function( itemModel, beforeModel ) { |
| | 66 | + var beforeView = container.lookupItemView( beforeModel ), |
| | 67 | + itemView = recycleItemView( itemModel, true ); |
| | 68 | + itemView.on( 'update', container.relayUpdate ); |
| | 69 | + if ( beforeView ) { |
| | 70 | + container.views.splice( container.views.indexOf( beforeView ), 0, itemView ); |
| | 71 | + itemView.$.insertBefore( beforeView.$ ); |
| | 72 | + } else { |
| | 73 | + container.views.unshift( itemView ); |
| | 74 | + container.$.prepend( itemView.$ ); |
| | 75 | + } |
| | 76 | + container.emit( 'insertBefore', itemView, beforeView ); |
| | 77 | + container.emit( 'update' ); |
| | 78 | + } ); |
| | 79 | + this.model.on( 'insertAfter', function( itemModel, afterModel ) { |
| | 80 | + var afterView = container.lookupItemView( afterModel ), |
| | 81 | + itemView = recycleItemView( itemModel, true ); |
| | 82 | + itemView.on( 'update', container.relayUpdate ); |
| | 83 | + if ( afterView ) { |
| | 84 | + container.views.splice( container.views.indexOf( afterView ) + 1, 0, itemView ); |
| | 85 | + itemView.$.insertAfter( afterView.$ ); |
| | 86 | + } else { |
| | 87 | + container.views.push( itemView ); |
| | 88 | + container.$.append( itemView.$ ); |
| | 89 | + } |
| | 90 | + container.emit( 'insertAfter', itemView, afterView ); |
| | 91 | + container.emit( 'update' ); |
| | 92 | + } ); |
| | 93 | + this.model.on( 'remove', function( itemModel ) { |
| | 94 | + var itemView = recycleItemView( itemModel ); |
| | 95 | + itemView.removeListener( 'update', container.relayUpdate ); |
| | 96 | + container.emit( 'remove', itemView ); |
| | 97 | + container.emit( 'update' ); |
| | 98 | + } ); |
| | 99 | + // Auto-add views for existing items |
| | 100 | + var itemModels = this.model.all(); |
| | 101 | + for ( var i = 0; i < itemModels.length; i++ ) { |
| | 102 | + var itemView = itemModels[i].createView(); |
| | 103 | + itemView.on( 'update', container.relayUpdate ); |
| | 104 | + this.items.push( itemView ); |
| | 105 | + this.$.append( itemView.$ ); |
| | 106 | + } |
| | 107 | +}; |
| | 108 | + |
| | 109 | +es.ViewList.prototype.lookupItemView = function( itemModel ) { |
| | 110 | + for ( var i = 0; i < this.items.length; i++ ) { |
| | 111 | + if ( this.items[i].getModel() === itemModel ) { |
| | 112 | + return this.items[i]; |
| | 113 | + } |
| | 114 | + } |
| | 115 | + return null; |
| | 116 | +}; |
| | 117 | + |
| | 118 | +/* Inheritance */ |
| | 119 | + |
| | 120 | +es.extend( es.ViewList, es.EventEmitter ); |
| Property changes on: trunk/parsers/wikidom/lib/synth/bases/es.ViewList.js |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| 1 | 121 | + native |
| Added: svn:mime-type |
| 2 | 122 | + text/plain |
| Index: trunk/parsers/wikidom/lib/synth/bases/es.ModelListItem.js |
| — | — | @@ -0,0 +1,133 @@ |
| | 2 | +/** |
| | 3 | + * Creates an es.ModelListItem object. |
| | 4 | + * |
| | 5 | + * @class |
| | 6 | + * @constructor |
| | 7 | + * @extends {es.EventEmitter} |
| | 8 | + * @property container {Object} Reference to container, if attached |
| | 9 | + */ |
| | 10 | +es.ModelListItem = function() { |
| | 11 | + es.EventEmitter.call( this ); |
| | 12 | + this.container = null; |
| | 13 | +}; |
| | 14 | + |
| | 15 | +/* Methods */ |
| | 16 | + |
| | 17 | +es.ModelListItem.prototype.parent = function() { |
| | 18 | + return this.container; |
| | 19 | +}; |
| | 20 | + |
| | 21 | +/** |
| | 22 | + * Creates a view for this model |
| | 23 | + */ |
| | 24 | +es.ModelListItem.prototype.createView = function() { |
| | 25 | + throw 'ModelListItem.createView not implemented in this subclass.'; |
| | 26 | +}; |
| | 27 | + |
| | 28 | +/** |
| | 29 | + * Attaches item to a container. |
| | 30 | + * |
| | 31 | + * @method |
| | 32 | + * @param container {es.Container} Container to attach to |
| | 33 | + * @emits "attach" with container argument |
| | 34 | + */ |
| | 35 | +es.ModelListItem.prototype.attach = function( container ) { |
| | 36 | + this.container = container; |
| | 37 | + this.emit( 'attach', container ); |
| | 38 | +}; |
| | 39 | + |
| | 40 | +/** |
| | 41 | + * Detaches item from a container. |
| | 42 | + * |
| | 43 | + * @method |
| | 44 | + * @emits "detach" with container argument |
| | 45 | + */ |
| | 46 | +es.ModelListItem.prototype.detach = function() { |
| | 47 | + var container = this.container; |
| | 48 | + this.container = null; |
| | 49 | + this.emit( 'detach', container ); |
| | 50 | +}; |
| | 51 | + |
| | 52 | +/** |
| | 53 | + * Gets the index of this item within it's container. |
| | 54 | + * |
| | 55 | + * @method |
| | 56 | + * @returns {Integer} Index of item in it's container |
| | 57 | + * @throws Unknown item error if this item is not in it's container |
| | 58 | + * @throws Missing container error if this container can't be accessed. |
| | 59 | + */ |
| | 60 | +es.ModelListItem.prototype.getIndex = function() { |
| | 61 | + try { |
| | 62 | + var index = this.container.indexOf( this ); |
| | 63 | + if ( index === -1 ) { |
| | 64 | + throw 'Unknown item error. Can not get index of item that is not in a container. ' + e; |
| | 65 | + } |
| | 66 | + return index; |
| | 67 | + } catch ( e ) { |
| | 68 | + throw 'Missing container error. Can not get index of item in missing container. ' + e; |
| | 69 | + } |
| | 70 | +}; |
| | 71 | + |
| | 72 | +/** |
| | 73 | + * Gets the previous item in container. |
| | 74 | + * |
| | 75 | + * @method |
| | 76 | + * @returns {Object} Previous item, or null if none exists |
| | 77 | + * @throws Missing container error if getting the previous item item failed |
| | 78 | + */ |
| | 79 | +es.ModelListItem.prototype.previous = function() { |
| | 80 | + try { |
| | 81 | + return this.container.get( this.container.indexOf( this ) - 1 ); |
| | 82 | + } catch ( e ) { |
| | 83 | + throw 'Missing container error. Can not get previous item in missing container. ' + e; |
| | 84 | + } |
| | 85 | +}; |
| | 86 | + |
| | 87 | +/** |
| | 88 | + * Gets the next item in container. |
| | 89 | + * |
| | 90 | + * @method |
| | 91 | + * @returns {Object} Next item, or null if none exists |
| | 92 | + * @throws Missing container error if getting the next item item failed |
| | 93 | + */ |
| | 94 | +es.ModelListItem.prototype.next = function() { |
| | 95 | + try { |
| | 96 | + return this.container.get( this.container.indexOf( this ) + 1 ); |
| | 97 | + } catch ( e ) { |
| | 98 | + throw 'Missing container error. Can not get next item in missing container. ' + e; |
| | 99 | + } |
| | 100 | +}; |
| | 101 | + |
| | 102 | +/** |
| | 103 | + * Checks if this item is the first in it's container. |
| | 104 | + * |
| | 105 | + * @method |
| | 106 | + * @returns {Boolean} If item is the first in it's container |
| | 107 | + * @throws Missing container error if getting the index of this item failed |
| | 108 | + */ |
| | 109 | +es.ModelListItem.prototype.isFirst = function() { |
| | 110 | + try { |
| | 111 | + return this.container.indexOf( this ) === 0; |
| | 112 | + } catch ( e ) { |
| | 113 | + throw 'Missing container error. Can not get index of item in missing container. ' + e; |
| | 114 | + } |
| | 115 | +}; |
| | 116 | + |
| | 117 | +/** |
| | 118 | + * Checks if this item is the last in it's container. |
| | 119 | + * |
| | 120 | + * @method |
| | 121 | + * @returns {Boolean} If item is the last in it's container |
| | 122 | + * @throws Missing container error if getting the index of this item failed |
| | 123 | + */ |
| | 124 | +es.ModelListItem.prototype.isLast = function() { |
| | 125 | + try { |
| | 126 | + return this.container.indexOf( this ) === this.container.getLength() - 1; |
| | 127 | + } catch ( e ) { |
| | 128 | + throw 'Missing container error. Can not get index of item in missing container. ' + e; |
| | 129 | + } |
| | 130 | +}; |
| | 131 | + |
| | 132 | +/* Inheritance */ |
| | 133 | + |
| | 134 | +es.extend( es.ModelListItem, es.EventEmitter ); |
| Property changes on: trunk/parsers/wikidom/lib/synth/bases/es.ModelListItem.js |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| 1 | 135 | + native |
| Added: svn:mime-type |
| 2 | 136 | + text/plain |
| Index: trunk/parsers/wikidom/lib/synth/bases/es.ModelList.js |
| — | — | @@ -0,0 +1,220 @@ |
| | 2 | +/** |
| | 3 | + * Creates an es.ModelList object. |
| | 4 | + * |
| | 5 | + * Child objects must extend es.ModelListItem. |
| | 6 | + * |
| | 7 | + * @class |
| | 8 | + * @constructor |
| | 9 | + * @extends {es.EventEmitter} |
| | 10 | + * @property items {Array} list of items |
| | 11 | + */ |
| | 12 | +es.ModelList = function() { |
| | 13 | + es.EventEmitter.call( this ); |
| | 14 | + this.items = new es.AggregateArray(); |
| | 15 | + var container = this; |
| | 16 | + this.relayUpdate = function() { |
| | 17 | + container.emit( 'update' ); |
| | 18 | + }; |
| | 19 | +}; |
| | 20 | + |
| | 21 | +/* Methods */ |
| | 22 | + |
| | 23 | +/** |
| | 24 | + * Gets an item at a specific index. |
| | 25 | + * |
| | 26 | + * @method |
| | 27 | + * @returns {Object} Child object at index |
| | 28 | + */ |
| | 29 | +es.ModelList.prototype.get = function( index ) { |
| | 30 | + return this.items[index] || null; |
| | 31 | +}; |
| | 32 | + |
| | 33 | +/** |
| | 34 | + * Gets all items. |
| | 35 | + * |
| | 36 | + * @method |
| | 37 | + * @returns {Array} List of all items. |
| | 38 | + */ |
| | 39 | +es.ModelList.prototype.all = function() { |
| | 40 | + return this.items; |
| | 41 | +}; |
| | 42 | + |
| | 43 | +/** |
| | 44 | + * Gets the number of items in container. |
| | 45 | + * |
| | 46 | + * @method |
| | 47 | + * @returns {Integer} Number of items in container |
| | 48 | + */ |
| | 49 | +es.ModelList.prototype.getLength = function() { |
| | 50 | + return this.items.length |
| | 51 | +}; |
| | 52 | + |
| | 53 | +/** |
| | 54 | + * Gets the index of an item. |
| | 55 | + * |
| | 56 | + * @method |
| | 57 | + * @returns {Integer} Index of item, -1 if item is not in container |
| | 58 | + */ |
| | 59 | +es.ModelList.prototype.indexOf = function( item ) { |
| | 60 | + return this.items.indexOf( item ); |
| | 61 | +}; |
| | 62 | + |
| | 63 | +/** |
| | 64 | + * Gets the first item in the container. |
| | 65 | + * |
| | 66 | + * @method |
| | 67 | + * @returns {Object} First item |
| | 68 | + */ |
| | 69 | +es.ModelList.prototype.first = function() { |
| | 70 | + return this.items.length ? this.items[0] : null; |
| | 71 | +}; |
| | 72 | + |
| | 73 | +/** |
| | 74 | + * Gets the last item in the container. |
| | 75 | + * |
| | 76 | + * @method |
| | 77 | + * @returns {Object} Last item |
| | 78 | + */ |
| | 79 | +es.ModelList.prototype.last = function() { |
| | 80 | + return this.items.length |
| | 81 | + ? this.items[this.items.length - 1] : null; |
| | 82 | +}; |
| | 83 | + |
| | 84 | +/** |
| | 85 | + * Iterates over items, executing a callback for each. |
| | 86 | + * |
| | 87 | + * Returning false in the callback will stop iteration. |
| | 88 | + * |
| | 89 | + * @method |
| | 90 | + * @param callback {Function} Function to call on each item which takes item and index arguments |
| | 91 | + */ |
| | 92 | +es.ModelList.prototype.each = function( callback ) { |
| | 93 | + for ( var i = 0; i < this.items.length; i++ ) { |
| | 94 | + if ( callback( this.items[i], i ) === false ) { |
| | 95 | + break; |
| | 96 | + } |
| | 97 | + } |
| | 98 | +}; |
| | 99 | + |
| | 100 | +/** |
| | 101 | + * Adds an item to the end of the container. |
| | 102 | + * |
| | 103 | + * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
| | 104 | + * |
| | 105 | + * @method |
| | 106 | + * @param item {Object} Item to append |
| | 107 | + * @emits "update" |
| | 108 | + */ |
| | 109 | +es.ModelList.prototype.append = function( item ) { |
| | 110 | + var parent = item.parent(); |
| | 111 | + if ( parent === this ) { |
| | 112 | + this.items.splice( this.indexOf( item ), 1 ); |
| | 113 | + } else if ( parent ) { |
| | 114 | + parent.remove( item ); |
| | 115 | + } |
| | 116 | + this.items.push( item ); |
| | 117 | + item.on( 'update', this.relayUpdate ); |
| | 118 | + item.attach( this ); |
| | 119 | + this.emit( 'append', item ); |
| | 120 | + this.emit( 'update' ); |
| | 121 | +}; |
| | 122 | + |
| | 123 | +/** |
| | 124 | + * Adds an item to the beginning of the container. |
| | 125 | + * |
| | 126 | + * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
| | 127 | + * |
| | 128 | + * @method |
| | 129 | + * @param item {Object} Item to prepend |
| | 130 | + * @emits "update" |
| | 131 | + */ |
| | 132 | +es.ModelList.prototype.prepend = function( item ) { |
| | 133 | + var parent = item.parent(); |
| | 134 | + if ( parent === this ) { |
| | 135 | + this.items.splice( this.indexOf( item ), 1 ); |
| | 136 | + } else if ( parent ) { |
| | 137 | + parent.remove( item ); |
| | 138 | + } |
| | 139 | + this.items.unshift( item ); |
| | 140 | + item.on( 'update', this.relayUpdate ); |
| | 141 | + item.attach( this ); |
| | 142 | + this.emit( 'prepend', item ); |
| | 143 | + this.emit( 'update' ); |
| | 144 | +}; |
| | 145 | + |
| | 146 | +/** |
| | 147 | + * Adds an item to the container after an existing item. |
| | 148 | + * |
| | 149 | + * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
| | 150 | + * |
| | 151 | + * @method |
| | 152 | + * @param item {Object} Item to insert |
| | 153 | + * @param before {Object} Item to insert before, if null then item will be inserted at the end |
| | 154 | + * @emits "update" |
| | 155 | + */ |
| | 156 | +es.ModelList.prototype.insertBefore = function( item, before ) { |
| | 157 | + var parent = item.parent(); |
| | 158 | + if ( parent === this ) { |
| | 159 | + this.items.splice( this.indexOf( item ), 1 ); |
| | 160 | + } else if ( parent ) { |
| | 161 | + parent.remove( item ); |
| | 162 | + } |
| | 163 | + if ( before ) { |
| | 164 | + this.items.splice( this.items.indexOf( before ), 0, item ); |
| | 165 | + } else { |
| | 166 | + this.items.unshift( item ); |
| | 167 | + } |
| | 168 | + item.on( 'update', this.relayUpdate ); |
| | 169 | + item.attach( this ); |
| | 170 | + this.emit( 'insertBefore', item, before ); |
| | 171 | + this.emit( 'update' ); |
| | 172 | +}; |
| | 173 | + |
| | 174 | +/** |
| | 175 | + * Adds an item to the container after an existing item. |
| | 176 | + * |
| | 177 | + * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
| | 178 | + * |
| | 179 | + * @method |
| | 180 | + * @param item {Object} Item to insert |
| | 181 | + * @param after {Object} Item to insert after, if null item will be inserted at the end |
| | 182 | + * @emits "update" |
| | 183 | + */ |
| | 184 | +es.ModelList.prototype.insertAfter = function( item, after ) { |
| | 185 | + var parent = item.parent(); |
| | 186 | + if ( parent === this ) { |
| | 187 | + this.items.splice( this.indexOf( item ), 1 ); |
| | 188 | + } else if ( parent ) { |
| | 189 | + parent.remove( item ); |
| | 190 | + } |
| | 191 | + if ( after ) { |
| | 192 | + this.items.splice( this.items.indexOf( after ) + 1, 0, item ); |
| | 193 | + } else { |
| | 194 | + this.items.push( item ); |
| | 195 | + } |
| | 196 | + item.on( 'update', this.relayUpdate ); |
| | 197 | + item.attach( this ); |
| | 198 | + this.emit( 'insertAfter', item, after ); |
| | 199 | + this.emit( 'update' ); |
| | 200 | +}; |
| | 201 | + |
| | 202 | +/** |
| | 203 | + * Removes an item from the container. |
| | 204 | + * |
| | 205 | + * Also detaches item's Element object to the DOM and removes all listeners its "update" events. |
| | 206 | + * |
| | 207 | + * @method |
| | 208 | + * @param item {Object} Item to remove |
| | 209 | + * @emits "update" |
| | 210 | + */ |
| | 211 | +es.ModelList.prototype.remove = function( item ) { |
| | 212 | + item.removeListener( 'update', this.relayUpdate ); |
| | 213 | + this.items.splice( this.indexOf( item ), 1 ); |
| | 214 | + item.detach(); |
| | 215 | + this.emit( 'remove', item ); |
| | 216 | + this.emit( 'update' ); |
| | 217 | +}; |
| | 218 | + |
| | 219 | +/* Inheritance */ |
| | 220 | + |
| | 221 | +es.extend( es.ModelList, es.EventEmitter ); |
| Property changes on: trunk/parsers/wikidom/lib/synth/bases/es.ModelList.js |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| 1 | 222 | + native |
| Added: svn:mime-type |
| 2 | 223 | + text/plain |
| Index: trunk/parsers/wikidom/lib/synth/views/es.ListBlockItemView.js |
| — | — | @@ -5,7 +5,7 @@ |
| 6 | 6 | * @constructor |
| 7 | 7 | */ |
| 8 | 8 | es.ListBlockItemView = function( model ) { |
| 9 | | - es.ViewContainerItem.call( this, model, 'listItem' ); |
| | 9 | + es.ViewListItem.call( this, model, 'listItem' ); |
| 10 | 10 | this.$icon = $( '<div class="editSurface-listItem-icon"></div>' ); |
| 11 | 11 | this.$content = $( '<div class="editSurface-listItem-content"></div>' ); |
| 12 | 12 | this.$ |
| — | — | @@ -77,4 +77,4 @@ |
| 78 | 78 | |
| 79 | 79 | /* Inheritance */ |
| 80 | 80 | |
| 81 | | -es.extend( es.ListBlockItemView, es.ViewContainerItem ); |
| | 81 | +es.extend( es.ListBlockItemView, es.ViewListItem ); |
| Index: trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js |
| — | — | @@ -5,7 +5,7 @@ |
| 6 | 6 | * @constructor |
| 7 | 7 | */ |
| 8 | 8 | es.ListBlockView = function( model ) { |
| 9 | | - es.ViewContainer.call( this, model, 'list' ); |
| | 9 | + es.ViewList.call( this, model, 'list' ); |
| 10 | 10 | es.BlockView.call( this, model, 'list' ); |
| 11 | 11 | var view = this; |
| 12 | 12 | this.on( 'update', function() { |
| — | — | @@ -91,5 +91,5 @@ |
| 92 | 92 | |
| 93 | 93 | /* Inheritance */ |
| 94 | 94 | |
| 95 | | -es.extend( es.ListBlockView, es.ViewContainer ); |
| | 95 | +es.extend( es.ListBlockView, es.ViewList ); |
| 96 | 96 | es.extend( es.ListBlockView, es.BlockView ); |
| Index: trunk/parsers/wikidom/lib/synth/views/es.BlockView.js |
| — | — | @@ -9,7 +9,7 @@ |
| 10 | 10 | * @param tagName {String} HTML tag name to use in rendering (optional, default: "div") |
| 11 | 11 | */ |
| 12 | 12 | es.BlockView = function( blockModel, typeName, tagName ) { |
| 13 | | - es.ViewContainerItem.call( this, blockModel, typeName || 'block', tagName || 'div' ); |
| | 13 | + es.ViewListItem.call( this, blockModel, typeName || 'block', tagName || 'div' ); |
| 14 | 14 | this.$.addClass( 'editSurface-block' ); |
| 15 | 15 | }; |
| 16 | 16 | |
| — | — | @@ -50,4 +50,4 @@ |
| 51 | 51 | |
| 52 | 52 | /* Inheritance */ |
| 53 | 53 | |
| 54 | | -es.extend( es.BlockView, es.ViewContainerItem ); |
| | 54 | +es.extend( es.BlockView, es.ViewListItem ); |
| Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js |
| — | — | @@ -5,8 +5,8 @@ |
| 6 | 6 | * @constructor |
| 7 | 7 | */ |
| 8 | 8 | es.TableBlockRowView = function( model ) { |
| 9 | | - es.ViewContainer.call( this, model, 'row', 'tr' ) |
| 10 | | - es.ViewContainerItem.call( this, model, 'tr' ); |
| | 9 | + es.ViewList.call( this, model, 'row', 'tr' ) |
| | 10 | + es.ViewListItem.call( this, model, 'tr' ); |
| 11 | 11 | |
| 12 | 12 | var classes = this.$.attr('class'); |
| 13 | 13 | for ( var name in this.model.attributes ) { |
| — | — | @@ -52,5 +52,5 @@ |
| 53 | 53 | |
| 54 | 54 | /* Inheritance */ |
| 55 | 55 | |
| 56 | | -es.extend( es.TableBlockRowView, es.ViewContainer ); |
| 57 | | -es.extend( es.TableBlockRowView, es.ViewContainerItem ); |
| | 56 | +es.extend( es.TableBlockRowView, es.ViewList ); |
| | 57 | +es.extend( es.TableBlockRowView, es.ViewListItem ); |
| Index: trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js |
| — | — | @@ -5,7 +5,7 @@ |
| 6 | 6 | * @constructor |
| 7 | 7 | */ |
| 8 | 8 | es.DocumentView = function( documentModel ) { |
| 9 | | - es.ViewContainer.call( this, documentModel, 'document' ); |
| | 9 | + es.ViewList.call( this, documentModel, 'document' ); |
| 10 | 10 | }; |
| 11 | 11 | |
| 12 | 12 | /** |
| — | — | @@ -49,4 +49,4 @@ |
| 50 | 50 | |
| 51 | 51 | /* Inheritance */ |
| 52 | 52 | |
| 53 | | -es.extend( es.DocumentView, es.ViewContainer ); |
| | 53 | +es.extend( es.DocumentView, es.ViewList ); |
| Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js |
| — | — | @@ -5,7 +5,7 @@ |
| 6 | 6 | * @constructor |
| 7 | 7 | */ |
| 8 | 8 | es.TableBlockCellView = function( model ) { |
| 9 | | - es.ViewContainerItem.call( this, model, 'cell', 'td' ); |
| | 9 | + es.ViewListItem.call( this, model, 'cell', 'td' ); |
| 10 | 10 | |
| 11 | 11 | this.documentView = new es.DocumentView( this.model.documentModel ); |
| 12 | 12 | this.$.append( this.documentView.$ ); |
| — | — | @@ -45,4 +45,4 @@ |
| 46 | 46 | |
| 47 | 47 | /* Inheritance */ |
| 48 | 48 | |
| 49 | | -es.extend( es.TableBlockCellView, es.ViewContainerItem ); |
| | 49 | +es.extend( es.TableBlockCellView, es.ViewListItem ); |
| Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js |
| — | — | @@ -5,7 +5,7 @@ |
| 6 | 6 | * @constructor |
| 7 | 7 | */ |
| 8 | 8 | es.TableBlockView = function( model ) { |
| 9 | | - es.ViewContainer.call( this, model, 'table', 'table' ); |
| | 9 | + es.ViewList.call( this, model, 'table', 'table' ); |
| 10 | 10 | es.BlockView.call( this, model, 'table', 'table' ); |
| 11 | 11 | |
| 12 | 12 | var classes = this.$.attr('class'); |
| — | — | @@ -52,5 +52,5 @@ |
| 53 | 53 | |
| 54 | 54 | /* Inheritance */ |
| 55 | 55 | |
| 56 | | -es.extend( es.TableBlockView, es.ViewContainer ); |
| | 56 | +es.extend( es.TableBlockView, es.ViewList ); |
| 57 | 57 | es.extend( es.TableBlockView, es.BlockView ); |
| Index: trunk/parsers/wikidom/demos/synth/index.html |
| — | — | @@ -60,10 +60,11 @@ |
| 61 | 61 | <script src="../../lib/synth/es.Selection.js"></script> |
| 62 | 62 | <script src="../../lib/synth/bases/es.EventEmitter.js"></script> |
| 63 | 63 | <script src="../../lib/synth/bases/es.AggregateArray.js"></script> |
| 64 | | - <script src="../../lib/synth/bases/es.ModelContainer.js"></script> |
| 65 | | - <script src="../../lib/synth/bases/es.ModelContainerItem.js"></script> |
| 66 | | - <script src="../../lib/synth/bases/es.ViewContainer.js"></script> |
| 67 | | - <script src="../../lib/synth/bases/es.ViewContainerItem.js"></script> |
| | 64 | + |
| | 65 | + <script src="../../lib/synth/bases/es.ModelList.js"></script> |
| | 66 | + <script src="../../lib/synth/bases/es.ModelListItem.js"></script> |
| | 67 | + <script src="../../lib/synth/bases/es.ViewList.js"></script> |
| | 68 | + <script src="../../lib/synth/bases/es.ViewListItem.js"></script> |
| 68 | 69 | |
| 69 | 70 | <!-- Controllers --> |
| 70 | 71 | <script src="../../lib/synth/controllers/es.SurfaceController.js"></script> |