Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js |
— | — | @@ -89,34 +89,54 @@ |
90 | 90 | * @returns {es.Position} Position of offset |
91 | 91 | */ |
92 | 92 | 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 ) { |
93 | 119 | var globalOffset = 0, |
94 | | - globalLines = 0, |
| 120 | + linesBefore = 0, |
95 | 121 | itemLength, |
96 | | - position, |
97 | | - blockOffset = this.$.offset(); |
| 122 | + location; |
98 | 123 | |
99 | 124 | this.list.traverseItems( function( item, index ) { |
100 | 125 | itemLength = item.content.getLength(); |
101 | 126 | 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 | + }; |
108 | 132 | return false; |
109 | 133 | } |
110 | 134 | globalOffset += itemLength + 1; |
111 | | - globalLines += item.flow.lines.length; |
| 135 | + linesBefore += item.flow.lines.length; |
112 | 136 | } ); |
113 | 137 | |
114 | | - return position; |
| 138 | + return location; |
115 | 139 | }; |
116 | 140 | |
117 | | -es.ListBlock.prototype.getText = function( range, render ) { |
118 | | - return ""; |
119 | | -}; |
120 | | - |
121 | 141 | /* Registration */ |
122 | 142 | |
123 | 143 | /** |