r61637 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61636‎ | r61637 | r61638 >
Date:16:00, 28 January 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Rewrite the Firefox branch of ownline handling to be more readable and to actually work. Hopefully fixes (some of) bug 22281
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -72,7 +72,7 @@
7373 array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
7474 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 7 ),
7575 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 26 ),
76 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 80 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 81 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 25 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 45 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 11 ),
@@ -82,10 +82,10 @@
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 2 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 193 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 194 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 193 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 194 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -447,17 +447,38 @@
448448 // Firefox and Opera
449449 var range = context.$iframe[0].contentWindow.getSelection().getRangeAt( 0 );
450450 if ( options.ownline ) {
 451+ // We need to figure out if the cursor is at the start or end of a line
 452+ var atStart = false, atEnd = false;
451453 var body = context.$content.get( 0 );
452 - // TODO: This'll probably break with syntax highlighting
453 - // When the selection starts at the beginning of a line, it'll have either
454 - // startOffset == 0 or startContainer == body
455 - if ( range.startOffset != 0 && range.startContainer != body ) {
 454+ console.log(range);
 455+ if ( range.startOffset == 0 ) {
 456+ // Start of a line
 457+ // FIXME: Not necessarily the case with syntax highlighting or
 458+ // template collapsing
 459+ atStart = true;
 460+ } else if ( range.startContainer == body ) {
 461+ // Look up the node just before the start of the selection
 462+ // If it's a <BR>, we're at the start of a line that starts with a
 463+ // block element; if not, we're at the end of a line
 464+ var n = body.firstChild;
 465+ for ( var i = 0; i < range.startOffset - 1 && n; i++ ) {
 466+ n = n.nextSibling;
 467+ }
 468+ if ( n && n.nodeName == 'BR' ) {
 469+ atStart = true;
 470+ } else {
 471+ atEnd = true;
 472+ }
 473+ } else if ( range.startContainer.nodeName == '#text' &&
 474+ range.startOffset == range.startContainer.nodeValue.length ) {
 475+ // Apparently this happens when splitting text nodes
 476+ atEnd = true;
 477+ }
 478+
 479+ if ( !atStart ) {
456480 pre = "\n" + options.pre;
457481 }
458 - // TODO: Will this still work with syntax highlighting?
459 - // When the selection ends at the end of a line, it'll have endContainer == body
460 - // and endOffset != 0
461 - if ( range.endContainer != body || range.endOffset == 0 ) {
 482+ if ( !atEnd ) {
462483 post += "\n";
463484 }
464485 }
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6871,17 +6871,38 @@
68726872 // Firefox and Opera
68736873 var range = context.$iframe[0].contentWindow.getSelection().getRangeAt( 0 );
68746874 if ( options.ownline ) {
 6875+ // We need to figure out if the cursor is at the start or end of a line
 6876+ var atStart = false, atEnd = false;
68756877 var body = context.$content.get( 0 );
6876 - // TODO: This'll probably break with syntax highlighting
6877 - // When the selection starts at the beginning of a line, it'll have either
6878 - // startOffset == 0 or startContainer == body
6879 - if ( range.startOffset != 0 && range.startContainer != body ) {
 6878+ console.log(range);
 6879+ if ( range.startOffset == 0 ) {
 6880+ // Start of a line
 6881+ // FIXME: Not necessarily the case with syntax highlighting or
 6882+ // template collapsing
 6883+ atStart = true;
 6884+ } else if ( range.startContainer == body ) {
 6885+ // Look up the node just before the start of the selection
 6886+ // If it's a <BR>, we're at the start of a line that starts with a
 6887+ // block element; if not, we're at the end of a line
 6888+ var n = body.firstChild;
 6889+ for ( var i = 0; i < range.startOffset - 1 && n; i++ ) {
 6890+ n = n.nextSibling;
 6891+ }
 6892+ if ( n && n.nodeName == 'BR' ) {
 6893+ atStart = true;
 6894+ } else {
 6895+ atEnd = true;
 6896+ }
 6897+ } else if ( range.startContainer.nodeName == '#text' &&
 6898+ range.startOffset == range.startContainer.nodeValue.length ) {
 6899+ // Apparently this happens when splitting text nodes
 6900+ atEnd = true;
 6901+ }
 6902+
 6903+ if ( !atStart ) {
68806904 pre = "\n" + options.pre;
68816905 }
6882 - // TODO: Will this still work with syntax highlighting?
6883 - // When the selection ends at the end of a line, it'll have endContainer == body
6884 - // and endOffset != 0
6885 - if ( range.endContainer != body || range.endOffset == 0 ) {
 6906+ if ( !atEnd ) {
68866907 post += "\n";
68876908 }
68886909 }
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -454,8 +454,10 @@
455455 if(typeof retval.text!='undefined'){retval=context.fn.htmlToText(retval.htmlText);}else if(retval.toString){retval=retval.toString();}
456456 return retval;},'encapsulateSelection':function(options){var selText=$(this).textSelection('getSelection');var selTextArr;var selectAfter=false;var pre=options.pre,post=options.post;if(!selText){selText=options.peri;selectAfter=true;}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' ';}
457457 if(options.splitlines){selTextArr=selText.split(/\n/);}
458 -if(context.$iframe[0].contentWindow.getSelection){var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);if(options.ownline){var body=context.$content.get(0);if(range.startOffset!=0&&range.startContainer!=body){pre="\n"+options.pre;}
459 -if(range.endContainer!=body||range.endOffset==0){post+="\n";}}
 458+if(context.$iframe[0].contentWindow.getSelection){var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);if(options.ownline){var atStart=false,atEnd=false;var body=context.$content.get(0);console.log(range);if(range.startOffset==0){atStart=true;}else if(range.startContainer==body){var n=body.firstChild;for(var i=0;i<range.startOffset-1&&n;i++){n=n.nextSibling;}
 459+if(n&&n.nodeName=='BR'){atStart=true;}else{atEnd=true;}}else if(range.startContainer.nodeName=='#text'&&range.startOffset==range.startContainer.nodeValue.length){atEnd=true;}
 460+if(!atStart){pre="\n"+options.pre;}
 461+if(!atEnd){post+="\n";}}
460462 var insertText="";if(options.splitlines){for(var i=0;i<selTextArr.length;i++){insertText=insertText+pre+selTextArr[i]+post;if(i!=selTextArr.length-1)insertText+="\n";}}else{insertText=pre+selText+post;}
461463 var insertLines=insertText.split("\n");range.extractContents();var lastNode;for(var i=insertLines.length-1;i>=0;i--){range.insertNode(context.$iframe[0].contentWindow.document.createTextNode(insertLines[i]));if(i>0){lastNode=range.insertNode(context.$iframe[0].contentWindow.document.createElement('br'));}}
462464 if(lastNode){context.fn.scrollToTop(lastNode);}}else if(context.$iframe[0].contentWindow.document.selection){context.$iframe[0].contentWindow.focus();var range=context.$iframe[0].contentWindow.document.selection.createRange();if(options.ownline&&range.moveStart){var range2=context.$iframe[0].contentWindow.document.selection.createRange();range2.collapse();range2.moveStart('character',-1);if(range2.text!="\r"&&range2.text!="\n"&&range2.text!=""){pre="\n"+pre;}

Follow-up revisions

RevisionCommit summaryAuthorDate
r61669Removing the console.log() call introduced in r61637adam17:22, 29 January 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r61577UsabilityInitiative: (bug 22281) Ownline was broken in Firefox when the curso...catrope15:19, 27 January 2010

Status & tagging log