Index: trunk/extensions/UploadWizard/UploadWizardHooks.php |
— | — | @@ -50,6 +50,7 @@ |
51 | 51 | 'resources/mw.Api.edit.js', |
52 | 52 | 'resources/mw.Title.js', |
53 | 53 | 'resources/mw.Feedback.js', |
| 54 | + 'resources/mw.ConfirmCloseWindow.js', |
54 | 55 | |
55 | 56 | // language menus |
56 | 57 | 'resources/mw.LanguageUpWiz.js', |
— | — | @@ -234,6 +235,7 @@ |
235 | 236 | 'mwe-upwiz-home', |
236 | 237 | 'mwe-upwiz-upload-another', |
237 | 238 | 'mwe-prevent-close', |
| 239 | + 'mwe-upwiz-prevent-close', |
238 | 240 | 'mwe-upwiz-files-complete', |
239 | 241 | 'mwe-upwiz-tooltip-author', |
240 | 242 | 'mwe-upwiz-tooltip-source', |
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php |
— | — | @@ -166,8 +166,8 @@ |
167 | 167 | 'mwe-upwiz-next-details' => 'Next', |
168 | 168 | 'mwe-upwiz-home' => 'Go to wiki home page', |
169 | 169 | 'mwe-upwiz-upload-another' => 'Upload more files', |
170 | | - 'mwe-prevent-close' => 'Your files are still uploading. |
171 | | -Are you sure you want to navigate away from this page?', |
| 170 | + 'mwe-prevent-close' => 'Leaving this page may cause you to lose any changes you have made.', |
| 171 | + 'mwe-upwiz-prevent-close' => 'You haven\'t finished uploading and publishing {{PLURAL:$1|this file|these files}} yet.', |
172 | 172 | 'mwe-upwiz-files-complete' => 'Your files finished uploading!', |
173 | 173 | 'mwe-upwiz-tooltip-author' => 'The name of the person who took the photo, or painted the picture, drew the drawing, etc.', |
174 | 174 | 'mwe-upwiz-tooltip-source' => 'Where this digital file came from — could be a URL, or a book or publication', |
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizard.js |
— | — | @@ -689,6 +689,9 @@ |
690 | 690 | $j( '.mwe-upwiz-hint' ).each( function(i) { $j( this ).tipsy( 'hide' ); } ); // close tipsy help balloons |
691 | 691 | if ( _this.detailsValid() ) { |
692 | 692 | _this.detailsSubmit( function() { |
| 693 | + if ( mw.isDefined( _this.allowCloseWindow ) ) { |
| 694 | + _this.allowCloseWindow(); |
| 695 | + } |
693 | 696 | _this.prefillThanksPage(); |
694 | 697 | _this.moveToStep( 'thanks' ); |
695 | 698 | } ); |
— | — | @@ -992,8 +995,9 @@ |
993 | 996 | } |
994 | 997 | } ); |
995 | 998 | |
996 | | - var allowCloseWindow = $j().preventCloseWindow( { |
997 | | - message: gM( 'mwe-prevent-close') |
| 999 | + this.allowCloseWindow = mw.confirmCloseWindow( { |
| 1000 | + message: function() { return gM( 'mwe-upwiz-prevent-close', _this.uploads.length ) }, |
| 1001 | + test: function() { return _this.uploads.length > 0 } |
998 | 1002 | } ); |
999 | 1003 | |
1000 | 1004 | $j( '#mwe-upwiz-progress' ).show(); |
— | — | @@ -1021,7 +1025,6 @@ |
1022 | 1026 | upload.start(); |
1023 | 1027 | }, |
1024 | 1028 | function() { |
1025 | | - allowCloseWindow(); |
1026 | 1029 | $j().notify( gM( 'mwe-upwiz-files-complete' ) ); |
1027 | 1030 | _this.showFileNext(); |
1028 | 1031 | } |
— | — | @@ -1296,38 +1299,8 @@ |
1297 | 1300 | |
1298 | 1301 | } )( jQuery ); |
1299 | 1302 | |
1300 | | -( function ( $j ) { |
1301 | | - /** |
1302 | | - * Prevent the closing of a window with a confirm message (the onbeforeunload event seems to |
1303 | | - * work in most browsers |
1304 | | - * e.g. |
1305 | | - * var allowCloseWindow = jQuery().preventCloseWindow( { message: "Don't go away!" } ); |
1306 | | - * // ... do stuff that can't be interrupted ... |
1307 | | - * allowCloseWindow(); |
1308 | | - * |
1309 | | - * @param options object which should have a message string, already internationalized |
1310 | | - * @return closure execute this when you want to allow the user to close the window |
1311 | | - */ |
1312 | | - $j.fn.preventCloseWindow = function( options ) { |
1313 | | - if ( typeof options === 'undefined' ) { |
1314 | | - options = {}; |
1315 | | - } |
| 1303 | +( function ( $j ) { |
1316 | 1304 | |
1317 | | - if ( typeof options.message === 'undefined' ) { |
1318 | | - options.message = 'Are you sure you want to close this window?'; |
1319 | | - } |
1320 | | - |
1321 | | - $j( window ).unload( function() { |
1322 | | - return options.message; |
1323 | | - } ); |
1324 | | - |
1325 | | - return function() { |
1326 | | - $j( window ).removeAttr( 'unload' ); |
1327 | | - }; |
1328 | | - |
1329 | | - }; |
1330 | | - |
1331 | | - |
1332 | 1305 | $j.fn.notify = function ( message ) { |
1333 | 1306 | // could do something here with Chrome's in-browser growl-like notifications. |
1334 | 1307 | // play a sound? |
Index: trunk/extensions/UploadWizard/resources/mw.ConfirmCloseWindow.js |
— | — | @@ -0,0 +1,57 @@ |
| 2 | +( function( mw, $ ) { |
| 3 | + /** |
| 4 | + * Prevent the closing of a window with a confirm message (the onbeforeunload event seems to |
| 5 | + * work in most browsers.) |
| 6 | + * |
| 7 | + * This supersedes any previous onbeforeunload handler. If there was a handler before, it is |
| 8 | + * restored when you execute the returned function. |
| 9 | + * e.g. |
| 10 | + * |
| 11 | + * var allowCloseWindow = mw.confirmCloseWindow( { message: 'Dont close me!' } ); |
| 12 | + * // ... do stuff that can't be interrupted ... |
| 13 | + * allowCloseWindow(); |
| 14 | + * |
| 15 | + * |
| 16 | + * @param options options - optional set of the following optional arguments: |
| 17 | + * message: function returning string message to show. |
| 18 | + * test: function returning boolean. If true, alert is shown. Defaults to always true. |
| 19 | + * @return closure execute this when you want to allow the user to close the window |
| 20 | + */ |
| 21 | + mw.confirmCloseWindow = function( options ) { |
| 22 | + if ( ! mw.isDefined( options ) ) { |
| 23 | + options = {}; |
| 24 | + } |
| 25 | + |
| 26 | + var defaults = { |
| 27 | + message: function() { return gM( 'mwe-prevent-close' ) }, |
| 28 | + test: function() { return true; } |
| 29 | + }; |
| 30 | + options = $.extend( defaults, options ); |
| 31 | + |
| 32 | + var oldUnloadHandler = window.onbeforeunload; |
| 33 | + |
| 34 | + window.onbeforeunload = function() { |
| 35 | + if ( options.test() ) { |
| 36 | + // remove the handler while the alert is showing - otherwise breaks caching in Firefox (3?). |
| 37 | + // but if they continue working on this page, immediately re-register this handler |
| 38 | + var thisFunction = arguments.callee; |
| 39 | + window.onbeforeunload = null; |
| 40 | + setTimeout( function() { |
| 41 | + window.onbeforeunload = thisFunction; |
| 42 | + } ); |
| 43 | + |
| 44 | + // show an alert with this message |
| 45 | + return options.message(); |
| 46 | + } |
| 47 | + }; |
| 48 | + |
| 49 | + // return the function they can use to stop this |
| 50 | + return function() { |
| 51 | + window.onbeforeunload = oldUnloadHandler; |
| 52 | + }; |
| 53 | + |
| 54 | + }; |
| 55 | + |
| 56 | +} )( window.mediaWiki, jQuery ); |
| 57 | + |
| 58 | + |
Property changes on: trunk/extensions/UploadWizard/resources/mw.ConfirmCloseWindow.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 59 | + native |