r89686 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89685‎ | r89686 | r89687 >
Date:20:47, 7 June 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Moved selection event handling to document, rather than paragraphs.
Modified paths:
  • /trunk/parsers/wikidom/lib/jquery.editSurface.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/jquery.editSurface.js
@@ -11,7 +11,53 @@
1212 .append( '<div class="editSurface-document"></div>' )
1313 .before( '<div class="editSurface-range"></div>'
1414 + '<div class="editSurface-range"></div>'
15 - + '<div class="editSurface-range"></div>');
 15+ + '<div class="editSurface-range"></div>')
 16+ .mousedown( function( e ) {
 17+ var $target = $( e.target );
 18+ // TODO: If the target is not a line, find the nearest line to the cursor and use it
 19+ if ( $target.is( '.editSurface-line' ) ) {
 20+ e.preventDefault();
 21+ e.stopPropagation();
 22+ sel = {
 23+ 'active': true,
 24+ 'from': null,
 25+ 'to': null,
 26+ 'start': getSelection( e ),
 27+ 'end': null
 28+ };
 29+ drawSelection( $target.parent() );
 30+ }
 31+ return false;
 32+ } )
 33+ .mouseup( function( e ) {
 34+ var $target = $( e.target );
 35+ if ( !$target.is( '.editSurface-line' ) || !sel.from || !sel.to
 36+ || ( sel.from.line === sel.to.line && sel.from.index === sel.to.index ) ) {
 37+ sel.from = null;
 38+ sel.to = null;
 39+ sel.start = null;
 40+ sel.end = null;
 41+ }
 42+ sel.active = false;
 43+ drawSelection( $target.parent() );
 44+ } )
 45+ .mousemove( function( e ) {
 46+ var $target = $( e.target );
 47+ // TODO: If the target is not a line, find the nearest line to the cursor and use it
 48+ if ( $target.is( '.editSurface-line' ) && sel.active ) {
 49+ sel.end = getSelection( e );
 50+ if ( sel.start.line < sel.end.line
 51+ || ( sel.start.line === sel.end.line
 52+ && sel.start.index < sel.end.index ) ) {
 53+ sel.from = sel.start;
 54+ sel.to = sel.end;
 55+ } else {
 56+ sel.from = sel.end;
 57+ sel.to = sel.start;
 58+ }
 59+ drawSelection( $target.parent() );
 60+ }
 61+ } );
1662 var ranges = {
1763 '$all': $( '.editSurface-range' ),
1864 '$first': $( '.editSurface-range:eq(0)' ),
@@ -147,50 +193,6 @@
148194 lines.push( paragraph.lines[i].text );
149195 }
150196 $paragraph.flow( lines.join( ' ' ) );
151 - $paragraph
152 - .mousedown( function( e ) {
153 - // TODO: If the target is not a line, find the nearest line to the cursor and use it
154 - if ( $( e.target ).is( '.editSurface-line' ) ) {
155 - e.preventDefault();
156 - e.stopPropagation();
157 - sel = {
158 - 'active': true,
159 - 'from': null,
160 - 'to': null,
161 - 'start': getSelection( e ),
162 - 'end': null
163 - };
164 - drawSelection( $paragraph );
165 - }
166 - return false;
167 - } )
168 - .mouseup( function( e ) {
169 - if ( !$( e.target ).is( '.editSurface-line' ) || !sel.from || !sel.to
170 - || ( sel.from.line === sel.to.line && sel.from.index === sel.to.index ) ) {
171 - sel.from = null;
172 - sel.to = null;
173 - sel.start = null;
174 - sel.end = null;
175 - }
176 - sel.active = false;
177 - drawSelection( $paragraph );
178 - } )
179 - .mousemove( function( e ) {
180 - // TODO: If the target is not a line, find the nearest line to the cursor and use it
181 - if ( $( e.target ).is( '.editSurface-line' ) && sel.active ) {
182 - sel.end = getSelection( e );
183 - if ( sel.start.line < sel.end.line
184 - || ( sel.start.line === sel.end.line
185 - && sel.start.index < sel.end.index ) ) {
186 - sel.from = sel.start;
187 - sel.to = sel.end;
188 - } else {
189 - sel.from = sel.end;
190 - sel.to = sel.start;
191 - }
192 - drawSelection( $paragraph );
193 - }
194 - } );
195197 }
196198
197199 function update() {

Status & tagging log