r92918 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92917‎ | r92918 | r92919 >
Date:23:42, 22 July 2011
Author:inez
Status:deferred
Tags:
Comment:
Make cursor works in lists, selection partially works
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.ListBlock.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js
@@ -7,6 +7,7 @@
88 for ( var i = 0; i < items.length; i++ ) {
99 listItems.push( new es.ListBlockItem( items[i].line, items[i].lists || [] ) );
1010 }
 11+
1112 /*
1213 * Initialize container
1314 *
@@ -37,14 +38,6 @@
3839 itemLength = this.items[i].getLength();
3940
4041 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 -
4942 var location = this.items[i].getLocationFromOffset( offset - itemOffset );
5043 return {
5144 'item': location.item,
@@ -105,18 +98,17 @@
10699 return length;
107100 };
108101
109 -
110 -
111102 es.ListBlockItem.prototype.getLocationFromOffset = function( offset ) {
 103+ var contentLength = this.content.getLength();
112104
113 - if ( offset < this.content.getLength() ) {
 105+ if ( offset < contentLength ) {
114106 return {
115107 'item': this,
116108 'offset': offset
117109 };
118110 }
119111
120 - offset -= this.content.getLength();
 112+ offset -= contentLength;
121113
122114 var listOffset = 0,
123115 listLength;
@@ -167,6 +159,46 @@
168160 this.list.renderContent( offset );
169161 };
170162
 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+
171203 es.Block.models['list'] = es.ListBlock;
172204
173205 es.extend( es.ListBlock, es.Block );

Status & tagging log