r60098 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60097‎ | r60098 | r60099 >
Date:23:09, 15 December 2009
Author:adam
Status:resolved (Comments)
Tags:
Comment:
Fixing the NTOC buidling in Safari, and probably other webkit browsers. Fixing NTOC scrolling in Safari and possibly other webkit browsers.
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)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -71,20 +71,20 @@
7272 array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
7373 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 6 ),
7474 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 21 ),
75 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 35 ),
 75+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 36 ),
7676 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 2 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 40 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 10 ),
79 - array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 51 ),
 79+ array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 52 ),
8080 array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 8 ),
8181 array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 2 ),
8282 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 1 ),
8383 ),
8484 'combined' => array(
85 - array( 'src' => 'js/plugins.combined.js', 'version' => 111 ),
 85+ array( 'src' => 'js/plugins.combined.js', 'version' => 112 ),
8686 ),
8787 'minified' => array(
88 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 111 ),
 88+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 112 ),
8989 ),
9090 ),
9191 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js
@@ -414,6 +414,7 @@
415415 outline[h] = { 'text': match[2], 'wrapper': div, 'level': match[1].length, 'index': h + 1 };
416416 h++;
417417 }
 418+ context.$content.html( context.$content.html().replace( /[\r\n]+/g, "<br>" ) );
