diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2011-12-03 13:29:22 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2011-12-03 13:29:22 +0100 |
commit | ca32f08966f1b51fcb19460f0996bb0c4048e6fe (patch) | |
tree | ec04cc15b867bc21eedca904cea9af0254531a11 /extensions/Vector/modules/ext.vector.editWarning.js | |
parent | a22fbfc60f36f5f7ee10d5ae6fe347340c2ee67c (diff) |
Update to MediaWiki 1.18.0
* also update ArchLinux skin to chagnes in MonoBook
* Use only css to hide our menu bar when printing
Diffstat (limited to 'extensions/Vector/modules/ext.vector.editWarning.js')
-rw-r--r-- | extensions/Vector/modules/ext.vector.editWarning.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/extensions/Vector/modules/ext.vector.editWarning.js b/extensions/Vector/modules/ext.vector.editWarning.js new file mode 100644 index 00000000..d7494c70 --- /dev/null +++ b/extensions/Vector/modules/ext.vector.editWarning.js @@ -0,0 +1,71 @@ +/* + * Edit warning for Vector + */ +(function( $ ) { + $(document).ready( function() { + // Check if EditWarning is enabled and if we need it + if ( $( '#wpTextbox1' ).size() == 0 ) { + return true; + } + // Get the original values of some form elements + $( '#wpTextbox1, #wpSummary' ).each( function() { + $(this).data( 'origtext', $(this).val() ); + }); + // Attach our own handler for onbeforeunload which respects the current one + var fallbackWindowOnBeforeUnload = window.onbeforeunload; + var ourWindowOnBeforeUnload = function() { + var fallbackResult = undefined; + var retval = undefined; + var thisFunc = arguments.callee; + // Check if someone already set on onbeforeunload hook + if ( fallbackWindowOnBeforeUnload ) { + // Get the result of their onbeforeunload hook + fallbackResult = fallbackWindowOnBeforeUnload(); + } + // Check if their onbeforeunload hook returned something + if ( fallbackResult !== undefined ) { + // Exit here, returning their message + retval = fallbackResult; + } else { + // Check if the current values of some form elements are the same as + // the original values + if ( + wgAction == 'submit' || + $( '#wpTextbox1' ).data( 'origtext' ) != $( '#wpTextbox1' ).val() || + $( '#wpSummary' ).data( 'origtext' ) != $( '#wpSummary' ).val() + ) { + // Return our message + retval = mediaWiki.msg( 'vector-editwarning-warning' ); + } + } + + // Unset the onbeforeunload handler so we don't break page caching in Firefox + window.onbeforeunload = null; + if ( retval !== undefined ) { + // ...but if the user chooses not to leave the page, we need to rebind it + setTimeout( function() { + window.onbeforeunload = thisFunc; + } ); + return retval; + } + }; + var pageShowHandler = function() { + // Re-add onbeforeunload handler + window.onbeforeunload = ourWindowOnBeforeUnload; + }; + pageShowHandler(); + if ( window.addEventListener ) { + window.addEventListener('pageshow', pageShowHandler, false); + } else if ( window.attachEvent ) { + window.attachEvent( 'pageshow', pageShowHandler ); + } + + // Add form submission handler + $( 'form' ).submit( function() { + // Restore whatever previous onbeforeload hook existed + window.onbeforeunload = fallbackWindowOnBeforeUnload; + }); + }); + //Global storage of fallback for onbeforeunload hook + var fallbackWindowOnBeforeUnload = null; +})( jQuery ); |