PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.14
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.14
2.0.14 2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / assets / js / admin-notices.js

admin-notices.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.14, at assets/js/admin-notices.js

44 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function ($) {
2 'use strict';
3 $(function () {
4 var body = document.getElementById('wpbody-content');
5 if (!body) return;
6 var roots = '#bkbg-template-catalog,#bkbg-dashboard,.bkbg-ai-settings';
7 var headers = '.bkbg-catalog-header,.bkbg-header,.bkbg-ai-settings-header';
8 var notices = '.notice,.updated,.error,.update-nag,.fs-notice';
9 var slot = document.createElement('div');
10 slot.className = 'bkbg-admin-notices';
11 slot.setAttribute('role', 'region');
12 slot.setAttribute('aria-label', bkbgAdminNotices.label);
13 slot.hidden = true;
14 var queued = false;
15
16 function placeNotices() {
17 queued = false;
18 var root = body.querySelector(roots);
19 var header = root && root.querySelector(headers);
20 if (!header) return;
21 // Retain the original nodes and their dismissal handlers when catalog
22 // navigation replaces the entire root through AJAX.
23 if (header.nextElementSibling !== slot) header.after(slot);
24 body.querySelectorAll(notices).forEach(function (notice) {
25 if (slot.contains(notice)) return;
26 var parent = notice.parentElement;
27 if (!parent || parent.closest(notices)) return;
28 if (header.contains(notice) || parent === root || parent === body) {
29 slot.appendChild(notice);
30 }
31 });
32 slot.hidden = !slot.children.length;
33 }
34 function schedule() {
35 if (queued) return;
36 queued = true;
37 window.requestAnimationFrame(placeNotices);
38 }
39 placeNotices();
40 // Only child changes matter: no attribute polling or recurring timer.
41 new MutationObserver(schedule).observe(body, { childList: true, subtree: true });
42 });
43 })(jQuery);
44