r52950 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52949‎ | r52950 | r52951 >
Date:23:23, 8 July 2009
Author:tparscal
Status:deferred
Tags:
Comment:
Added support for allowing an existing onbeforeunload hook to be evaluated and returned if needed - thus superceding our own.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.js
@@ -1,19 +1,43 @@
22 /* JavaScript for EditWarning extension */
33
44 $( document ).ready( function() {
 5+ // Checks if the skin is not vector
56 if( skin != 'vector' )
 7+ // Exits
68 return;
7 -
 9+ // Gets the original values of some form elements
810 $( '#wpTextbox1, #wpSummary' ).each( function() {
911 $(this).data( 'origtext', $(this).val() );
1012 });
11 - if( !( 'onbeforeunload' in window ) )
12 - window.onbeforeunload = function() {
13 - if( $( '#wpTextbox1' ).data( 'origtext' ) != $( '#wpTextbox1' ).val() ||
14 - $( '#wpSummary' ).data( 'origtext' ) != $( '#wpSummary' ).val() )
15 - return gM( 'editwarning-warning' );
16 - };
 13+
 14+ fallbackWindowOnBeforeUnload = window.onbeforeunload;
 15+ window.onbeforeunload = function() {
 16+ var fallbackResult = null;
 17+ // Checks if someone already set on onbeforunload hook
 18+ if ( fallbackWindowOnBeforeUnload ) {
 19+ // Gets the result of their onbeforeunload hook
 20+ fallbackResult = fallbackWindowOnBeforeUnload();
 21+ }
 22+ // Checks if their onbeforeunload hook returned something
 23+ if ( fallbackResult !== null ) {
 24+ // Exits here, returning their message
 25+ return fallbackResult;
 26+ }
 27+ // Checks if the current values of some form elements are the same as
 28+ // the original values
 29+ if(
 30+ $( '#wpTextbox1' ).data( 'origtext' ) != $( '#wpTextbox1' ).val() ||
 31+ $( '#wpSummary' ).data( 'origtext' ) != $( '#wpSummary' ).val()
 32+ ) {
 33+ // Returns our message
 34+ return gM( 'editwarning-warning' );
 35+ }
 36+ }
 37+ // Adds form submission handler
1738 $( 'form' ).submit( function() {
18 - window.onbeforeunload = function() {};
 39+ // Restores whatever previous onbeforeload hook existed
 40+ window.onbeforeunload = fallbackWindowOnBeforeUnload;
1941 });
2042 });
 43+//Global storage of fallback for onbeforeunload hook
 44+var fallbackWindowOnBeforeUnload = null;
\ No newline at end of file

Status & tagging log