r93376 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93375‎ | r93376 | r93377 >
Date:07:45, 28 July 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Comments and cleanup
Modified paths:
  • /trunk/parsers/wikidom/demos/es/index.html (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Block.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Container.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Content.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Cursor.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Document.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.EventEmitter.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.ListBlock.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.ListBlockItem.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.ListBlockList.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.ParagraphBlock.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Position.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Range.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Selection.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.js
@@ -1,5 +1,5 @@
22 /**
3 - * EditSurafce namespace.
 3+ * EditSurface namespace.
44 *
55 * All classes and functions will be attached to this object to keep the global namespace clean.
66 */
@@ -26,6 +26,8 @@
2727 * // Extend prototype
2828 * extend( Bar, Foo );
2929 *
 30+ * @static
 31+ * @method
3032 * @param dst {Function} Class to extend
3133 * @param src {Function} Base class to use methods from
3234 */
Index: trunk/parsers/wikidom/lib/es/es.Position.js
@@ -18,53 +18,151 @@
1919 this.bottom = bottom || this.top;
2020 };
2121
 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+ */
2232 es.Position.newFromEventScreenPosition = function( event ) {
2333 return new es.Position( event.screenX, event.screenY );
2434 };
2535
 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+ */
2644 es.Position.newFromEventPagePosition = function( event ) {
2745 return new es.Position( event.pageX, event.pageY );
2846 };
2947
 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+ */
3056 es.Position.newFromEventLayerPosition = function( event ) {
3157 return new es.Position( event.layerX, event.layerY );
3258 };
3359
 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+ */
3469 es.Position.prototype.at = function( position ) {
3570 return this.left === position.left && this.top === position.top;
3671 };
3772
 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+ */
3880 es.Position.prototype.perpendicularWith = function( position ) {
3981 return this.left === position.left || this.top === position.top;
4082 };
4183
 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+ */
4291 es.Position.prototype.levelWith = function( position ) {
4392 return this.top === position.top;
4493 };
4594
 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+ */
46102 es.Position.prototype.plumbWith = function( position ) {
47103 return this.left === position.left;
48104 };
49105
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 ) {
51117 return Math.sqrt(
52118 Math.pow( this.left - position.left, 2 ),
53119 Math.pow( this.top - position.top )
54 - ) <= range;
 120+ ) <= radius;
55121 };
56122
 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+ */
57132 es.Position.prototype.above = function( position ) {
58133 return this.bottom < position.top;
59134 };
60135
 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+ */
61145 es.Position.prototype.below = function( position ) {
62146 return this.top > position.bottom;
63147 };
64148
 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+ */
65156 es.Position.prototype.leftOf = function( left ) {
66157 return this.left < left;
67158 };
68159
 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+ */
69167 es.Position.prototype.rightOf = function( left ) {
70168 return this.left > left;
71169 };
Index: trunk/parsers/wikidom/lib/es/es.ListBlockItem.js
@@ -5,18 +5,18 @@
66 * @constructor
77 * @extends {es.EventEmitter}
88 * @extends {es.Container}
9 - * @param line {es.Content} Item content
 9+ * @param content {es.Content} Item content
1010 * @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
1616 */
17 -es.ListBlockItem = function( line, lists ) {
 17+es.ListBlockItem = function( content, lists ) {
1818 es.EventEmitter.call( this );
1919 es.Container.call( this, 'item', 'lists', lists );
20 - this.content = line || new es.Content();
 20+ this.content = content || new es.Content();
2121 this.$line = $( '<div class="editSurface-list-line"></div>' );
2222 this.$content = $( '<div class="editSurface-list-content"></div>' );
2323 this.$.prepend( this.$line.append( this.$content ) );
@@ -29,15 +29,23 @@
3030
3131 /* Static Methods */
3232
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 ) {
3442 // Convert items to es.ListBlockItem objects
3543 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] ) );
3947 }
4048 }
41 - return new es.ListBlockItem( es.Content.newFromWikiDomLine( wikidomItem.line ), lists );
 49+ return new es.ListBlockItem( es.Content.newFromWikiDomLine( wikidomListItem.line ), lists );
