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.

git-svn-id: https://develop.svn.wordpress.org/trunk@56809 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter
2023-10-09 21:29:42 +00:00
parent 9ec564607c
commit fbe3732917
7 changed files with 43 additions and 28 deletions

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>