r61022 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61021‎ | r61022 | r61023 >
Date:20:34, 13 January 2010
Author:adam
Status:ok (Comments)
Tags:
Comment:
Making scrollToTop() in jquery.wikiEditor.js work better. Fixing some bugs with the parent windows scroll position screwing with offset measurements of elements in the iframe
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
@@ -84,7 +84,7 @@
8585 array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
8686 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 7 ),
8787 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 22 ),
88 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 43 ),
 88+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 44 ),
8989 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 12 ),
9090 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 40 ),
9191 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 10 ),
@@ -94,10 +94,10 @@
9595 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 1 ),
9696 ),
9797 'combined' => array(
98 - array( 'src' => 'js/plugins.combined.js', 'version' => 139 ),
 98+ array( 'src' => 'js/plugins.combined.js', 'version' => 140 ),
9999 ),
100100 'minified' => array(
101 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 139 ),
 101+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 140 ),
102102 ),
103103 ),
104104 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -555,13 +555,12 @@
556556 */
557557 'scrollToTop': function( $element, force ) {
558558 var html = context.$content.closest( 'html' ),
559 - body = context.$content.closest( 'body' );
 559+ body = context.$content.closest( 'body' ),
 560+ parent = $( 'html' );
560561 var y = $element.offset().top - context.$content.offset().top;
561 - if ( force || y < html.scrollTop() || y < body.scrollTop()
562 - || y > html.scrollTop() + context.$iframe.height()
563 - || y > body.scrollTop() + context.$iframe.height() ) {
 562+ y = parent.scrollTop() > 0 ? y + html.scrollTop() - parent.scrollTop() : y;
 563+ if ( force || y < html.scrollTop() || y > html.scrollTop() + context.$iframe.height() ) {
564564 html.scrollTop( y );
565 - body.scrollTop( y );
566565 }
567566 $element.trigger( 'scrollToTop' );
568567 },
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6922,13 +6922,12 @@
69236923 */
69246924 'scrollToTop': function( $element, force ) {
69256925 var html = context.$content.closest( 'html' ),
6926 - body = context.$content.closest( 'body' );
 6926+ body = context.$content.closest( 'body' ),
 6927+ parent = $( 'html' );
69276928 var y = $element.offset().top - context.$content.offset().top;
6928 - if ( force || y < html.scrollTop() || y < body.scrollTop()
6929 - || y > html.scrollTop() + context.$iframe.height()
6930 - || y > body.scrollTop() + context.$iframe.height() ) {
 6929+ y = parent.scrollTop() > 0 ? y + html.scrollTop() - parent.scrollTop() : y;
 6930+ if ( force || y < html.scrollTop() || y > html.scrollTop() + context.$iframe.height() ) {
69316931 html.scrollTop( y );
6932 - body.scrollTop( y );
69336932 }
69346933 $element.trigger( 'scrollToTop' );
69356934 },
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -453,7 +453,7 @@
454454 if(lastNode){context.fn.scrollToTop(lastNode);}}else if(context.$iframe[0].contentWindow.document.selection){}
455455 context.$content.trigger('encapsulateSelection',[pre,options.peri,post,options.ownline,options.replace]);return context.$textarea;},'getCaretPosition':function(options){},'setSelection':function(options){var sc=options.startContainer,ec=options.endContainer;sc=sc.jquery?sc[0]:sc;ec=ec.jquery?ec[0]:ec;if(context.$iframe[0].contentWindow.getSelection){var sel=context.$iframe[0].contentWindow.getSelection();while(sc.firstChild&&sc.nodeName!='#text'){sc=sc.firstChild;}
456456 while(ec.firstChild&&ec.nodeName!='#text'){ec=ec.firstChild;}
457 -var range=document.createRange();range.setStart(sc,options.start);range.setEnd(ec,options.end);sel.removeAllRanges();sel.addRange(range);context.$iframe[0].contentWindow.focus();}else if(context.$iframe[0].contentWindow.document.selection){var range=document.selection.createRange();range.moveToElementText(sc);range.moveStart('character',options.start);var range2=document.selection.createRange();range2.moveToElementText(ec);range2.moveEnd('character',options.end);range.setEndPoint(EndToEnd,range2);range.select();}},'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);}
 457+var range=document.createRange();range.setStart(sc,options.start);range.setEnd(ec,options.end);sel.removeAllRanges();sel.addRange(range);context.$iframe[0].contentWindow.focus();}else if(context.$iframe[0].contentWindow.document.selection){var range=document.selection.createRange();range.moveToElementText(sc);range.moveStart('character',options.start);var range2=document.selection.createRange();range2.moveToElementText(ec);range2.moveEnd('character',options.end);range.setEndPoint(EndToEnd,range2);range.select();}},'scrollToCaretPosition':function(options){},'scrollToTop':function($element,force){var html=context.$content.closest('html'),body=context.$content.closest('body'),parent=$('html');var y=$element.offset().top-context.$content.offset().top;y=parent.scrollTop()>0?y+html.scrollTop()-parent.scrollTop():y;if(force||y<html.scrollTop()||y>html.scrollTop()+context.$iframe.height()){html.scrollTop(y);}
458458 $element.trigger('scrollToTop');},'beforeSelection':function(selector,strict){if(typeof selector=='undefined')
459459 selector='*';var e;if(context.$iframe[0].contentWindow.getSelection){var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);e=range.startContainer;}else if(context.$iframe[0].contentWindow.document.selection){return $([]);}
460460 if(e.nodeName!='#text'){var newE=e.firstChild;for(var i=0;i<range.startOffset-1&&newE;i++){newE=newE.nextSibling;}

Comments

#Comment by Catrope (talk | contribs)   21:33, 17 January 2010

For some reason scrollToTop(true) doesn't work in IE in that it doesn't force a scroll if the element is already in view. This does work in Firefox. I'm not sure if it's caused by this revision, but it looks suspicious.

#Comment by Pdhanda (talk | contribs)   18:18, 26 January 2010

Status & tagging log