r96077 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96076‎ | r96077 | r96078 >
Date:01:20, 2 September 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Renamed some things and rewrote DomContainer to be a ViewContainer which stalks a ModelContainer and mimics it's structure
Modified paths:
  • /trunk/parsers/wikidom/lib/synth/bases/es.AggregateArray.js (added) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.Container.js (deleted) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.ContainerItem.js (deleted) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.ContentSeries.js (deleted) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.DomContainer.js (deleted) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.DomContainerItem.js (deleted) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.ModelContainer.js (added) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.ModelContainerItem.js (added) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js (added) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.ViewContainerItem.js (added) (history)
  • /trunk/parsers/wikidom/lib/synth/controllers/es.DocumentController.js (modified) (history)
  • /trunk/parsers/wikidom/tests/synth/index.html (modified) (history)
  • /trunk/parsers/wikidom/tests/synth/test.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/synth/index.html
@@ -12,9 +12,9 @@
1313 <ol id="qunit-tests"></ol>
1414 <script src="../../lib/synth/es.js"></script>
1515 <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>
1919 <script src="../../lib/synth/es.Range.js"></script>
2020 <script src="../../lib/jquery.js"></script>
2121 <script src="../../lib/qunit.js"></script>
Index: trunk/parsers/wikidom/tests/synth/test.js
@@ -1,10 +1,10 @@
22 module( 'Base classes' );
33
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' );
99
1010 var updates = 0;
1111 container1.on( 'update', function( item ) {
@@ -13,9 +13,9 @@
1414
1515 // Creating
1616
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' );
2020
2121 strictEqual( item1.a, null, 'Item container name can be specialized' );
2222 strictEqual( item2.b, null, 'Item container name can be specialized' );
@@ -24,32 +24,32 @@
2525 // Adding
2626
2727 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' );
3030 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' );
3333 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' );
3636
3737 // Accessing
3838
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' )
4040
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' );
4545
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' );
5050
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' );
5454
5555 // Iterating
5656
@@ -59,9 +59,9 @@
6060 items.push( item );
6161 indexes.push( index );
6262 } );
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' );
6666
6767 var count = 0;
6868 container1.each( function( item, index ) {
@@ -70,88 +70,88 @@
7171 return false;
7272 }
7373 } );
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' )
7575
7676 // Updating
7777
7878 updates = 0;
7979
8080 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' );
8282 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' );
8484 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' );
8686
8787 // Removing
8888
8989 updates = 0;
9090
9191 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' );
9494
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' );
9696
9797 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' );
100100
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' );
104104
105105 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' );
108108
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' );
112112
113113 updates = 0;
114114
115115 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' );
117117 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' );
119119 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' );
121121
122122 // Inserting
123123
124124 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' );
126126 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' );
128128 container1.insertBefore( item2, item1 );
129129 deepEqual(
130130 container1.items(),
131131 [item3, item2, item1],
132 - 'es.Container.insertBefore inserts item before another'
 132+ 'es.ModelContainer.insertBefore inserts item before another'
133133 );
134134 container1.insertBefore( item2, item3 );
135135 deepEqual(
136136 container1.items(),
137137 [item2, item3, item1],
138 - 'es.Container.insertBefore moves item before another'
 138+ 'es.ModelContainer.insertBefore moves item before another'
139139 );
140140
141141 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' );
143143 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' );
145145 container2.insertAfter( item2, item1 );
146146 deepEqual(
147147 container2.items(),
148148 [item1, item2, item3],
149 - 'es.Container.insertAfter inserts item after another'
 149+ 'es.ModelContainer.insertAfter inserts item after another'
150150 );
151151 container2.insertAfter( item1, item2 );
152152 deepEqual(
153153 container2.items(),
154154 [item2, item1, item3],
155 - 'es.Container.insertAfter moves item after another'
 155+ 'es.ModelContainer.insertAfter moves item after another'
156156 );
157157
158158 // TODO: Events for appending, prepending, inserting and removing
@@ -166,7 +166,7 @@
167167 return this.size;
168168 };
169169
170 -test( 'ContentSeries', function() {
 170+test( 'es.AggregateArray', function() {
171171 strictEqual(
172172 ( new ContentStub( 'a', 0 ) ).getLength(),
173173 0,
@@ -177,7 +177,7 @@
178178 c = new ContentStub( 'c', 2 ),
179179 d = new ContentStub( 'd', 3 ),
180180 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] );
182182
183183 var lengthOfItemsTests = [
184184 { 'input': [], 'output': 0 },
@@ -190,9 +190,9 @@
191191
192192 for ( var i = 0; i < lengthOfItemsTests.length; i++ ) {
193193 strictEqual(
194 - ( new es.ContentSeries( lengthOfItemsTests[i].input ) ).getLengthOfItems(),
 194+ ( new es.AggregateArray( lengthOfItemsTests[i].input ) ).getLengthOfItems(),
195195 lengthOfItemsTests[i].output,
196 - 'es.ContentSeries.getLengthOfItems returns correct value'
 196+ 'es.AggregateArray.getLengthOfItems returns correct value'
197197 );
198198 }
199199
@@ -220,7 +220,7 @@
221221 strictEqual(
222222 contentSeries1.lookup( lookupTests[i].input ),
223223 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'
225225 );
226226 }
227227
@@ -237,14 +237,14 @@
238238 deepEqual(
239239 contentSeries1.rangeOf( rangeOfTests[i].input ),
240240 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'
242242 );
243243 }
244244
245245 var f = new ContentStub( 'f', 10 ),
246246 g = new ContentStub( 'g', 10 ),
247247 h = new ContentStub( 'h', 10 ),
248 - contentSeries2 = new es.ContentSeries( [f, g, h] );
 248+ contentSeries2 = new es.AggregateArray( [f, g, h] );
249249 var selectTests = [
250250 {
251251 'input': [0, 5],
@@ -316,7 +316,7 @@
317317 deepEqual(
318318 contentSeries2.select.apply( contentSeries2, selectTests[i].input ),
319319 selectTests[i].output,
320 - 'es.ContentSeries.select returns the correct items and ranges.'
 320+ 'es.AggregateArray.select returns the correct items and ranges.'
321321 );
322322 }
323323 } );
Index: trunk/parsers/wikidom/lib/synth/controllers/es.DocumentController.js
@@ -21,27 +21,3 @@
2222 es.DocumentController.prototype.prepareAnnotateContent = function( range, annotation ) {
2323 // generate transaction
2424 };
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
1114 + native
Added: svn:mime-type
2115 + 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
1251 + native
Added: svn:mime-type
2252 + 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
1101 + native
Added: svn:mime-type
2102 + 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
130 + native
Added: svn:mime-type
231 + 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
193 + native
Added: svn:mime-type
294 + text/plain

Status & tagging log