r63016 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63015‎ | r63016 | r63017 >
Date:19:51, 26 February 2010
Author:adam
Status:deferred
Tags:
Comment:
Follow up to r62980: Implimenting support for IE and adding more comments explaining what this code is doing. TODO: IE8 seems to still have a weird bug with this, but all other browsers appear fine
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' => 27 ),
76 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 155 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 156 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 35 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 52 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 19 ),
@@ -82,10 +82,10 @@
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 3 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 292 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 293 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 292 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 293 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -1195,11 +1195,13 @@
11961196 if ( !selText ) {
11971197 selText = options.peri;
11981198 selectAfter = true;
1199 - } else if ( $.wikiEditor.autoMsg( options, 'peri' ) == selText.replace( /\s\s*$/, '' ) ) {
 1199+ } else if ( options.peri == selText.replace( /\s+$/, '' ) ) {
12001200 // Probably a successive button press
1201 - // strip any extra white space from selText and set variables we'll need for later
1202 - selText = selText.replace( /\s\s*$/, '' );
 1201+ // strip any extra white space from selText
 1202+ selText = selText.replace( /\s+$/, '' );
 1203+ // set the collapseToEnd flag to ensure our selection is collapsed to the end before any insertion is done
12031204 collapseToEnd = true;
 1205+ // set selectAfter to true since we know we'll be populating with our default text
12041206 selectAfter = true;
12051207 } else if ( options.replace ) {
12061208 selText = options.peri;
@@ -1216,6 +1218,8 @@
12171219 if ( context.$iframe[0].contentWindow.getSelection ) {
12181220 // Firefox and Opera
12191221 var range = context.$iframe[0].contentWindow.getSelection().getRangeAt( 0 );
 1222+ // if our test above indicated that this was a sucessive button press, we need to collapse the
 1223+ // selection to the end to avoid replacing text
12201224 if ( collapseToEnd ) {
12211225 // Make sure we're not collapsing ourselves into a BR tag
12221226 if ( range.endContainer.nodeName == 'BR' ) {
@@ -1347,6 +1351,11 @@
13481352 post += "\n";
13491353 }
13501354 }
 1355+ // if our test above indicated that this was a sucessive button press, we need to collapse the
 1356+ // selection to the end to avoid replacing text
 1357+ if ( collapseToEnd ) {
 1358+ range.collapse( false );
 1359+ }
13511360 // TODO: Clean this up. Duplicate code due to the pre-existing browser specific structure of this
13521361 // function
13531362 var insertText = "";
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -7632,11 +7632,13 @@
76337633 if ( !selText ) {
76347634 selText = options.peri;
76357635 selectAfter = true;
7636 - } else if ( $.wikiEditor.autoMsg( options, 'peri' ) == selText.replace( /\s\s*$/, '' ) ) {
 7636+ } else if ( options.peri == selText.replace( /\s+$/, '' ) ) {
76377637 // Probably a successive button press
7638 - // strip any extra white space from selText and set variables we'll need for later
7639 - selText = selText.replace( /\s\s*$/, '' );
 7638+ // strip any extra white space from selText
 7639+ selText = selText.replace( /\s+$/, '' );
 7640+ // set the collapseToEnd flag to ensure our selection is collapsed to the end before any insertion is done
76407641 collapseToEnd = true;
 7642+ // set selectAfter to true since we know we'll be populating with our default text
76417643 selectAfter = true;
76427644 } else if ( options.replace ) {
76437645 selText = options.peri;
@@ -7653,6 +7655,8 @@
76547656 if ( context.$iframe[0].contentWindow.getSelection ) {
76557657 // Firefox and Opera
76567658 var range = context.$iframe[0].contentWindow.getSelection().getRangeAt( 0 );
 7659+ // if our test above indicated that this was a sucessive button press, we need to collapse the
 7660+ // selection to the end to avoid replacing text
76577661 if ( collapseToEnd ) {
76587662 // Make sure we're not collapsing ourselves into a BR tag
76597663 if ( range.endContainer.nodeName == 'BR' ) {
@@ -7784,6 +7788,11 @@
77857789 post += "\n";
77867790 }
77877791 }
 7792+ // if our test above indicated that this was a sucessive button press, we need to collapse the
 7793+ // selection to the end to avoid replacing text
 7794+ if ( collapseToEnd ) {
 7795+ range.collapse( false );
 7796+ }
77887797 // TODO: Clean this up. Duplicate code due to the pre-existing browser specific structure of this
77897798 // function
77907799 var insertText = "";
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -516,7 +516,7 @@
517517 context.$textarea.attr('disabled',true);context.$textarea.hide();context.$iframe.show();context.fn.trigger('ready');context.oldHTML=context.oldDelayedHTML=context.$content.html();$(context.$iframe[0].contentWindow.document).bind('keydown',function(event){return context.fn.trigger('keydown',event);}).bind('paste',function(event){return context.fn.trigger('paste',event);}).bind('cut',function(event){return context.fn.trigger('cut',event);}).bind('keyup paste mouseup cut encapsulateSelection',function(event){return context.fn.trigger('change',event);}).delayedBind(250,'keyup paste mouseup cut encapsulateSelection',function(event){context.fn.trigger('delayedChange',event);});});context.$textarea.closest('form').submit(function(){context.$textarea.attr('disabled',false);context.$textarea.val(context.$textarea.textSelection('getContents'));});context.fallbackWindowOnBeforeUnload=window.onbeforeunload;window.onbeforeunload=function(){context.$textarea.val(context.$textarea.textSelection('getContents'));if(context.fallbackWindowOnBeforeUnload){return context.fallbackWindowOnBeforeUnload();}};},'getContents':function(){var html;if($.browser.msie){var $c=$(context.$content.get(0).cloneNode(true));$c.find('p').each(function(){if($(this).html()==''){$(this).replaceWith('<p></p>');}});html=$c.html();}else{html=context.$content.html();}
518518 return context.fn.htmlToText(html);},'getSelection':function(){var retval;if(context.$iframe[0].contentWindow.getSelection){retval=context.$iframe[0].contentWindow.getSelection();if($.browser.opera){if(retval.rangeCount>0){retval=context.fn.htmlToText($('<pre />').append(retval.getRangeAt(0).cloneContents()).html());}else{retval='';}}}else if(context.$iframe[0].contentWindow.document.selection){retval=context.$iframe[0].contentWindow.document.selection.createRange();}
519519 if(typeof retval.text!='undefined'){retval=context.fn.htmlToText(retval.htmlText);}else if(typeof retval.toString!='undefined'){retval=retval.toString();}
520 -return retval;},'encapsulateSelection':function(options){var selText=$(this).textSelection('getSelection');var selTextArr;var collapseToEnd=false;var selectAfter=false;var setSelectionTo=null;var pre=options.pre,post=options.post;if(!selText){selText=options.peri;selectAfter=true;}else if($.wikiEditor.autoMsg(options,'peri')==selText.replace(/\s\s*$/,'')){selText=selText.replace(/\s\s*$/,'');collapseToEnd=true;selectAfter=true;}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' ';}
 520+return retval;},'encapsulateSelection':function(options){var selText=$(this).textSelection('getSelection');var selTextArr;var collapseToEnd=false;var selectAfter=false;var setSelectionTo=null;var pre=options.pre,post=options.post;if(!selText){selText=options.peri;selectAfter=true;}else if(options.peri==selText.replace(/\s+$/,'')){selText=selText.replace(/\s+$/,'');collapseToEnd=true;selectAfter=true;}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' ';}