4250 };
4351
4452 /* Methods */
@@ -45,12 +53,21 @@
4654 /**
4755 * Gets the index of the item within it's list.
4856 *
 57+ * TODO: Move to es.Container
 58+ *
 59+ * @method
4960 * @returns {Integer} Index of item
5061 */
5162 es.ListBlockItem.prototype.getIndex = function() {
5263 return this.list._list.indexOf( this );
5364 };
5465
 66+/**
 67+ * Gets the length of content in both the line and sub-lists.
 68+ *
 69+ * @method
 70+ * @returns {Integer} Length of content
 71+ */
5572 es.ListBlockItem.prototype.getLength = function() {
5673 var length = this.content.getLength() + 1;
5774 for ( var i = 0; i < this.lists.length; i++ ) {
@@ -59,18 +76,23 @@
6077 return length;
6178 };
6279
 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+ */
6388 es.ListBlockItem.prototype.getLocationFromOffset = function( offset ) {
6489 var contentLength = this.content.getLength() + 1;
65 -
6690 if ( offset < contentLength ) {
6791 return {
6892 'item': this,
6993 'offset': offset
7094 };
7195 }
72 -
7396 offset -= contentLength;
74 -
7597 var listOffset = 0,
7698 listLength;
7799 for ( var i = 0; i < this.lists.length; i++ ) {
@@ -82,6 +104,14 @@
83105 }
84106 };
85107
 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+ */
86116 es.ListBlockItem.prototype.getOffsetFromPosition = function( position ) {
87117 var itemOffset = this.$.offset(),
88118 itemHeight = this.$.height(),
@@ -97,7 +127,7 @@
98128 }
99129
100130 for ( var i = 0; i < this.lists.length; i++ ) {
101 - offset = this.lists[i].getOffsetFromPosition( position );
 131+ offset = this.lists[i].getOffsetFromPosition( position );
102132 if ( offset != null ) {
103133 return globalOffset + offset + this.content.getLength() + 1;
104134 } else {
@@ -108,6 +138,12 @@
109139 return null;
110140 };
111141
 142+/**
 143+ * Renders content and sub-lists.
 144+ *
 145+ * @method
 146+ * @param offset {Integer} Offset to render from if possible
 147+ */
112148 es.ListBlockItem.prototype.renderContent = function( offset ) {
113149 // TODO: Abstract offset and use it when rendering
114150 this.flow.render();
@@ -116,5 +152,7 @@
117153 }
118154 };
119155
 156+/* Inheritance */
 157+
120158 es.extend( es.ListBlockItem, es.EventEmitter );
121159 es.extend( es.ListBlockItem, es.Container );
Index: trunk/parsers/wikidom/lib/es/es.Content.js
@@ -9,12 +9,12 @@
1010 * @class
1111 * @constructor
1212 * @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
1515 */
16 -es.Content = function( content ) {
 16+es.Content = function( data ) {
1717 es.EventEmitter.call( this );
18 - this.data = content || [];
 18+ this.data = data || [];
1919 };
2020
2121 /* Static Members */
@@ -83,67 +83,12 @@
8484 /* Static Methods */
8585
8686 /**
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 -/**
14287 * Creates a new Content object from a WikiDom line object.
14388 *
14489 * @static
14590 * @method
14691 * @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
14893 */
14994 es.Content.newFromWikiDomLine = function( wikidomLine ) {
15095 return new es.Content( es.Content.convertWikiDomLine( wikidomLine ) );
@@ -217,6 +162,61 @@
218163 };
219164
220165 /**
 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+/**
221221 * Gets a rendered opening or closing of an annotation.
222222 *
223223 * Tag nesting is handled using a stack, which keeps track of what is currently open. A common stack
@@ -294,7 +294,7 @@
295295 * @param start {Integer} Optional beginning of range, if omitted range will begin at 0
296296 * @param end {Integer} Optional end of range, if omitted range will end a this.data.length
297297 * @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
299299 */
300300 es.Content.prototype.getText = function( range, render ) {
301301 if ( !range ) {
@@ -321,7 +321,7 @@
322322 *
323323 * @method
324324 * @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
326326 */
327327 es.Content.prototype.getContent = function( range ) {
328328 if ( !range ) {
@@ -623,7 +623,7 @@
624624 * @method
625625 * @returns {Array} List of WikiDom line objects
626626 */
627 -es.Content.prototype.getLines = function() {
 627+es.Content.prototype.getWikiDomLines = function() {
628628 var lines = [],
629629 right = '',
630630 rightPlain,
Index: trunk/parsers/wikidom/lib/es/es.EventEmitter.js
@@ -9,6 +9,16 @@
1010 this.events = {};
1111 }
1212
 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+ */
1323 es.EventEmitter.prototype.emit = function( type ) {
1424 if ( type === 'error' && !( 'error' in this.events ) ) {
1525 throw 'Missing error handler error.';
@@ -24,6 +34,15 @@
2535 return true;
2636 };
2737
 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+ */
2847 es.EventEmitter.prototype.addListener = function( type, listener ) {
2948 if ( typeof listener !== 'function' ) {
3049 throw 'Invalid listener error. Function expected.';
@@ -37,18 +56,38 @@
3857 return this;
3958 };
4059
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;
4466
 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+ */
4575 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 );
5080 } );
5181 };
5282
 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+ */
5392 es.EventEmitter.prototype.removeListener = function( type, listener ) {
5493 if ( typeof listener !== 'function' ) {
5594 throw 'Invalid listener error. Function expected.';
@@ -72,6 +111,13 @@
73112 return this;
74113 };
75114
 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+ */
76122 es.EventEmitter.prototype.removeAllListeners = function( type ) {
77123 if ( type in this.events ) {
78124 delete this.events[type];
@@ -79,6 +125,13 @@
80126 return this;
81127 };
82128
 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+ */
83136 es.EventEmitter.prototype.listeners = function( type ) {
84137 return type in this.events ? this.events[type] : [];
85138 };
Index: trunk/parsers/wikidom/lib/es/es.Cursor.js
@@ -3,17 +3,18 @@
44 *
55 * @class
66 * @constructor
7 - * @property cursorInterval {Interval}
8 - * @property $ {jQuery}
 7+ * @property blinkInterval {Interval} Blink interval
 8+ * @property $ {jQuery} Cursor element
99 */
1010 es.Cursor = function() {
11 - this.cursorInterval = null;
 11+ this.blinkInterval = null;
1212 this.$ = $( '<div class="editSurface-cursor"></div>' );
13 -}
 13+};
1414
1515 /**
1616 * Shows the cursor in a new position.
1717 *
 18+ * @method
1819 * @param position {Position} Position to show the cursor at
1920 * @param offset {Position} Offset to be added to position
2021 */
@@ -33,10 +34,10 @@
3435 this.$.show();
3536 }
3637
37 - if ( this.cursorInterval ) {
38 - clearInterval( this.cursorInterval );
 38+ if ( this.blinkInterval ) {
 39+ clearInterval( this.blinkInterval );
3940 }
40 - this.cursorInterval = setInterval( function( cursor ) {
 41+ this.blinkInterval = setInterval( function( cursor ) {
4142 cursor.$.css( 'display' ) == 'block'
4243 ? cursor.$.hide() : cursor.$.show();
4344 }, 500, this );
@@ -44,10 +45,12 @@
4546
4647 /**
4748 * Hides the cursor.
 49+ *
 50+ * @method
4851 */
4952 es.Cursor.prototype.hide = function() {
50 - if( this.cursorInterval ) {
51 - clearInterval( this.cursorInterval );
 53+ if( this.blinkInterval ) {
 54+ clearInterval( this.blinkInterval );
5255 }
5356 this.$.hide();
5457 };
Index: trunk/parsers/wikidom/lib/es/es.Document.js
@@ -11,24 +11,34 @@
1212 es.Document = function( blocks ) {
1313 es.Container.call( this, 'document', 'blocks', blocks );
1414 this.width = null;
15 -}
 15+};
1616
1717 /* Static Methods */
1818
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 ) {
2027 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] ) );
2631 }
2732 }
2833 return new es.Document( blocks );
29 -}
 34+};
3035
3136 /* Methods */
3237
 38+/**
 39+ * Forces all blocks in the document to render.
 40+ *
 41+ * @method
 42+ */
3343 es.Document.prototype.renderBlocks = function() {
3444 // Bypass rendering when width has not changed
3545 var width = this.$.innerWidth();
Index: trunk/parsers/wikidom/lib/es/es.ParagraphBlock.js
@@ -29,6 +29,8 @@
3030 * @static
3131 * @method
3232 * @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"
3335 */
3436 es.ParagraphBlock.newFromWikiDomParagraphBlock = function( wikidomParagraphBlock ) {
3537 if ( wikidomParagraphBlock.type !== 'paragraph' ) {
Index: trunk/parsers/wikidom/lib/es/es.Container.js
@@ -4,14 +4,11 @@
55 * @class
66 * @constructor
77 * @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
1111 * @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
1613 */
1714 es.Container = function( typeName, listName, items ) {
1815 es.EventEmitter.call( this );
@@ -35,11 +32,13 @@
3633 }
3734 };
3835
 36+/* Methods */
 37+
3938 /**
4039 * Gets the first item in the container.
4140 *
4241 * @method
43 - * @returns {Object}
 42+ * @returns {Object} First child object
4443 */
4544 es.Container.prototype.first = function() {
4645 return this._list.length ? this._list[0] : null;
@@ -49,7 +48,7 @@
5049 * Gets the last item in the container.
5150 *
5251 * @method
53 - * @returns {Object}
 52+ * @returns {Object} Last child object
5453 */
5554 es.Container.prototype.last = function() {
5655 return this._list.length
@@ -164,4 +163,6 @@
165164 this.emit( 'update' );
166165 };
167166
 167+/* Inheritance */
 168+
168169 es.extend( es.Container, es.EventEmitter );
Index: trunk/parsers/wikidom/lib/es/es.ListBlockList.js
@@ -18,6 +18,14 @@
1919
2020 /* Static Methods */
2121
 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+ */
2230 es.ListBlockList.newFromWikiDomList = function( wikidomList ) {
2331 var items = [];
2432 for ( var i = 0; i < wikidomList.items.length; i++ ) {
@@ -28,6 +36,12 @@
2937
3038 /* Methods */
3139
 40+/**
 41+ * Gets the length of content in both the line and sub-lists.
 42+ *
 43+ * @method
 44+ * @returns {Integer} Length of content
 45+ */
3246 es.ListBlockList.prototype.getLength = function() {
3347 var length = 0;
3448 for ( var i = 0; i < this.items.length; i++ ) {
@@ -36,6 +50,14 @@
3751 return length;
3852 };
3953
 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+ */
4062 es.ListBlockList.prototype.getLocationFromOffset = function( offset ) {
4163 var itemOffset = 0,
4264 itemLength;
@@ -48,6 +70,14 @@
4971 }
5072 };
5173
 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+ */
5282 es.ListBlockList.prototype.getOffsetFromPosition = function( position ) {
5383 var itemOffset = null,
5484 globalOffset = null;
@@ -64,7 +94,10 @@
6595 };
6696
6797 /**
68 - * Renders content into a container.
 98+ * Renders items.
 99+ *
 100+ * @method
 101+ * @param offset {Integer} Offset to render from if possible
69102 */
70103 es.ListBlockList.prototype.renderContent = function( offset ) {
71104 // TODO: Abstract offset and use it when rendering
@@ -73,5 +106,7 @@
74107 }
75108 };
76109
 110+/* Inheritance */
 111+
77112 es.extend( es.ListBlockList, es.EventEmitter );
78113 es.extend( es.ListBlockList, es.Container );
Index: trunk/parsers/wikidom/lib/es/es.Selection.js
@@ -5,10 +5,10 @@
66 * @constructor
77 * @param from {es.Location} Starting location
88 * @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
1313 */
1414 es.Selection = function( from, to ) {
1515 this.from = from;
@@ -17,8 +17,15 @@
1818 this.end = to;
1919 }
2020
 21+/* Methods */
 22+
2123 /**
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
2330 */
2431 es.Selection.prototype.normalize = function() {
2532 if ( this.from.block.getIndex() < this.to.block.getIndex()
@@ -36,6 +43,7 @@
3744 *
3845 * If from and to are adjacent blocks, or the same block, the result will always be an empty array.
3946 *
 47+ * @method
4048 * @returns {Array} List of blocks
4149 */
4250 es.Selection.prototype.through = function() {
Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js
@@ -1,7 +1,6 @@
22 /**
3 - * es.ListBlock
 3+ * Creates a list block.
44 *
5 - *
65 * @class
76 * @constructor
87 * @extends {es.Block}
@@ -26,7 +25,10 @@
2726 /**
2827 * Creates a new list block object from WikiDom data.
2928 *
 29+ * @static
 30+ * @method
3031 * @param wikidomParagraphBlock {Object} WikiDom data to convert from
 32+ * @returns {es.ListBlock} EditSurface list block
3133 */
3234 es.ListBlock.newFromWikiDomListBlock = function( wikidomListBlock ) {
3335 if ( wikidomListBlock.type !== 'list' ) {
@@ -39,6 +41,9 @@
4042
4143 /**
4244 * Gets the length of all block content.
 45+ *
 46+ * @method
 47+ * @returns {Integer} Length of content
4348 */
4449 es.ListBlock.prototype.getLength = function() {
4550 // Compensate for n+1 virtual position on the last item's content
@@ -48,6 +53,7 @@
4954 /**
5055 * Inserts content into a block at an offset.
5156 *
 57+ * @method
5258 * @param offset {Integer} Position to insert content at
5359 * @param content {Object} Content to insert
5460 */
@@ -59,6 +65,7 @@
6066 /**
6167 * Deletes content in a block within a range.
6268 *
 69+ * @method
6370 * @param range {es.Range} Range of content to remove
6471 */
6572 es.ListBlock.prototype.deleteContent = function( range ) {
@@ -74,6 +81,7 @@
7582 *
7683 * If a range arguments are not provided, all content will be annotated.
7784 *
 85+ * @method
7886 * @param method {String} Way to apply annotation ("toggle", "add" or "remove")
7987 * @param annotation {Object} Annotation to apply
8088 * @param range {es.Range} Range of content to annotate
@@ -124,18 +132,22 @@
125133 /**
126134 * Gets content within a range.
127135 *
 136+ * @method
128137 * @param range {es.Range} Range of content to get
 138+ * @returns {es.Content} Content within range
129139 */
130140 es.ListBlock.prototype.getContent = function( range ) {
131141 // TODO: Implement me!
132 - return new Content();
 142+ return new es.Content();
133143 };
134144
135145 /**
136146 * Gets content as plain text within a range.
137147 *
 148+ * @method
138149 * @param range {Range} Range of text to get
139150 * @param render {Boolean} If annotations should have any influence on output
 151+ * @returns {String} Text within range
140152 */
141153 es.ListBlock.prototype.getText = function( range ) {
142154 // TODO: Implement me!
@@ -144,6 +156,9 @@
145157
146158 /**
147159 * Renders content into a container.
 160+ *
 161+ * @method
 162+ * @param offset {Integer} Offset to render from, if possible
148163 */
149164 es.ListBlock.prototype.renderContent = function( offset ) {
150165 this.list.renderContent( offset );
@@ -152,7 +167,9 @@
153168 /**
154169 * Gets the offset of a position.
155170 *
156 - * @param position {Integer} Offset to translate
 171+ * @method
 172+ * @param position {es.Position} Position to translate
 173+ * @returns {Integer} Offset nearest to position
157174 */
158175 es.ListBlock.prototype.getOffset = function( position ) {
159176 if ( position.top < 0 ) {
@@ -169,7 +186,9 @@
170187 /**
171188 * Gets the position of an offset.
172189 *
 190+ * @method
173191 * @param offset {Integer} Offset to translate
 192+ * @returns {es.Position} Position of offset
174193 */
175194 es.ListBlock.prototype.getPosition = function( offset ) {
176195 var location = this.list.getLocationFromOffset( offset )
@@ -193,8 +212,9 @@
194213 /**
195214 * Gets the start and end points of the word closest a given offset.
196215 *
 216+ * @method
197217 * @param offset {Integer} Offset to find word nearest to
198 - * @return {Object} Range object of boundaries
 218+ * @returns {Object} Range object of boundaries
199219 */
200220 es.ListBlock.prototype.getWordBoundaries = function( offset ) {
201221 var location = this.list.getLocationFromOffset( offset );
@@ -207,8 +227,9 @@
208228 /**
209229 * Gets the start and end points of the section closest a given offset.
210230 *
 231+ * @method
211232 * @param offset {Integer} Offset to find section nearest to
212 - * @return {Object} Range object of boundaries
 233+ * @returns {Object} Range object of boundaries
213234 */
214235 es.ListBlock.prototype.getSectionBoundaries = function( offset ) {
215236 var location = this.list.getLocationFromOffset( offset ),
@@ -222,8 +243,9 @@
223244 * Traversal is performed in a depth-first pattern, which is equivilant to a vertical scan of list
224245 * items. To stop traversal, return false within the callback function.
225246 *
 247+ * @method
226248 * @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
228250 */
229251 es.ListBlock.prototype.traverseItems = function( callback ) {
230252 var stack = [{ 'list': this.list, 'index': 0 }],
Index: trunk/parsers/wikidom/lib/es/es.Block.js
@@ -7,12 +7,12 @@
88 * @class
99 * @constructor
1010 * @extends {es.EventEmitter}
11 - * @property document {es.Document}
 11+ * @property document {es.Document} Document block is attached to
1212 */
1313 es.Block = function() {
1414 es.EventEmitter.call( this );
1515 this.document = null;
16 -}
 16+};
1717
1818 /* Static Members */
1919
@@ -33,12 +33,14 @@
3434 * @static
3535 * @method
3636 * @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
3739 */
3840 es.Block.newFromWikiDomBlock = function( wikidomBlock ) {
3941 if ( wikidomBlock.type in es.Block.blockConstructors ) {
4042 return es.Block.blockConstructors[wikidomBlock.type]( wikidomBlock );
4143 } else {
42 - throw 'Unknown block type: ' + wikidomBlock.type;
 44+ throw 'Unknown block type error. Block type does exist in es.Block.blockConstructors';
4345 }
4446 };
4547
@@ -48,7 +50,8 @@
4951 * Gets the index of the block within it's document.
5052 *
5153 * @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
5356 */
5457 es.Block.prototype.getIndex = function() {
5558 if ( !this.document ) {
@@ -63,6 +66,7 @@
6467 * @method
6568 * @returns {es.Block} Block directly proceeding this one
6669 * @returns {Null} If block does not exist in document
 70+ * @throws "Missing document error" if block is not attached to a document
6771 */
6872 es.Block.prototype.nextBlock = function() {
6973 if ( !this.document ) {
@@ -78,6 +82,7 @@
7983 * @method
8084 * @returns {es.Block} Block directly preceding this one
8185 * @returns {Null} If block does not exist in document
 86+ * @throws "Missing document error" if block is not attached to a document
8287 */
8388 es.Block.prototype.previousBlock = function() {
8489 if ( !this.document ) {
Index: trunk/parsers/wikidom/lib/es/es.Range.js
@@ -3,12 +3,12 @@
44 *
55 * @class
66 * @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
1313 */
1414 es.Range = function( from, to ) {
1515 this.from = from || 0;
@@ -16,15 +16,38 @@
1717 this.normalize();
1818 };
1919
 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+ */
2029 es.Range.prototype.containsOffset = function( offset ) {
2130 this.normalize();
2231 return offset >= this.start && offset < this.end;
2332 };
2433
 34+/**
 35+ * Gets the length of the range.
 36+ *
 37+ * @method
 38+ * @returns {Integer} Length of range
 39+ */
2540 es.Range.prototype.getLength = function() {
2641 return Math.abs( this.from - this.to );
2742 };
2843
 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+ */
2952 es.Range.prototype.normalize = function() {
3053 if ( this.from < this.to ) {
3154 this.start = this.from;
Index: trunk/parsers/wikidom/demos/es/index.html
@@ -73,7 +73,7 @@
7474 <!-- Demo -->
7575 <script>
7676 $(document).ready( function() {
77 - doc = es.Document.newFromWikidom([
 77+ doc = es.Document.newFromWikiDomDocument( { 'blocks': [
7878 {
7979 "type": "paragraph",
8080 "lines": [
@@ -122,21 +122,18 @@
123123 'line': { 'text': 'Operating Systems' },
124124 'lists': [
125125 {
126 - 'type': 'list',
127126 'style': 'bullet',
128127 'items': [
129128 {
130129 'line': { 'text': 'Linux' },
131130 'lists': [
132131 {
133 - 'type': 'list',
134132 'style': 'bullet',
135133 'items': [
136134 {
137135 'line': { 'text': 'Ubuntu' },
138136 'lists': [
139137 {
140 - 'type': 'list',
141138 'style': 'bullet',
142139 'items': [
143140 {
@@ -227,7 +224,7 @@
228225 { 'text': 'Text might have\ttabs\tin it too. Not all text will end in a line breaking character' }
229226 ]
230227 }
231 - ]);
 228+ ] } );
232229 var surface = new es.Surface( $('#es-editor'), doc );
233230
234231 $( '#es-toolbar .es-toolbarTool' ).mousedown( function( e ) {

Status & tagging log