From 73479254bc82b37cc6964e8f8c4a929a3688938b Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Tue, 14 Apr 2015 16:41:24 +0000 Subject: [PATCH] Use named function instead of anonymous function The named function is testable and replaceable. Fixes #31964 Props DavidAnderson, adamsilverstein, jorbin git-svn-id: https://develop.svn.wordpress.org/trunk@32126 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/updates.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/wp-admin/js/updates.js b/src/wp-admin/js/updates.js index 9a3dd7646a..d8df2d8743 100644 --- a/src/wp-admin/js/updates.js +++ b/src/wp-admin/js/updates.js @@ -417,6 +417,21 @@ window.wp = window.wp || {}; $message.html( $message.data( 'originaltext' ) ); wp.a11y.speak( wp.updates.l10n.updateCancel ); }; + /** + * Potentially add an AYS to a user attempting to leave the page + * + * If an update is on-going and a user attempts to leave the page, + * open an "Are you sure?" alert. + * + * @since 4.2.0 + */ + + wp.updates.beforeunload = function() { + if ( wp.updates.updateLock ) { + return wp.updates.l10n.beforeunload; + } + }; + $( document ).ready( function() { /* @@ -530,18 +545,8 @@ window.wp = window.wp || {}; break; } - - } ); - /* - * If an update is on-going and a user attempts to leave the page, - * open an "Are you sure?" alert. - */ - $( window ).on( 'beforeunload', function() { - if ( wp.updates.updateLock ) { - return wp.updates.l10n.beforeunload; - } - }); + $( window ).on( 'beforeunload', wp.updates.beforeunload ); })( jQuery, window.wp, window.pagenow, window.ajaxurl );