Index: trunk/parsers/wikidom/lib/es/es.js |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | /** |
3 | | - * EditSurafce namespace. |
| 3 | + * EditSurface namespace. |
4 | 4 | * |
5 | 5 | * All classes and functions will be attached to this object to keep the global namespace clean. |
6 | 6 | */ |
— | — | @@ -26,6 +26,8 @@ |
27 | 27 | * // Extend prototype |
28 | 28 | * extend( Bar, Foo ); |
29 | 29 | * |
| 30 | + * @static |
| 31 | + * @method |
30 | 32 | * @param dst {Function} Class to extend |
31 | 33 | * @param src {Function} Base class to use methods from |
32 | 34 | */ |
Index: trunk/parsers/wikidom/lib/es/es.Position.js |
— | — | @@ -18,53 +18,151 @@ |
19 | 19 | this.bottom = bottom || this.top; |
20 | 20 | }; |
21 | 21 | |
| 22 | +/* Static Methods */ |
| 23 | + |
| 24 | +/** |
| 25 | + * Creates position object from the screen position data in an Event object. |
| 26 | + * |
| 27 | + * @static |
| 28 | + * @method |
| 29 | + * @param event {Event} Event to get position data from |
| 30 | + * @returns {es.Position} Position with event data applied |
| 31 | + */ |
22 | 32 | es.Position.newFromEventScreenPosition = function( event ) { |
23 | 33 | return new es.Position( event.screenX, event.screenY ); |
24 | 34 | }; |
25 | 35 | |
| 36 | +/** |
| 37 | + * Creates position object from the page position data in an Event object. |
| 38 | + * |
| 39 | + * @static |
| 40 | + * @method |
| 41 | + * @param event {Event} Event to get position data from |
| 42 | + * @returns {es.Position} Position with event data applied |
| 43 | + */ |
26 | 44 | es.Position.newFromEventPagePosition = function( event ) { |
27 | 45 | return new es.Position( event.pageX, event.pageY ); |
28 | 46 | }; |
29 | 47 | |
| 48 | +/** |
| 49 | + * Creates position object from the layer position data in an Event object. |
| 50 | + * |
| 51 | + * @static |
| 52 | + * @method |
| 53 | + * @param event {Event} Event to get position data from |
| 54 | + * @returns {es.Position} Position with event data applied |
| 55 | + */ |
30 | 56 | es.Position.newFromEventLayerPosition = function( event ) { |
31 | 57 | return new es.Position( event.layerX, event.layerY ); |
32 | 58 | }; |
33 | 59 | |
| 60 | +/* Methods */ |
| 61 | + |
| 62 | +/** |
| 63 | + * Checks if this position is the same as another one. |
| 64 | + * |
| 65 | + * @method |
| 66 | + * @param position {es.Position} Position to compare with |
| 67 | + * @returns {Boolean} If positions have the same left and top values |
| 68 | + */ |
34 | 69 | es.Position.prototype.at = function( position ) { |
35 | 70 | return this.left === position.left && this.top === position.top; |
36 | 71 | }; |
37 | 72 | |
| 73 | +/** |
| 74 | + * Checks if this position perpendicular with another one, sharing either a top or left value. |
| 75 | + * |
| 76 | + * @method |
| 77 | + * @param position {es.Position} Position to compare with |
| 78 | + * @returns {Boolean} If positions share a top or a left value |
| 79 | + */ |
38 | 80 | es.Position.prototype.perpendicularWith = function( position ) { |
39 | 81 | return this.left === position.left || this.top === position.top; |
40 | 82 | }; |
41 | 83 | |
| 84 | +/** |
| 85 | + * Checks if this position is level with another one, having the same top value. |
| 86 | + * |
| 87 | + * @method |
| 88 | + * @param position {es.Position} Position to compare with |
| 89 | + * @returns {Boolean} If positions have the same top value |
| 90 | + */ |
42 | 91 | es.Position.prototype.levelWith = function( position ) { |
43 | 92 | return this.top === position.top; |
44 | 93 | }; |
45 | 94 | |
| 95 | +/** |
| 96 | + * Checks if this position is plumb with another one, having the same left value. |
| 97 | + * |
| 98 | + * @method |
| 99 | + * @param position {es.Position} Position to compare with |
| 100 | + * @returns {Boolean} If positions have the same left value |
| 101 | + */ |
46 | 102 | es.Position.prototype.plumbWith = function( position ) { |
47 | 103 | return this.left === position.left; |
48 | 104 | }; |
49 | 105 | |
50 | | -es.Position.prototype.near = function( position, range ) { |
| 106 | +/** |
| 107 | + * Checks if this position is nearby another one. |
| 108 | + * |
| 109 | + * Distance is measured radially. |
| 110 | + * |
| 111 | + * @method |
| 112 | + * @param position {es.Position} Position to compare with |
| 113 | + * @param radius {Integer} Pixel distance from this position to consider "near-by" |
| 114 | + * @returns {Boolean} If positions are near-by each other |
| 115 | + */ |
| 116 | +es.Position.prototype.near = function( position, radius ) { |
51 | 117 | return Math.sqrt( |
52 | 118 | Math.pow( this.left - position.left, 2 ), |
53 | 119 | Math.pow( this.top - position.top ) |
54 | | - ) <= range; |
| 120 | + ) <= radius; |
55 | 121 | }; |
56 | 122 | |
| 123 | +/** |
| 124 | + * Checks if this position is above another one. |
| 125 | + * |
| 126 | + * This method utilizes the bottom property. |
| 127 | + * |
| 128 | + * @method |
| 129 | + * @param position {es.Position} Position to compare with |
| 130 | + * @returns {Boolean} If this position is above the other |
| 131 | + */ |
57 | 132 | es.Position.prototype.above = function( position ) { |
58 | 133 | return this.bottom < position.top; |
59 | 134 | }; |
60 | 135 | |
| 136 | +/** |
| 137 | + * Checks if this position is below another one. |
| 138 | + * |
| 139 | + * This method utilizes the bottom property. |
| 140 | + * |
| 141 | + * @method |
| 142 | + * @param position {es.Position} Position to compare with |
| 143 | + * @returns {Boolean} If this position is below the other |
| 144 | + */ |
61 | 145 | es.Position.prototype.below = function( position ) { |
62 | 146 | return this.top > position.bottom; |
63 | 147 | }; |
64 | 148 | |
| 149 | +/** |
| 150 | + * Checks if this position is to the left of another one. |
| 151 | + * |
| 152 | + * @method |
| 153 | + * @param position {es.Position} Position to compare with |
| 154 | + * @returns {Boolean} If this position is the left the other |
| 155 | + */ |
65 | 156 | es.Position.prototype.leftOf = function( left ) { |
66 | 157 | return this.left < left; |
67 | 158 | }; |
68 | 159 | |
| 160 | +/** |
| 161 | + * Checks if this position is to the right of another one. |
| 162 | + * |
| 163 | + * @method |
| 164 | + * @param position {es.Position} Position to compare with |
| 165 | + * @returns {Boolean} If this position is the right the other |
| 166 | + */ |
69 | 167 | es.Position.prototype.rightOf = function( left ) { |
70 | 168 | return this.left > left; |
71 | 169 | }; |
Index: trunk/parsers/wikidom/lib/es/es.ListBlockItem.js |
— | — | @@ -5,18 +5,18 @@ |
6 | 6 | * @constructor |
7 | 7 | * @extends {es.EventEmitter} |
8 | 8 | * @extends {es.Container} |
9 | | - * @param line {es.Content} Item content |
| 9 | + * @param content {es.Content} Item content |
10 | 10 | * @param lists {Array} List of item sub-lists |
11 | | - * @property lists {Array} |
12 | | - * @property $line |
13 | | - * @property $content |
14 | | - * @property content |
15 | | - * @property flow |
| 11 | + * @property content {es.Content} Item content |
| 12 | + * @property lists {Array} List of item sub-lists |
| 13 | + * @property $line {jQuery} Line element |
| 14 | + * @property $content {jQuery} Content element |
| 15 | + * @property flow {es.TextFlow} Text flow object for content |
16 | 16 | */ |
17 | | -es.ListBlockItem = function( line, lists ) { |
| 17 | +es.ListBlockItem = function( content, lists ) { |
18 | 18 | es.EventEmitter.call( this ); |
19 | 19 | es.Container.call( this, 'item', 'lists', lists ); |
20 | | - this.content = line || new es.Content(); |
| 20 | + this.content = content || new es.Content(); |
21 | 21 | this.$line = $( '<div class="editSurface-list-line"></div>' ); |
22 | 22 | this.$content = $( '<div class="editSurface-list-content"></div>' ); |
23 | 23 | this.$.prepend( this.$line.append( this.$content ) ); |
— | — | @@ -29,15 +29,23 @@ |
30 | 30 | |
31 | 31 | /* Static Methods */ |
32 | 32 | |
33 | | -es.ListBlockItem.newFromWikiDomListItem = function( wikidomItem ) { |
| 33 | +/** |
| 34 | + * Creates an EditSurface list item object from a WikiDom list item object. |
| 35 | + * |
| 36 | + * @static |
| 37 | + * @method |
| 38 | + * @param wikidomListItem {Object} WikiDom list item |
| 39 | + * @returns {es.ListBlockItem} EditSurface list block item |
| 40 | + */ |
| 41 | +es.ListBlockItem.newFromWikiDomListItem = function( wikidomListItem ) { |
34 | 42 | // Convert items to es.ListBlockItem objects |
35 | 43 | var lists = []; |
36 | | - if ( wikidomItem.lists ) { |
37 | | - for ( var i = 0; i < wikidomItem.lists.length; i++ ) { |
38 | | - lists.push( es.ListBlockList.newFromWikiDomList( wikidomItem.lists[i] ) ); |
| 44 | + if ( wikidomListItem.lists ) { |
| 45 | + for ( var i = 0; i < wikidomListItem.lists.length; i++ ) { |
| 46 | + lists.push( es.ListBlockList.newFromWikiDomList( wikidomListItem.lists[i] ) ); |
39 | 47 | } |
40 | 48 | } |
41 | | - return new es.ListBlockItem( es.Content.newFromWikiDomLine( wikidomItem.line ), lists ); |
| 49 | + return new es.ListBlockItem( es.Content.newFromWikiDomLine( wikidomListItem.line ), lists ); |
42 | 50 | }; |
43 | 51 | |
44 | 52 | /* Methods */ |
— | — | @@ -45,12 +53,21 @@ |
46 | 54 | /** |
47 | 55 | * Gets the index of the item within it's list. |
48 | 56 | * |
| 57 | + * TODO: Move to es.Container |
| 58 | + * |
| 59 | + * @method |
49 | 60 | * @returns {Integer} Index of item |
50 | 61 | */ |
51 | 62 | es.ListBlockItem.prototype.getIndex = function() { |
52 | 63 | return this.list._list.indexOf( this ); |
53 | 64 | }; |
54 | 65 | |
| 66 | +/** |
| 67 | + * Gets the length of content in both the line and sub-lists. |
| 68 | + * |
| 69 | + * @method |
| 70 | + * @returns {Integer} Length of content |
| 71 | + */ |
55 | 72 | es.ListBlockItem.prototype.getLength = function() { |
56 | 73 | var length = this.content.getLength() + 1; |
57 | 74 | for ( var i = 0; i < this.lists.length; i++ ) { |
— | — | @@ -59,18 +76,23 @@ |
60 | 77 | return length; |
61 | 78 | }; |
62 | 79 | |
| 80 | +/** |
| 81 | + * Gets a location from an offset. |
| 82 | + * |
| 83 | + * @method |
| 84 | + * @param offset {Integer} Offset to get location for |
| 85 | + * @returns {Object} Location object with item and offset properties, where offset is local |
| 86 | + * to item. |
| 87 | + */ |
63 | 88 | es.ListBlockItem.prototype.getLocationFromOffset = function( offset ) { |
64 | 89 | var contentLength = this.content.getLength() + 1; |
65 | | - |
66 | 90 | if ( offset < contentLength ) { |
67 | 91 | return { |
68 | 92 | 'item': this, |
69 | 93 | 'offset': offset |
70 | 94 | }; |
71 | 95 | } |
72 | | - |
73 | 96 | offset -= contentLength; |
74 | | - |
75 | 97 | var listOffset = 0, |
76 | 98 | listLength; |
77 | 99 | for ( var i = 0; i < this.lists.length; i++ ) { |
— | — | @@ -82,6 +104,14 @@ |
83 | 105 | } |
84 | 106 | }; |
85 | 107 | |
| 108 | +/** |
| 109 | + * Gets an offset within the item from a position. |
| 110 | + * |
| 111 | + * @method |
| 112 | + * @param position {es.Position} Position to translate |
| 113 | + * @returns {Integer} Offset nearest position |
| 114 | + * @returns {Null} If offset could not be found |
| 115 | + */ |
86 | 116 | es.ListBlockItem.prototype.getOffsetFromPosition = function( position ) { |
87 | 117 | var itemOffset = this.$.offset(), |
88 | 118 | itemHeight = this.$.height(), |
— | — | @@ -97,7 +127,7 @@ |
98 | 128 | } |
99 | 129 | |
100 | 130 | for ( var i = 0; i < this.lists.length; i++ ) { |
101 | | - offset = this.lists[i].getOffsetFromPosition( position ); |
| 131 | + offset = this.lists[i].getOffsetFromPosition( position ); |
102 | 132 | if ( offset != null ) { |
103 | 133 | return globalOffset + offset + this.content.getLength() + 1; |
104 | 134 | } else { |
— | — | @@ -108,6 +138,12 @@ |
109 | 139 | return null; |
110 | 140 | }; |
111 | 141 | |
| 142 | +/** |
| 143 | + * Renders content and sub-lists. |
| 144 | + * |
| 145 | + * @method |
| 146 | + * @param offset {Integer} Offset to render from if possible |
| 147 | + */ |
112 | 148 | es.ListBlockItem.prototype.renderContent = function( offset ) { |
113 | 149 | // TODO: Abstract offset and use it when rendering |
114 | 150 | this.flow.render(); |
— | — | @@ -116,5 +152,7 @@ |
117 | 153 | } |
118 | 154 | }; |
119 | 155 | |
| 156 | +/* Inheritance */ |
| 157 | + |
120 | 158 | es.extend( es.ListBlockItem, es.EventEmitter ); |
121 | 159 | es.extend( es.ListBlockItem, es.Container ); |
Index: trunk/parsers/wikidom/lib/es/es.Content.js |
— | — | @@ -9,12 +9,12 @@ |
10 | 10 | * @class |
11 | 11 | * @constructor |
12 | 12 | * @extends {es.EventEmitter} |
13 | | - * @param content {Array} List of plain or annotated characters |
14 | | - * @property data {Array} |
| 13 | + * @param data {Array} List of plain or annotated characters |
| 14 | + * @property data {Array} List of plain or annotated characters |
15 | 15 | */ |
16 | | -es.Content = function( content ) { |
| 16 | +es.Content = function( data ) { |
17 | 17 | es.EventEmitter.call( this ); |
18 | | - this.data = content || []; |
| 18 | + this.data = data || []; |
19 | 19 | }; |
20 | 20 | |
21 | 21 | /* Static Members */ |
— | — | @@ -83,67 +83,12 @@ |
84 | 84 | /* Static Methods */ |
85 | 85 | |
86 | 86 | /** |
87 | | - * Recursively compares string and number property between two objects. |
88 | | - * |
89 | | - * A false result may be caused by property inequality or by properties in one object missing from |
90 | | - * the other. An asymmetrical test may also be performed, which checks only that properties in the |
91 | | - * first object are present in the second object, but not the inverse. |
92 | | - * |
93 | | - * @static |
94 | | - * @method |
95 | | - * @param a {Object} First object to compare |
96 | | - * @param b {Object} Second object to compare |
97 | | - * @param asymmetrical {Boolean} Whether to check only that b contains values from a |
98 | | - * @returns {Boolean} If the objects contain the same values as each other |
99 | | - */ |
100 | | -es.Content.compareObjects = function( a, b, asymmetrical ) { |
101 | | - var aValue, bValue, aType, bType; |
102 | | - var k; |
103 | | - for ( k in a ) { |
104 | | - aValue = a[k]; |
105 | | - bValue = b[k]; |
106 | | - aType = typeof aValue; |
107 | | - bType = typeof bValue; |
108 | | - if ( aType !== bType |
109 | | - || ( ( aType === 'string' || aType === 'number' ) && aValue !== bValue ) |
110 | | - || ( $.isPlainObject( aValue ) && !es.Content.compareObjects( aValue, bValue ) ) ) { |
111 | | - return false; |
112 | | - } |
113 | | - } |
114 | | - // If the check is not asymmetrical, recursing with the arguments swapped will verify our result |
115 | | - return asymmetrical ? true : es.Content.compareObjects( b, a, true ); |
116 | | -}; |
117 | | - |
118 | | -/** |
119 | | - * Gets a recursive copy of an object's string, number and plain-object property. |
120 | | - * |
121 | | - * @static |
122 | | - * @method |
123 | | - * @param source {Object} Object to copy |
124 | | - * @returns {Object} Copy of source object |
125 | | - */ |
126 | | -es.Content.copyObject = function( source ) { |
127 | | - var destination = {}; |
128 | | - var key; |
129 | | - for ( key in source ) { |
130 | | - sourceValue = source[key]; |
131 | | - sourceType = typeof sourceValue; |
132 | | - if ( sourceType === 'string' || sourceType === 'number' ) { |
133 | | - destination[key] = sourceValue; |
134 | | - } else if ( $.isPlainObject( sourceValue ) ) { |
135 | | - destination[key] = es.Content.copyObject( sourceValue ); |
136 | | - } |
137 | | - } |
138 | | - return destination; |
139 | | -}; |
140 | | - |
141 | | -/** |
142 | 87 | * Creates a new Content object from a WikiDom line object. |
143 | 88 | * |
144 | 89 | * @static |
145 | 90 | * @method |
146 | 91 | * @param wikidomLine {Object} WikiDom compatible line object - @see Content.convertLine |
147 | | - * @returns {es.Content} New content object containing data derived from the WikiDom line |
| 92 | + * @returns {es.Content} EditSurface content object containing data derived from the WikiDom line |
148 | 93 | */ |
149 | 94 | es.Content.newFromWikiDomLine = function( wikidomLine ) { |
150 | 95 | return new es.Content( es.Content.convertWikiDomLine( wikidomLine ) ); |
— | — | @@ -217,6 +162,61 @@ |
218 | 163 | }; |
219 | 164 | |
220 | 165 | /** |
| 166 | + * Recursively compares string and number property between two objects. |
| 167 | + * |
| 168 | + * A false result may be caused by property inequality or by properties in one object missing from |
| 169 | + * the other. An asymmetrical test may also be performed, which checks only that properties in the |
| 170 | + * first object are present in the second object, but not the inverse. |
| 171 | + * |
| 172 | + * @static |
| 173 | + * @method |
| 174 | + * @param a {Object} First object to compare |
| 175 | + * @param b {Object} Second object to compare |
| 176 | + * @param asymmetrical {Boolean} Whether to check only that b contains values from a |
| 177 | + * @returns {Boolean} If the objects contain the same values as each other |
| 178 | + */ |
| 179 | +es.Content.compareObjects = function( a, b, asymmetrical ) { |
| 180 | + var aValue, bValue, aType, bType; |
| 181 | + var k; |
| 182 | + for ( k in a ) { |
| 183 | + aValue = a[k]; |
| 184 | + bValue = b[k]; |
| 185 | + aType = typeof aValue; |
| 186 | + bType = typeof bValue; |
| 187 | + if ( aType !== bType |
| 188 | + || ( ( aType === 'string' || aType === 'number' ) && aValue !== bValue ) |
| 189 | + || ( $.isPlainObject( aValue ) && !es.Content.compareObjects( aValue, bValue ) ) ) { |
| 190 | + return false; |
| 191 | + } |
| 192 | + } |
| 193 | + // If the check is not asymmetrical, recursing with the arguments swapped will verify our result |
| 194 | + return asymmetrical ? true : es.Content.compareObjects( b, a, true ); |
| 195 | +}; |
| 196 | + |
| 197 | +/** |
| 198 | + * Gets a recursive copy of an object's string, number and plain-object property. |
| 199 | + * |
| 200 | + * @static |
| 201 | + * @method |
| 202 | + * @param source {Object} Object to copy |
| 203 | + * @returns {Object} Copy of source object |
| 204 | + */ |
| 205 | +es.Content.copyObject = function( source ) { |
| 206 | + var destination = {}; |
| 207 | + var key; |
| 208 | + for ( key in source ) { |
| 209 | + sourceValue = source[key]; |
| 210 | + sourceType = typeof sourceValue; |
| 211 | + if ( sourceType === 'string' || sourceType === 'number' ) { |
| 212 | + destination[key] = sourceValue; |
| 213 | + } else if ( $.isPlainObject( sourceValue ) ) { |
| 214 | + destination[key] = es.Content.copyObject( sourceValue ); |
| 215 | + } |
| 216 | + } |
| 217 | + return destination; |
| 218 | +}; |
| 219 | + |
| 220 | +/** |
221 | 221 | * Gets a rendered opening or closing of an annotation. |
222 | 222 | * |
223 | 223 | * Tag nesting is handled using a stack, which keeps track of what is currently open. A common stack |
— | — | @@ -294,7 +294,7 @@ |
295 | 295 | * @param start {Integer} Optional beginning of range, if omitted range will begin at 0 |
296 | 296 | * @param end {Integer} Optional end of range, if omitted range will end a this.data.length |
297 | 297 | * @param render {Boolean} If annotations should have any influence on output |
298 | | - * @returns {String} Plain text within given range |
| 298 | + * @returns {String} Text within given range |
299 | 299 | */ |
300 | 300 | es.Content.prototype.getText = function( range, render ) { |
301 | 301 | if ( !range ) { |
— | — | @@ -321,7 +321,7 @@ |
322 | 322 | * |
323 | 323 | * @method |
324 | 324 | * @param range {es.Range} Range of content to get |
325 | | - * @returns {es.Content} New content object |
| 325 | + * @returns {es.Content} New content object containing content within range |
326 | 326 | */ |
327 | 327 | es.Content.prototype.getContent = function( range ) { |
328 | 328 | if ( !range ) { |
— | — | @@ -623,7 +623,7 @@ |
624 | 624 | * @method |
625 | 625 | * @returns {Array} List of WikiDom line objects |
626 | 626 | */ |
627 | | -es.Content.prototype.getLines = function() { |
| 627 | +es.Content.prototype.getWikiDomLines = function() { |
628 | 628 | var lines = [], |
629 | 629 | right = '', |
630 | 630 | rightPlain, |
Index: trunk/parsers/wikidom/lib/es/es.EventEmitter.js |
— | — | @@ -9,6 +9,16 @@ |
10 | 10 | this.events = {}; |
11 | 11 | } |
12 | 12 | |
| 13 | +/* Methods */ |
| 14 | + |
| 15 | +/** |
| 16 | + * Emits an event. |
| 17 | + * |
| 18 | + * @method |
| 19 | + * @param type {String} Type of event |
| 20 | + * @param args {Mixed} First in a list of variadic arguments passed to event handler (optional) |
| 21 | + * @returns {Boolean} If event was handled by at least one listener |
| 22 | + */ |
13 | 23 | es.EventEmitter.prototype.emit = function( type ) { |
14 | 24 | if ( type === 'error' && !( 'error' in this.events ) ) { |
15 | 25 | throw 'Missing error handler error.'; |
— | — | @@ -24,6 +34,15 @@ |
25 | 35 | return true; |
26 | 36 | }; |
27 | 37 | |
| 38 | +/** |
| 39 | + * Adds a listener to events of a specific type. |
| 40 | + * |
| 41 | + * @method |
| 42 | + * @param type {String} Type of event to listen to |
| 43 | + * @param listener {Function} Listener to call when event occurs |
| 44 | + * @returns {es.EventEmitter} This object |
| 45 | + * @throws "Invalid listener error" if listener argument is not a function |
| 46 | + */ |
28 | 47 | es.EventEmitter.prototype.addListener = function( type, listener ) { |
29 | 48 | if ( typeof listener !== 'function' ) { |
30 | 49 | throw 'Invalid listener error. Function expected.'; |
— | — | @@ -37,18 +56,38 @@ |
38 | 57 | return this; |
39 | 58 | }; |
40 | 59 | |
41 | | -es.EventEmitter.prototype.on = function( type, listener ) { |
42 | | - this.addListener( type, listener ); |
43 | | -}; |
| 60 | +/** |
| 61 | + * Alias for addListener |
| 62 | + * |
| 63 | + * @method |
| 64 | + */ |
| 65 | +es.EventEmitter.prototype.on = es.EventEmitter.prototype.addListener; |
44 | 66 | |
| 67 | +/** |
| 68 | + * Adds a one-time listener to a specific event. |
| 69 | + * |
| 70 | + * @method |
| 71 | + * @param type {String} Type of event to listen to |
| 72 | + * @param listener {Function} Listener to call when event occurs |
| 73 | + * @returns {es.EventEmitter} This object |
| 74 | + */ |
45 | 75 | es.EventEmitter.prototype.once = function( type, listener ) { |
46 | | - var that = this; |
47 | | - this.addListener( type, function g() { |
48 | | - that.removeListener( type, g ); |
49 | | - listener.apply( that, arguments ); |
| 76 | + var eventEmitter = this; |
| 77 | + return this.addListener( type, function listenerWrapper() { |
| 78 | + that.removeListener( type, listenerWrapper ); |
| 79 | + listener.apply( eventEmitter, arguments ); |
50 | 80 | } ); |
51 | 81 | }; |
52 | 82 | |
| 83 | +/** |
| 84 | + * Removes a specific listener from a specific event. |
| 85 | + * |
| 86 | + * @method |
| 87 | + * @param type {String} Type of event to remove listener from |
| 88 | + * @param listener {Function} Listener to remove |
| 89 | + * @returns {es.EventEmitter} This object |
| 90 | + * @throws "Invalid listener error" if listener argument is not a function |
| 91 | + */ |
53 | 92 | es.EventEmitter.prototype.removeListener = function( type, listener ) { |
54 | 93 | if ( typeof listener !== 'function' ) { |
55 | 94 | throw 'Invalid listener error. Function expected.'; |
— | — | @@ -72,6 +111,13 @@ |
73 | 112 | return this; |
74 | 113 | }; |
75 | 114 | |
| 115 | +/** |
| 116 | + * Removes all listeners from a specific event. |
| 117 | + * |
| 118 | + * @method |
| 119 | + * @param type {String} Type of event to remove listeners from |
| 120 | + * @returns {es.EventEmitter} This object |
| 121 | + */ |
76 | 122 | es.EventEmitter.prototype.removeAllListeners = function( type ) { |
77 | 123 | if ( type in this.events ) { |
78 | 124 | delete this.events[type]; |
— | — | @@ -79,6 +125,13 @@ |
80 | 126 | return this; |
81 | 127 | }; |
82 | 128 | |
| 129 | +/** |
| 130 | + * Gets a list of listeners attached to a specific event. |
| 131 | + * |
| 132 | + * @method |
| 133 | + * @param type {String} Type of event to get listeners for |
| 134 | + * @returns {Array} List of listeners to an event |
| 135 | + */ |
83 | 136 | es.EventEmitter.prototype.listeners = function( type ) { |
84 | 137 | return type in this.events ? this.events[type] : []; |
85 | 138 | }; |
Index: trunk/parsers/wikidom/lib/es/es.Cursor.js |
— | — | @@ -3,17 +3,18 @@ |
4 | 4 | * |
5 | 5 | * @class |
6 | 6 | * @constructor |
7 | | - * @property cursorInterval {Interval} |
8 | | - * @property $ {jQuery} |
| 7 | + * @property blinkInterval {Interval} Blink interval |
| 8 | + * @property $ {jQuery} Cursor element |
9 | 9 | */ |
10 | 10 | es.Cursor = function() { |
11 | | - this.cursorInterval = null; |
| 11 | + this.blinkInterval = null; |
12 | 12 | this.$ = $( '<div class="editSurface-cursor"></div>' ); |
13 | | -} |
| 13 | +}; |
14 | 14 | |
15 | 15 | /** |
16 | 16 | * Shows the cursor in a new position. |
17 | 17 | * |
| 18 | + * @method |
18 | 19 | * @param position {Position} Position to show the cursor at |
19 | 20 | * @param offset {Position} Offset to be added to position |
20 | 21 | */ |
— | — | @@ -33,10 +34,10 @@ |
34 | 35 | this.$.show(); |
35 | 36 | } |
36 | 37 | |
37 | | - if ( this.cursorInterval ) { |
38 | | - clearInterval( this.cursorInterval ); |
| 38 | + if ( this.blinkInterval ) { |
| 39 | + clearInterval( this.blinkInterval ); |
39 | 40 | } |
40 | | - this.cursorInterval = setInterval( function( cursor ) { |
| 41 | + this.blinkInterval = setInterval( function( cursor ) { |
41 | 42 | cursor.$.css( 'display' ) == 'block' |
42 | 43 | ? cursor.$.hide() : cursor.$.show(); |
43 | 44 | }, 500, this ); |
— | — | @@ -44,10 +45,12 @@ |
45 | 46 | |
46 | 47 | /** |
47 | 48 | * Hides the cursor. |
| 49 | + * |
| 50 | + * @method |
48 | 51 | */ |
49 | 52 | es.Cursor.prototype.hide = function() { |
50 | | - if( this.cursorInterval ) { |
51 | | - clearInterval( this.cursorInterval ); |
| 53 | + if( this.blinkInterval ) { |
| 54 | + clearInterval( this.blinkInterval ); |
52 | 55 | } |
53 | 56 | this.$.hide(); |
54 | 57 | }; |
Index: trunk/parsers/wikidom/lib/es/es.Document.js |
— | — | @@ -11,24 +11,34 @@ |
12 | 12 | es.Document = function( blocks ) { |
13 | 13 | es.Container.call( this, 'document', 'blocks', blocks ); |
14 | 14 | this.width = null; |
15 | | -} |
| 15 | +}; |
16 | 16 | |
17 | 17 | /* Static Methods */ |
18 | 18 | |
19 | | -es.Document.newFromWikiDomDocument = function( wikidomBlocks ) { |
| 19 | +/** |
| 20 | + * Creates new es.Document from a WikiDom Document object |
| 21 | + * |
| 22 | + * @method |
| 23 | + * @param {Object} WikiDom document object |
| 24 | + * @returns {es.Document} EditSurface document object |
| 25 | + */ |
| 26 | +es.Document.newFromWikiDomDocument = function( wikidomDocument ) { |
20 | 27 | var blocks = []; |
21 | | - var block; |
22 | | - for ( var i = 0; i < wikidomBlocks.length; i++ ) { |
23 | | - block = es.Block.newFromWikiDomBlock( wikidomBlocks[i] ); |
24 | | - if ( block ) { |
25 | | - blocks.push( block ); |
| 28 | + if ( $.isArray( wikidomDocument.blocks ) ) { |
| 29 | + for ( var i = 0; i < wikidomDocument.blocks.length; i++ ) { |
| 30 | + blocks.push( es.Block.newFromWikiDomBlock( wikidomDocument.blocks[i] ) ); |
26 | 31 | } |
27 | 32 | } |
28 | 33 | return new es.Document( blocks ); |
29 | | -} |
| 34 | +}; |
30 | 35 | |
31 | 36 | /* Methods */ |
32 | 37 | |
| 38 | +/** |
| 39 | + * Forces all blocks in the document to render. |
| 40 | + * |
| 41 | + * @method |
| 42 | + */ |
33 | 43 | es.Document.prototype.renderBlocks = function() { |
34 | 44 | // Bypass rendering when width has not changed |
35 | 45 | var width = this.$.innerWidth(); |
Index: trunk/parsers/wikidom/lib/es/es.ParagraphBlock.js |
— | — | @@ -29,6 +29,8 @@ |
30 | 30 | * @static |
31 | 31 | * @method |
32 | 32 | * @param wikidomParagraphBlock {Object} WikiDom data to convert from |
| 33 | + * @returns {es.ParagraphBlock} EditSurface paragraph block |
| 34 | + * @throws "Invalid block type error" if block type is not "paragraph" |
33 | 35 | */ |
34 | 36 | es.ParagraphBlock.newFromWikiDomParagraphBlock = function( wikidomParagraphBlock ) { |
35 | 37 | if ( wikidomParagraphBlock.type !== 'paragraph' ) { |
Index: trunk/parsers/wikidom/lib/es/es.Container.js |
— | — | @@ -4,14 +4,11 @@ |
5 | 5 | * @class |
6 | 6 | * @constructor |
7 | 7 | * @extends {es.EventEmitter} |
8 | | - * @param typeName {String} |
9 | | - * @param listName {String} |
10 | | - * @param items {Array} List of items |
| 8 | + * @param typeName {String} Property name to set references to this object to in child objects |
| 9 | + * @param listName {String} Property name for list of child objects |
| 10 | + * @param items {Array} List of initial items |
11 | 11 | * @emits "update" when items argument causes items to be appended |
12 | | - * @property _typeName {String} |
13 | | - * @property _listName {String} |
14 | | - * @property _list {Array} |
15 | | - * @property $ {jQuery} |
| 12 | + * @property $ {jQuery} Container element |
16 | 13 | */ |
17 | 14 | es.Container = function( typeName, listName, items ) { |
18 | 15 | es.EventEmitter.call( this ); |
— | — | @@ -35,11 +32,13 @@ |
36 | 33 | } |
37 | 34 | }; |
38 | 35 | |
| 36 | +/* Methods */ |
| 37 | + |
39 | 38 | /** |
40 | 39 | * Gets the first item in the container. |
41 | 40 | * |
42 | 41 | * @method |
43 | | - * @returns {Object} |
| 42 | + * @returns {Object} First child object |
44 | 43 | */ |
45 | 44 | es.Container.prototype.first = function() { |
46 | 45 | return this._list.length ? this._list[0] : null; |
— | — | @@ -49,7 +48,7 @@ |
50 | 49 | * Gets the last item in the container. |
51 | 50 | * |
52 | 51 | * @method |
53 | | - * @returns {Object} |
| 52 | + * @returns {Object} Last child object |
54 | 53 | */ |
55 | 54 | es.Container.prototype.last = function() { |
56 | 55 | return this._list.length |
— | — | @@ -164,4 +163,6 @@ |
165 | 164 | this.emit( 'update' ); |
166 | 165 | }; |
167 | 166 | |
| 167 | +/* Inheritance */ |
| 168 | + |
168 | 169 | es.extend( es.Container, es.EventEmitter ); |
Index: trunk/parsers/wikidom/lib/es/es.ListBlockList.js |
— | — | @@ -18,6 +18,14 @@ |
19 | 19 | |
20 | 20 | /* Static Methods */ |
21 | 21 | |
| 22 | +/** |
| 23 | + * Creates an EditSurface list object from a WikiDom list object. |
| 24 | + * |
| 25 | + * @static |
| 26 | + * @method |
| 27 | + * @param wikidomListItem {Object} WikiDom list item |
| 28 | + * @returns {es.ListBlockItem} EditSurface list block item |
| 29 | + */ |
22 | 30 | es.ListBlockList.newFromWikiDomList = function( wikidomList ) { |
23 | 31 | var items = []; |
24 | 32 | for ( var i = 0; i < wikidomList.items.length; i++ ) { |
— | — | @@ -28,6 +36,12 @@ |
29 | 37 | |
30 | 38 | /* Methods */ |
31 | 39 | |
| 40 | +/** |
| 41 | + * Gets the length of content in both the line and sub-lists. |
| 42 | + * |
| 43 | + * @method |
| 44 | + * @returns {Integer} Length of content |
| 45 | + */ |
32 | 46 | es.ListBlockList.prototype.getLength = function() { |
33 | 47 | var length = 0; |
34 | 48 | for ( var i = 0; i < this.items.length; i++ ) { |
— | — | @@ -36,6 +50,14 @@ |
37 | 51 | return length; |
38 | 52 | }; |
39 | 53 | |
| 54 | +/** |
| 55 | + * Gets a location from an offset. |
| 56 | + * |
| 57 | + * @method |
| 58 | + * @param offset {Integer} Offset to get location for |
| 59 | + * @returns {Object} Location object with item and offset properties, where offset is local |
| 60 | + * to item. |
| 61 | + */ |
40 | 62 | es.ListBlockList.prototype.getLocationFromOffset = function( offset ) { |
41 | 63 | var itemOffset = 0, |
42 | 64 | itemLength; |
— | — | @@ -48,6 +70,14 @@ |
49 | 71 | } |
50 | 72 | }; |
51 | 73 | |
| 74 | +/** |
| 75 | + * Gets an offset within the list from a position. |
| 76 | + * |
| 77 | + * @method |
| 78 | + * @param position {es.Position} Position to translate |
| 79 | + * @returns {Integer} Offset nearest position |
| 80 | + * @returns {Null} If offset could not be found |
| 81 | + */ |
52 | 82 | es.ListBlockList.prototype.getOffsetFromPosition = function( position ) { |
53 | 83 | var itemOffset = null, |
54 | 84 | globalOffset = null; |
— | — | @@ -64,7 +94,10 @@ |
65 | 95 | }; |
66 | 96 | |
67 | 97 | /** |
68 | | - * Renders content into a container. |
| 98 | + * Renders items. |
| 99 | + * |
| 100 | + * @method |
| 101 | + * @param offset {Integer} Offset to render from if possible |
69 | 102 | */ |
70 | 103 | es.ListBlockList.prototype.renderContent = function( offset ) { |
71 | 104 | // TODO: Abstract offset and use it when rendering |
— | — | @@ -73,5 +106,7 @@ |
74 | 107 | } |
75 | 108 | }; |
76 | 109 | |
| 110 | +/* Inheritance */ |
| 111 | + |
77 | 112 | es.extend( es.ListBlockList, es.EventEmitter ); |
78 | 113 | es.extend( es.ListBlockList, es.Container ); |
Index: trunk/parsers/wikidom/lib/es/es.Selection.js |
— | — | @@ -5,10 +5,10 @@ |
6 | 6 | * @constructor |
7 | 7 | * @param from {es.Location} Starting location |
8 | 8 | * @param to {es.Location} Ending location |
9 | | - * @property from {es.Location} |
10 | | - * @property to {es.Location} |
11 | | - * @property start {es.Location} |
12 | | - * @property end {es.Location} |
| 9 | + * @property from {es.Location} Starting location |
| 10 | + * @property to {es.Location} Ending location |
| 11 | + * @property start {es.Location} Normalized starting location |
| 12 | + * @property end {es.Location} Normalized ending location |
13 | 13 | */ |
14 | 14 | es.Selection = function( from, to ) { |
15 | 15 | this.from = from; |
— | — | @@ -17,8 +17,15 @@ |
18 | 18 | this.end = to; |
19 | 19 | } |
20 | 20 | |
| 21 | +/* Methods */ |
| 22 | + |
21 | 23 | /** |
22 | | - * Ensures that "from" is before "to". |
| 24 | + * Sets start and end properties, ensuring start is always before end. |
| 25 | + * |
| 26 | + * This should always be called before using the start or end properties. Do not call this unless |
| 27 | + * you are about to use these properties. |
| 28 | + * |
| 29 | + * @method |
23 | 30 | */ |
24 | 31 | es.Selection.prototype.normalize = function() { |
25 | 32 | if ( this.from.block.getIndex() < this.to.block.getIndex() |
— | — | @@ -36,6 +43,7 @@ |
37 | 44 | * |
38 | 45 | * If from and to are adjacent blocks, or the same block, the result will always be an empty array. |
39 | 46 | * |
| 47 | + * @method |
40 | 48 | * @returns {Array} List of blocks |
41 | 49 | */ |
42 | 50 | es.Selection.prototype.through = function() { |
Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js |
— | — | @@ -1,7 +1,6 @@ |
2 | 2 | /** |
3 | | - * es.ListBlock |
| 3 | + * Creates a list block. |
4 | 4 | * |
5 | | - * |
6 | 5 | * @class |
7 | 6 | * @constructor |
8 | 7 | * @extends {es.Block} |
— | — | @@ -26,7 +25,10 @@ |
27 | 26 | /** |
28 | 27 | * Creates a new list block object from WikiDom data. |
29 | 28 | * |
| 29 | + * @static |
| 30 | + * @method |
30 | 31 | * @param wikidomParagraphBlock {Object} WikiDom data to convert from |
| 32 | + * @returns {es.ListBlock} EditSurface list block |
31 | 33 | */ |
32 | 34 | es.ListBlock.newFromWikiDomListBlock = function( wikidomListBlock ) { |
33 | 35 | if ( wikidomListBlock.type !== 'list' ) { |
— | — | @@ -39,6 +41,9 @@ |
40 | 42 | |
41 | 43 | /** |
42 | 44 | * Gets the length of all block content. |
| 45 | + * |
| 46 | + * @method |
| 47 | + * @returns {Integer} Length of content |
43 | 48 | */ |
44 | 49 | es.ListBlock.prototype.getLength = function() { |
45 | 50 | // Compensate for n+1 virtual position on the last item's content |
— | — | @@ -48,6 +53,7 @@ |
49 | 54 | /** |
50 | 55 | * Inserts content into a block at an offset. |
51 | 56 | * |
| 57 | + * @method |
52 | 58 | * @param offset {Integer} Position to insert content at |
53 | 59 | * @param content {Object} Content to insert |
54 | 60 | */ |
— | — | @@ -59,6 +65,7 @@ |
60 | 66 | /** |
61 | 67 | * Deletes content in a block within a range. |
62 | 68 | * |
| 69 | + * @method |
63 | 70 | * @param range {es.Range} Range of content to remove |
64 | 71 | */ |
65 | 72 | es.ListBlock.prototype.deleteContent = function( range ) { |
— | — | @@ -74,6 +81,7 @@ |
75 | 82 | * |
76 | 83 | * If a range arguments are not provided, all content will be annotated. |
77 | 84 | * |
| 85 | + * @method |
78 | 86 | * @param method {String} Way to apply annotation ("toggle", "add" or "remove") |
79 | 87 | * @param annotation {Object} Annotation to apply |
80 | 88 | * @param range {es.Range} Range of content to annotate |
— | — | @@ -124,18 +132,22 @@ |
125 | 133 | /** |
126 | 134 | * Gets content within a range. |
127 | 135 | * |
| 136 | + * @method |
128 | 137 | * @param range {es.Range} Range of content to get |
| 138 | + * @returns {es.Content} Content within range |
129 | 139 | */ |
130 | 140 | es.ListBlock.prototype.getContent = function( range ) { |
131 | 141 | // TODO: Implement me! |
132 | | - return new Content(); |
| 142 | + return new es.Content(); |
133 | 143 | }; |
134 | 144 | |
135 | 145 | /** |
136 | 146 | * Gets content as plain text within a range. |
137 | 147 | * |
| 148 | + * @method |
138 | 149 | * @param range {Range} Range of text to get |
139 | 150 | * @param render {Boolean} If annotations should have any influence on output |
| 151 | + * @returns {String} Text within range |
140 | 152 | */ |
141 | 153 | es.ListBlock.prototype.getText = function( range ) { |
142 | 154 | // TODO: Implement me! |
— | — | @@ -144,6 +156,9 @@ |
145 | 157 | |
146 | 158 | /** |
147 | 159 | * Renders content into a container. |
| 160 | + * |
| 161 | + * @method |
| 162 | + * @param offset {Integer} Offset to render from, if possible |
148 | 163 | */ |
149 | 164 | es.ListBlock.prototype.renderContent = function( offset ) { |
150 | 165 | this.list.renderContent( offset ); |
— | — | @@ -152,7 +167,9 @@ |
153 | 168 | /** |
154 | 169 | * Gets the offset of a position. |
155 | 170 | * |
156 | | - * @param position {Integer} Offset to translate |
| 171 | + * @method |
| 172 | + * @param position {es.Position} Position to translate |
| 173 | + * @returns {Integer} Offset nearest to position |
157 | 174 | */ |
158 | 175 | es.ListBlock.prototype.getOffset = function( position ) { |
159 | 176 | if ( position.top < 0 ) { |
— | — | @@ -169,7 +186,9 @@ |
170 | 187 | /** |
171 | 188 | * Gets the position of an offset. |
172 | 189 | * |
| 190 | + * @method |
173 | 191 | * @param offset {Integer} Offset to translate |
| 192 | + * @returns {es.Position} Position of offset |
174 | 193 | */ |
175 | 194 | es.ListBlock.prototype.getPosition = function( offset ) { |
176 | 195 | var location = this.list.getLocationFromOffset( offset ) |
— | — | @@ -193,8 +212,9 @@ |
194 | 213 | /** |
195 | 214 | * Gets the start and end points of the word closest a given offset. |
196 | 215 | * |
| 216 | + * @method |
197 | 217 | * @param offset {Integer} Offset to find word nearest to |
198 | | - * @return {Object} Range object of boundaries |
| 218 | + * @returns {Object} Range object of boundaries |
199 | 219 | */ |
200 | 220 | es.ListBlock.prototype.getWordBoundaries = function( offset ) { |
201 | 221 | var location = this.list.getLocationFromOffset( offset ); |
— | — | @@ -207,8 +227,9 @@ |
208 | 228 | /** |
209 | 229 | * Gets the start and end points of the section closest a given offset. |
210 | 230 | * |
| 231 | + * @method |
211 | 232 | * @param offset {Integer} Offset to find section nearest to |
212 | | - * @return {Object} Range object of boundaries |
| 233 | + * @returns {Object} Range object of boundaries |
213 | 234 | */ |
214 | 235 | es.ListBlock.prototype.getSectionBoundaries = function( offset ) { |
215 | 236 | var location = this.list.getLocationFromOffset( offset ), |
— | — | @@ -222,8 +243,9 @@ |
223 | 244 | * Traversal is performed in a depth-first pattern, which is equivilant to a vertical scan of list |
224 | 245 | * items. To stop traversal, return false within the callback function. |
225 | 246 | * |
| 247 | + * @method |
226 | 248 | * @param callback {Function} Function to execute for each item, accepts an item and index argument |
227 | | - * @return {Boolean} Whether all items were traversed, or traversal was cut short |
| 249 | + * @returns {Boolean} Whether all items were traversed, or traversal was cut short |
228 | 250 | */ |
229 | 251 | es.ListBlock.prototype.traverseItems = function( callback ) { |
230 | 252 | var stack = [{ 'list': this.list, 'index': 0 }], |
Index: trunk/parsers/wikidom/lib/es/es.Block.js |
— | — | @@ -7,12 +7,12 @@ |
8 | 8 | * @class |
9 | 9 | * @constructor |
10 | 10 | * @extends {es.EventEmitter} |
11 | | - * @property document {es.Document} |
| 11 | + * @property document {es.Document} Document block is attached to |
12 | 12 | */ |
13 | 13 | es.Block = function() { |
14 | 14 | es.EventEmitter.call( this ); |
15 | 15 | this.document = null; |
16 | | -} |
| 16 | +}; |
17 | 17 | |
18 | 18 | /* Static Members */ |
19 | 19 | |
— | — | @@ -33,12 +33,14 @@ |
34 | 34 | * @static |
35 | 35 | * @method |
36 | 36 | * @param wikidomBlock {Object} WikiDom data to convert from |
| 37 | + * @returns {es.Block} EditSurface block object |
| 38 | + * @throws "Unknown block type error" if block type does exist in es.Block.blockConstructors |
37 | 39 | */ |
38 | 40 | es.Block.newFromWikiDomBlock = function( wikidomBlock ) { |
39 | 41 | if ( wikidomBlock.type in es.Block.blockConstructors ) { |
40 | 42 | return es.Block.blockConstructors[wikidomBlock.type]( wikidomBlock ); |
41 | 43 | } else { |
42 | | - throw 'Unknown block type: ' + wikidomBlock.type; |
| 44 | + throw 'Unknown block type error. Block type does exist in es.Block.blockConstructors'; |
43 | 45 | } |
44 | 46 | }; |
45 | 47 | |
— | — | @@ -48,7 +50,8 @@ |
49 | 51 | * Gets the index of the block within it's document. |
50 | 52 | * |
51 | 53 | * @method |
52 | | - * @returns {Integer} Index of block |
| 54 | + * @returns {Integer} Index of block in document |
| 55 | + * @throws "Missing document error" if block is not attached to a document |
53 | 56 | */ |
54 | 57 | es.Block.prototype.getIndex = function() { |
55 | 58 | if ( !this.document ) { |
— | — | @@ -63,6 +66,7 @@ |
64 | 67 | * @method |
65 | 68 | * @returns {es.Block} Block directly proceeding this one |
66 | 69 | * @returns {Null} If block does not exist in document |
| 70 | + * @throws "Missing document error" if block is not attached to a document |
67 | 71 | */ |
68 | 72 | es.Block.prototype.nextBlock = function() { |
69 | 73 | if ( !this.document ) { |
— | — | @@ -78,6 +82,7 @@ |
79 | 83 | * @method |
80 | 84 | * @returns {es.Block} Block directly preceding this one |
81 | 85 | * @returns {Null} If block does not exist in document |
| 86 | + * @throws "Missing document error" if block is not attached to a document |
82 | 87 | */ |
83 | 88 | es.Block.prototype.previousBlock = function() { |
84 | 89 | if ( !this.document ) { |
Index: trunk/parsers/wikidom/lib/es/es.Range.js |
— | — | @@ -3,12 +3,12 @@ |
4 | 4 | * |
5 | 5 | * @class |
6 | 6 | * @constructor |
7 | | - * @param start {Integer} Starting point |
8 | | - * @param end {Integer} Ending point |
9 | | - * @property to {Integer} |
10 | | - * @property from {Integer} |
11 | | - * @property start {Integer} |
12 | | - * @property end {Integer} |
| 7 | + * @param from {Integer} Starting offset |
| 8 | + * @param to {Integer} Ending offset |
| 9 | + * @property from {Integer} Starting offset |
| 10 | + * @property to {Integer} Ending offset |
| 11 | + * @property start {Integer} Normalized starting offset |
| 12 | + * @property end {Integer} Normalized ending offset |
13 | 13 | */ |
14 | 14 | es.Range = function( from, to ) { |
15 | 15 | this.from = from || 0; |
— | — | @@ -16,15 +16,38 @@ |
17 | 17 | this.normalize(); |
18 | 18 | }; |
19 | 19 | |
| 20 | +/* Methods */ |
| 21 | + |
| 22 | +/** |
| 23 | + * Checks if an offset is within this range. |
| 24 | + * |
| 25 | + * @method |
| 26 | + * @param offset {Integer} Offset to check |
| 27 | + * @returns {Boolean} If offset is within this range |
| 28 | + */ |
20 | 29 | es.Range.prototype.containsOffset = function( offset ) { |
21 | 30 | this.normalize(); |
22 | 31 | return offset >= this.start && offset < this.end; |
23 | 32 | }; |
24 | 33 | |
| 34 | +/** |
| 35 | + * Gets the length of the range. |
| 36 | + * |
| 37 | + * @method |
| 38 | + * @returns {Integer} Length of range |
| 39 | + */ |
25 | 40 | es.Range.prototype.getLength = function() { |
26 | 41 | return Math.abs( this.from - this.to ); |
27 | 42 | }; |
28 | 43 | |
| 44 | +/** |
| 45 | + * Sets start and end properties, ensuring start is always before end. |
| 46 | + * |
| 47 | + * This should always be called before using the start or end properties. Do not call this unless |
| 48 | + * you are about to use these properties. |
| 49 | + * |
| 50 | + * @method |
| 51 | + */ |
29 | 52 | es.Range.prototype.normalize = function() { |
30 | 53 | if ( this.from < this.to ) { |
31 | 54 | this.start = this.from; |
Index: trunk/parsers/wikidom/demos/es/index.html |
— | — | @@ -73,7 +73,7 @@ |
74 | 74 | <!-- Demo --> |
75 | 75 | <script> |
76 | 76 | $(document).ready( function() { |
77 | | - doc = es.Document.newFromWikidom([ |
| 77 | + doc = es.Document.newFromWikiDomDocument( { 'blocks': [ |
78 | 78 | { |
79 | 79 | "type": "paragraph", |
80 | 80 | "lines": [ |
— | — | @@ -122,21 +122,18 @@ |
123 | 123 | 'line': { 'text': 'Operating Systems' }, |
124 | 124 | 'lists': [ |
125 | 125 | { |
126 | | - 'type': 'list', |
127 | 126 | 'style': 'bullet', |
128 | 127 | 'items': [ |
129 | 128 | { |
130 | 129 | 'line': { 'text': 'Linux' }, |
131 | 130 | 'lists': [ |
132 | 131 | { |
133 | | - 'type': 'list', |
134 | 132 | 'style': 'bullet', |
135 | 133 | 'items': [ |
136 | 134 | { |
137 | 135 | 'line': { 'text': 'Ubuntu' }, |
138 | 136 | 'lists': [ |
139 | 137 | { |
140 | | - 'type': 'list', |
141 | 138 | 'style': 'bullet', |
142 | 139 | 'items': [ |
143 | 140 | { |
— | — | @@ -227,7 +224,7 @@ |
228 | 225 | { 'text': 'Text might have\ttabs\tin it too. Not all text will end in a line breaking character' } |
229 | 226 | ] |
230 | 227 | } |
231 | | - ]); |
| 228 | + ] } ); |
232 | 229 | var surface = new es.Surface( $('#es-editor'), doc ); |
233 | 230 | |
234 | 231 | $( '#es-toolbar .es-toolbarTool' ).mousedown( function( e ) { |