PluginProbe
Tableberg – Simple Gutenberg Table Block / 0.5.5
Tableberg – Simple Gutenberg Table Block v0.5.5
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
tableberg / includes / assets / js / PreviewDeviceChangeObserver.js

PreviewDeviceChangeObserver.js in Tableberg – Simple Gutenberg Table Block 0.5.5, at includes/assets/js/PreviewDeviceChangeObserver.js

46 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (() => {
2 let lastDevice = null;
3
4 function register() {
5 if (lastDevice) {
6 return;
7 }
8
9 const previewEl = document.querySelector(
10 ".is-tablet-preview, .is-desktop-preview, .is-mobile-preview"
11 );
12 if (!previewEl) {
13 return;
14 }
15 lastDevice = previewEl.className.match(/is-(\w*)-preview/)[1];
16 const previewObserver = new MutationObserver((mutationList) => {
17 for (let mutation of mutationList) {
18 if (mutation.attributeName === "class") {
19 const currentPreview =
20 mutation.target.className.match(/is-(\w*)-preview/)[1];
21 if (!currentPreview) {
22 return;
23 }
24 lastDevice = currentPreview;
25 const event = new CustomEvent("TablebergPreviewDeviceChange", {
26 detail: {
27 currentPreview
28 }
29 });
30 document.dispatchEvent(event);
31 return;
32 }
33 }
34 });
35
36 previewObserver.observe(previewEl, {
37 attributes: true,
38 attributeFilter: ["class"],
39 attributeOldValue: true,
40 });
41 }
42
43 window.registerTablebergPreviewDeviceChangeObserver = register;
44 window.tablebergGetLastDevice = () => lastDevice;
45 })();
46