r66565 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66564‎ | r66565 | r66566 >
Date:15:14, 17 May 2010
Author:adam
Status:ok (Comments)
Tags:
Comment:
Fix for bug 23498 and an unreported bug where context was not being setup correctly in the suggestsions code
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.suggestions.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -70,7 +70,7 @@
7171 array( 'src' => 'js/plugins/jquery.color.js', 'version' => 1 ),
7272 array( 'src' => 'js/plugins/jquery.cookie.js', 'version' => 4 ),
7373 array( 'src' => 'js/plugins/jquery.delayedBind.js', 'version' => 1 ),
74 - array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 14 ),
 74+ array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 15 ),
7575 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 33 ),
7676 array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 187 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 53 ),
@@ -83,10 +83,10 @@
8484 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 5 ),
8585 ),
8686 'combined' => array(
87 - array( 'src' => 'js/plugins.combined.js', 'version' => 396 ),
 87+ array( 'src' => 'js/plugins.combined.js', 'version' => 397 ),
8888 ),
8989 'minified' => array(
90 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 396 ),
 90+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 397 ),
9191 ),
9292 ),
9393 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.suggestions.js
@@ -258,7 +258,11 @@
259259 context.data.$container.hide();
260260 preventDefault = wasVisible;
261261 selected = context.data.$container.find( '.suggestions-result-current' );
262 - if ( selected.is( '.suggestions-special' ) ) {
 262+ if ( selected.size() == 0 ) {
 263+ // if nothing is selected, cancel any current requests and submit the form
 264+ $.suggestions.cancel( context );
 265+ context.config.$region.closest( 'form' ).submit();
 266+ } else if ( selected.is( '.suggestions-special' ) ) {
263267 if ( typeof context.config.special.select == 'function' ) {
264268 context.config.special.select.call( selected, context.data.$textbox );
265269 }
@@ -292,7 +296,7 @@
293297 /* Construction / Loading */
294298
295299 var context = $(this).data( 'suggestions-context' );
296 - if ( typeof context == 'undefined' ) {
 300+ if ( typeof context == 'undefined' || context == null ) {
297301 context = {
298302 config: {
299303 'fetch' : function() {},
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6009,7 +6009,11 @@
60106010 context.data.$container.hide();
60116011 preventDefault = wasVisible;
60126012 selected = context.data.$container.find( '.suggestions-result-current' );
6013 - if ( selected.is( '.suggestions-special' ) ) {
 6013+ if ( selected.size() == 0 ) {
 6014+ // if nothing is selected, cancel any current requests and submit the form
 6015+ $.suggestions.cancel( context );
 6016+ context.config.$region.closest( 'form' ).submit();
 6017+ } else if ( selected.is( '.suggestions-special' ) ) {
60146018 if ( typeof context.config.special.select == 'function' ) {
60156019 context.config.special.select.call( selected, context.data.$textbox );
60166020 }
@@ -6043,7 +6047,7 @@
60446048 /* Construction / Loading */
60456049
60466050 var context = $(this).data( 'suggestions-context' );
6047 - if ( typeof context == 'undefined' ) {
 6051+ if ( typeof context == 'undefined' || context == null ) {
60486052 context = {
60496053 config: {
60506054 'fetch' : function() {},
@@ -6685,6 +6689,7 @@
66866690 'isSupported': function( module ) {
66876691 // Fallback to the wikiEditor browser map if no special map is provided in the module
66886692 var mod = module && 'browsers' in module ? module : $.wikiEditor;
 6693+ return mod.supported = true;
66896694 // Check for and make use of cached value and early opportunities to bail
66906695 if ( typeof mod.supported !== 'undefined' ) {
66916696 // Cache hit
@@ -7018,8 +7023,12 @@
70197024 'paste': function( event ) {
70207025 // Save the cursor position to restore it after all this voodoo
70217026 var cursorPos = context.fn.getCaretPosition();
7022 - var oldLength = context.fn.getContents().length - ( cursorPos[1] - cursorPos[0] );
7023 - context.$content.find( ':not(.wikiEditor)' ).addClass( 'wikiEditor' );
 7027+ if ( !context.$content.text() ) {
 7028+ context.$content.empty();
 7029+ }
 7030+ var oldLength = context.fn.getContents().length;
 7031+
 7032+ context.$content.find( '*' ).addClass( 'wikiEditor' );
70247033 if ( $.layout.name !== 'webkit' ) {
70257034 context.$content.addClass( 'pasting' );
70267035 }
@@ -7039,58 +7048,82 @@
70407049 var outerParent = $(this).parent();
70417050 outerParent.replaceWith( outerParent.childNodes );
70427051 } );
 7052+
70437053 // Unwrap the span found in webkit copies (Apple Richtext)
7044 - context.$content.find( 'span.Apple-style-span' ).each( function() {
7045 - $(this).replaceWith( this.childNodes );
7046 - } );
 7054+ if ( ! $.browser.msie ) {
 7055+ context.$content.find( 'span.Apple-style-span' ).each( function() {
 7056+ $(this).replaceWith( this.childNodes );
 7057+ } );
 7058+ }
70477059
7048 - // If the pasted content is plain text then wrap it in a <p> and adjust the <br> accordingly
7049 - var pasteContent = context.fn.getOffset( cursorPos[0] ).node;
7050 - var removeNextBR = false;
7051 - while ( pasteContent != null && !$( pasteContent ).hasClass( 'wikiEditor' ) ) {
7052 - var currentNode = pasteContent;
7053 - pasteContent = pasteContent.nextSibling;
7054 - if ( currentNode.nodeName == '#text' && currentNode.nodeValue == currentNode.wholeText ) {
7055 - var pWrapper = $( '<p />' ).addClass( 'wikiEditor' );
7056 - $( currentNode ).wrap( pWrapper );
7057 - $( currentNode ).addClass( 'wikiEditor' );
7058 - removeNextBR = true;
7059 - } else if ( currentNode.nodeName == 'BR' && removeNextBR ) {
7060 - $( currentNode ).remove();
7061 - removeNextBR = false;
7062 - } else {
7063 - removeNextBR = false;
7064 - }
7065 - }
70667060 var $selection = context.$content.find( ':not(.wikiEditor)' );
 7061+ var $previousElement;
70677062 while ( $selection.length && $selection.length > 0 ) {
70687063 var $currentElement = $selection.eq( 0 );
 7064+
 7065+ //go up till we find the first pasted element
70697066 while ( !$currentElement.parent().is( 'body' ) && !$currentElement.parent().is( '.wikiEditor' ) ) {
70707067 $currentElement = $currentElement.parent();
70717068 }
 7069+ //go to the previous element till we find the first pasted element
 7070+ while ( $currentElement[0] != null &&
 7071+ $currentElement[0].previousSibling != null &&
 7072+ !$( $currentElement[0].previousSibling ).hasClass( 'wikiEditor' ) ) {
 7073+ $currentElement = $( $currentElement[0].previousSibling );
 7074+ }
70727075
 7076+ //each pasted element is always wrapped in a <p>
70737077 var $newElement;
7074 - if ( $currentElement.is( 'p' ) || $currentElement.is( 'div' ) || $currentElement.is( 'pre' ) ) {
7075 - //Convert all <div>, <p> and <pre> that was pasted into a <p> element
7076 - $newElement = $( '<p />' );
 7078+ var textNode = false;
 7079+ if ( $currentElement[0].nodeName == '#text' ) {
 7080+ $newElement = $( '<p></p>' );
 7081+ textNode = true;
 7082+ } else if ( $currentElement.is( 'p' ) || $currentElement.is( 'pre' ) || $currentElement.is( 'br' ) ) {
 7083+ $newElement = $( '<p></p>' );
70777084 } else {
7078 - // everything else becomes a <span>
7079 - $newElement = $( '<span />' ).addClass( 'wikiEditor' );
 7085+ $newElement = $( '<span></span>' );
70807086 }
 7087+ var newElementHTML = '';
 7088+ var currentHTML = '';
70817089
7082 - // If the pasted content was html, just convert it into text and <br>
7083 - var pieces = $.trim( $currentElement.text() ).split( '\n' );
7084 - var newElementHTML = '';
 7090+
 7091+ if ( $currentElement[0].nodeName == '#text' ) {
 7092+ //if it is a text node then just append it
 7093+ currentHTML = $currentElement[0].nodeValue;
 7094+ } else {
 7095+ currentHTML = $currentElement.html();
 7096+ //replace all forms of <p> tags with a \n. All other tags get removed.
 7097+ currentHTML = currentHTML.replace(/(<[\s]*p[^>]*>)|(<[\s]*\/p[^>]*>)|(<[\s]*p[^\/>]*\/>)/gi, '\n');
 7098+ currentHTML = currentHTML.replace(/(<[^>]*>)|(<[^\>]*\>)/gi, '');
 7099+
 7100+ }
 7101+
 7102+ //wrap each piece in a <p> with a <br> in between.
 7103+ var pieces = currentHTML.split( '\n' );
70857104 for ( var i = 0; i < pieces.length; i++ ) {
70867105 if ( pieces[i] ) {
7087 - newElementHTML += $.trim( pieces[i] );
7088 - } else {
7089 - newElementHTML += '<span><br class="wikiEditor" /></span>';
 7106+ if ( textNode || ! $newElement.is( 'p' ) ) {
 7107+ newElementHTML += '<p class="wikiEditor">' + pieces[i] + '</p>';
 7108+ } else {
 7109+ newElementHTML += pieces[i];
 7110+ }
 7111+ } else if ( textNode || ! $newElement.is( 'p' ) ) {
 7112+ newElementHTML += '<br class="wikiEditor" >';
70907113 }
 7114+
 7115+ if ( !textNode ) {
 7116+ newElementHTML += '<br class="wikiEditor" >';
 7117+ }
70917118 }
7092 - $newElement.html( newElementHTML )
7093 - .addClass( 'wikiEditor' )
7094 - .insertAfter( $currentElement );
 7119+
 7120+ $newElement.html( newElementHTML ).addClass( 'wikiEditor' );
 7121+
 7122+ //remove extra <br>s
 7123+ if ( $newElement.is( 'p' ) && $currentElement[0].nextSibling != null && $( $currentElement[0].nextSibling ).is( 'br' ) ) {
 7124+ $( $currentElement[0].nextSibling ).remove();
 7125+ }
 7126+ //swap out the original content with with newly sanitized one
 7127+ $newElement.insertAfter( $currentElement );
70957128 $currentElement.remove();
70967129
70977130 $selection = context.$content.find( ':not(.wikiEditor)' );
@@ -7101,10 +7134,14 @@
71027135 context.$content.removeClass( 'pasting' );
71037136 }
71047137
 7138+
71057139 // Restore cursor position
71067140 context.fn.purgeOffsets();
71077141 var newLength = context.fn.getContents().length;
71087142 var restoreTo = cursorPos[0] + newLength - oldLength;
 7143+ if ( restoreTo > newLength ) {
 7144+ restoreTo = newLength;
 7145+ }
71097146 context.fn.setSelection( { start: restoreTo, end: restoreTo } );
71107147 }, 0 );
71117148 return true;
@@ -8226,10 +8263,10 @@
82278264 end = e ? e.offset : null;
82288265 // Don't try to set the selection past the end of a node, causes errors
82298266 // Just put the selection at the end of the node in this case
8230 - if ( sc.nodeName == '#text' && start > sc.nodeValue.length ) {
 8267+ if ( sc != null && sc.nodeName == '#text' && start > sc.nodeValue.length ) {
82318268 start = sc.nodeValue.length - 1;
82328269 }
8233 - if ( ec.nodeName == '#text' && end > ec.nodeValue.length ) {
 8270+ if ( ec != null && ec.nodeName == '#text' && end > ec.nodeValue.length ) {
82348271 end = ec.nodeValue.length - 1;
82358272 }
82368273 }
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -401,9 +401,9 @@
402402 context.data.$textbox.trigger('change');}
403403 $.suggestions.special(context);},keypress:function(e,context,key){var wasVisible=context.data.$container.is(':visible');var preventDefault=false;switch(key){case 40:if(wasVisible){$.suggestions.highlight(context,'next',false);}else{$.suggestions.update(context,false);}
404404 preventDefault=true;break;case 38:if(wasVisible){$.suggestions.highlight(context,'prev',false);}
405 -preventDefault=wasVisible;break;case 27:context.data.$container.hide();$.suggestions.restore(context);$.suggestions.cancel(context);context.data.$textbox.trigger('change');preventDefault=wasVisible;break;case 13:context.data.$container.hide();preventDefault=wasVisible;selected=context.data.$container.find('.suggestions-result-current');if(selected.is('.suggestions-special')){if(typeof context.config.special.select=='function'){context.config.special.select.call(selected,context.data.$textbox);}}else{if(typeof context.config.result.select=='function'){$.suggestions.highlight(context,selected,true);context.config.result.select.call(selected,context.data.$textbox);}else{$.suggestions.highlight(context,selected,true);}}
 405+preventDefault=wasVisible;break;case 27:context.data.$container.hide();$.suggestions.restore(context);$.suggestions.cancel(context);context.data.$textbox.trigger('change');preventDefault=wasVisible;break;case 13:context.data.$container.hide();preventDefault=wasVisible;selected=context.data.$container.find('.suggestions-result-current');if(selected.size()==0){$.suggestions.cancel(context);context.config.$region.closest('form').submit();}else if(selected.is('.suggestions-special')){if(typeof context.config.special.select=='function'){context.config.special.select.call(selected,context.data.$textbox);}}else{if(typeof context.config.result.select=='function'){$.suggestions.highlight(context,selected,true);context.config.result.select.call(selected,context.data.$textbox);}else{$.suggestions.highlight(context,selected,true);}}
406406 break;default:$.suggestions.update(context,true);break;}
407 -if(preventDefault){e.preventDefault();e.stopImmediatePropagation();}}};$.fn.suggestions=function(){var returnValue=null;var args=arguments;$(this).each(function(){var context=$(this).data('suggestions-context');if(typeof context=='undefined'){context={config:{'fetch':function(){},'cancel':function(){},'special':{},'result':{},'$region':$(this),'suggestions':[],'maxRows':7,'delay':120,'submitOnClick':false}};}
 407+if(preventDefault){e.preventDefault();e.stopImmediatePropagation();}}};$.fn.suggestions=function(){var returnValue=null;var args=arguments;$(this).each(function(){var context=$(this).data('suggestions-context');if(typeof context=='undefined'||context==null){context={config:{'fetch':function(){},'cancel':function(){},'special':{},'result':{},'$region':$(this),'suggestions':[],'maxRows':7,'delay':120,'submitOnClick':false}};}
408408 if(args.length>0){if(typeof args[0]=='object'){for(var key in args[0]){$.suggestions.configure(context,key,args[0][key]);}}else if(typeof args[0]=='string'){if(args.length>1){$.suggestions.configure(context,args[0],args[1]);}else if(returnValue==null){returnValue=(args[0]in context.config?undefined:context.config[args[0]]);}}}
409409 if(typeof context.data=='undefined'){context.data={'timerID':null,'prevText':null,'visibleResults':0,'mouseDownOn':$([]),'$textbox':$(this)};context.data.$container=$('<div />').css({'top':Math.round(context.data.$textbox.offset().top+context.data.$textbox.outerHeight()),'left':Math.round(context.data.$textbox.offset().left),'width':context.data.$textbox.outerWidth(),'display':'none'}).addClass('suggestions').append($('<div />').addClass('suggestions-results').mousedown(function(e){context.data.mouseDownOn=$(e.target).closest('.suggestions-results div');}).mouseup(function(e){var $result=$(e.target).closest('.suggestions-results div');var $other=context.data.mouseDownOn;context.data.mouseDownOn=$([]);if($result.get(0)!=$other.get(0)){return;}
410410 $.suggestions.highlight(context,$result,true);context.data.$container.hide();if(typeof context.config.result.select=='function'){context.config.result.select.call($result,context.data.$textbox);}
@@ -444,7 +444,7 @@
445445 options.endContainer=options.startContainer;break;case'scrollToCaretPosition':options=$.extend({'force':false},options);break;}
446446 var context=$(this).data('wikiEditor-context');var hasIframe=context!==undefined&&context.$iframe!==undefined;var needSave=false;if(hasIframe&&context.savedSelection!==null){context.fn.restoreSelection();needSave=true;}
447447 retval=(hasIframe?context.fn:fn)[command].call(this,options);if(hasIframe&&needSave){context.fn.saveSelection();}
448 -return retval;};})(jQuery);(function($){$.wikiEditor={'modules':{},'instances':[],'browsers':{'ltr':{'msie':[['>=',7]],'firefox':[['>=',2]],'opera':[['>=',9.6]],'safari':[['>=',3]],'chrome':[['>=',3]],'blackberry':false,'ipod':false,'iphone':false},'rtl':{'msie':[['>=',8]],'firefox':[['>=',2]],'opera':[['>=',9.6]],'safari':[['>=',3]],'chrome':[['>=',3]],'blackberry':false,'ipod':false,'iphone':false}},'imgPath':wgScriptPath+'/extensions/UsabilityInitiative/images/wikiEditor/','isSupported':function(module){var mod=module&&'browsers'in module?module:$.wikiEditor;if(typeof mod.supported!=='undefined'){return mod.supported;}
 448+return retval;};})(jQuery);(function($){$.wikiEditor={'modules':{},'instances':[],'browsers':{'ltr':{'msie':[['>=',7]],'firefox':[['>=',2]],'opera':[['>=',9.6]],'safari':[['>=',3]],'chrome':[['>=',3]],'blackberry':false,'ipod':false,'iphone':false},'rtl':{'msie':[['>=',8]],'firefox':[['>=',2]],'opera':[['>=',9.6]],'safari':[['>=',3]],'chrome':[['>=',3]],'blackberry':false,'ipod':false,'iphone':false}},'imgPath':wgScriptPath+'/extensions/UsabilityInitiative/images/wikiEditor/','isSupported':function(module){var mod=module&&'browsers'in module?module:$.wikiEditor;return mod.supported=true;if(typeof mod.supported!=='undefined'){return mod.supported;}
449449 if(!($.browser.name in mod.browsers[$('body').is('.rtl')?'rtl':'ltr'])){return mod.supported=true;}
450450 var browser=mod.browsers[$('body').is('.rtl')?'rtl':'ltr'][$.browser.name];if(typeof browser!='object'){return mod.supported=false;}
451451 for(var condition in browser){var op=browser[condition][0];var val=browser[condition][1];if(val===false){return mod.supported=false;}else if(typeof val=='string'){if(!(eval('$.browser.version'+op+'"'+val+'"'))){return mod.supported=false;}}else if(typeof val=='number'){if(!(eval('$.browser.versionNumber'+op+val))){return mod.supported=false;}}}
@@ -464,14 +464,20 @@
465465 return true;},'change':function(event){event.data.scope='division';var newHTML=context.$content.html();if(context.oldHTML!=newHTML){context.fn.purgeOffsets();context.oldHTML=newHTML;event.data.scope='realchange';}
466466 if(context.$content.children().length==0){context.$content.append('<p></p>');}
467467 return true;},'delayedChange':function(event){event.data.scope='division';var newHTML=context.$content.html();if(context.oldDelayedHTML!=newHTML){context.oldDelayedHTML=newHTML;event.data.scope='realchange';var cursorPos=context.fn.getCaretPosition();var t=context.fn.getOffset(cursorPos[0]);if(t&&t.node.nodeName=='#text'&&t.node.parentNode.nodeName.toLowerCase()=='body'){$(t.node).wrap("<p></p>");context.fn.purgeOffsets();context.fn.setSelection({start:cursorPos[0],end:cursorPos[1]});}}
468 -context.fn.updateHistory(event.data.scope=='realchange');return true;},'cut':function(event){setTimeout(function(){context.$content.find('br').each(function(){if($(this).parent().is('body')){$(this).wrap($('<p></p>'));}});},100);return true;},'paste':function(event){var cursorPos=context.fn.getCaretPosition();var oldLength=context.fn.getContents().length-(cursorPos[1]-cursorPos[0]);context.$content.find(':not(.wikiEditor)').addClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.addClass('pasting');}
469 -setTimeout(function(){context.$content.find('script,style,img,input,select,textarea,hr,button,link,meta').remove();context.$content.find('*').each(function(){if($(this).children().length==0&&this.childNodes.length>0){$(this).text($(this).text());}});context.$content.find('p:not(.wikiEditor) p:not(.wikiEditor)').each(function(){var outerParent=$(this).parent();outerParent.replaceWith(outerParent.childNodes);});context.$content.find('span.Apple-style-span').each(function(){$(this).replaceWith(this.childNodes);});var pasteContent=context.fn.getOffset(cursorPos[0]).node;var removeNextBR=false;while(pasteContent!=null&&!$(pasteContent).hasClass('wikiEditor')){var currentNode=pasteContent;pasteContent=pasteContent.nextSibling;if(currentNode.nodeName=='#text'&&currentNode.nodeValue==currentNode.wholeText){var pWrapper=$('<p />').addClass('wikiEditor');$(currentNode).wrap(pWrapper);$(currentNode).addClass('wikiEditor');removeNextBR=true;}else if(currentNode.nodeName=='BR'&&removeNextBR){$(currentNode).remove();removeNextBR=false;}else{removeNextBR=false;}}
470 -var $selection=context.$content.find(':not(.wikiEditor)');while($selection.length&&$selection.length>0){var $currentElement=$selection.eq(0);while(!$currentElement.parent().is('body')&&!$currentElement.parent().is('.wikiEditor')){$currentElement=$currentElement.parent();}
471 -var $newElement;if($currentElement.is('p')||$currentElement.is('div')||$currentElement.is('pre')){$newElement=$('<p />');}else{$newElement=$('<span />').addClass('wikiEditor');}
472 -var pieces=$.trim($currentElement.text()).split('\n');var newElementHTML='';for(var i=0;i<pieces.length;i++){if(pieces[i]){newElementHTML+=$.trim(pieces[i]);}else{newElementHTML+='<span><br class="wikiEditor" /></span>';}}
473 -$newElement.html(newElementHTML).addClass('wikiEditor').insertAfter($currentElement);$currentElement.remove();$selection=context.$content.find(':not(.wikiEditor)');}
 468+context.fn.updateHistory(event.data.scope=='realchange');return true;},'cut':function(event){setTimeout(function(){context.$content.find('br').each(function(){if($(this).parent().is('body')){$(this).wrap($('<p></p>'));}});},100);return true;},'paste':function(event){var cursorPos=context.fn.getCaretPosition();if(!context.$content.text()){context.$content.empty();}
 469+var oldLength=context.fn.getContents().length;context.$content.find('*').addClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.addClass('pasting');}
 470+setTimeout(function(){context.$content.find('script,style,img,input,select,textarea,hr,button,link,meta').remove();context.$content.find('*').each(function(){if($(this).children().length==0&&this.childNodes.length>0){$(this).text($(this).text());}});context.$content.find('p:not(.wikiEditor) p:not(.wikiEditor)').each(function(){var outerParent=$(this).parent();outerParent.replaceWith(outerParent.childNodes);});if(!$.browser.msie){context.$content.find('span.Apple-style-span').each(function(){$(this).replaceWith(this.childNodes);});}
 471+var $selection=context.$content.find(':not(.wikiEditor)');var $previousElement;while($selection.length&&$selection.length>0){var $currentElement=$selection.eq(0);while(!$currentElement.parent().is('body')&&!$currentElement.parent().is('.wikiEditor')){$currentElement=$currentElement.parent();}
 472+while($currentElement[0]!=null&&$currentElement[0].previousSibling!=null&&!$($currentElement[0].previousSibling).hasClass('wikiEditor')){$currentElement=$($currentElement[0].previousSibling);}
 473+var $newElement;var textNode=false;if($currentElement[0].nodeName=='#text'){$newElement=$('<p></p>');textNode=true;}else if($currentElement.is('p')||$currentElement.is('pre')||$currentElement.is('br')){$newElement=$('<p></p>');}else{$newElement=$('<span></span>');}
 474+var newElementHTML='';var currentHTML='';if($currentElement[0].nodeName=='#text'){currentHTML=$currentElement[0].nodeValue;}else{currentHTML=$currentElement.html();currentHTML=currentHTML.replace(/(<[\s]*p[^>]*>)|(<[\s]*\/p[^>]*>)|(<[\s]*p[^\/>]*\/>)/gi,'\n');currentHTML=currentHTML.replace(/(<[^>]*>)|(<[^\>]*\>)/gi,'');}
 475+var pieces=currentHTML.split('\n');for(var i=0;i<pieces.length;i++){if(pieces[i]){if(textNode||!$newElement.is('p')){newElementHTML+='<p class="wikiEditor">'+pieces[i]+'</p>';}else{newElementHTML+=pieces[i];}}else if(textNode||!$newElement.is('p')){newElementHTML+='<br class="wikiEditor" >';}
 476+if(!textNode){newElementHTML+='<br class="wikiEditor" >';}}
 477+$newElement.html(newElementHTML).addClass('wikiEditor');if($newElement.is('p')&&$currentElement[0].nextSibling!=null&&$($currentElement[0].nextSibling).is('br')){$($currentElement[0].nextSibling).remove();}
 478+$newElement.insertAfter($currentElement);$currentElement.remove();$selection=context.$content.find(':not(.wikiEditor)');}
474479 context.$content.find('.wikiEditor').removeClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.removeClass('pasting');}
475 -context.fn.purgeOffsets();var newLength=context.fn.getContents().length;var restoreTo=cursorPos[0]+newLength-oldLength;context.fn.setSelection({start:restoreTo,end:restoreTo});},0);return true;},'ready':function(event){context.history.push({'html':context.$content.html(),'sel':context.fn.getCaretPosition()});return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};}
 480+context.fn.purgeOffsets();var newLength=context.fn.getContents().length;var restoreTo=cursorPos[0]+newLength-oldLength;if(restoreTo>newLength){restoreTo=newLength;}
 481+context.fn.setSelection({start:restoreTo,end:restoreTo});},0);return true;},'ready':function(event){context.history.push({'html':context.$content.html(),'sel':context.fn.getCaretPosition()});return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};}
476482 if(typeof event.data=='undefined'){event.data={};}
477483 if(name in context.evt){if(!context.evt[name](event)){return false;}}
478484 var returnFromModules=null;for(var module in context.modules){if(module in $.wikiEditor.modules&&'evt'in $.wikiEditor.modules[module]&&name in $.wikiEditor.modules[module].evt){var ret=$.wikiEditor.modules[module].evt[name](context,event);if(ret!=null){if(returnFromModules==null){returnFromModules=ret;}else{returnFromModules=returnFromModules&&ret;}}}}
@@ -561,8 +567,8 @@
562568 if(periRange.text==periText){rawPeriText+="\r\n";}else{periFinished=true;}}}
563569 if(!postFinished){if(postRange.compareEndPoints("StartToEnd",postRange)==0){postFinished=true;}else{postRange.moveEnd("character",-1)
564570 if(postRange.text==postText){rawPostText+="\r\n";}else{postFinished=true;}}}}while((!postFinished||!periFinished||!postFinished));startPos=rawPreText.replace(/\r\n/g,"\n").length;endPos=startPos+rawPeriText.replace(/\r\n/g,"\n").length;}catch(e){startPos=endPos=0;}}
565 -return[startPos,endPos];},'setSelection':function(options){var sc=options.startContainer,ec=options.endContainer;sc=sc&&sc.jquery?sc[0]:sc;ec=ec&&ec.jquery?ec[0]:ec;if(context.$iframe[0].contentWindow.getSelection){var start=options.start,end=options.end;if(!sc||!ec){var s=context.fn.getOffset(start);var e=context.fn.getOffset(end);sc=s?s.node:null;ec=e?e.node:null;start=s?s.offset:null;end=e?e.offset:null;if(sc.nodeName=='#text'&&start>sc.nodeValue.length){start=sc.nodeValue.length-1;}
566 -if(ec.nodeName=='#text'&&end>ec.nodeValue.length){end=ec.nodeValue.length-1;}}
 571+return[startPos,endPos];},'setSelection':function(options){var sc=options.startContainer,ec=options.endContainer;sc=sc&&sc.jquery?sc[0]:sc;ec=ec&&ec.jquery?ec[0]:ec;if(context.$iframe[0].contentWindow.getSelection){var start=options.start,end=options.end;if(!sc||!ec){var s=context.fn.getOffset(start);var e=context.fn.getOffset(end);sc=s?s.node:null;ec=e?e.node:null;start=s?s.offset:null;end=e?e.offset:null;if(sc!=null&&sc.nodeName=='#text'&&start>sc.nodeValue.length){start=sc.nodeValue.length-1;}
 572+if(ec!=null&&ec.nodeName=='#text'&&end>ec.nodeValue.length){end=ec.nodeValue.length-1;}}
567573 if(!sc||!ec){return context.$textarea;}
568574 var sel=context.$iframe[0].contentWindow.getSelection();while(sc.firstChild&&sc.nodeName!='#text'){sc=sc.firstChild;}
569575 while(ec.firstChild&&ec.nodeName!='#text'){ec=ec.firstChild;}

Follow-up revisions

RevisionCommit summaryAuthorDate
r667081.16wmf4: Merge SimpleSearch fixes from trunk: r66565, rr66623, r66631, r6664...catrope21:00, 20 May 2010

Comments

#Comment by Catrope (talk | contribs)   16:22, 17 May 2010

The changed to the combined and minified JS include other changes not present in this revision.

#Comment by Catrope (talk | contribs)   16:29, 17 May 2010

Never mind, seems to be belated changes from another rev. That's what I get for being 200+ revs behind on review.

Status & tagging log