Index: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | var obj = { |
24 | 24 | 'type': 'document', |
25 | 25 | 'children': [ |
26 | | - { |
| 26 | + { |
27 | 27 | 'type': 'paragraph', |
28 | 28 | 'content': { |
29 | 29 | 'text': 'abc', |
— | — | @@ -49,51 +49,51 @@ |
50 | 50 | { |
51 | 51 | 'type': 'tableCell', |
52 | 52 | 'children': [ |
53 | | - { |
54 | | - 'type': 'paragraph', |
55 | | - 'content': { |
56 | | - 'text': 'a' |
57 | | - } |
58 | | - }, |
59 | | - { |
60 | | - 'type': 'list', |
61 | | - 'children': [ |
62 | | - { |
63 | | - 'type': 'listItem', |
64 | | - 'attributes': { |
65 | | - 'styles': ['bullet'] |
66 | | - }, |
67 | | - 'content': { |
68 | | - 'text': 'a' |
69 | | - } |
70 | | - }, |
71 | | - { |
72 | | - 'type': 'listItem', |
73 | | - 'attributes': { |
74 | | - 'styles': ['bullet', 'bullet'] |
75 | | - }, |
76 | | - 'content': { |
77 | | - 'text': 'b' |
78 | | - } |
79 | | - }, |
80 | | - { |
81 | | - 'type': 'listItem', |
82 | | - 'attributes': { |
83 | | - 'styles': ['number'] |
84 | | - }, |
85 | | - 'content': { |
86 | | - 'text': 'c' |
87 | | - } |
88 | | - } |
89 | | - ] |
90 | | - } |
91 | | - ] |
| 53 | + { |
| 54 | + 'type': 'paragraph', |
| 55 | + 'content': { |
| 56 | + 'text': 'a' |
| 57 | + } |
| 58 | + }, |
| 59 | + { |
| 60 | + 'type': 'list', |
| 61 | + 'children': [ |
| 62 | + { |
| 63 | + 'type': 'listItem', |
| 64 | + 'attributes': { |
| 65 | + 'styles': ['bullet'] |
| 66 | + }, |
| 67 | + 'content': { |
| 68 | + 'text': 'a' |
| 69 | + } |
| 70 | + }, |
| 71 | + { |
| 72 | + 'type': 'listItem', |
| 73 | + 'attributes': { |
| 74 | + 'styles': ['bullet', 'bullet'] |
| 75 | + }, |
| 76 | + 'content': { |
| 77 | + 'text': 'b' |
| 78 | + } |
| 79 | + }, |
| 80 | + { |
| 81 | + 'type': 'listItem', |
| 82 | + 'attributes': { |
| 83 | + 'styles': ['number'] |
| 84 | + }, |
| 85 | + 'content': { |
| 86 | + 'text': 'c' |
| 87 | + } |
| 88 | + } |
| 89 | + ] |
| 90 | + } |
| 91 | + ] |
92 | 92 | } |
93 | 93 | ] |
94 | 94 | } |
95 | 95 | ] |
96 | 96 | }, |
97 | | - { |
| 97 | + { |
98 | 98 | 'type': 'paragraph', |
99 | 99 | 'content': { |
100 | 100 | 'text': 'a' |
— | — | @@ -120,8 +120,8 @@ |
121 | 121 | * [attributes]: {Object} List of symbolic attribute name and literal value pairs |
122 | 122 | */ |
123 | 123 | var data = [ |
124 | | - // 0 - Beginning of paragraph |
125 | | - { 'type': 'paragraph' }, |
| 124 | + // 0 - Beginning of paragraph |
| 125 | + { 'type': 'paragraph' }, |
126 | 126 | // 1 - Plain content |
127 | 127 | 'a', |
128 | 128 | // 2 - Annotated content |
— | — | @@ -130,39 +130,39 @@ |
131 | 131 | ['c', { 'type': 'italic', 'hash': '#italic' }], |
132 | 132 | // 4 - End of paragraph |
133 | 133 | { 'type': '/paragraph' }, |
134 | | - // 5 - Beginning of table |
| 134 | + // 5 - Beginning of table |
135 | 135 | { 'type': 'table' }, |
136 | | - // 6 - Beginning of row |
| 136 | + // 6 - Beginning of row |
137 | 137 | { 'type': 'tableRow' }, |
138 | | - // 7 - Beginning of cell |
| 138 | + // 7 - Beginning of cell |
139 | 139 | { 'type': 'tableCell' }, |
140 | | - // 8 - Beginning of paragraph |
| 140 | + // 8 - Beginning of paragraph |
141 | 141 | { 'type': 'paragraph' }, |
142 | 142 | // 9 - Plain content |
143 | 143 | 'a', |
144 | | - // 10 - End of paragraph |
| 144 | + // 10 - End of paragraph |
145 | 145 | { 'type': '/paragraph' }, |
146 | | - // 11 - Beginning of list |
| 146 | + // 11 - Beginning of list |
147 | 147 | { 'type': 'list' }, |
148 | | - // 12 - Beginning of bullet list item |
| 148 | + // 12 - Beginning of bullet list item |
149 | 149 | { 'type': 'listItem', 'attributes': { 'styles': ['bullet'] } }, |
150 | 150 | // 13 - Plain content |
151 | 151 | 'a', |
152 | | - // 14 - End of item |
| 152 | + // 14 - End of item |
153 | 153 | { 'type': '/listItem' }, |
154 | | - // 15 - Beginning of nested bullet list item |
| 154 | + // 15 - Beginning of nested bullet list item |
155 | 155 | { 'type': 'listItem', 'attributes': { 'styles': ['bullet', 'bullet'] } }, |
156 | 156 | // 16 - Plain content |
157 | 157 | 'b', |
158 | | - // 17 - End of item |
| 158 | + // 17 - End of item |
159 | 159 | { 'type': '/listItem' }, |
160 | | - // 18 - Beginning of numbered list item |
| 160 | + // 18 - Beginning of numbered list item |
161 | 161 | { 'type': 'listItem', 'attributes': { 'styles': ['number'] } }, |
162 | 162 | // 19 - Plain content |
163 | 163 | 'c', |
164 | | - // 20 - End of item |
| 164 | + // 20 - End of item |
165 | 165 | { 'type': '/listItem' }, |
166 | | - // 21 - End of list |
| 166 | + // 21 - End of list |
167 | 167 | { 'type': '/list' }, |
168 | 168 | // 22 - End of cell |
169 | 169 | { 'type': '/tableCell' }, |
— | — | @@ -170,11 +170,11 @@ |
171 | 171 | { 'type': '/tableRow' }, |
172 | 172 | // 24 - End of table |
173 | 173 | { 'type': '/table' }, |
174 | | - // 25 - Beginning of paragraph |
| 174 | + // 25 - Beginning of paragraph |
175 | 175 | { 'type': 'paragraph' }, |
176 | 176 | // 26 - Plain content |
177 | 177 | 'a', |
178 | | - // 27 - End of paragraph |
| 178 | + // 27 - End of paragraph |
179 | 179 | { 'type': '/paragraph' } |
180 | 180 | ]; |
181 | 181 | |
— | — | @@ -231,13 +231,13 @@ |
232 | 232 | |
233 | 233 | try { |
234 | 234 | documentModel[0].getContent( new es.Range( -1, 3 ) ); |
235 | | - } catch ( err ) { |
| 235 | + } catch ( negativeIndexError ) { |
236 | 236 | ok( true, 'getContent throws exceptions when given a range with start < 0' ); |
237 | 237 | } |
238 | 238 | |
239 | 239 | try { |
240 | 240 | documentModel[0].getContent( new es.Range( 0, 4 ) ); |
241 | | - } catch ( err ) { |
| 241 | + } catch ( outOfRangeError ) { |
242 | 242 | ok( true, 'getContent throws exceptions when given a range with end > length' ); |
243 | 243 | } |
244 | 244 | |
— | — | @@ -286,8 +286,8 @@ |
287 | 287 | ); |
288 | 288 | |
289 | 289 | try { |
290 | | - documentModel.prepareElementAttributeChange( 1, 'set', 'test', 1234 ) |
291 | | - } catch ( err ) { |
| 290 | + documentModel.prepareElementAttributeChange( 1, 'set', 'test', 1234 ); |
| 291 | + } catch ( invalidOffsetError ) { |
292 | 292 | ok( |
293 | 293 | true, |
294 | 294 | 'prepareElementAttributeChange throws an exception when offset is not an element' |
— | — | @@ -295,8 +295,8 @@ |
296 | 296 | } |
297 | 297 | |
298 | 298 | try { |
299 | | - documentModel.prepareElementAttributeChange( 4, 'set', 'test', 1234 ) |
300 | | - } catch ( err ) { |
| 299 | + documentModel.prepareElementAttributeChange( 4, 'set', 'test', 1234 ); |
| 300 | + } catch ( closingElementError ) { |
301 | 301 | ok( |
302 | 302 | true, |
303 | 303 | 'prepareElementAttributeChange throws an exception when offset is a closing element' |
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js |
— | — | @@ -114,7 +114,7 @@ |
115 | 115 | } |
116 | 116 | // Automatically clean up attributes object |
117 | 117 | var empty = true; |
118 | | - for ( key in element.attributes ) { |
| 118 | + for ( var key in element.attributes ) { |
119 | 119 | empty = false; |
120 | 120 | break; |
121 | 121 | } |
— | — | @@ -127,11 +127,15 @@ |
128 | 128 | } |
129 | 129 | |
130 | 130 | function annotate( to ) { |
| 131 | + var i, |
| 132 | + j, |
| 133 | + length, |
| 134 | + annotation; |
131 | 135 | // Handle annotations |
132 | 136 | if ( this.set.length ) { |
133 | | - for ( var i = 0, length = this.set.length; i < length; i++ ) { |
134 | | - var annotation = this.set[i]; |
135 | | - for ( var j = this.cursor; j < to; j++ ) { |
| 137 | + for ( i = 0, length = this.set.length; i < length; i++ ) { |
| 138 | + annotation = this.set[i]; |
| 139 | + for ( j = this.cursor; j < to; j++ ) { |
136 | 140 | if ( $.isArray( this.data[j] ) ) { |
137 | 141 | this.data[j].push( annotation ); |
138 | 142 | } else { |
— | — | @@ -143,9 +147,9 @@ |
144 | 148 | } |
145 | 149 | } |
146 | 150 | if ( this.clear.length ) { |
147 | | - for ( var i = 0, length = this.clear.length; i < length; i++ ) { |
148 | | - var annotation = this.clear[i]; |
149 | | - for ( var j = this.cursor; j < to; j++ ) { |
| 151 | + for ( i = 0, length = this.clear.length; i < length; i++ ) { |
| 152 | + annotation = this.clear[i]; |
| 153 | + for ( j = this.cursor; j < to; j++ ) { |
150 | 154 | var index = es.DocumentModel.getIndexOfAnnotation( this.data[j], annotation ); |
151 | 155 | if ( index !== -1 ) { |
152 | 156 | this.data[j].splice( index, 1 ); |
— | — | @@ -261,7 +265,7 @@ |
262 | 266 | |
263 | 267 | es.DocumentModel.getIndexOfAnnotation = function( character, annotation ) { |
264 | 268 | if ( annotation === undefined || annotation.type === undefined ) { |
265 | | - throw 'Invalid annotation error. Can not find non-annotation data in character.' |
| 269 | + throw 'Invalid annotation error. Can not find non-annotation data in character.'; |
266 | 270 | } |
267 | 271 | if ( $.isArray( character ) ) { |
268 | 272 | // Find the index of a comparable annotation (checking for same value, not reference) |
— | — | @@ -333,7 +337,9 @@ |
334 | 338 | } |
335 | 339 | for ( var j = src.start; j < src.end; j++ ) { |
336 | 340 | // Auto-convert to array |
337 | | - typeof data[j] === 'string' && ( data[j] = [data[j]] ); |
| 341 | + if ( typeof data[j] === 'string' ) { |
| 342 | + data[j] = [data[j]]; |
| 343 | + } |
338 | 344 | // Append |
339 | 345 | data[j].push( dst ); |
340 | 346 | } |
— | — | @@ -424,7 +430,7 @@ |
425 | 431 | */ |
426 | 432 | es.DocumentModel.prototype.getData = function( range, deep ) { |
427 | 433 | var start = 0, |
428 | | - end = undefined; |
| 434 | + end; |
429 | 435 | if ( range !== undefined ) { |
430 | 436 | range.normalize(); |
431 | 437 | start = Math.max( 0, Math.min( this.data.length, range.start ) ); |
— | — | @@ -481,8 +487,8 @@ |
482 | 488 | for ( var i = 0, length = this.length; i < length; i++ ) { |
483 | 489 | nodeLength = this[i].getElementLength(); |
484 | 490 | if ( offset >= nodeOffset && offset < nodeOffset + nodeLength ) { |
485 | | - return this[i].length |
486 | | - ? es.DocumentModel.prototype.getNode.call( this[i], offset - nodeOffset ) : this[i]; |
| 491 | + return this[i].length ? |
| 492 | + es.DocumentModel.prototype.getNode.call( this[i], offset - nodeOffset ) : this[i]; |
487 | 493 | } |
488 | 494 | nodeOffset += nodeLength; |
489 | 495 | } |
— | — | @@ -525,7 +531,7 @@ |
526 | 532 | range = { |
527 | 533 | 'start': 0, |
528 | 534 | 'end': length |
529 | | - } |
| 535 | + }; |
530 | 536 | } |
531 | 537 | var offset = this.getOffsetFromNode( node ); |
532 | 538 | if ( offset !== -1 ) { |
— | — | @@ -583,7 +589,6 @@ |
584 | 590 | * } |
585 | 591 | * } |
586 | 592 | */ |
587 | | - return tx; |
588 | 593 | }; |
589 | 594 | |
590 | 595 | /** |
— | — | @@ -718,10 +723,10 @@ |
719 | 724 | tx.pushRetain( offset ); |
720 | 725 | } |
721 | 726 | if ( this.data[offset].type === undefined ) { |
722 | | - throw 'Invalid element offset error. Can not set attributes to non-element data.' |
| 727 | + throw 'Invalid element offset error. Can not set attributes to non-element data.'; |
723 | 728 | } |
724 | 729 | if ( this.data[offset].type[0] === '/' ) { |
725 | | - throw 'Invalid element offset error. Can not set attributes on closing element.' |
| 730 | + throw 'Invalid element offset error. Can not set attributes on closing element.'; |
726 | 731 | } |
727 | 732 | tx.pushChangeElementAttribute( method, key, value ); |
728 | 733 | if ( offset < this.data.length ) { |