Administration: Remove deprecated `unload` event handlers and use `pagehide` (and `pageshow`) when appropriate.

Use `pagehide` event instead of `unload` in the following cases:

* For classic editor to release the post lock.
* In Text widget to rebuild editor after dragging widget to new location in classic widgets interface.
* To clear out the `window.name` when navigating away from a post preview.
* To suspend heartbeat, while also using `pageshow` event to resume as if it had been a focused tab in case page restored from bfcache. 

Also:

* Remove obsolete mobile cleanup code in `js/_enqueues/lib/gallery.js` (introduced in [9894]). Do same for `src/js/_enqueues/wp/media/models.js` (introduced in [22872]). See #22552.
* Remove obsolete Firefox-specific workaround in `js/_enqueues/wp/mce-view.js` from [39282]. See #38511.

Fixes #55491.
Props spenserhale, westonruter, adamsilverstein, azaozz, shawfactor, peterwilsoncc, swissspidy.
Built from https://develop.svn.wordpress.org/trunk@56809


git-svn-id: http://core.svn.wordpress.org/trunk@56321 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2023-10-09 21:31:27 +00:00
parent d605f96c0f
commit 2869e3a186
14 changed files with 50 additions and 35 deletions

View File

@ -88,8 +88,6 @@ jQuery( function($) {
}
});
jQuery(window).on( 'unload', function () { window.tinymce = window.tinyMCE = window.wpgallery = null; } ); // Cleanup.
/* gallery settings */
window.tinymce = null;

View File

