r68229 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68228‎ | r68229 | r68230 >
Date:18:28, 18 June 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: (bug 22680) Make EditWarning no longer break Firefox's page caching by setting window,onbeforeunload to null inside the onbeforeunload function and restoring it in a pageshow hook. Thanks to Cacycle for finding out about this trick
Modified paths:
  • /trunk/extensions/UsabilityInitiative/Vector/Modules/EditWarning/EditWarning.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/Vector/Vector.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/Vector/Vector.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/Vector/Vector.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/Vector/Modules/EditWarning/EditWarning.js
@@ -10,9 +10,10 @@
1111 $j(this).data( 'origtext', $j(this).val() );
1212 });
1313 // Attach our own handler for onbeforeunload which respects the current one
14 - fallbackWindowOnBeforeUnload = window.onbeforeunload;
15 - window.onbeforeunload = function() {
 14+ var fallbackWindowOnBeforeUnload = window.onbeforeunload;
 15+ var ourWindowOnBeforeUnload = function() {
1616 var fallbackResult = undefined;
 17+ var retval = undefined;
1718 // Check if someone already set on onbeforeunload hook
1819 if ( fallbackWindowOnBeforeUnload ) {
1920 // Get the result of their onbeforeunload hook
@@ -21,19 +22,37 @@
2223 // Check if their onbeforeunload hook returned something
2324 if ( fallbackResult !== undefined ) {
2425 // Exit here, returning their message
25 - return fallbackResult;
 26+ retval = fallbackResult;
 27+ } else {
 28+ // Check if the current values of some form elements are the same as
 29+ // the original values
 30+ if (
 31+ wgAction == 'submit' ||
 32+ $j( '#wpTextbox1' ).data( 'origtext' ) != $j( '#wpTextbox1' ).val() ||
 33+ $j( '#wpSummary' ).data( 'origtext' ) != $j( '#wpSummary' ).val()
 34+ ) {
 35+ // Return our message
 36+ retval = mw.usability.getMsg( 'vector-editwarning-warning' );
 37+ }
2638 }
27 - // Check if the current values of some form elements are the same as
28 - // the original values
29 - if(
30 - wgAction == 'submit' ||
31 - $j( '#wpTextbox1' ).data( 'origtext' ) != $j( '#wpTextbox1' ).val() ||
32 - $j( '#wpSummary' ).data( 'origtext' ) != $j( '#wpSummary' ).val()
33 - ) {
34 - // Return our message
35 - return mw.usability.getMsg( 'vector-editwarning-warning' );
 39+
 40+ // Unset the onbeforeunload handler so we don't break page caching in Firefox
 41+ window.onbeforeunload = null;
 42+ if ( retval !== undefined ) {
 43+ return retval;
3644 }
 45+ };
 46+ var pageShowHandler = function() {
 47+ // Re-add onbeforeunload handler
 48+ window.onbeforeunload = ourWindowOnBeforeUnload;
 49+ };
 50+ pageShowHandler();
 51+ if ( window.addEventListener ) {
 52+ window.addEventListener('pageshow', pageShowHandler, false);
 53+ } else if ( window.attachEvent ) {
 54+ window.attachEvent( 'pageshow', pageShowHandler );
3755 }
 56+
3857 // Add form submission handler
3958 $j( 'form' ).submit( function() {
4059 // Restore whatever previous onbeforeload hook existed
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.hooks.php
@@ -15,15 +15,15 @@
1616 array( 'src' => 'Modules/CollapsibleNav/CollapsibleNav.js', 'version' => 25 ),
1717 array( 'src' => 'Modules/CollapsibleTabs/CollapsibleTabs.js', 'version' => 8 ),
1818 array( 'src' => 'Modules/ExpandableSearch/ExpandableSearch.js', 'version' => 5 ),
19 - array( 'src' => 'Modules/EditWarning/EditWarning.js', 'version' => 8 ),
 19+ array( 'src' => 'Modules/EditWarning/EditWarning.js', 'version' => 9 ),
2020 array( 'src' => 'Modules/FooterCleanup/FooterCleanup.js', 'version' => 5 ),
2121 array( 'src' => 'Modules/SimpleSearch/SimpleSearch.js', 'version' => 18 ),
2222 ),
2323 'combined' => array(
24 - array( 'src' => 'Vector.combined.js', 'version' => 55 ),
 24+ array( 'src' => 'Vector.combined.js', 'version' => 56 ),
2525 ),
2626 'minified' => array(
27 - array( 'src' => 'Vector.combined.min.js', 'version' => 56 ),
 27+ array( 'src' => 'Vector.combined.min.js', 'version' => 57 ),
2828 ),
2929 );
3030 static $modules = array(
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.combined.js
@@ -308,9 +308,10 @@
309309 $j(this).data( 'origtext', $j(this).val() );
310310 });
311311 // Attach our own handler for onbeforeunload which respects the current one
312 - fallbackWindowOnBeforeUnload = window.onbeforeunload;
313 - window.onbeforeunload = function() {
 312+ var fallbackWindowOnBeforeUnload = window.onbeforeunload;
 313+ var ourWindowOnBeforeUnload = function() {
314314 var fallbackResult = undefined;
 315+ var retval = undefined;
315316 // Check if someone already set on onbeforeunload hook
316317 if ( fallbackWindowOnBeforeUnload ) {
317318 // Get the result of their onbeforeunload hook
@@ -319,19 +320,37 @@
320321 // Check if their onbeforeunload hook returned something
321322 if ( fallbackResult !== undefined ) {
322323 // Exit here, returning their message
323 - return fallbackResult;
 324+ retval = fallbackResult;
 325+ } else {
 326+ // Check if the current values of some form elements are the same as
 327+ // the original values
 328+ if (
 329+ wgAction == 'submit' ||
 330+ $j( '#wpTextbox1' ).data( 'origtext' ) != $j( '#wpTextbox1' ).val() ||
 331+ $j( '#wpSummary' ).data( 'origtext' ) != $j( '#wpSummary' ).val()
 332+ ) {
 333+ // Return our message
 334+ retval = mw.usability.getMsg( 'vector-editwarning-warning' );
 335+ }
324336 }
325 - // Check if the current values of some form elements are the same as
326 - // the original values
327 - if(
328 - wgAction == 'submit' ||
329 - $j( '#wpTextbox1' ).data( 'origtext' ) != $j( '#wpTextbox1' ).val() ||
330 - $j( '#wpSummary' ).data( 'origtext' ) != $j( '#wpSummary' ).val()
331 - ) {
332 - // Return our message
333 - return mw.usability.getMsg( 'vector-editwarning-warning' );
 337+
 338+ // Unset the onbeforeunload handler so we don't break page caching in Firefox
 339+ window.onbeforeunload = null;
 340+ if ( retval !== undefined ) {
 341+ return retval;
334342 }
 343+ };
 344+ var pageShowHandler = function() {
 345+ // Re-add onbeforeunload handler
 346+ window.onbeforeunload = ourWindowOnBeforeUnload;
 347+ };
 348+ pageShowHandler();
 349+ if ( window.addEventListener ) {
 350+ window.addEventListener('pageshow', pageShowHandler, false);
 351+ } else if ( window.attachEvent ) {
 352+ window.attachEvent( 'pageshow', pageShowHandler );
335353 }
 354+
336355 // Add form submission handler
337356 $j( 'form' ).submit( function() {
338357 // Restore whatever previous onbeforeload hook existed
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.combined.min.js
@@ -15,9 +15,9 @@
1616 var rtl=$j('body').is('.rtl');$j.collapsibleTabs.moveToCollapsed=function(ele){var $moving=$j(ele);$j.collapsibleTabs.getSettings($j($j.collapsibleTabs.getSettings($moving).expandedContainer)).shifting=true;var data=$j.collapsibleTabs.getSettings($moving);var target=data.collapsedContainer;$moving.css("position","relative").css((rtl?'left':'right'),0).animate({width:'1px'},"normal",function(){$j(this).hide();$j('<span class="placeholder" style="display:none;"></span>').insertAfter(this);$j(this).remove().prependTo(target).data('collapsibleTabsSettings',data);$j(this).attr('style','display:list-item;');$j.collapsibleTabs.getSettings($j($j.collapsibleTabs.getSettings($j(ele)).expandedContainer)).shifting=false;$j.collapsibleTabs.handleResize();});};$j.collapsibleTabs.moveToExpanded=function(ele){var $moving=$j(ele);$j.collapsibleTabs.getSettings($j($j.collapsibleTabs.getSettings($moving).expandedContainer)).shifting=true;var data=$j.collapsibleTabs.getSettings($moving);var $target=$j(data.expandedContainer).find('span.placeholder:first');var expandedWidth=data.expandedWidth;$moving.css("position","relative").css((rtl?'right':'left'),0).css('width','1px');$target.replaceWith($moving.remove().css('width','1px').data('collapsibleTabsSettings',data).animate({width:expandedWidth+"px"},"normal",function(){$j(this).attr('style','display:block;');$j.collapsibleTabs.getSettings($j($j.collapsibleTabs.getSettings($moving).expandedContainer)).shifting=false;$j.collapsibleTabs.handleResize();}));};$j('#p-views ul').bind("beforeTabCollapse",function(){if($j('#p-cactions').css('display')=='none')
1717 $j("#p-cactions").addClass("filledPortlet").removeClass("emptyPortlet").find('h5').css('width','1px').animate({'width':'26px'},390);}).bind("beforeTabExpand",function(){if($j('#p-cactions li').length==1)
1818 $j("#p-cactions h5").animate({'width':'1px'},370,function(){$j(this).attr('style','').parent().addClass("emptyPortlet").removeClass("filledPortlet");});}).collapsibleTabs({expandCondition:function(eleWidth){if(rtl){return($j('#right-navigation').position().left+$j('#right-navigation').width()+1)<($j('#left-navigation').position().left-eleWidth);}else{return($j('#left-navigation').position().left+$j('#left-navigation').width()+1)<($j('#right-navigation').position().left-eleWidth);}},collapseCondition:function(){if(rtl){return($j('#right-navigation').position().left+$j('#right-navigation').width())>$j('#left-navigation').position().left;}else{return($j('#left-navigation').position().left+$j('#left-navigation').width())>$j('#right-navigation').position().left;}}});});$j(document).ready(function(){if(!wgVectorEnabledModules.editwarning||$j('#wpTextbox1').size()==0){return true;}
19 -$j('#wpTextbox1, #wpSummary').each(function(){$j(this).data('origtext',$j(this).val());});fallbackWindowOnBeforeUnload=window.onbeforeunload;window.onbeforeunload=function(){var fallbackResult=undefined;if(fallbackWindowOnBeforeUnload){fallbackResult=fallbackWindowOnBeforeUnload();}
20 -if(fallbackResult!==undefined){return fallbackResult;}
21 -if(wgAction=='submit'||$j('#wpTextbox1').data('origtext')!=$j('#wpTextbox1').val()||$j('#wpSummary').data('origtext')!=$j('#wpSummary').val()){return mw.usability.getMsg('vector-editwarning-warning');}}
 19+$j('#wpTextbox1, #wpSummary').each(function(){$j(this).data('origtext',$j(this).val());});var fallbackWindowOnBeforeUnload=window.onbeforeunload;var ourWindowOnBeforeUnload=function(){var fallbackResult=undefined;var retval=undefined;if(fallbackWindowOnBeforeUnload){fallbackResult=fallbackWindowOnBeforeUnload();}
 20+if(fallbackResult!==undefined){retval=fallbackResult;}else{if(wgAction=='submit'||$j('#wpTextbox1').data('origtext')!=$j('#wpTextbox1').val()||$j('#wpSummary').data('origtext')!=$j('#wpSummary').val()){retval=mw.usability.getMsg('vector-editwarning-warning');}}
 21+window.onbeforeunload=null;if(retval!==undefined){return retval;}};var pageShowHandler=function(){window.onbeforeunload=ourWindowOnBeforeUnload;};pageShowHandler();if(window.addEventListener){window.addEventListener('pageshow',pageShowHandler,false);}else if(window.attachEvent){window.attachEvent('pageshow',pageShowHandler);}
2222 $j('form').submit(function(){window.onbeforeunload=fallbackWindowOnBeforeUnload;});});var fallbackWindowOnBeforeUnload=null;$j(document).ready(function(){if(!wgVectorEnabledModules.expandablesearch||skin!='vector'){return true;}
2323 var map={'ltr':{'msie':[['>=',8]],'blackberry':false,'ipod':false,'iphone':false,'ps3':false},'rtl':{'msie':[['>=',8]],'blackberry':false,'ipod':false,'iphone':false,'ps3':false}};if(!mw.usability.testBrowser(map)){return true;}
2424 $j('#searchInput').expandableField({'beforeExpand':function(context){$j(this).parent().animate({'borderTopColor':'#a0d8ff','borderLeftColor':'#a0d8ff','borderRightColor':'#a0d8ff','borderBottomColor':'#a0d8ff'},'fast');},'beforeCondense':function(context){$j(this).parent().animate({'borderTopColor':'#aaaaaa','borderLeftColor':'#aaaaaa','borderRightColor':'#aaaaaa','borderBottomColor':'#aaaaaa'},'fast');},'afterExpand':function(context){if(typeof $j.collapsibleTabs!='undefined'){$j.collapsibleTabs.handleResize();}},'afterCondense':function(context){if(typeof $j.collapsibleTabs!='undefined'){$j.collapsibleTabs.handleResize();}},'expandToLeft':!$j('body').is('.rtl')}).css('float',$j('body').is('.rtl')?'right':'left').siblings('button').css('float',$j('body').is('.rtl')?'right':'left');});$j(document).ready(function(){if(!wgVectorEnabledModules.footercleanup){return true;}

Follow-up revisions

RevisionCommit summaryAuthorDate
r68845UsabilityInitiative: (bug 24216) Fix regression from r68229 causing the secon...catrope18:37, 1 July 2010
r74267ArticleAssessment: Fix bug in jquery.stars plugin that was contributing to bu...catrope19:48, 4 October 2010

Status & tagging log