521521 if(options.splitlines){selTextArr=selText.split(/\n/);}
522522 if(context.$iframe[0].contentWindow.getSelection){var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);if(collapseToEnd){if(range.endContainer.nodeName=='BR'){range.setEndBefore(range.endContainer);}
523523 range.collapse(false);}
@@ -533,6 +533,7 @@
534534 if(firstNode){context.fn.scrollToTop($(firstNode.parentNode));}
535535 if(selectAfter){setSelectionTo={startContainer:selSC,endContainer:selEC,start:selSO,end:selEO};}else if(lastNode){setSelectionTo={startContainer:lastNode,endContainer:lastNode,start:lastNode.nodeValue.length,end:lastNode.nodeValue.length};}}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;}
536536 var range3=context.$iframe[0].contentWindow.document.selection.createRange();range3.collapse(false);range3.moveEnd('character',1);if(range3.text!="\r"&&range3.text!="\n"&&range3.text!=""){post+="\n";}}
 537+if(collapseToEnd){range.collapse(false);}
537538 var insertText="";if(options.splitlines){for(var j=0;j<selTextArr.length;j++){insertText=insertText+pre+selTextArr[j]+post;if(j!=selTextArr.length-1){insertText+="\n";}}}else{insertText=pre+selText+post;}
538539 range.pasteHTML(insertText.replace(/\</g,'&lt;').replace(/>/g,'&gt;').replace(/\r?\n/g,'<br />'));if(selectAfter){range.moveStart('character',-post.length-selText.length);range.moveEnd('character',-post.length);range.select();}}
539540 if(setSelectionTo){context.fn.setSelection(setSelectionTo);}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r62980WikiEditor: partial fix for bug 22347 and updating one image asset for the te...adam23:05, 25 February 2010

Status & tagging log