Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js |
— | — | @@ -7,6 +7,7 @@ |
8 | 8 | for ( var i = 0; i < items.length; i++ ) {
|
9 | 9 | listItems.push( new es.ListBlockItem( items[i].line, items[i].lists || [] ) );
|
10 | 10 | }
|
| 11 | +
|
11 | 12 | /*
|
12 | 13 | * Initialize container
|
13 | 14 | *
|
— | — | @@ -37,14 +38,6 @@ |
38 | 39 | itemLength = this.items[i].getLength();
|
39 | 40 |
|
40 | 41 | if ( offset >= itemOffset && offset < itemOffset + itemLength ) {
|
41 | | -
|
42 | | - if ( offset - itemOffset < this.items[i].content.getLength() ) {
|
43 | | - return {
|
44 | | - 'item': this.items[i],
|
45 | | - 'offset': offset - itemOffset
|
46 | | - };
|
47 | | - }
|
48 | | -
|
49 | 42 | var location = this.items[i].getLocationFromOffset( offset - itemOffset );
|
50 | 43 | return {
|
51 | 44 | 'item': location.item,
|
— | — | @@ -105,18 +98,17 @@ |
106 | 99 | return length;
|
107 | 100 | };
|
108 | 101 |
|
109 | | -
|
110 | | -
|
111 | 102 | es.ListBlockItem.prototype.getLocationFromOffset = function( offset ) {
|
| 103 | + var contentLength = this.content.getLength();
|
112 | 104 |
|
113 | | - if ( offset < this.content.getLength() ) {
|
| 105 | + if ( offset < contentLength ) {
|
114 | 106 | return {
|
115 | 107 | 'item': this,
|
116 | 108 | 'offset': offset
|
117 | 109 | };
|
118 | 110 | }
|
119 | 111 |
|
120 | | - offset -= this.content.getLength();
|
| 112 | + offset -= contentLength;
|
121 | 113 |
|
122 | 114 | var listOffset = 0,
|
123 | 115 | listLength;
|
— | — | @@ -167,6 +159,46 @@ |
168 | 160 | this.list.renderContent( offset );
|
169 | 161 | };
|
170 | 162 |
|
| 163 | +es.ListBlock.prototype.getPosition = function( offset ) {
|
| 164 | + var location = this.list.getLocationFromOffset( offset ),
|
| 165 | + position = location.item.flow.getPosition( location.offset ),
|
| 166 | + blockOffset = this.$.offset(),
|
| 167 | + lineOffset = location.item.$line.find( '.editSurface-list-content' ).offset();
|
| 168 | +
|
| 169 | +
|
| 170 | +
|
| 171 | + position.top += lineOffset.top - blockOffset.top;
|
| 172 | + position.left += lineOffset.left - blockOffset.left;
|
| 173 | + position.bottom += lineOffset.top - blockOffset.top;
|
| 174 | +
|
| 175 | + return position;
|
| 176 | +};
|
| 177 | +
|
| 178 | +es.ListBlock.prototype.getOffset = function( position ) {
|
| 179 | + var $lines = this.$.find( '.editSurface-line' ),
|
| 180 | + $line,
|
| 181 | + blockOffset = this.$.offset();
|
| 182 | + var length = 0;
|
| 183 | + $lines.each( function() {
|
| 184 | + if ( position.top <= ( $(this).offset().top - blockOffset.top ) ) {
|
| 185 | + return false;
|
| 186 | + }
|
| 187 | + length += $(this).closest( '.editSurface-item' ).data('item').content.getLength();
|
| 188 | + $line = $(this);
|
| 189 | + } );
|
| 190 | +
|
| 191 | + var item = $line.closest( '.editSurface-item' ).data( 'item' ),
|
| 192 | + lineOffset = $line.parent().offset();
|
| 193 | + length -= item.content.getLength();
|
| 194 | +
|
| 195 | +
|
| 196 | + position.top -= lineOffset.top - blockOffset.top;
|
| 197 | + position.left -= lineOffset.left - blockOffset.left;
|
| 198 | + position.bottom -= lineOffset.top - blockOffset.top;
|
| 199 | +
|
| 200 | + return length + item.flow.getOffset( position );
|
| 201 | +};
|
| 202 | +
|
171 | 203 | es.Block.models['list'] = es.ListBlock;
|
172 | 204 |
|
173 | 205 | es.extend( es.ListBlock, es.Block );
|