| 1 |
/** |
| 2 |
* Keeps WordPress core's admin-menu pinning in sync with the real page height. |
| 3 |
* |
| 4 |
* Core measures #wpwrap once and reuses that figure to decide whether to pin |
| 5 |
* the admin menu. Plugin pages change height after that measurement — tab |
| 6 |
* panels being shown or hidden, list tables loading over AJAX, sections |
| 7 |
* expanding — and core is never told. It then works from a stale height, |
| 8 |
* concludes the page is too short to pin, and lets the menu scroll off-screen |
| 9 |
* on a page that is in fact tall enough. |
| 10 |
* |
| 11 |
* Watching the document for height changes and re-firing the event core |
| 12 |
* already listens for keeps the two in agreement, without having to patch |
| 13 |
* every feature that changes layout. |
| 14 |
* |
| 15 |
* @package Metasync |
| 16 |
*/ |
| 17 |
(function ($) { |
| 18 |
'use strict'; |
| 19 |
|
| 20 |
if (typeof window.ResizeObserver === 'undefined') { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
$(function () { |
| 25 |
var lastHeight = document.documentElement.scrollHeight; |
| 26 |
var pending = null; |
| 27 |
|
| 28 |
function notifyCore() { |
| 29 |
var height = document.documentElement.scrollHeight; |
| 30 |
|
| 31 |
// Ignore sub-pixel churn so the observer cannot feed itself. |
| 32 |
if (Math.abs(height - lastHeight) < 2) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
lastHeight = height; |
| 37 |
$(document).trigger('wp-window-resized'); |
| 38 |
} |
| 39 |
|
| 40 |
function schedule() { |
| 41 |
window.clearTimeout(pending); |
| 42 |
pending = window.setTimeout(notifyCore, 100); |
| 43 |
} |
| 44 |
|
| 45 |
new window.ResizeObserver(schedule).observe(document.body); |
| 46 |
|
| 47 |
// Late-loading fonts, images and iframes shift the page after ready. |
| 48 |
$(window).on('load', schedule); |
| 49 |
}); |
| 50 |
})(jQuery); |
| 51 |
|