r98219 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98218‎ | r98219 | r98220 >
Date:12:39, 27 September 2011
Author:inez
Status:deferred
Tags:
Comment:
Implemntation and usage of getOffsetFromEvent
Modified paths:
  • /trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js
@@ -238,8 +238,7 @@
239239 };
240240
241241 es.SurfaceView.prototype.onMouseDown = function( e ) {
242 - var mousePosition = es.Position.newFromEventPagePosition( e );
243 - var contentOffset = this.documentView.getOffsetFromPosition( mousePosition );
 242+ var contentOffset = this.documentView.getOffsetFromEvent( e );
244243
245244 this.from = contentOffset;
246245 this.selecting = true;
@@ -253,8 +252,7 @@
254253
255254 es.SurfaceView.prototype.onMouseMove = function( e ) {
256255 if (this.selecting ) {
257 - var mousePosition = es.Position.newFromEventPagePosition( e );
258 - var contentOffset = this.documentView.getOffsetFromPosition( mousePosition );
 256+ var contentOffset = this.documentView.getOffsetFromEvent( e );
259257
260258 this.to = contentOffset;
261259 this.documentView.drawSelection( new es.Range( this.from, this.to ) );
Index: trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js
@@ -12,6 +12,25 @@
1313
1414 /* Methods */
1515
 16+es.DocumentView.prototype.getOffsetFromEvent = function( e ) {
 17+ var $target = $( e.target ),
 18+ $block = $target.is( '.editSurface-block' )
 19+ ? $target : $target.closest( '.editSurface-block' ),
 20+ position = es.Position.newFromEventPagePosition( e );
 21+
 22+ if( $block.length ) {
 23+ var block = $block.data( 'block' ),
 24+ offset = block.getOffsetFromPosition( position );
 25+ while ( typeof block.list !== 'undefined' ) {
 26+ offset += block.list.items.offsetOf( block );
 27+ block = block.list;
 28+ }
 29+ return offset;
 30+ } else {
 31+ return this.getOffsetFromPosition( position );
 32+ }
 33+};
 34+
1635 es.DocumentView.prototype.getOffsetFromPosition = function( position ) {
1736 if ( this.items.length === 0 ) {
1837 return 0;

Status & tagging log