Index: trunk/parsers/wikidom/lib/hype/bases/es.DocumentModelNode.js |
— | — | @@ -1,10 +1,13 @@ |
2 | 2 | /** |
3 | 3 | * Creates an es.DocumentModelNode object. |
4 | 4 | * |
| 5 | + * es.DocumentModelNode is a simple wrapper around es.ModelNode, which adds functionality for model |
| 6 | + * nodes to be used as nodes in a space partitioning tree. |
| 7 | + * |
5 | 8 | * @class |
6 | 9 | * @constructor |
7 | | - * @param {Integer} contentLength Length of contents |
8 | | - * @property {Integer} contentLength Length of contents |
| 10 | + * @param {Integer} contentLength Length of content |
| 11 | + * @property {Integer} contentLength Length of content |
9 | 12 | */ |
10 | 13 | es.DocumentModelNode = function( contentLength ) { |
11 | 14 | // Inheritance |
— | — | @@ -16,6 +19,51 @@ |
17 | 20 | |
18 | 21 | /* Methods */ |
19 | 22 | |
| 23 | +/** |
| 24 | + * Sets the content length. |
| 25 | + * |
| 26 | + * @method |
| 27 | + * @param {Integer} contentLength Length of content |
| 28 | + * @throws Invalid content length error if contentLength is less than 0 |
| 29 | + */ |
| 30 | +es.DocumentModelNode.setContentLength = function( contentLength ) { |
| 31 | + if ( contentLength < 0 ) { |
| 32 | + throw 'Invalid content length error. Content length can not be less than 0.'; |
| 33 | + } |
| 34 | + var diff = contentLength - this.contentLength; |
| 35 | + this.contentLength = contentLength; |
| 36 | + if ( this.parent ) { |
| 37 | + this.parent.adjustContentLength( diff ); |
| 38 | + } |
| 39 | +}; |
| 40 | + |
| 41 | +/** |
| 42 | + * Adjust the content length. |
| 43 | + * |
| 44 | + * @method |
| 45 | + * @param {Integer} adjustment Amount to adjust content length by |
| 46 | + * @throws Invalid adjustment error if resulting length is less than 0 |
| 47 | + */ |
| 48 | +es.DocumentModelNode.adjustContentLength = function( adjustment ) { |
| 49 | + this.contentLength += adjustment; |
| 50 | + // Make sure the adjustment was sane |
| 51 | + if ( this.contentLength < 0 ) { |
| 52 | + // Reverse the adjustment |
| 53 | + this.contentLength -= adjustment; |
| 54 | + // Complain about it |
| 55 | + throw 'Invalid adjustment error. Content length can not be less than 0.'; |
| 56 | + } |
| 57 | + if ( this.parent ) { |
| 58 | + this.parent.adjustContentLength( adjustment ); |
| 59 | + } |
| 60 | +}; |
| 61 | + |
| 62 | +/** |
| 63 | + * Gets the content length. |
| 64 | + * |
| 65 | + * @method |
| 66 | + * @returns {Integer} Length of content |
| 67 | + */ |
20 | 68 | es.DocumentModelNode.getContentLength = function() { |
21 | 69 | return this.contentLength; |
22 | 70 | }; |