r94556 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94555‎ | r94556 | r94557 >
Date:20:01, 15 August 2011
Author:inez
Status:deferred
Tags:
Comment:
Implement getLocationFromOffset method and use it in getPosition method
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.ListBlock.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js
@@ -89,34 +89,54 @@
9090 * @returns {es.Position} Position of offset
9191 */
9292 es.ListBlock.prototype.getPosition = function( offset ) {
 93+ var location = this.getLocationFromOffset( offset ),
 94+ position = location.item.flow.getPosition( location.offset ),
 95+ contentOffset = location.item.$content.offset(),
 96+ blockOffset = this.$.offset();
 97+
 98+ position.top += contentOffset.top - blockOffset.top;
 99+ position.left += contentOffset.left - blockOffset.left;
 100+ position.bottom += contentOffset.top - blockOffset.top;
 101+ position.line += location.linesBefore;
 102+
 103+ return position;
 104+};
 105+
 106+es.ListBlock.prototype.getText = function( range, render ) {
 107+ return "";
 108+};
 109+
 110+/**
 111+ * Gets a location from an offset.
 112+ *
 113+ * @method
 114+ * @param offset {Integer} Offset to get location for
 115+ * @returns {Object} Location object with item, offset and linesBefore properties, where offset
 116+ * is local to item and linesBefore is total number of flow lines above returned item
 117+ */
 118+es.ListBlock.prototype.getLocationFromOffset = function( offset ) {
93119 var globalOffset = 0,
94 - globalLines = 0,
 120+ linesBefore = 0,
95121 itemLength,
96 - position,
97 - blockOffset = this.$.offset();
 122+ location;
98123
99124 this.list.traverseItems( function( item, index ) {
100125 itemLength = item.content.getLength();
101126 if ( offset >= globalOffset && offset <= globalOffset + itemLength ) {
102 - position = item.flow.getPosition( offset - globalOffset );
103 - contentOffset = item.$content.offset();
104 - position.top += contentOffset.top - blockOffset.top;
105 - position.left += contentOffset.left - blockOffset.left;
106 - position.bottom += contentOffset.top - blockOffset.top;
107 - position.line += globalLines;
 127+ location = {
 128+ 'item' : item,
 129+ 'offset' : offset - globalOffset,
 130+ 'linesBefore': linesBefore
 131+ };
108132 return false;
109133 }
110134 globalOffset += itemLength + 1;
111 - globalLines += item.flow.lines.length;
 135+ linesBefore += item.flow.lines.length;
112136 } );
113137
114 - return position;
 138+ return location;
115139 };
116140
117 -es.ListBlock.prototype.getText = function( range, render ) {
118 - return "";
119 -};
120 -
121141 /* Registration */
122142
123143 /**

Status & tagging log