Index: trunk/parsers/wikidom/tests/synth/index.html |
— | — | @@ -12,9 +12,9 @@ |
13 | 13 | <ol id="qunit-tests"></ol> |
14 | 14 | <script src="../../lib/synth/es.js"></script> |
15 | 15 | <script src="../../lib/synth/bases/es.EventEmitter.js"></script> |
16 | | - <script src="../../lib/synth/bases/es.Container.js"></script> |
17 | | - <script src="../../lib/synth/bases/es.ContainerItem.js"></script> |
18 | | - <script src="../../lib/synth/bases/es.ContentSeries.js"></script> |
| 16 | + <script src="../../lib/synth/bases/es.ModelContainer.js"></script> |
| 17 | + <script src="../../lib/synth/bases/es.ModelContainerItem.js"></script> |
| 18 | + <script src="../../lib/synth/bases/es.AggregateArray.js"></script> |
19 | 19 | <script src="../../lib/synth/es.Range.js"></script> |
20 | 20 | <script src="../../lib/jquery.js"></script> |
21 | 21 | <script src="../../lib/qunit.js"></script> |
Index: trunk/parsers/wikidom/tests/synth/test.js |
— | — | @@ -1,10 +1,10 @@ |
2 | 2 | module( 'Base classes' ); |
3 | 3 | |
4 | | -test( 'Containers', function() { |
5 | | - var container1 = new es.Container( 'a' ), |
6 | | - container2 = new es.Container( 'b' ); |
7 | | - deepEqual( container1.a, [], 'Container list name can be specialized' ); |
8 | | - deepEqual( container2.b, [], 'Container list name can be specialized' ); |
| 4 | +test( 'es.ModelContainer', function() { |
| 5 | + var container1 = new es.ModelContainer( 'a' ), |
| 6 | + container2 = new es.ModelContainer( 'b' ); |
| 7 | + deepEqual( container1.a, [], 'es.ModelContainer list name can be specialized' ); |
| 8 | + deepEqual( container2.b, [], 'es.ModelContainer list name can be specialized' ); |
9 | 9 | |
10 | 10 | var updates = 0; |
11 | 11 | container1.on( 'update', function( item ) { |
— | — | @@ -13,9 +13,9 @@ |
14 | 14 | |
15 | 15 | // Creating |
16 | 16 | |
17 | | - var item1 = new es.ContainerItem( 'a' ), |
18 | | - item2 = new es.ContainerItem( 'b' ), |
19 | | - item3 = new es.ContainerItem( 'c' ); |
| 17 | + var item1 = new es.ModelContainerItem( 'a' ), |
| 18 | + item2 = new es.ModelContainerItem( 'b' ), |
| 19 | + item3 = new es.ModelContainerItem( 'c' ); |
20 | 20 | |
21 | 21 | strictEqual( item1.a, null, 'Item container name can be specialized' ); |
22 | 22 | strictEqual( item2.b, null, 'Item container name can be specialized' ); |
— | — | @@ -24,32 +24,32 @@ |
25 | 25 | // Adding |
26 | 26 | |
27 | 27 | container1.append( item1 ); |
28 | | - equal( updates, 1, 'es.Container emits update events on append' ); |
29 | | - strictEqual( item1.a, container1, 'es.Container.append attaches item to container' ); |
| 28 | + equal( updates, 1, 'es.ModelContainer emits update events on append' ); |
| 29 | + strictEqual( item1.a, container1, 'es.ModelContainer.append attaches item to container' ); |
30 | 30 | container1.append( item2 ); |
31 | | - equal( updates, 2, 'es.Container emits update events on append' ); |
32 | | - strictEqual( item2.b, container1, 'es.Container.append attaches item to container' ); |
| 31 | + equal( updates, 2, 'es.ModelContainer emits update events on append' ); |
| 32 | + strictEqual( item2.b, container1, 'es.ModelContainer.append attaches item to container' ); |
33 | 33 | container1.append( item3 ); |
34 | | - equal( updates, 3, 'es.Container emits update events on append' ); |
35 | | - strictEqual( item3.c, container1, 'es.Container.append attaches item to container' ); |
| 34 | + equal( updates, 3, 'es.ModelContainer emits update events on append' ); |
| 35 | + strictEqual( item3.c, container1, 'es.ModelContainer.append attaches item to container' ); |
36 | 36 | |
37 | 37 | // Accessing |
38 | 38 | |
39 | | - deepEqual( container1.items(), [item1, item2, item3], 'es.Container.items returns all items' ) |
| 39 | + deepEqual( container1.items(), [item1, item2, item3], 'es.ModelContainer.items returns all items' ) |
40 | 40 | |
41 | | - strictEqual( container1.get( 0 ), item1, 'es.Container.get returns correct item at index' ); |
42 | | - strictEqual( container1.get( 1 ), item2, 'es.Container.get returns correct item at index' ); |
43 | | - strictEqual( container1.get( 2 ), item3, 'es.Container.get returns correct item at index' ); |
44 | | - strictEqual( container1.get( 3 ), null, 'es.Container.get returns null for invalid item' ); |
| 41 | + strictEqual( container1.get( 0 ), item1, 'es.ModelContainer.get returns correct item at index' ); |
| 42 | + strictEqual( container1.get( 1 ), item2, 'es.ModelContainer.get returns correct item at index' ); |
| 43 | + strictEqual( container1.get( 2 ), item3, 'es.ModelContainer.get returns correct item at index' ); |
| 44 | + strictEqual( container1.get( 3 ), null, 'es.ModelContainer.get returns null for invalid item' ); |
45 | 45 | |
46 | | - equal( container1.indexOf( item1 ), 0, 'es.Container.indexOf returns correct index of item' ); |
47 | | - equal( container1.indexOf( item2 ), 1, 'es.Container.indexOf returns correct index of item' ); |
48 | | - equal( container1.indexOf( item3 ), 2, 'es.Container.indexOf returns correct index of item' ); |
49 | | - equal( container1.indexOf( null ), -1, 'es.Container.indexOf returns -1 for nonexistent items' ); |
| 46 | + equal( container1.indexOf( item1 ), 0, 'es.ModelContainer.indexOf returns correct index of item' ); |
| 47 | + equal( container1.indexOf( item2 ), 1, 'es.ModelContainer.indexOf returns correct index of item' ); |
| 48 | + equal( container1.indexOf( item3 ), 2, 'es.ModelContainer.indexOf returns correct index of item' ); |
| 49 | + equal( container1.indexOf( null ), -1, 'es.ModelContainer.indexOf returns -1 for nonexistent items' ); |
50 | 50 | |
51 | | - equal( container1.getLength(), 3, 'es.Container.getLength returns correct number of items' ); |
52 | | - strictEqual( container1.first(), item1, 'es.Container.first returns correct first item' ); |
53 | | - strictEqual( container1.last(), item3, 'es.Container.last returns correct first item' ); |
| 51 | + equal( container1.getLength(), 3, 'es.ModelContainer.getLength returns correct number of items' ); |
| 52 | + strictEqual( container1.first(), item1, 'es.ModelContainer.first returns correct first item' ); |
| 53 | + strictEqual( container1.last(), item3, 'es.ModelContainer.last returns correct first item' ); |
54 | 54 | |
55 | 55 | // Iterating |
56 | 56 | |
— | — | @@ -59,9 +59,9 @@ |
60 | 60 | items.push( item ); |
61 | 61 | indexes.push( index ); |
62 | 62 | } ); |
63 | | - equal( items.length, 3, 'es.Container.each iterates over all items' ); |
64 | | - deepEqual( items, [item1, item2, item3], 'es.Container.each provides item as first argument' ); |
65 | | - deepEqual( indexes, [0, 1, 2], 'es.Container.each provides index as first argument' ); |
| 63 | + equal( items.length, 3, 'es.ModelContainer.each iterates over all items' ); |
| 64 | + deepEqual( items, [item1, item2, item3], 'es.ModelContainer.each provides item as first argument' ); |
| 65 | + deepEqual( indexes, [0, 1, 2], 'es.ModelContainer.each provides index as first argument' ); |
66 | 66 | |
67 | 67 | var count = 0; |
68 | 68 | container1.each( function( item, index ) { |
— | — | @@ -70,88 +70,88 @@ |
71 | 71 | return false; |
72 | 72 | } |
73 | 73 | } ); |
74 | | - equal( count, 2, 'es.Container.each stops iterating when a callback returns false' ) |
| 74 | + equal( count, 2, 'es.ModelContainer.each stops iterating when a callback returns false' ) |
75 | 75 | |
76 | 76 | // Updating |
77 | 77 | |
78 | 78 | updates = 0; |
79 | 79 | |
80 | 80 | item1.emit( 'update' ); |
81 | | - equal( updates, 1, 'es.Container relays update events from items' ); |
| 81 | + equal( updates, 1, 'es.ModelContainer relays update events from items' ); |
82 | 82 | item2.emit( 'update' ); |
83 | | - equal( updates, 2, 'es.Container relays update events from items' ); |
| 83 | + equal( updates, 2, 'es.ModelContainer relays update events from items' ); |
84 | 84 | item3.emit( 'update' ); |
85 | | - equal( updates, 3, 'es.Container relays update events from items' ); |
| 85 | + equal( updates, 3, 'es.ModelContainer relays update events from items' ); |
86 | 86 | |
87 | 87 | // Removing |
88 | 88 | |
89 | 89 | updates = 0; |
90 | 90 | |
91 | 91 | container1.remove( item3 ); |
92 | | - equal( updates, 1, 'es.Container emits update event on item removal' ); |
93 | | - strictEqual( item3.c, null, 'es.Container.append detaches item to container' ); |
| 92 | + equal( updates, 1, 'es.ModelContainer emits update event on item removal' ); |
| 93 | + strictEqual( item3.c, null, 'es.ModelContainer.append detaches item to container' ); |
94 | 94 | |
95 | | - equal( container1.getLength(), 2, 'es.Container.getLength returns correct number of items' ); |
| 95 | + equal( container1.getLength(), 2, 'es.ModelContainer.getLength returns correct number of items' ); |
96 | 96 | |
97 | 97 | container1.remove( item1 ); |
98 | | - equal( updates, 2, 'es.Container emits update event on item removal' ); |
99 | | - strictEqual( item1.a, null, 'es.Container.append detaches item to container' ); |
| 98 | + equal( updates, 2, 'es.ModelContainer emits update event on item removal' ); |
| 99 | + strictEqual( item1.a, null, 'es.ModelContainer.append detaches item to container' ); |
100 | 100 | |
101 | | - equal( container1.getLength(), 1, 'es.Container.getLength returns correct number of items' ); |
102 | | - strictEqual( container1.first(), item2, 'es.Container.first returns correct first item' ); |
103 | | - strictEqual( container1.last(), item2, 'es.Container.last returns correct first item' ); |
| 101 | + equal( container1.getLength(), 1, 'es.ModelContainer.getLength returns correct number of items' ); |
| 102 | + strictEqual( container1.first(), item2, 'es.ModelContainer.first returns correct first item' ); |
| 103 | + strictEqual( container1.last(), item2, 'es.ModelContainer.last returns correct first item' ); |
104 | 104 | |
105 | 105 | container1.remove( item2 ); |
106 | | - equal( updates, 3, 'es.Container emits update event on item removal' ); |
107 | | - strictEqual( item2.b, null, 'es.Container.append detaches item to container' ); |
| 106 | + equal( updates, 3, 'es.ModelContainer emits update event on item removal' ); |
| 107 | + strictEqual( item2.b, null, 'es.ModelContainer.append detaches item to container' ); |
108 | 108 | |
109 | | - equal( container1.getLength(), 0, 'es.Container.getLength returns correct number of items' ); |
110 | | - strictEqual( container1.first(), null, 'es.Container.first returns null when empty' ); |
111 | | - strictEqual( container1.last(), null, 'es.Container.last returns null when empty' ); |
| 109 | + equal( container1.getLength(), 0, 'es.ModelContainer.getLength returns correct number of items' ); |
| 110 | + strictEqual( container1.first(), null, 'es.ModelContainer.first returns null when empty' ); |
| 111 | + strictEqual( container1.last(), null, 'es.ModelContainer.last returns null when empty' ); |
112 | 112 | |
113 | 113 | updates = 0; |
114 | 114 | |
115 | 115 | item1.emit( 'update' ); |
116 | | - equal( updates, 0, 'es.Container does not relay events from removed items' ); |
| 116 | + equal( updates, 0, 'es.ModelContainer does not relay events from removed items' ); |
117 | 117 | item2.emit( 'update' ); |
118 | | - equal( updates, 0, 'es.Container does not relay events from removed items' ); |
| 118 | + equal( updates, 0, 'es.ModelContainer does not relay events from removed items' ); |
119 | 119 | item3.emit( 'update' ); |
120 | | - equal( updates, 0, 'es.Container does not relay events from removed items' ); |
| 120 | + equal( updates, 0, 'es.ModelContainer does not relay events from removed items' ); |
121 | 121 | |
122 | 122 | // Inserting |
123 | 123 | |
124 | 124 | container1.append( item1 ); |
125 | | - deepEqual( container1.items(), [item1], 'es.Container.append adds item to end' ); |
| 125 | + deepEqual( container1.items(), [item1], 'es.ModelContainer.append adds item to end' ); |
126 | 126 | container1.prepend( item3 ); |
127 | | - deepEqual( container1.items(), [item3, item1], 'es.Container.prepend adds item to begining' ); |
| 127 | + deepEqual( container1.items(), [item3, item1], 'es.ModelContainer.prepend adds item to begining' ); |
128 | 128 | container1.insertBefore( item2, item1 ); |
129 | 129 | deepEqual( |
130 | 130 | container1.items(), |
131 | 131 | [item3, item2, item1], |
132 | | - 'es.Container.insertBefore inserts item before another' |
| 132 | + 'es.ModelContainer.insertBefore inserts item before another' |
133 | 133 | ); |
134 | 134 | container1.insertBefore( item2, item3 ); |
135 | 135 | deepEqual( |
136 | 136 | container1.items(), |
137 | 137 | [item2, item3, item1], |
138 | | - 'es.Container.insertBefore moves item before another' |
| 138 | + 'es.ModelContainer.insertBefore moves item before another' |
139 | 139 | ); |
140 | 140 | |
141 | 141 | container2.prepend( item1 ); |
142 | | - deepEqual( container2.items(), [item1], 'es.Container.prepend adds item to begining' ); |
| 142 | + deepEqual( container2.items(), [item1], 'es.ModelContainer.prepend adds item to begining' ); |
143 | 143 | container2.append( item3 ); |
144 | | - deepEqual( container2.items(), [item1, item3], 'es.Container.append adds item to end' ); |
| 144 | + deepEqual( container2.items(), [item1, item3], 'es.ModelContainer.append adds item to end' ); |
145 | 145 | container2.insertAfter( item2, item1 ); |
146 | 146 | deepEqual( |
147 | 147 | container2.items(), |
148 | 148 | [item1, item2, item3], |
149 | | - 'es.Container.insertAfter inserts item after another' |
| 149 | + 'es.ModelContainer.insertAfter inserts item after another' |
150 | 150 | ); |
151 | 151 | container2.insertAfter( item1, item2 ); |
152 | 152 | deepEqual( |
153 | 153 | container2.items(), |
154 | 154 | [item2, item1, item3], |
155 | | - 'es.Container.insertAfter moves item after another' |
| 155 | + 'es.ModelContainer.insertAfter moves item after another' |
156 | 156 | ); |
157 | 157 | |
158 | 158 | // TODO: Events for appending, prepending, inserting and removing |
— | — | @@ -166,7 +166,7 @@ |
167 | 167 | return this.size; |
168 | 168 | }; |
169 | 169 | |
170 | | -test( 'ContentSeries', function() { |
| 170 | +test( 'es.AggregateArray', function() { |
171 | 171 | strictEqual( |
172 | 172 | ( new ContentStub( 'a', 0 ) ).getLength(), |
173 | 173 | 0, |
— | — | @@ -177,7 +177,7 @@ |
178 | 178 | c = new ContentStub( 'c', 2 ), |
179 | 179 | d = new ContentStub( 'd', 3 ), |
180 | 180 | e = new ContentStub( 'e', 4 ), |
181 | | - contentSeries1 = new es.ContentSeries( [a, b, c, d, e] ); |
| 181 | + contentSeries1 = new es.AggregateArray( [a, b, c, d, e] ); |
182 | 182 | |
183 | 183 | var lengthOfItemsTests = [ |
184 | 184 | { 'input': [], 'output': 0 }, |
— | — | @@ -190,9 +190,9 @@ |
191 | 191 | |
192 | 192 | for ( var i = 0; i < lengthOfItemsTests.length; i++ ) { |
193 | 193 | strictEqual( |
194 | | - ( new es.ContentSeries( lengthOfItemsTests[i].input ) ).getLengthOfItems(), |
| 194 | + ( new es.AggregateArray( lengthOfItemsTests[i].input ) ).getLengthOfItems(), |
195 | 195 | lengthOfItemsTests[i].output, |
196 | | - 'es.ContentSeries.getLengthOfItems returns correct value' |
| 196 | + 'es.AggregateArray.getLengthOfItems returns correct value' |
197 | 197 | ); |
198 | 198 | } |
199 | 199 | |
— | — | @@ -220,7 +220,7 @@ |
221 | 221 | strictEqual( |
222 | 222 | contentSeries1.lookup( lookupTests[i].input ), |
223 | 223 | lookupTests[i].output, |
224 | | - 'es.ContentSeries.lookup finds the right item or returns null when out of range' |
| 224 | + 'es.AggregateArray.lookup finds the right item or returns null when out of range' |
225 | 225 | ); |
226 | 226 | } |
227 | 227 | |
— | — | @@ -237,14 +237,14 @@ |
238 | 238 | deepEqual( |
239 | 239 | contentSeries1.rangeOf( rangeOfTests[i].input ), |
240 | 240 | rangeOfTests[i].output, |
241 | | - 'es.ContentSeries.rangeOf returns the correct range or null if item is not found' |
| 241 | + 'es.AggregateArray.rangeOf returns the correct range or null if item is not found' |
242 | 242 | ); |
243 | 243 | } |
244 | 244 | |
245 | 245 | var f = new ContentStub( 'f', 10 ), |
246 | 246 | g = new ContentStub( 'g', 10 ), |
247 | 247 | h = new ContentStub( 'h', 10 ), |
248 | | - contentSeries2 = new es.ContentSeries( [f, g, h] ); |
| 248 | + contentSeries2 = new es.AggregateArray( [f, g, h] ); |
249 | 249 | var selectTests = [ |
250 | 250 | { |
251 | 251 | 'input': [0, 5], |
— | — | @@ -316,7 +316,7 @@ |
317 | 317 | deepEqual( |
318 | 318 | contentSeries2.select.apply( contentSeries2, selectTests[i].input ), |
319 | 319 | selectTests[i].output, |
320 | | - 'es.ContentSeries.select returns the correct items and ranges.' |
| 320 | + 'es.AggregateArray.select returns the correct items and ranges.' |
321 | 321 | ); |
322 | 322 | } |
323 | 323 | } ); |
Index: trunk/parsers/wikidom/lib/synth/controllers/es.DocumentController.js |
— | — | @@ -21,27 +21,3 @@ |
22 | 22 | es.DocumentController.prototype.prepareAnnotateContent = function( range, annotation ) { |
23 | 23 | // generate transaction |
24 | 24 | }; |
25 | | - |
26 | | -es.DocumentController.prototype.prepareInsertBlock = function( index, block ) { |
27 | | - // generate transaction |
28 | | -}; |
29 | | - |
30 | | -es.DocumentController.prototype.prepareRemoveBlock = function( index ) { |
31 | | - // generate transaction |
32 | | -}; |
33 | | - |
34 | | -es.DocumentController.prototype.prepareMoveBlock = function( index, index ) { |
35 | | - // generate transaction |
36 | | -}; |
37 | | - |
38 | | -es.DocumentController.prototype.prepareSplitBlocks = function( offset ) { |
39 | | - // generate transaction |
40 | | -}; |
41 | | - |
42 | | -es.DocumentController.prototype.prepareMergeBlocks = function( range ) { |
43 | | - // generate transaction |
44 | | -}; |
45 | | - |
46 | | -es.DocumentController.prototype.prepareConvertBlock = function( index, type ) { |
47 | | - // generate transaction |
48 | | -}; |
Index: trunk/parsers/wikidom/lib/synth/bases/es.ContainerItem.js |
— | — | @@ -1,112 +0,0 @@ |
2 | | -/** |
3 | | - * Generic Object container item. |
4 | | - * |
5 | | - * @class |
6 | | - * @constructor |
7 | | - * @extends {es.EventEmitter} |
8 | | - * @param containerName {String} Name of container type |
9 | | - * @property [containerName] {Object} Reference to container, if attached |
10 | | - */ |
11 | | -es.ContainerItem = function( containerName ) { |
12 | | - es.EventEmitter.call( this ); |
13 | | - if ( typeof containerName !== 'string' ) { |
14 | | - containerName = 'container'; |
15 | | - } |
16 | | - this._containerName = containerName; |
17 | | - this[this._containerName] = null; |
18 | | -}; |
19 | | - |
20 | | -/* Methods */ |
21 | | - |
22 | | -es.ContainerItem.prototype.parent = function() { |
23 | | - return this[this._containerName]; |
24 | | -}; |
25 | | - |
26 | | -/** |
27 | | - * Attaches item to a container. |
28 | | - * |
29 | | - * @method |
30 | | - * @param container {es.Container} Container to attach to |
31 | | - * @emits "attach" with container argument |
32 | | - */ |
33 | | -es.ContainerItem.prototype.attach = function( container ) { |
34 | | - this[this._containerName] = container; |
35 | | - this.emit( 'attach', container ); |
36 | | -}; |
37 | | - |
38 | | -/** |
39 | | - * Detaches item from a container. |
40 | | - * |
41 | | - * @method |
42 | | - * @emits "detach" with container argument |
43 | | - */ |
44 | | -es.ContainerItem.prototype.detach = function() { |
45 | | - var container = this[this._containerName]; |
46 | | - this[this._containerName] = null; |
47 | | - this.emit( 'detach', container ); |
48 | | -}; |
49 | | - |
50 | | -/** |
51 | | - * Gets the previous item in container. |
52 | | - * |
53 | | - * @method |
54 | | - * @returns {Object} Previous item, or null if none exists |
55 | | - * @throws Missing container error if getting the previous item item failed |
56 | | - */ |
57 | | -es.ContainerItem.prototype.previous = function() { |
58 | | - try { |
59 | | - return this[this._containerName].get( this[this._containerName].indexOf( this ) - 1 ); |
60 | | - } catch ( e ) { |
61 | | - throw 'Missing container error. Can not get previous item in missing container. ' + e; |
62 | | - } |
63 | | -}; |
64 | | - |
65 | | -/** |
66 | | - * Gets the next item in container. |
67 | | - * |
68 | | - * @method |
69 | | - * @returns {Object} Next item, or null if none exists |
70 | | - * @throws Missing container error if getting the next item item failed |
71 | | - */ |
72 | | -es.ContainerItem.prototype.next = function() { |
73 | | - try { |
74 | | - return this[this._containerName].get( this[this._containerName].indexOf( this ) + 1 ); |
75 | | - } catch ( e ) { |
76 | | - throw 'Missing container error. Can not get next item in missing container. ' + e; |
77 | | - } |
78 | | -}; |
79 | | - |
80 | | -/** |
81 | | - * Checks if this item is the first in it's container. |
82 | | - * |
83 | | - * @method |
84 | | - * @returns {Boolean} If item is the first in it's container |
85 | | - * @throws Missing container error if getting the index of this item failed |
86 | | - */ |
87 | | -es.ContainerItem.prototype.isFirst = function() { |
88 | | - try { |
89 | | - return this[this._containerName].indexOf( this ) === 0; |
90 | | - } catch ( e ) { |
91 | | - throw 'Missing container error. Can not get index of item in missing container. ' + e; |
92 | | - } |
93 | | -}; |
94 | | - |
95 | | -/** |
96 | | - * Checks if this item is the last in it's container. |
97 | | - * |
98 | | - * @method |
99 | | - * @returns {Boolean} If item is the last in it's container |
100 | | - * @throws Missing container error if getting the index of this item failed |
101 | | - */ |
102 | | -es.ContainerItem.prototype.isLast = function() { |
103 | | - try { |
104 | | - return this[this._containerName].indexOf( this ) |
105 | | - === this[this._containerName].getLength() - 1; |
106 | | - } catch ( e ) { |
107 | | - throw 'Missing container error. Can not get index of item in missing container. ' + e; |
108 | | - } |
109 | | -}; |
110 | | - |
111 | | -/* Inheritance */ |
112 | | - |
113 | | -es.extend( es.ContainerItem, es.EventEmitter ); |
Index: trunk/parsers/wikidom/lib/synth/bases/es.DomContainerItem.js |
— | — | @@ -1,25 +0,0 @@ |
2 | | -/** |
3 | | - * Generic synchronized Object/Element container item. |
4 | | - * |
5 | | - * @class |
6 | | - * @constructor |
7 | | - * @extends {es.EventEmitter} |
8 | | - * @param containerName {String} Name of container type |
9 | | - * @param typeName {String} Name to use in CSS classes and HTML element data |
10 | | - * @param tagName {String} HTML element name to use (optional, default: "div") |
11 | | - * @property $ {jQuery} Container element |
12 | | - */ |
13 | | -es.DomContainerItem = function( containerName, typeName, tagName ) { |
14 | | - if ( typeof tagName !== 'string' ) { |
15 | | - tagName = 'div'; |
16 | | - } |
17 | | - this.$ = $( '<' + tagName + '/>' ) |
18 | | - .addClass( 'editSurface-' + typeName ) |
19 | | - .data( typeName, this ); |
20 | | - |
21 | | - es.ContainerItem.call( this, containerName ); |
22 | | -}; |
23 | | - |
24 | | -/* Inheritance */ |
25 | | - |
26 | | -es.extend( es.DomContainerItem, es.ContainerItem ); |
Index: trunk/parsers/wikidom/lib/synth/bases/es.Container.js |
— | — | @@ -1,249 +0,0 @@ |
2 | | -/** |
3 | | - * Generic Object container. |
4 | | - * |
5 | | - * Child objects must extend es.ContainerItem. |
6 | | - * |
7 | | - * @class |
8 | | - * @constructor |
9 | | - * @extends {es.EventEmitter} |
10 | | - * @param listName {String} Property name for list of items |
11 | | - * @property [listName] {Array} list of items |
12 | | - */ |
13 | | -es.Container = function( listName ) { |
14 | | - es.EventEmitter.call( this ); |
15 | | - if ( typeof listName !== 'string' ) { |
16 | | - listName = 'items'; |
17 | | - } |
18 | | - this._listName = listName; |
19 | | - this[this._listName] = []; |
20 | | - var container = this; |
21 | | - this.relayUpdate = function() { |
22 | | - container.emit( 'update' ); |
23 | | - }; |
24 | | -}; |
25 | | - |
26 | | -/* Methods */ |
27 | | - |
28 | | -/** |
29 | | - * Gets an item at a specific index. |
30 | | - * |
31 | | - * @method |
32 | | - * @returns {Object} Child object at index |
33 | | - */ |
34 | | -es.Container.prototype.get = function( index ) { |
35 | | - return this[this._listName][index] || null; |
36 | | -}; |
37 | | - |
38 | | -/** |
39 | | - * Gets all items. |
40 | | - * |
41 | | - * @method |
42 | | - * @returns {Array} List of all items. |
43 | | - */ |
44 | | -es.Container.prototype.items = function() { |
45 | | - return this[this._listName]; |
46 | | -}; |
47 | | - |
48 | | -/** |
49 | | - * Gets the number of items in container. |
50 | | - * |
51 | | - * @method |
52 | | - * @returns {Integer} Number of items in container |
53 | | - */ |
54 | | -es.Container.prototype.getLength = function() { |
55 | | - return this[this._listName].length |
56 | | -}; |
57 | | - |
58 | | -/** |
59 | | - * Gets the index of an item. |
60 | | - * |
61 | | - * @method |
62 | | - * @returns {Integer} Index of item, -1 if item is not in container |
63 | | - */ |
64 | | -es.Container.prototype.indexOf = function( item ) { |
65 | | - return this[this._listName].indexOf( item ); |
66 | | -}; |
67 | | - |
68 | | -/** |
69 | | - * Gets the first item in the container. |
70 | | - * |
71 | | - * @method |
72 | | - * @returns {Object} First item |
73 | | - */ |
74 | | -es.Container.prototype.first = function() { |
75 | | - return this[this._listName].length ? this[this._listName][0] : null; |
76 | | -}; |
77 | | - |
78 | | -/** |
79 | | - * Gets the last item in the container. |
80 | | - * |
81 | | - * @method |
82 | | - * @returns {Object} Last item |
83 | | - */ |
84 | | -es.Container.prototype.last = function() { |
85 | | - return this[this._listName].length |
86 | | - ? this[this._listName][this[this._listName].length - 1] : null; |
87 | | -}; |
88 | | - |
89 | | -/** |
90 | | - * Iterates over items, executing a callback for each. |
91 | | - * |
92 | | - * Returning false in the callback will stop iteration. |
93 | | - * |
94 | | - * @method |
95 | | - * @param callback {Function} Function to call on each item which takes item and index arguments |
96 | | - */ |
97 | | -es.Container.prototype.each = function( callback ) { |
98 | | - for ( var i = 0; i < this[this._listName].length; i++ ) { |
99 | | - if ( callback( this[this._listName][i], i ) === false ) { |
100 | | - break; |
101 | | - } |
102 | | - } |
103 | | -}; |
104 | | - |
105 | | -/** |
106 | | - * Adds an item to the end of the container. |
107 | | - * |
108 | | - * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
109 | | - * |
110 | | - * @method |
111 | | - * @param item {Object} Item to append |
112 | | - * @emits "update" |
113 | | - */ |
114 | | -es.Container.prototype.append = function( item ) { |
115 | | - var parent = item.parent(); |
116 | | - if ( parent === this ) { |
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 ); |
127 | | - } |
128 | | - this.emit( 'append', item ); |
129 | | - this.emit( 'update' ); |
130 | | -}; |
131 | | - |
132 | | -/** |
133 | | - * Adds an item to the beginning of the container. |
134 | | - * |
135 | | - * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
136 | | - * |
137 | | - * @method |
138 | | - * @param item {Object} Item to prepend |
139 | | - * @emits "update" |
140 | | - */ |
141 | | -es.Container.prototype.prepend = function( item ) { |
142 | | - var parent = item.parent(); |
143 | | - if ( parent === this ) { |
144 | | - 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 ); |
154 | | - } |
155 | | - this.emit( 'prepend', item ); |
156 | | - this.emit( 'update' ); |
157 | | -}; |
158 | | - |
159 | | -/** |
160 | | - * Adds an item to the container after an existing item. |
161 | | - * |
162 | | - * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
163 | | - * |
164 | | - * @method |
165 | | - * @param item {Object} Item to insert |
166 | | - * @param before {Object} Item to insert before, if null then item will be inserted at the end |
167 | | - * @emits "update" |
168 | | - */ |
169 | | -es.Container.prototype.insertBefore = function( item, before ) { |
170 | | - var parent = item.parent(); |
171 | | - if ( parent === this ) { |
172 | | - 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 | | - } |
178 | | - } 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 ); |
190 | | - } |
191 | | - this.emit( 'insertBefore', item, before ); |
192 | | - this.emit( 'update' ); |
193 | | -}; |
194 | | - |
195 | | -/** |
196 | | - * Adds an item to the container after an existing item. |
197 | | - * |
198 | | - * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
199 | | - * |
200 | | - * @method |
201 | | - * @param item {Object} Item to insert |
202 | | - * @param after {Object} Item to insert after, if null item will be inserted at the end |
203 | | - * @emits "update" |
204 | | - */ |
205 | | -es.Container.prototype.insertAfter = function( item, after ) { |
206 | | - var parent = item.parent(); |
207 | | - if ( parent === this ) { |
208 | | - 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 | | - } |
214 | | - } 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 ); |
226 | | - } |
227 | | - this.emit( 'insertAfter', item, after ); |
228 | | - this.emit( 'update' ); |
229 | | -}; |
230 | | - |
231 | | -/** |
232 | | - * Removes an item from the container. |
233 | | - * |
234 | | - * Also detaches item's Element object to the DOM and removes all listeners its "update" events. |
235 | | - * |
236 | | - * @method |
237 | | - * @param item {Object} Item to remove |
238 | | - * @emits "update" |
239 | | - */ |
240 | | -es.Container.prototype.remove = function( item ) { |
241 | | - item.removeListener( 'update', this.relayUpdate ); |
242 | | - this[this._listName].splice( this.indexOf( item ), 1 ); |
243 | | - item.detach(); |
244 | | - this.emit( 'remove', item ); |
245 | | - this.emit( 'update' ); |
246 | | -}; |
247 | | - |
248 | | -/* Inheritance */ |
249 | | - |
250 | | -es.extend( es.Container, es.EventEmitter ); |
Index: trunk/parsers/wikidom/lib/synth/bases/es.DomContainer.js |
— | — | @@ -1,49 +0,0 @@ |
2 | | -/** |
3 | | - * Generic synchronized Object/Element container. |
4 | | - * |
5 | | - * Items must extend es.DomContainerItem. |
6 | | - * |
7 | | - * @class |
8 | | - * @constructor |
9 | | - * @extends {es.EventEmitter} |
10 | | - * @param listName {String} Property name for list of items |
11 | | - * @param typeName {String} Name to use in CSS classes and HTML element data |
12 | | - * @param tagName {String} HTML element name to use (optional, default: "div") |
13 | | - * @property $ {jQuery} Container element |
14 | | - */ |
15 | | -es.DomContainer = function( listName, typeName, tagName ) { |
16 | | - if ( typeof tagName !== 'string' ) { |
17 | | - tagName = 'div'; |
18 | | - } |
19 | | - this.$ = $( '<' + tagName + '/>' ) |
20 | | - .addClass( 'editSurface-' + typeName ) |
21 | | - .data( typeName, this ); |
22 | | - es.Container.call( this, listName ); |
23 | | - this.on( 'prepend', function( item ) { |
24 | | - this.$.prepend( item.$ ); |
25 | | - } ); |
26 | | - this.on( 'append', function( item ) { |
27 | | - this.$.append( item.$ ); |
28 | | - } ); |
29 | | - this.on( 'insertBefore', function( item, before ) { |
30 | | - if ( before ) { |
31 | | - item.$.insertBefore( before.$ ); |
32 | | - } else { |
33 | | - this.$.append( item.$ ); |
34 | | - } |
35 | | - } ); |
36 | | - this.on( 'insertAfter', function( item, after ) { |
37 | | - if ( after ) { |
38 | | - item.$.insertAfter( after.$ ); |
39 | | - } else { |
40 | | - this.$.append( item.$ ); |
41 | | - } |
42 | | - } ); |
43 | | - this.on( 'remove', function( item ) { |
44 | | - item.$.detach(); |
45 | | - } ); |
46 | | -}; |
47 | | - |
48 | | -/* Inheritance */ |
49 | | - |
50 | | -es.extend( es.DomContainer, es.Container ); |
Index: trunk/parsers/wikidom/lib/synth/bases/es.ContentSeries.js |
— | — | @@ -1,99 +0,0 @@ |
2 | | -/** |
3 | | - * Creates an es.ContentSeries object. |
4 | | - * |
5 | | - * A content series is an array of items which have a getLength method. |
6 | | - */ |
7 | | -es.ContentSeries = function( items ) { |
8 | | - var series = items || []; |
9 | | - $.extend( series, this ); |
10 | | - return series; |
11 | | -}; |
12 | | - |
13 | | -es.ContentSeries.prototype.lookup = function( offset ) { |
14 | | - if ( this.length ) { |
15 | | - var i = 0, |
16 | | - length = this.length, |
17 | | - left = 0, |
18 | | - right; |
19 | | - while ( i < length ) { |
20 | | - right = left + this[i].getLength() + 1; |
21 | | - if ( offset >= left && offset < right ) { |
22 | | - return this[i]; |
23 | | - } |
24 | | - left = right; |
25 | | - i++; |
26 | | - } |
27 | | - } |
28 | | - return null; |
29 | | -}; |
30 | | - |
31 | | -es.ContentSeries.prototype.rangeOf = function( item ) { |
32 | | - if ( this.length ) { |
33 | | - var i = 0, |
34 | | - length = this.length, |
35 | | - left = 0; |
36 | | - while ( i < length ) { |
37 | | - if ( this[i] === item ) { |
38 | | - return new es.Range( left, left + this[i].getLength() ); |
39 | | - } |
40 | | - left += this[i].getLength() + 1; |
41 | | - i++; |
42 | | - } |
43 | | - } |
44 | | - return null; |
45 | | -}; |
46 | | - |
47 | | -es.ContentSeries.prototype.getLengthOfItems = function() { |
48 | | - var sum = 0; |
49 | | - for ( var i = 0, length = this.length; i < length; i++ ) { |
50 | | - sum += this[i].getLength(); |
51 | | - } |
52 | | - return Math.max( 0, sum + this.length - 1 ); |
53 | | -}; |
54 | | - |
55 | | -es.ContentSeries.prototype.select = function( start, end ) { |
56 | | - // Support es.Range object as first argument |
57 | | - if ( typeof start.from === 'number' && typeof start.to === 'number') { |
58 | | - start.normalize(); |
59 | | - end = start.end; |
60 | | - start = start.start; |
61 | | - } |
62 | | - var items = []; |
63 | | - if ( this.length ) { |
64 | | - var i = 0, |
65 | | - length = this.length, |
66 | | - left = 0, |
67 | | - right, |
68 | | - inside = false, |
69 | | - from, |
70 | | - to; |
71 | | - while ( i < length ) { |
72 | | - right = left + this[i].getLength() + 1; |
73 | | - if ( inside ) { |
74 | | - // Append items until we reach the end |
75 | | - from = 0; |
76 | | - to = Math.min( right - left - 1, end - left ); |
77 | | - if ( from !== to ) { |
78 | | - items.push( { 'item': this[i], 'from': from, 'to': to } ); |
79 | | - } |
80 | | - if ( end >= left && end < right ) { |
81 | | - break; |
82 | | - } |
83 | | - } else if ( start >= left && start < right ) { |
84 | | - inside = true; |
85 | | - // Append first item |
86 | | - from = start - left; |
87 | | - to = Math.min( right - 1, end - left ); |
88 | | - if ( from !== to ) { |
89 | | - items.push( { 'item': this[i], 'from': from, 'to': to } ); |
90 | | - } |
91 | | - if ( right >= end ) { |
92 | | - break; |
93 | | - } |
94 | | - } |
95 | | - left = right; |
96 | | - i++; |
97 | | - } |
98 | | - } |
99 | | - return items; |
100 | | -}; |
Index: trunk/parsers/wikidom/lib/synth/bases/es.ModelContainerItem.js |
— | — | @@ -0,0 +1,112 @@ |
| 2 | +/** |
| 3 | + * Creates an es.ModelContainerItem object. |
| 4 | + * |
| 5 | + * @class |
| 6 | + * @constructor |
| 7 | + * @extends {es.EventEmitter} |
| 8 | + * @param containerName {String} Name of container type |
| 9 | + * @property [containerName] {Object} Reference to container, if attached |
| 10 | + */ |
| 11 | +es.ModelContainerItem = function( containerName ) { |
| 12 | + es.EventEmitter.call( this ); |
| 13 | + if ( typeof containerName !== 'string' ) { |
| 14 | + containerName = 'container'; |
| 15 | + } |
| 16 | + this._containerName = containerName; |
| 17 | + this[this._containerName] = null; |
| 18 | +}; |
| 19 | + |
| 20 | +/* Methods */ |
| 21 | + |
| 22 | +es.ModelContainerItem.prototype.parent = function() { |
| 23 | + return this[this._containerName]; |
| 24 | +}; |
| 25 | + |
| 26 | +/** |
| 27 | + * Attaches item to a container. |
| 28 | + * |
| 29 | + * @method |
| 30 | + * @param container {es.Container} Container to attach to |
| 31 | + * @emits "attach" with container argument |
| 32 | + */ |
| 33 | +es.ModelContainerItem.prototype.attach = function( container ) { |
| 34 | + this[this._containerName] = container; |
| 35 | + this.emit( 'attach', container ); |
| 36 | +}; |
| 37 | + |
| 38 | +/** |
| 39 | + * Detaches item from a container. |
| 40 | + * |
| 41 | + * @method |
| 42 | + * @emits "detach" with container argument |
| 43 | + */ |
| 44 | +es.ModelContainerItem.prototype.detach = function() { |
| 45 | + var container = this[this._containerName]; |
| 46 | + this[this._containerName] = null; |
| 47 | + this.emit( 'detach', container ); |
| 48 | +}; |
| 49 | + |
| 50 | +/** |
| 51 | + * Gets the previous item in container. |
| 52 | + * |
| 53 | + * @method |
| 54 | + * @returns {Object} Previous item, or null if none exists |
| 55 | + * @throws Missing container error if getting the previous item item failed |
| 56 | + */ |
| 57 | +es.ModelContainerItem.prototype.previous = function() { |
| 58 | + try { |
| 59 | + return this[this._containerName].get( this[this._containerName].indexOf( this ) - 1 ); |
| 60 | + } catch ( e ) { |
| 61 | + throw 'Missing container error. Can not get previous item in missing container. ' + e; |
| 62 | + } |
| 63 | +}; |
| 64 | + |
| 65 | +/** |
| 66 | + * Gets the next item in container. |
| 67 | + * |
| 68 | + * @method |
| 69 | + * @returns {Object} Next item, or null if none exists |
| 70 | + * @throws Missing container error if getting the next item item failed |
| 71 | + */ |
| 72 | +es.ModelContainerItem.prototype.next = function() { |
| 73 | + try { |
| 74 | + return this[this._containerName].get( this[this._containerName].indexOf( this ) + 1 ); |
| 75 | + } catch ( e ) { |
| 76 | + throw 'Missing container error. Can not get next item in missing container. ' + e; |
| 77 | + } |
| 78 | +}; |
| 79 | + |
| 80 | +/** |
| 81 | + * Checks if this item is the first in it's container. |
| 82 | + * |
| 83 | + * @method |
| 84 | + * @returns {Boolean} If item is the first in it's container |
| 85 | + * @throws Missing container error if getting the index of this item failed |
| 86 | + */ |
| 87 | +es.ModelContainerItem.prototype.isFirst = function() { |
| 88 | + try { |
| 89 | + return this[this._containerName].indexOf( this ) === 0; |
| 90 | + } catch ( e ) { |
| 91 | + throw 'Missing container error. Can not get index of item in missing container. ' + e; |
| 92 | + } |
| 93 | +}; |
| 94 | + |
| 95 | +/** |
| 96 | + * Checks if this item is the last in it's container. |
| 97 | + * |
| 98 | + * @method |
| 99 | + * @returns {Boolean} If item is the last in it's container |
| 100 | + * @throws Missing container error if getting the index of this item failed |
| 101 | + */ |
| 102 | +es.ModelContainerItem.prototype.isLast = function() { |
| 103 | + try { |
| 104 | + return this[this._containerName].indexOf( this ) |
| 105 | + === this[this._containerName].getLength() - 1; |
| 106 | + } catch ( e ) { |
| 107 | + throw 'Missing container error. Can not get index of item in missing container. ' + e; |
| 108 | + } |
| 109 | +}; |
| 110 | + |
| 111 | +/* Inheritance */ |
| 112 | + |
| 113 | +es.extend( es.ModelContainerItem, es.EventEmitter ); |
Property changes on: trunk/parsers/wikidom/lib/synth/bases/es.ModelContainerItem.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 114 | + native |
Added: svn:mime-type |
2 | 115 | + text/plain |
Index: trunk/parsers/wikidom/lib/synth/bases/es.ModelContainer.js |
— | — | @@ -0,0 +1,249 @@ |
| 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 | + * @param listName {String} Property name for list of items |
| 11 | + * @property [listName] {Array} list of items |
| 12 | + */ |
| 13 | +es.ModelContainer = function( listName ) { |
| 14 | + es.EventEmitter.call( this ); |
| 15 | + if ( typeof listName !== 'string' ) { |
| 16 | + listName = 'items'; |
| 17 | + } |
| 18 | + this._listName = listName; |
| 19 | + this[this._listName] = []; |
| 20 | + var container = this; |
| 21 | + this.relayUpdate = function() { |
| 22 | + container.emit( 'update' ); |
| 23 | + }; |
| 24 | +}; |
| 25 | + |
| 26 | +/* Methods */ |
| 27 | + |
| 28 | +/** |
| 29 | + * Gets an item at a specific index. |
| 30 | + * |
| 31 | + * @method |
| 32 | + * @returns {Object} Child object at index |
| 33 | + */ |
| 34 | +es.ModelContainer.prototype.get = function( index ) { |
| 35 | + return this[this._listName][index] || null; |
| 36 | +}; |
| 37 | + |
| 38 | +/** |
| 39 | + * Gets all items. |
| 40 | + * |
| 41 | + * @method |
| 42 | + * @returns {Array} List of all items. |
| 43 | + */ |
| 44 | +es.ModelContainer.prototype.items = function() { |
| 45 | + return this[this._listName]; |
| 46 | +}; |
| 47 | + |
| 48 | +/** |
| 49 | + * Gets the number of items in container. |
| 50 | + * |
| 51 | + * @method |
| 52 | + * @returns {Integer} Number of items in container |
| 53 | + */ |
| 54 | +es.ModelContainer.prototype.getLength = function() { |
| 55 | + return this[this._listName].length |
| 56 | +}; |
| 57 | + |
| 58 | +/** |
| 59 | + * Gets the index of an item. |
| 60 | + * |
| 61 | + * @method |
| 62 | + * @returns {Integer} Index of item, -1 if item is not in container |
| 63 | + */ |
| 64 | +es.ModelContainer.prototype.indexOf = function( item ) { |
| 65 | + return this[this._listName].indexOf( item ); |
| 66 | +}; |
| 67 | + |
| 68 | +/** |
| 69 | + * Gets the first item in the container. |
| 70 | + * |
| 71 | + * @method |
| 72 | + * @returns {Object} First item |
| 73 | + */ |
| 74 | +es.ModelContainer.prototype.first = function() { |
| 75 | + return this[this._listName].length ? this[this._listName][0] : null; |
| 76 | +}; |
| 77 | + |
| 78 | +/** |
| 79 | + * Gets the last item in the container. |
| 80 | + * |
| 81 | + * @method |
| 82 | + * @returns {Object} Last item |
| 83 | + */ |
| 84 | +es.ModelContainer.prototype.last = function() { |
| 85 | + return this[this._listName].length |
| 86 | + ? this[this._listName][this[this._listName].length - 1] : null; |
| 87 | +}; |
| 88 | + |
| 89 | +/** |
| 90 | + * Iterates over items, executing a callback for each. |
| 91 | + * |
| 92 | + * Returning false in the callback will stop iteration. |
| 93 | + * |
| 94 | + * @method |
| 95 | + * @param callback {Function} Function to call on each item which takes item and index arguments |
| 96 | + */ |
| 97 | +es.ModelContainer.prototype.each = function( callback ) { |
| 98 | + for ( var i = 0; i < this[this._listName].length; i++ ) { |
| 99 | + if ( callback( this[this._listName][i], i ) === false ) { |
| 100 | + break; |
| 101 | + } |
| 102 | + } |
| 103 | +}; |
| 104 | + |
| 105 | +/** |
| 106 | + * Adds an item to the end of the container. |
| 107 | + * |
| 108 | + * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
| 109 | + * |
| 110 | + * @method |
| 111 | + * @param item {Object} Item to append |
| 112 | + * @emits "update" |
| 113 | + */ |
| 114 | +es.ModelContainer.prototype.append = function( item ) { |
| 115 | + var parent = item.parent(); |
| 116 | + if ( parent === this ) { |
| 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 ); |
| 127 | + } |
| 128 | + this.emit( 'append', item ); |
| 129 | + this.emit( 'update' ); |
| 130 | +}; |
| 131 | + |
| 132 | +/** |
| 133 | + * Adds an item to the beginning of the container. |
| 134 | + * |
| 135 | + * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
| 136 | + * |
| 137 | + * @method |
| 138 | + * @param item {Object} Item to prepend |
| 139 | + * @emits "update" |
| 140 | + */ |
| 141 | +es.ModelContainer.prototype.prepend = function( item ) { |
| 142 | + var parent = item.parent(); |
| 143 | + if ( parent === this ) { |
| 144 | + 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 ); |
| 154 | + } |
| 155 | + this.emit( 'prepend', item ); |
| 156 | + this.emit( 'update' ); |
| 157 | +}; |
| 158 | + |
| 159 | +/** |
| 160 | + * Adds an item to the container after an existing item. |
| 161 | + * |
| 162 | + * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
| 163 | + * |
| 164 | + * @method |
| 165 | + * @param item {Object} Item to insert |
| 166 | + * @param before {Object} Item to insert before, if null then item will be inserted at the end |
| 167 | + * @emits "update" |
| 168 | + */ |
| 169 | +es.ModelContainer.prototype.insertBefore = function( item, before ) { |
| 170 | + var parent = item.parent(); |
| 171 | + if ( parent === this ) { |
| 172 | + 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 | + } |
| 178 | + } 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 ); |
| 190 | + } |
| 191 | + this.emit( 'insertBefore', item, before ); |
| 192 | + this.emit( 'update' ); |
| 193 | +}; |
| 194 | + |
| 195 | +/** |
| 196 | + * Adds an item to the container after an existing item. |
| 197 | + * |
| 198 | + * Also inserts item's Element object to the DOM and adds a listener to its "update" events. |
| 199 | + * |
| 200 | + * @method |
| 201 | + * @param item {Object} Item to insert |
| 202 | + * @param after {Object} Item to insert after, if null item will be inserted at the end |
| 203 | + * @emits "update" |
| 204 | + */ |
| 205 | +es.ModelContainer.prototype.insertAfter = function( item, after ) { |
| 206 | + var parent = item.parent(); |
| 207 | + if ( parent === this ) { |
| 208 | + 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 | + } |
| 214 | + } 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 ); |
| 226 | + } |
| 227 | + this.emit( 'insertAfter', item, after ); |
| 228 | + this.emit( 'update' ); |
| 229 | +}; |
| 230 | + |
| 231 | +/** |
| 232 | + * Removes an item from the container. |
| 233 | + * |
| 234 | + * Also detaches item's Element object to the DOM and removes all listeners its "update" events. |
| 235 | + * |
| 236 | + * @method |
| 237 | + * @param item {Object} Item to remove |
| 238 | + * @emits "update" |
| 239 | + */ |
| 240 | +es.ModelContainer.prototype.remove = function( item ) { |
| 241 | + item.removeListener( 'update', this.relayUpdate ); |
| 242 | + this[this._listName].splice( this.indexOf( item ), 1 ); |
| 243 | + item.detach(); |
| 244 | + this.emit( 'remove', item ); |
| 245 | + this.emit( 'update' ); |
| 246 | +}; |
| 247 | + |
| 248 | +/* Inheritance */ |
| 249 | + |
| 250 | +es.extend( es.ModelContainer, es.EventEmitter ); |
Property changes on: trunk/parsers/wikidom/lib/synth/bases/es.ModelContainer.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 251 | + native |
Added: svn:mime-type |
2 | 252 | + text/plain |
Index: trunk/parsers/wikidom/lib/synth/bases/es.AggregateArray.js |
— | — | @@ -0,0 +1,99 @@ |
| 2 | +/** |
| 3 | + * Creates an es.AggregateArray object. |
| 4 | + * |
| 5 | + * A content series is an array of items which have a getLength method. |
| 6 | + */ |
| 7 | +es.AggregateArray = function( items ) { |
| 8 | + var series = items || []; |
| 9 | + $.extend( series, this ); |
| 10 | + return series; |
| 11 | +}; |
| 12 | + |
| 13 | +es.AggregateArray.prototype.lookup = function( offset ) { |
| 14 | + if ( this.length ) { |
| 15 | + var i = 0, |
| 16 | + length = this.length, |
| 17 | + left = 0, |
| 18 | + right; |
| 19 | + while ( i < length ) { |
| 20 | + right = left + this[i].getLength() + 1; |
| 21 | + if ( offset >= left && offset < right ) { |
| 22 | + return this[i]; |
| 23 | + } |
| 24 | + left = right; |
| 25 | + i++; |
| 26 | + } |
| 27 | + } |
| 28 | + return null; |
| 29 | +}; |
| 30 | + |
| 31 | +es.AggregateArray.prototype.rangeOf = function( item ) { |
| 32 | + if ( this.length ) { |
| 33 | + var i = 0, |
| 34 | + length = this.length, |
| 35 | + left = 0; |
| 36 | + while ( i < length ) { |
| 37 | + if ( this[i] === item ) { |
| 38 | + return new es.Range( left, left + this[i].getLength() ); |
| 39 | + } |
| 40 | + left += this[i].getLength() + 1; |
| 41 | + i++; |
| 42 | + } |
| 43 | + } |
| 44 | + return null; |
| 45 | +}; |
| 46 | + |
| 47 | +es.AggregateArray.prototype.getLengthOfItems = function() { |
| 48 | + var sum = 0; |
| 49 | + for ( var i = 0, length = this.length; i < length; i++ ) { |
| 50 | + sum += this[i].getLength(); |
| 51 | + } |
| 52 | + return Math.max( 0, sum + this.length - 1 ); |
| 53 | +}; |
| 54 | + |
| 55 | +es.AggregateArray.prototype.select = function( start, end ) { |
| 56 | + // Support es.Range object as first argument |
| 57 | + if ( typeof start.from === 'number' && typeof start.to === 'number') { |
| 58 | + start.normalize(); |
| 59 | + end = start.end; |
| 60 | + start = start.start; |
| 61 | + } |
| 62 | + var items = []; |
| 63 | + if ( this.length ) { |
| 64 | + var i = 0, |
| 65 | + length = this.length, |
| 66 | + left = 0, |
| 67 | + right, |
| 68 | + inside = false, |
| 69 | + from, |
| 70 | + to; |
| 71 | + while ( i < length ) { |
| 72 | + right = left + this[i].getLength() + 1; |
| 73 | + if ( inside ) { |
| 74 | + // Append items until we reach the end |
| 75 | + from = 0; |
| 76 | + to = Math.min( right - left - 1, end - left ); |
| 77 | + if ( from !== to ) { |
| 78 | + items.push( { 'item': this[i], 'from': from, 'to': to } ); |
| 79 | + } |
| 80 | + if ( end >= left && end < right ) { |
| 81 | + break; |
| 82 | + } |
| 83 | + } else if ( start >= left && start < right ) { |
| 84 | + inside = true; |
| 85 | + // Append first item |
| 86 | + from = start - left; |
| 87 | + to = Math.min( right - 1, end - left ); |
| 88 | + if ( from !== to ) { |
| 89 | + items.push( { 'item': this[i], 'from': from, 'to': to } ); |
| 90 | + } |
| 91 | + if ( right >= end ) { |
| 92 | + break; |
| 93 | + } |
| 94 | + } |
| 95 | + left = right; |
| 96 | + i++; |
| 97 | + } |
| 98 | + } |
| 99 | + return items; |
| 100 | +}; |
Property changes on: trunk/parsers/wikidom/lib/synth/bases/es.AggregateArray.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 101 | + native |
Added: svn:mime-type |
2 | 102 | + text/plain |
Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainerItem.js |
— | — | @@ -0,0 +1,28 @@ |
| 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 tagName !== 'string' ) { |
| 16 | + tagName = 'div'; |
| 17 | + } |
| 18 | + this.$ = $( '<' + tagName + '/>' ) |
| 19 | + .addClass( 'editSurface-' + typeName ) |
| 20 | + .data( typeName, this ); |
| 21 | +}; |
| 22 | + |
| 23 | +es.ViewContainerItem.prototype.getModel = function() { |
| 24 | + return this.model; |
| 25 | +}; |
| 26 | + |
| 27 | +/* Inheritance */ |
| 28 | + |
| 29 | +es.extend( es.ViewContainerItem, es.EventEmitter ); |
Property changes on: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainerItem.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 30 | + native |
Added: svn:mime-type |
2 | 31 | + text/plain |
Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js |
— | — | @@ -0,0 +1,91 @@ |
| 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 containerModel {es.ModelContainer} Property name for list of items |
| 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 views {Array} List of views, correlating to models in the model container |
| 16 | + */ |
| 17 | +es.ViewContainer = function( containerModel, typeName, tagName ) { |
| 18 | + es.EventEmitter.call( this ); |
| 19 | + this.containerModel = containerModel; |
| 20 | + this.views = []; |
| 21 | + if ( typeof tagName !== 'string' ) { |
| 22 | + tagName = 'div'; |
| 23 | + } |
| 24 | + this.$ = $( '<' + tagName + '/>' ) |
| 25 | + .addClass( 'editSurface-' + typeName ) |
| 26 | + .data( typeName, this ); |
| 27 | + var container = this; |
| 28 | + this.containerModel.on( 'prepend', function( itemModel ) { |
| 29 | + var itemView = container.createItem( itemModel ); |
| 30 | + container.views.unshift( itemView ); |
| 31 | + container.$.prepend( itemView.$ ); |
| 32 | + container.emit( 'prepend', itemView ); |
| 33 | + container.emit( 'update' ); |
| 34 | + } ); |
| 35 | + this.containerModel.on( 'append', function( itemModel ) { |
| 36 | + var itemView = container.createItem( itemModel ); |
| 37 | + container.views.push( itemView ); |
| 38 | + container.$.append( itemView.$ ); |
| 39 | + container.emit( 'append', itemView ); |
| 40 | + container.emit( 'update' ); |
| 41 | + } ); |
| 42 | + this.containerModel.on( 'insertBefore', function( item, before ) { |
| 43 | + var itemView = container.createItemView( item ), |
| 44 | + beforeView = container.lookupItemView( before ); |
| 45 | + if ( beforeView ) { |
| 46 | + container.views.splice( container.views.indexOf( beforeView ), 0, itemView ); |
| 47 | + itemView.$.insertBefore( beforeView.$ ); |
| 48 | + } else { |
| 49 | + container.views.unshift( itemView ); |
| 50 | + container.$.prepend( itemView.$ ); |
| 51 | + } |
| 52 | + container.emit( 'insertBefore', itemView, beforeView ); |
| 53 | + container.emit( 'update' ); |
| 54 | + } ); |
| 55 | + this.containerModel.on( 'insertAfter', function( itemModel, afterModel ) { |
| 56 | + var itemView = container.createItemView( item ), |
| 57 | + afterView = container.lookupItemView( afterModel ); |
| 58 | + if ( afterView ) { |
| 59 | + container.views.splice( container.views.indexOf( afterView ) + 1, 0, itemView ); |
| 60 | + itemView.$.insertAfter( afterView.$ ); |
| 61 | + } else { |
| 62 | + container.views.push( itemView ); |
| 63 | + container.$.append( itemView.$ ); |
| 64 | + } |
| 65 | + container.emit( 'insertAfter', itemView, afterView ); |
| 66 | + container.emit( 'update' ); |
| 67 | + } ); |
| 68 | + this.containerModel.on( 'remove', function( itemModel ) { |
| 69 | + var itemView = container.lookupItemView( itemModel ); |
| 70 | + container.views.splice( container.views.indexOf( itemView ), 1 ); |
| 71 | + itemView.$.detach(); |
| 72 | + container.emit( 'remove', itemView ); |
| 73 | + container.emit( 'update' ); |
| 74 | + } ); |
| 75 | +}; |
| 76 | + |
| 77 | +es.ViewContainer.prototype.lookupItemView = function( itemModel ) { |
| 78 | + for ( var i = 0; i < container.views.length; i++ ) { |
| 79 | + if ( this.views[i].getModel() === itemModel ) { |
| 80 | + return container.views[i]; |
| 81 | + } |
| 82 | + } |
| 83 | + return null; |
| 84 | +}; |
| 85 | + |
| 86 | +es.ViewContainer.prototype.createItemView = function( itemModel ) { |
| 87 | + throw 'es.ViewContainer.createItem not implemented in this subclass'; |
| 88 | +}; |
| 89 | + |
| 90 | +/* Inheritance */ |
| 91 | + |
| 92 | +es.extend( es.ViewContainer, es.EventEmitter ); |
Property changes on: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 93 | + native |
Added: svn:mime-type |
2 | 94 | + text/plain |