Index: trunk/extensions/Vector/modules/ext.vector.editWarning.js |
— | — | @@ -1,69 +1,71 @@ |
2 | 2 | /* |
3 | 3 | * Edit warning for Vector |
4 | 4 | */ |
5 | | -$(document).ready( function() { |
6 | | - // Check if EditWarning is enabled and if we need it |
7 | | - if ( $( '#wpTextbox1' ) == null ) { |
8 | | - return true; |
9 | | - } |
10 | | - // Get the original values of some form elements |
11 | | - $( '#wpTextbox1, #wpSummary' ).each( function() { |
12 | | - $(this).data( 'origtext', $(this).val() ); |
13 | | - }); |
14 | | - // Attach our own handler for onbeforeunload which respects the current one |
15 | | - var fallbackWindowOnBeforeUnload = window.onbeforeunload; |
16 | | - var ourWindowOnBeforeUnload = function() { |
17 | | - var fallbackResult = undefined; |
18 | | - var retval = undefined; |
19 | | - var thisFunc = arguments.callee; |
20 | | - // Check if someone already set on onbeforeunload hook |
21 | | - if ( fallbackWindowOnBeforeUnload ) { |
22 | | - // Get the result of their onbeforeunload hook |
23 | | - fallbackResult = fallbackWindowOnBeforeUnload(); |
| 5 | +(function( $ ) { |
| 6 | + $(document).ready( function() { |
| 7 | + // Check if EditWarning is enabled and if we need it |
| 8 | + if ( $( '#wpTextbox1' ).size() == 0 ) { |
| 9 | + return true; |
24 | 10 | } |
25 | | - // Check if their onbeforeunload hook returned something |
26 | | - if ( fallbackResult !== undefined ) { |
27 | | - // Exit here, returning their message |
28 | | - retval = fallbackResult; |
29 | | - } else { |
30 | | - // Check if the current values of some form elements are the same as |
31 | | - // the original values |
32 | | - if ( |
33 | | - wgAction == 'submit' || |
34 | | - $( '#wpTextbox1' ).data( 'origtext' ) != $( '#wpTextbox1' ).val() || |
35 | | - $( '#wpSummary' ).data( 'origtext' ) != $( '#wpSummary' ).val() |
36 | | - ) { |
37 | | - // Return our message |
38 | | - retval = mediaWiki.msg.get( 'vector-editwarning-warning' ); |
| 11 | + // Get the original values of some form elements |
| 12 | + $( '#wpTextbox1, #wpSummary' ).each( function() { |
| 13 | + $(this).data( 'origtext', $(this).val() ); |
| 14 | + }); |
| 15 | + // Attach our own handler for onbeforeunload which respects the current one |
| 16 | + var fallbackWindowOnBeforeUnload = window.onbeforeunload; |
| 17 | + var ourWindowOnBeforeUnload = function() { |
| 18 | + var fallbackResult = undefined; |
| 19 | + var retval = undefined; |
| 20 | + var thisFunc = arguments.callee; |
| 21 | + // Check if someone already set on onbeforeunload hook |
| 22 | + if ( fallbackWindowOnBeforeUnload ) { |
| 23 | + // Get the result of their onbeforeunload hook |
| 24 | + fallbackResult = fallbackWindowOnBeforeUnload(); |
39 | 25 | } |
| 26 | + // Check if their onbeforeunload hook returned something |
| 27 | + if ( fallbackResult !== undefined ) { |
| 28 | + // Exit here, returning their message |
| 29 | + retval = fallbackResult; |
| 30 | + } else { |
| 31 | + // Check if the current values of some form elements are the same as |
| 32 | + // the original values |
| 33 | + if ( |
| 34 | + wgAction == 'submit' || |
| 35 | + $( '#wpTextbox1' ).data( 'origtext' ) != $( '#wpTextbox1' ).val() || |
| 36 | + $( '#wpSummary' ).data( 'origtext' ) != $( '#wpSummary' ).val() |
| 37 | + ) { |
| 38 | + // Return our message |
| 39 | + retval = mediaWiki.msg.get( 'vector-editwarning-warning' ); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + // Unset the onbeforeunload handler so we don't break page caching in Firefox |
| 44 | + window.onbeforeunload = null; |
| 45 | + if ( retval !== undefined ) { |
| 46 | + // ...but if the user chooses not to leave the page, we need to rebind it |
| 47 | + setTimeout( function() { |
| 48 | + window.onbeforeunload = thisFunc; |
| 49 | + } ); |
| 50 | + return retval; |
| 51 | + } |
| 52 | + }; |
| 53 | + var pageShowHandler = function() { |
| 54 | + // Re-add onbeforeunload handler |
| 55 | + window.onbeforeunload = ourWindowOnBeforeUnload; |
| 56 | + }; |
| 57 | + pageShowHandler(); |
| 58 | + if ( window.addEventListener ) { |
| 59 | + window.addEventListener('pageshow', pageShowHandler, false); |
| 60 | + } else if ( window.attachEvent ) { |
| 61 | + window.attachEvent( 'pageshow', pageShowHandler ); |
40 | 62 | } |
41 | 63 | |
42 | | - // Unset the onbeforeunload handler so we don't break page caching in Firefox |
43 | | - window.onbeforeunload = null; |
44 | | - if ( retval !== undefined ) { |
45 | | - // ...but if the user chooses not to leave the page, we need to rebind it |
46 | | - setTimeout( function() { |
47 | | - window.onbeforeunload = thisFunc; |
48 | | - } ); |
49 | | - return retval; |
50 | | - } |
51 | | - }; |
52 | | - var pageShowHandler = function() { |
53 | | - // Re-add onbeforeunload handler |
54 | | - window.onbeforeunload = ourWindowOnBeforeUnload; |
55 | | - }; |
56 | | - pageShowHandler(); |
57 | | - if ( window.addEventListener ) { |
58 | | - window.addEventListener('pageshow', pageShowHandler, false); |
59 | | - } else if ( window.attachEvent ) { |
60 | | - window.attachEvent( 'pageshow', pageShowHandler ); |
61 | | - } |
62 | | - |
63 | | - // Add form submission handler |
64 | | - $( 'form' ).submit( function() { |
65 | | - // Restore whatever previous onbeforeload hook existed |
66 | | - window.onbeforeunload = fallbackWindowOnBeforeUnload; |
| 64 | + // Add form submission handler |
| 65 | + $( 'form' ).submit( function() { |
| 66 | + // Restore whatever previous onbeforeload hook existed |
| 67 | + window.onbeforeunload = fallbackWindowOnBeforeUnload; |
| 68 | + }); |
67 | 69 | }); |
68 | | -}); |
69 | | -//Global storage of fallback for onbeforeunload hook |
70 | | -var fallbackWindowOnBeforeUnload = null; |
| 70 | + //Global storage of fallback for onbeforeunload hook |
| 71 | + var fallbackWindowOnBeforeUnload = null; |
| 72 | +})( jQuery ); |