418419 context.$content.each( traverseTextNodes );
419420
420421 // Normalize heading levels for list creation
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -531,10 +531,15 @@
532532 * @param force If true, scroll the element even if it's already visible
533533 */
534534 'scrollToTop': function( $element, force ) {
535 - var html = context.$content.closest( 'html' );
 535+ var html = context.$content.closest( 'html' ),
 536+ body = context.$content.closest( 'body' );
536537 var y = $element.offset().top - context.$content.offset().top;
537 - if ( force || y < html.scrollTop() || y > html.scrollTop() + context.$iframe.height() )
538 - html.scrollTop( y );
 538+ if ( force || y < html.scrollTop() || y < body.scrollTop()
 539+ || y > html.scrollTop() + context.$iframe.height()
 540+ || y > body.scrollTop() + context.$iframe.height() ) {
 541+ html.scrollTop( y );
 542+ body.scrollTop( y );
 543+ }
539544 $element.trigger( 'scrollToTop' );
540545 },
541546 /**
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -1841,10 +1841,15 @@
18421842 * @param force If true, scroll the element even if it's already visible
18431843 */
18441844 'scrollToTop': function( $element, force ) {
1845 - var html = context.$content.closest( 'html' );
 1845+ var html = context.$content.closest( 'html' ),
 1846+ body = context.$content.closest( 'body' );
18461847 var y = $element.offset().top - context.$content.offset().top;
1847 - if ( force || y < html.scrollTop() || y > html.scrollTop() + context.$iframe.height() )
1848 - html.scrollTop( y );
 1848+ if ( force || y < html.scrollTop() || y < body.scrollTop()
 1849+ || y > html.scrollTop() + context.$iframe.height()
 1850+ || y > body.scrollTop() + context.$iframe.height() ) {
 1851+ html.scrollTop( y );
 1852+ body.scrollTop( y );
 1853+ }
18491854 $element.trigger( 'scrollToTop' );
18501855 },
18511856 /**
@@ -3306,6 +3311,7 @@
33073312 outline[h] = { 'text': match[2], 'wrapper': div, 'level': match[1].length, 'index': h + 1 };
33083313 h++;
33093314 }
 3315+ context.$content.html( context.$content.html().replace( /[\r\n]+/g, "<br>" ) );
33103316 context.$content.each( traverseTextNodes );
33113317
33123318 // Normalize heading levels for list creation
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -109,8 +109,8 @@
110110 if(lastNode){context.fn.scrollToTop(lastNode);}
111111 context.$content.trigger('encapsulateSelection',[pre,options.peri,post,options.ownline,options.replace]);return context.$textarea;},'getCaretPosition':function(options){},'setSelection':function(options){var sel=context.$iframe[0].contentWindow.getSelection();var sc=options.startContainer,ec=options.endContainer;sc=sc.jquery?sc[0]:sc;ec=ec.jquery?ec[0]:ec;while(sc.firstChild&&sc.nodeName!='#text'){sc=sc.firstChild;}
112112 while(ec.firstChild&&ec.nodeName!='#text'){ec=ec.firstChild;}
113 -sel.extend(sc,options.start);sel.collapseToStart();if(options.end!=options.start||sc!=ec){sel.extend(ec,options.end);}},'scrollToCaretPosition':function(options){},'scrollToTop':function($element,force){var html=context.$content.closest('html');var y=$element.offset().top-context.$content.offset().top;if(force||y<html.scrollTop()||y>html.scrollTop()+context.$iframe.height())
114 -html.scrollTop(y);$element.trigger('scrollToTop');},'beforeSelection':function(selector,getAll){if(typeof selector=='undefined')
 113+sel.extend(sc,options.start);sel.collapseToStart();if(options.end!=options.start||sc!=ec){sel.extend(ec,options.end);}},'scrollToCaretPosition':function(options){},'scrollToTop':function($element,force){var html=context.$content.closest('html'),body=context.$content.closest('body');var y=$element.offset().top-context.$content.offset().top;if(force||y<html.scrollTop()||y<body.scrollTop()||y>html.scrollTop()+context.$iframe.height()||y>body.scrollTop()+context.$iframe.height()){html.scrollTop(y);body.scrollTop(y);}
 114+$element.trigger('scrollToTop');},'beforeSelection':function(selector,getAll){if(typeof selector=='undefined')
115115 selector='*';var retval=[];var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);var e=range.startContainer;}};context.$textarea.wrap($('<div></div>').addClass('wikiEditor-ui')).wrap($('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-wikitext')).wrap($('<div></div>').addClass('wikiEditor-ui-left')).wrap($('<div></div>').addClass('wikiEditor-ui-bottom')).wrap($('<div></div>').addClass('wikiEditor-ui-text'));context.$ui=context.$textarea.parent().parent().parent().parent().parent();context.$wikitext=context.$textarea.parent().parent().parent().parent();context.$wikitext.before($('<div></div>').addClass('wikiEditor-ui-controls').append($('<div></div>').addClass('wikiEditor-ui-tabs').hide()).append($('<div></div>').addClass('wikiEditor-ui-buttons'))).before($('<div style="clear:both;"></div>'));context.$controls=context.$ui.find('.wikiEditor-ui-buttons').hide();context.$buttons=context.$ui.find('.wikiEditor-ui-buttons');context.$tabs=context.$ui.find('.wikiEditor-ui-tabs');context.$ui.after($('<div style="clear:both;"></div>'));context.$wikitext.append($('<div></div>').addClass('wikiEditor-ui-right'));context.$wikitext.find('.wikiEditor-ui-left').prepend($('<div></div>').addClass('wikiEditor-ui-top'));context.view='wikitext';$(window).resize(function(event){context.fn.trigger('resize',event)});context.$iframe=$('<iframe></iframe>').attr({'frameborder':0,'src':wgScriptPath+'/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html?'+'instance='+context.instance+'&ts='+(new Date()).getTime(),'id':'wikiEditor-iframe-'+context.instance}).css({'backgroundColor':'white','width':'100%','height':context.$textarea.height(),'display':'none','overflow-y':'scroll','overflow-x':'hidden'}).insertAfter(context.$textarea).load(function(){context.$iframe[0].contentWindow.document.designMode='on';context.$content=$(context.$iframe[0].contentWindow.document.body);context.$content.append(context.$textarea.val().replace(/</g,'&lt;').replace(/>/g,'&gt;'));if($('body').is('.rtl')){context.$content.addClass('rtl').attr('dir','rtl');}
116116 context.$textarea.attr('disabled',true);context.$textarea.hide();context.$iframe.show();context.fn.trigger('ready');});context.$textarea.closest('form').submit(function(){context.$textarea.attr('disabled',false);context.$textarea.val(context.$textarea.textSelection('getContents'));});}
117117 arguments=$.makeArray(arguments);if(arguments.length>0){var call=arguments.shift();if(call in context.api){context.api[call](context,typeof arguments[0]=='undefined'?{}:arguments[0]);}}
@@ -210,7 +210,7 @@
211211 div=$(this).parent();else if($(this).parent().is('div'))
212212 div=$(this).parent().addClass('wikiEditor-toc-header');else{div=$('<div />').text(text).css('display','inline').addClass('wikiEditor-toc-header');$(this).replaceWith(div);}
213213 outline[h]={'text':match[2],'wrapper':div,'level':match[1].length,'index':h+1};h++;}
214 -context.$content.each(traverseTextNodes);var lastLevel=0;var nLevel=0;for(var i=0;i<outline.length;i++){if(outline[i].level>lastLevel){nLevel++;}
 214+context.$content.html(context.$content.html().replace(/[\r\n]+/g,"<br>"));context.$content.each(traverseTextNodes);var lastLevel=0;var nLevel=0;for(var i=0;i<outline.length;i++){if(outline[i].level>lastLevel){nLevel++;}
215215 else if(outline[i].level<lastLevel){nLevel-=Math.max(1,lastLevel-outline[i].level);}
216216 if(nLevel<=0){nLevel=1;}
217217 outline[i].nLevel=nLevel;lastLevel=outline[i].level;}

Follow-up revisions

RevisionCommit summaryAuthorDate
r60101A better regex for the code committed in r60098adam23:21, 15 December 2009
r60103A better regex for the code committed in r60098. Again.adam23:29, 15 December 2009
r60123UsabilityInitiative: Remove Safari newline handling fix introduced in r60098;...catrope14:50, 16 December 2009

Comments

#Comment by Catrope (talk | contribs)   23:11, 15 December 2009
+		context.$content.html( context.$content.html().replace( /[\r\n]+/g, "<br>" ) );

This will convert a succession of newlines to one br. I believe the correct regex is \r?\n.

Status & tagging log