@ -1,2 +1,2 @@
/*! This file is auto-generated */
jQuery(function(n){var o=!1,e=function(){n("#media-items").sortable({items:"div.media-item",placeholder:"sorthelper",axis:"y",distance:2,handle:"div.filename",stop:function(){var e=n("#media-items").sortable("toArray"),i=e.length;n.each(e,function(e,t){e=o?i-e:1+e;n("#"+t+" .menu_order input").val(e)})}})},t=function(){var e=n(".menu_order_input"),t=e.length;e.each(function(e){e=o?t-e:1+e;n(this).val(e)})},i=function(e){e=e||0,n(".menu_order_input").each(function(){"0"!==this.value&&!e||(this.value="")})};n("#asc").on("click",function(e){e.preventDefault(),o=!1,t()}),n("#desc").on("click",function(e){e.preventDefault(),o=!0,t()}),n("#clear").on("click",function(e){e.preventDefault(),i(1)}),n("#showall").on("click",function(e){e.preventDefault(),n("#sort-buttons span a").toggle(),n("a.describe-toggle-on").hide(),n("a.describe-toggle-off, table.slidetoggle").show(),n("img.pinkynail").toggle(!1)}),n("#hideall").on("click",function(e){e.preventDefault(),n("#sort-buttons span a").toggle(),n("a.describe-toggle-on").show(),n("a.describe-toggle-off, table.slidetoggle").hide(),n("img.pinkynail").toggle(!0)}),e(),i(),1<n("#media-items>*").length&&(e=wpgallery.getWin(),n("#save-all, #gallery-settings").show(),void 0!==e.tinyMCE&&e.tinyMCE.activeEditor&&!e.tinyMCE.activeEditor.isHidden()?(wpgallery.mcemode=!0,wpgallery.init()):n("#insert-gallery").show())}),jQuery(window).on("unload",function(){window.tinymce=window.tinyMCE=window.wpgallery=null}),window.tinymce=null,window.wpgallery={mcemode:!1,editor:{},dom:{},is_update:!1,el:{},I:function(e){return document.getElementById(e)},init:function(){var e,t,i,n,o=this,l=o.getWin();if(o.mcemode){for(e=(""+document.location.search).replace(/^\?/,"").split("&"),t={},i=0;i<e.length;i++)n=e[i].split("="),t[unescape(n[0])]=unescape(n[1]);t.mce_rdomain&&(document.domain=t.mce_rdomain),window.tinymce=l.tinymce,window.tinyMCE=l.tinyMCE,o.editor=tinymce.EditorManager.activeEditor,o.setup()}},getWin:function(){return window.dialogArguments||opener||parent||top},setup:function(){var e,t,i,n=this,o=n.editor;if(n.mcemode){if(n.el=o.selection.getNode(),"IMG"!==n.el.nodeName||!o.dom.hasClass(n.el,"wpGallery")){if(!(i=o.dom.select("img.wpGallery"))||!i[0])return"1"===getUserSetting("galfile")&&(n.I("linkto-file").checked="checked"),"1"===getUserSetting("galdesc")&&(n.I("order-desc").checked="checked"),getUserSetting("galcols")&&(n.I("columns").value=getUserSetting("galcols")),getUserSetting("galord")&&(n.I("orderby").value=getUserSetting("galord")),void jQuery("#insert-gallery").show();n.el=i[0]}i=o.dom.getAttrib(n.el,"title"),(i=o.dom.decode(i))?(jQuery("#update-gallery").show(),n.is_update=!0,o=i.match(/columns=['"]([0-9]+)['"]/),e=i.match(/link=['"]([^'"]+)['"]/i),t=i.match(/order=['"]([^'"]+)['"]/i),i=i.match(/orderby=['"]([^'"]+)['"]/i),e&&e[1]&&(n.I("linkto-file").checked="checked"),t&&t[1]&&(n.I("order-desc").checked="checked"),o&&o[1]&&(n.I("columns").value=""+o[1]),i&&i[1]&&(n.I("orderby").value=i[1])):jQuery("#insert-gallery").show()}},update:function(){var e=this,t=e.editor,i="";e.mcemode&&e.is_update?"IMG"===e.el.nodeName&&(i=(i=t.dom.decode(t.dom.getAttrib(e.el,"title"))).replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi,""),i+=e.getSettings(),t.dom.setAttrib(e.el,"title",i),e.getWin().tb_remove()):(t="[gallery"+e.getSettings()+"]",e.getWin().send_to_editor(t))},getSettings:function(){var e=this.I,t="";return e("linkto-file").checked&&(t+=' link="file"',setUserSetting("galfile","1")),e("order-desc").checked&&(t+=' order="DESC"',setUserSetting("galdesc","1")),3!==e("columns").value&&(t+=' columns="'+e("columns").value+'"',setUserSetting("galcols",e("columns").value)),"menu_order"!==e("orderby").value&&(t+=' orderby="'+e("orderby").value+'"',setUserSetting("galord",e("orderby").value)),t}};
jQuery(function(n){var o=!1,e=function(){n("#media-items").sortable({items:"div.media-item",placeholder:"sorthelper",axis:"y",distance:2,handle:"div.filename",stop:function(){var e=n("#media-items").sortable("toArray"),i=e.length;n.each(e,function(e,t){e=o?i-e:1+e;n("#"+t+" .menu_order input").val(e)})}})},t=function(){var e=n(".menu_order_input"),t=e.length;e.each(function(e){e=o?t-e:1+e;n(this).val(e)})},i=function(e){e=e||0,n(".menu_order_input").each(function(){"0"!==this.value&&!e||(this.value="")})};n("#asc").on("click",function(e){e.preventDefault(),o=!1,t()}),n("#desc").on("click",function(e){e.preventDefault(),o=!0,t()}),n("#clear").on("click",function(e){e.preventDefault(),i(1)}),n("#showall").on("click",function(e){e.preventDefault(),n("#sort-buttons span a").toggle(),n("a.describe-toggle-on").hide(),n("a.describe-toggle-off, table.slidetoggle").show(),n("img.pinkynail").toggle(!1)}),n("#hideall").on("click",function(e){e.preventDefault(),n("#sort-buttons span a").toggle(),n("a.describe-toggle-on").show(),n("a.describe-toggle-off, table.slidetoggle").hide(),n("img.pinkynail").toggle(!0)}),e(),i(),1<n("#media-items>*").length&&(e=wpgallery.getWin(),n("#save-all, #gallery-settings").show(),void 0!==e.tinyMCE&&e.tinyMCE.activeEditor&&!e.tinyMCE.activeEditor.isHidden()?(wpgallery.mcemode=!0,wpgallery.init()):n("#insert-gallery").show())}),window.tinymce=null,window.wpgallery={mcemode:!1,editor:{},dom:{},is_update:!1,el:{},I:function(e){return document.getElementById(e)},init:function(){var e,t,i,n,o=this,l=o.getWin();if(o.mcemode){for(e=(""+document.location.search).replace(/^\?/,"").split("&"),t={},i=0;i<e.length;i++)n=e[i].split("="),t[unescape(n[0])]=unescape(n[1]);t.mce_rdomain&&(document.domain=t.mce_rdomain),window.tinymce=l.tinymce,window.tinyMCE=l.tinyMCE,o.editor=tinymce.EditorManager.activeEditor,o.setup()}},getWin:function(){return window.dialogArguments||opener||parent||top},setup:function(){var e,t,i,n=this,o=n.editor;if(n.mcemode){if(n.el=o.selection.getNode(),"IMG"!==n.el.nodeName||!o.dom.hasClass(n.el,"wpGallery")){if(!(i=o.dom.select("img.wpGallery"))||!i[0])return"1"===getUserSetting("galfile")&&(n.I("linkto-file").checked="checked"),"1"===getUserSetting("galdesc")&&(n.I("order-desc").checked="checked"),getUserSetting("galcols")&&(n.I("columns").value=getUserSetting("galcols")),getUserSetting("galord")&&(n.I("orderby").value=getUserSetting("galord")),void jQuery("#insert-gallery").show();n.el=i[0]}i=o.dom.getAttrib(n.el,"title"),(i=o.dom.decode(i))?(jQuery("#update-gallery").show(),n.is_update=!0,o=i.match(/columns=['"]([0-9]+)['"]/),e=i.match(/link=['"]([^'"]+)['"]/i),t=i.match(/order=['"]([^'"]+)['"]/i),i=i.match(/orderby=['"]([^'"]+)['"]/i),e&&e[1]&&(n.I("linkto-file").checked="checked"),t&&t[1]&&(n.I("order-desc").checked="checked"),o&&o[1]&&(n.I("columns").value=""+o[1]),i&&i[1]&&(n.I("orderby").value=i[1])):jQuery("#insert-gallery").show()}},update:function(){var e=this,t=e.editor,i="";e.mcemode&&e.is_update?"IMG"===e.el.nodeName&&(i=(i=t.dom.decode(t.dom.getAttrib(e.el,"title"))).replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi,""),i+=e.getSettings(),t.dom.setAttrib(e.el,"title",i),e.getWin().tb_remove()):(t="[gallery"+e.getSettings()+"]",e.getWin().send_to_editor(t))},getSettings:function(){var e=this.I,t="";return e("linkto-file").checked&&(t+=' link="file"',setUserSetting("galfile","1")),e("order-desc").checked&&(t+=' order="DESC"',setUserSetting("galdesc","1")),3!==e("columns").value&&(t+=' columns="'+e("columns").value+'"',setUserSetting("galcols",e("columns").value)),"menu_order"!==e("orderby").value&&(t+=' orderby="'+e("orderby").value+'"',setUserSetting("galord",e("orderby").value)),t}};

View File

@ -511,7 +511,7 @@ jQuery( function($) {
// See https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event.
return __( 'The changes you made will be lost if you navigate away from this page.' );
}
}).on( 'unload.edit-post', function( event ) {
}).on( 'pagehide.edit-post', function( event ) {
if ( ! releaseLock ) {
return;
}

File diff suppressed because one or more lines are too long

View File

@ -291,7 +291,7 @@ wp.textWidgets = ( function( $ ) {
onInit = function() {
// When a widget is moved in the DOM the dynamically-created TinyMCE iframe will be destroyed and has to be re-built.
$( editor.getWin() ).on( 'unload', function() {
$( editor.getWin() ).on( 'pagehide', function() {
_.defer( buildEditor );
});

File diff suppressed because one or more lines are too long

View File

@ -7585,7 +7585,7 @@ function wp_delete_file_from_directory( $file, $directory ) {
}
/**
* Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload.
* Outputs a small JS snippet on preview tabs/windows to remove `window.name` when a user is navigating to another page.
*
* This prevents reusing the same tab for a preview when the user has navigated away.
*
@ -7614,7 +7614,7 @@ function wp_post_preview_js() {
}
if ( window.addEventListener ) {
window.addEventListener( 'unload', function() { window.name = ''; }, false );
window.addEventListener( 'pagehide', function() { window.name = ''; } );
}
}());
</script>

View File

@ -223,9 +223,9 @@
settings.checkFocusTimer = window.setInterval( checkFocus, 10000 );
}
$(window).on( 'unload.wp-heartbeat', function() {
$(window).on( 'pagehide.wp-heartbeat', function() {
// Don't connect anymore.
settings.suspend = true;
suspend();
// Abort the last request if not completed.
if ( settings.xhr && settings.xhr.readyState !== 4 ) {
@ -233,6 +233,25 @@
}
});
$(window).on(
'pageshow.wp-heartbeat',
/**
* Handles pageshow event, specifically when page navigation is restored from back/forward cache.
*
* @param {jQuery.Event} event
* @param {PageTransitionEvent} event.originalEvent
*/
function ( event ) {
if ( event.originalEvent.persisted ) {
/*
* When page navigation is stored via bfcache (Back/Forward Cache), consider this the same as
* if the user had just switched to the tab since the behavior is similar.
*/
focused();
}
}
);
// Check for user activity every 30 seconds.
window.setInterval( checkUserActivity, 30000 );
@ -541,7 +560,7 @@
settings.userActivity = time();
// Resume if suspended.
settings.suspend = false;
resume();
if ( ! settings.hasFocus ) {
settings.hasFocus = true;
@ -549,6 +568,20 @@
}
}
/**
* Suspends connecting.
*/
function suspend() {
settings.suspend = true;
}
/**
* Resumes connecting.
*/
function resume() {
settings.suspend = false;
}
/**
* Runs when the user becomes active after a period of inactivity.
*
@ -593,7 +626,7 @@
// Suspend after 10 minutes of inactivity when suspending is enabled.
// Always suspend after 60 minutes of inactivity. This will release the post lock, etc.
if ( ( settings.suspendEnabled && lastActive > 600000 ) || lastActive > 3600000 ) {
settings.suspend = true;
suspend();
}
if ( ! settings.userActivityEvents ) {

File diff suppressed because one or more lines are too long

View File

@ -643,16 +643,6 @@
}, 3000 );
}
function reload() {
if ( ! editor.isHidden() ) {
$( node ).data( 'rendered', null );
setTimeout( function() {
wp.mce.views.render();
} );
}
}
function addObserver() {
observer = new MutationObserver( _.debounce( resize, 100 ) );
@ -663,7 +653,7 @@
} );
}
$( iframeWin ).on( 'load', resize ).on( 'unload', reload );
$( iframeWin ).on( 'load', resize );
MutationObserver = iframeWin.MutationObserver || iframeWin.WebKitMutationObserver || iframeWin.MozMutationObserver;

File diff suppressed because one or more lines are too long

View File

@ -1395,8 +1395,7 @@ var __webpack_exports__ = {};
* @output wp-includes/js/media-models.js
*/
var $ = jQuery,
Attachment, Attachments, l10n, media;
var Attachment, Attachments, l10n, media;
/** @namespace wp */
window.wp = window.wp || {};
@ -1631,11 +1630,6 @@ media.query = function( props ) {
});
};
// Clean up. Prevents mobile browsers caching.
$(window).on('unload', function(){
window.wp = null;
});
}();
/******/ })()
;

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.4-beta2-56808';
$wp_version = '6.4-beta2-56809';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.