Index: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js |
— | — | @@ -184,20 +184,20 @@ |
185 | 185 | * This is a node tree that describes each partition within the document's content data. |
186 | 186 | */ |
187 | 187 | var tree = [ |
188 | | - new es.ParagraphModel( 3 ), |
189 | | - new es.TableModel( [ |
190 | | - new es.TableRowModel( [ |
191 | | - new es.TableCellModel( [ |
192 | | - new es.ParagraphModel( 1 ), |
193 | | - new es.ListModel( [ |
194 | | - new es.ListItemModel( 1 ), |
195 | | - new es.ListItemModel( 1 ), |
196 | | - new es.ListItemModel( 1 ) |
| 188 | + new es.ParagraphModel( data[0], 3 ), |
| 189 | + new es.TableModel( data[5], [ |
| 190 | + new es.TableRowModel( data[6], [ |
| 191 | + new es.TableCellModel( data[7], [ |
| 192 | + new es.ParagraphModel( data[8], 1 ), |
| 193 | + new es.ListModel( data[11], [ |
| 194 | + new es.ListItemModel( data[12], 1 ), |
| 195 | + new es.ListItemModel( data[15], 1 ), |
| 196 | + new es.ListItemModel( data[18], 1 ) |
197 | 197 | ] ) |
198 | 198 | ] ) |
199 | 199 | ] ) |
200 | 200 | ] ), |
201 | | - new es.ParagraphModel( 1 ) |
| 201 | + new es.ParagraphModel( data[25], 1 ) |
202 | 202 | ]; |
203 | 203 | |
204 | 204 | test( 'es.DocumentModel', function() { |
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | */ |
13 | 13 | es.DocumentModel = function( data, attributes ) { |
14 | 14 | // Inheritance |
15 | | - var node = $.extend( new es.DocumentModelNode( length ), this ); |
| 15 | + var node = $.extend( new es.DocumentModelNode( null, length ), this ); |
16 | 16 | |
17 | 17 | // Properties |
18 | 18 | node.data = $.isArray( data ) ? data : []; |
— | — | @@ -20,9 +20,10 @@ |
21 | 21 | // Build a tree of models, which is a space partitioning data structure |
22 | 22 | var currentNode = node; |
23 | 23 | for ( var i = 0, length = node.data.length; i < length; i++ ) { |
24 | | - if ( node.data[i].type !== undefined ) { |
| 24 | + if ( data[i].type !== undefined ) { |
25 | 25 | // It's an element, figure out it's type |
26 | | - var type = node.data[i].type, |
| 26 | + var element = node.data[i], |
| 27 | + type = element.type, |
27 | 28 | open = type[0] !== '/'; |
28 | 29 | // Trim the "/" off the beginning of closing tag types |
29 | 30 | if ( !open ) { |
— | — | @@ -34,7 +35,7 @@ |
35 | 36 | throw 'Unsuported element error. No class registered for element type: ' + type; |
36 | 37 | } |
37 | 38 | // Create a model node for the element |
38 | | - var newNode = new es.DocumentModel.nodeModels[node.data[i].type](); |
| 39 | + var newNode = new es.DocumentModel.nodeModels[element.type]( element ); |
39 | 40 | // Add the new model node as a child |
40 | 41 | currentNode.push( newNode ); |
41 | 42 | // Descend into the new model node |
— | — | @@ -47,7 +48,7 @@ |
48 | 49 | // It's content, let's start tracking the length |
49 | 50 | var start = i; |
50 | 51 | // Move forward to the next object, tracking the length as we go |
51 | | - while ( node.data[i].type === undefined && i < length ) { |
| 52 | + while ( data[i].type === undefined && i < length ) { |
52 | 53 | i++; |
53 | 54 | } |
54 | 55 | // Now we know how long the current node is |
— | — | @@ -57,6 +58,8 @@ |
58 | 59 | } |
59 | 60 | } |
60 | 61 | |
| 62 | + console.dir( node ); |
| 63 | + |
61 | 64 | return node; |
62 | 65 | }; |
63 | 66 | |
— | — | @@ -174,7 +177,7 @@ |
175 | 178 | } |
176 | 179 | target.splice( index, 1 ); |
177 | 180 | } |
178 | | - }; |
| 181 | + } |
179 | 182 | |
180 | 183 | return { |
181 | 184 | // Retain |
Index: trunk/parsers/wikidom/lib/hype/models/es.TableRowModel.js |
— | — | @@ -4,9 +4,9 @@ |
5 | 5 | * @class |
6 | 6 | * @constructor |
7 | 7 | */ |
8 | | -es.TableRowModel = function( length ) { |
| 8 | +es.TableRowModel = function( element, length ) { |
9 | 9 | // Extension |
10 | | - return $.extend( new es.DocumentModelNode( length ), this ); |
| 10 | + return $.extend( new es.DocumentModelNode( element, length ), this ); |
11 | 11 | }; |
12 | 12 | |
13 | 13 | /* Methods */ |
Index: trunk/parsers/wikidom/lib/hype/models/es.ParagraphModel.js |
— | — | @@ -4,9 +4,9 @@ |
5 | 5 | * @class |
6 | 6 | * @constructor |
7 | 7 | */ |
8 | | -es.ParagraphModel = function( length ) { |
| 8 | +es.ParagraphModel = function( element, length ) { |
9 | 9 | // Extension |
10 | | - return $.extend( new es.DocumentModelNode( length ), this ); |
| 10 | + return $.extend( new es.DocumentModelNode( element, length ), this ); |
11 | 11 | }; |
12 | 12 | |
13 | 13 | /* Methods */ |
Index: trunk/parsers/wikidom/lib/hype/models/es.TableCellModel.js |
— | — | @@ -4,9 +4,9 @@ |
5 | 5 | * @class |
6 | 6 | * @constructor |
7 | 7 | */ |
8 | | -es.TableCellModel = function( length ) { |
| 8 | +es.TableCellModel = function( element, length ) { |
9 | 9 | // Extension |
10 | | - return $.extend( new es.DocumentModelNode( length ), this ); |
| 10 | + return $.extend( new es.DocumentModelNode( element, length ), this ); |
11 | 11 | }; |
12 | 12 | |
13 | 13 | /* Methods */ |
Index: trunk/parsers/wikidom/lib/hype/models/es.TableModel.js |
— | — | @@ -4,9 +4,9 @@ |
5 | 5 | * @class |
6 | 6 | * @constructor |
7 | 7 | */ |
8 | | -es.TableModel = function( length ) { |
| 8 | +es.TableModel = function( element, length ) { |
9 | 9 | // Extension |
10 | | - return $.extend( new es.DocumentModelNode( length ), this ); |
| 10 | + return $.extend( new es.DocumentModelNode( element, length ), this ); |
11 | 11 | }; |
12 | 12 | |
13 | 13 | /* Methods */ |
Index: trunk/parsers/wikidom/lib/hype/models/es.ListItemModel.js |
— | — | @@ -4,9 +4,9 @@ |
5 | 5 | * @class |
6 | 6 | * @constructor |
7 | 7 | */ |
8 | | -es.ListItemModel = function( length ) { |
| 8 | +es.ListItemModel = function( element, length ) { |
9 | 9 | // Extension |
10 | | - return $.extend( new es.DocumentModelNode( length ), this ); |
| 10 | + return $.extend( new es.DocumentModelNode( element, length ), this ); |
11 | 11 | }; |
12 | 12 | |
13 | 13 | /* Methods */ |
Index: trunk/parsers/wikidom/lib/hype/models/es.ListModel.js |
— | — | @@ -4,9 +4,9 @@ |
5 | 5 | * @class |
6 | 6 | * @constructor |
7 | 7 | */ |
8 | | -es.ListModel = function( length ) { |
| 8 | +es.ListModel = function( element, length ) { |
9 | 9 | // Extension |
10 | | - return $.extend( new es.DocumentModelNode( length ), this ); |
| 10 | + return $.extend( new es.DocumentModelNode( element, length ), this ); |
11 | 11 | }; |
12 | 12 | |
13 | 13 | /* Methods */ |
Index: trunk/parsers/wikidom/lib/hype/bases/es.DocumentModelNode.js |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | * @param {Integer|Array} contents Either Length of content or array of child nodes to append |
11 | 11 | * @property {Integer} contentLength Length of content |
12 | 12 | */ |
13 | | -es.DocumentModelNode = function( contents ) { |
| 13 | +es.DocumentModelNode = function( element, contents ) { |
14 | 14 | // Extension |
15 | 15 | var node = $.extend( new es.ModelNode(), this ); |
16 | 16 | |
— | — | @@ -23,6 +23,7 @@ |
24 | 24 | } ); |
25 | 25 | |
26 | 26 | // Properties |
| 27 | + node.element = element || null; |
27 | 28 | node.contentLength = 0; |
28 | 29 | if ( typeof contents === 'number' ) { |
29 | 30 | if ( contents < 0 ) { |
— | — | @@ -129,6 +130,16 @@ |
130 | 131 | }; |
131 | 132 | |
132 | 133 | /** |
| 134 | + * Gets the element object. |
| 135 | + * |
| 136 | + * @method |
| 137 | + * @returns {Object} Element object in linear data model |
| 138 | + */ |
| 139 | +es.DocumentModelNode.prototype.getElement = function() { |
| 140 | + return this.element; |
| 141 | +}; |
| 142 | + |
| 143 | +/** |
133 | 144 | * Gets the content length. |
134 | 145 | * |
135 | 146 | * FIXME: This method makes assumptions that a node with a data property is a DocumentModel, which |