r54704 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54703‎ | r54704 | r54705 >
Date:09:49, 10 August 2009
Author:catrope
Status:deferred
Tags:
Comment:
EditToolbar: Prevent JS error occurring when trying to access selectionStart attribute of a hidden textarea, resulting in the encapsulateSelection event never being triggered and breaking wikEd
Modified paths:
  • /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.textSelection.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.textSelection.js
@@ -55,7 +55,7 @@
5656 } else if ( document.body ) {
5757 document.body.scrollTop = winScroll;
5858 }
59 - } else if ( e.selectionStart || e.selectionStart == '0' ) {
 59+ } else if ( e.style.display != 'none' && ( e.selectionStart || e.selectionStart == '0' ) ) {
6060 // Mozilla
6161 var textScroll = e.scrollTop;
6262 $(this).focus();
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -312,7 +312,7 @@
313313 } else if ( document.body ) {
314314 document.body.scrollTop = winScroll;
315315 }
316 - } else if ( e.selectionStart || e.selectionStart == '0' ) {
 316+ } else if ( e.style.display != 'none' && ( e.selectionStart || e.selectionStart == '0' ) ) {
317317 // Mozilla
318318 var textScroll = e.scrollTop;
319319 $(this).focus();
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -22,7 +22,7 @@
2323 var e=this.jquery?this[0]:this;var selText;var isSample=false;if(document.selection&&document.selection.createRange){if(document.documentElement&&document.documentElement.scrollTop){var winScroll=document.documentElement.scrollTop;}else if(document.body){var winScroll=document.body.scrollTop;}
2424 $(this).focus();var range=document.selection.createRange();selText=range.text;checkSelectedText();range.text=pre+selText+post;if(isSample&&range.moveStart){if(window.opera){post=post.replace(/\n/g,'');}
2525 range.moveStart('character',-post.length-selText.length);range.moveEnd('character',-post.length);}
26 -range.select();if(document.documentElement&&document.documentElement.scrollTop){document.documentElement.scrollTop=winScroll}else if(document.body){document.body.scrollTop=winScroll;}}else if(e.selectionStart||e.selectionStart=='0'){var textScroll=e.scrollTop;$(this).focus();var startPos=e.selectionStart;var endPos=e.selectionEnd;selText=e.value.substring(startPos,endPos);checkSelectedText();e.value=e.value.substring(0,startPos)+pre+selText+post+
 26+range.select();if(document.documentElement&&document.documentElement.scrollTop){document.documentElement.scrollTop=winScroll}else if(document.body){document.body.scrollTop=winScroll;}}else if(e.style.display!='none'&&(e.selectionStart||e.selectionStart=='0')){var textScroll=e.scrollTop;$(this).focus();var startPos=e.selectionStart;var endPos=e.selectionEnd;selText=e.value.substring(startPos,endPos);checkSelectedText();e.value=e.value.substring(0,startPos)+pre+selText+post+
2727 e.value.substring(endPos,e.value.length);if(isSample){e.selectionStart=startPos+pre.length;e.selectionEnd=startPos+pre.length+selText.length;}else{e.selectionStart=startPos+pre.length+selText.length+post.length;e.selectionEnd=e.selectionStart;}
2828 e.scrollTop=textScroll;}
2929 $(this).trigger('encapsulateSelection',[pre,peri,post]);},getCaretPosition:function(){function getCaret(e){var caretPos=0;if($.browser.msie){var postFinished=false;var periFinished=false;var postFinished=false;var preText,rawPreText,periText;var rawPeriText,postText,rawPostText;var periRange=document.selection.createRange().duplicate();var preRange=document.body.createTextRange();preRange.moveToElementText(e);preRange.setEndPoint("EndToStart",periRange);var postRange=document.body.createTextRange();postRange.moveToElementText(e);postRange.setEndPoint("StartToEnd",periRange);preText=rawPreText=preRange.text;periText=rawPeriText=periRange.text;postText=rawPostText=postRange.text;do{if(!postFinished){if(preRange.compareEndPoints("StartToEnd",preRange)==0){postFinished=true;}else{preRange.moveEnd("character",-1)

Follow-up revisions

RevisionCommit summaryAuthorDate
r54707EditToolbar: Add special characters for Telugu, thanks to Veeven for providin...catrope10:42, 10 August 2009
r54716Fix up r54704: always skip insertion when the textarea is hidden, not just in...catrope13:25, 10 August 2009

Status & tagging log