http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89686
Revision: 89686
Author: tparscal
Date: 2011-06-07 20:47:43 +0000 (Tue, 07 Jun 2011)
Log Message:
-----------
Moved selection event handling to document, rather than paragraphs.
Modified Paths:
--------------
trunk/parsers/wikidom/lib/jquery.editSurface.js
Modified: trunk/parsers/wikidom/lib/jquery.editSurface.js
===================================================================
--- trunk/parsers/wikidom/lib/jquery.editSurface.js 2011-06-07 20:39:57 UTC
(rev 89685)
+++ trunk/parsers/wikidom/lib/jquery.editSurface.js 2011-06-07 20:47:43 UTC
(rev 89686)
@@ -11,7 +11,53 @@
.append( '<div class="editSurface-document"></div>' )
.before( '<div class="editSurface-range"></div>'
+ '<div class="editSurface-range"></div>'
- + '<div class="editSurface-range"></div>');
+ + '<div class="editSurface-range"></div>')
+ .mousedown( function( e ) {
+ var $target = $( e.target );
+ // TODO: If the target is not a line, find the nearest
line to the cursor and use it
+ if ( $target.is( '.editSurface-line' ) ) {
+ e.preventDefault();
+ e.stopPropagation();
+ sel = {
+ 'active': true,
+ 'from': null,
+ 'to': null,
+ 'start': getSelection( e ),
+ 'end': null
+ };
+ drawSelection( $target.parent() );
+ }
+ return false;
+ } )
+ .mouseup( function( e ) {
+ var $target = $( e.target );
+ if ( !$target.is( '.editSurface-line' ) || !sel.from ||
!sel.to
+ || ( sel.from.line === sel.to.line &&
sel.from.index === sel.to.index ) ) {
+ sel.from = null;
+ sel.to = null;
+ sel.start = null;
+ sel.end = null;
+ }
+ sel.active = false;
+ drawSelection( $target.parent() );
+ } )
+ .mousemove( function( e ) {
+ var $target = $( e.target );
+ // TODO: If the target is not a line, find the nearest
line to the cursor and use it
+ if ( $target.is( '.editSurface-line' ) && sel.active ) {
+ sel.end = getSelection( e );
+ if ( sel.start.line < sel.end.line
+ || ( sel.start.line ===
sel.end.line
+ &&
sel.start.index < sel.end.index ) ) {
+ sel.from = sel.start;
+ sel.to = sel.end;
+ } else {
+ sel.from = sel.end;
+ sel.to = sel.start;
+ }
+ drawSelection( $target.parent() );
+ }
+ } );
var ranges = {
'$all': $( '.editSurface-range' ),
'$first': $( '.editSurface-range:eq(0)' ),
@@ -147,50 +193,6 @@
lines.push( paragraph.lines[i].text );
}
$paragraph.flow( lines.join( ' ' ) );
- $paragraph
- .mousedown( function( e ) {
- // TODO: If the target is not a line, find the
nearest line to the cursor and use it
- if ( $( e.target ).is( '.editSurface-line' ) ) {
- e.preventDefault();
- e.stopPropagation();
- sel = {
- 'active': true,
- 'from': null,
- 'to': null,
- 'start': getSelection( e ),
- 'end': null
- };
- drawSelection( $paragraph );
- }
- return false;
- } )
- .mouseup( function( e ) {
- if ( !$( e.target ).is( '.editSurface-line' )
|| !sel.from || !sel.to
- || ( sel.from.line ===
sel.to.line && sel.from.index === sel.to.index ) ) {
- sel.from = null;
- sel.to = null;
- sel.start = null;
- sel.end = null;
- }
- sel.active = false;
- drawSelection( $paragraph );
- } )
- .mousemove( function( e ) {
- // TODO: If the target is not a line, find the
nearest line to the cursor and use it
- if ( $( e.target ).is( '.editSurface-line' ) &&
sel.active ) {
- sel.end = getSelection( e );
- if ( sel.start.line < sel.end.line
- || ( sel.start.line ===
sel.end.line
- &&
sel.start.index < sel.end.index ) ) {
- sel.from = sel.start;
- sel.to = sel.end;
- } else {
- sel.from = sel.end;
- sel.to = sel.start;
- }
- drawSelection( $paragraph );
- }
- } );
}
function update() {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs