PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.0.0
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.0.0
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
desktop-mode / assets / js / iframe-bridge.min.js

iframe-bridge.min.js in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.0.0, at assets/js/iframe-bridge.min.js

2 lines 13.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var openStationIframeBridge=function(T){"use strict";function k(){const h=window;if(h.__openStationEditorAutosaveInstalled)return;h.__openStationEditorAutosaveInstalled=!0;const l=window.location.origin,S=()=>window.wp,_=w=>{if(!(typeof w!="string"||w===""))try{return new URL(w,l).origin===l?w:void 0}catch{return}},M=w=>{try{window.parent.postMessage(w,l)}catch{}},b=new Map,A=(w,d)=>{const E=S(),y=E?.data?.select?.("core/editor");if(y&&typeof E?.data?.subscribe=="function"){const u=E.data.select?.("core/block-editor"),f=E.data.dispatch?.("core/editor");let e=null,n=!1,o=u?.getBlocks?.(),t=y.getEditedPostAttribute?.("title"),r=!1;const s=()=>{if(e=null,!n){if((y.isSavingPost?.()??!1)||(y.isAutosavingPost?.()??!1)){e=window.setTimeout(s,1e3);return}if(!(typeof y.isEditedPostAutosaveable=="function"&&!y.isEditedPostAutosaveable())){if(typeof f?.__unstableSaveForPreview=="function"){Promise.resolve(f.__unstableSaveForPreview()).then(c=>{n||M({type:"os-editor-live-saved",watchId:w,..._(c)?{previewUrl:_(c)}:{}})}).catch(()=>{});return}typeof f?.autosave=="function"&&(f.autosave(),M({type:"os-editor-live-saved",watchId:w}))}}},i=E.data.subscribe(()=>{const c=u?.getBlocks?.(),p=y.getEditedPostAttribute?.("title");if((y.isSavingPost?.()??!1)||(y.isAutosavingPost?.()??!1)){o=c,t=p,r=!0;return}if(r){r=!1,o=c,t=p;return}c===o&&p===t||(o=c,t=p,!(typeof y.isEditedPostDirty=="function"&&!y.isEditedPostDirty())&&(e!==null&&window.clearTimeout(e),e=window.setTimeout(s,d)))});return()=>{n=!0,i(),e!==null&&(window.clearTimeout(e),e=null)}}if(E?.autosave?.server){const f=window.jQuery;if(!f)return null;let e=null,n=!1,o=!1;const t=()=>{if(e=null,!n){if(o){e=window.setTimeout(t,1e3);return}try{E.autosave?.server?.triggerSave?.()}catch{}}},r=()=>{n||(e!==null&&window.clearTimeout(e),e=window.setTimeout(t,d))},s=`.os-live-${w}`;f(document).on(`before-autosave${s}`,()=>{o=!0}),f(document).on(`after-autosave${s}`,()=>{o=!1,M({type:"os-editor-live-saved",watchId:w})});const i=[];for(const a of["title","content","excerpt"]){const g=document.getElementById(a);g&&(g.addEventListener("input",r),i.push(g))}const c=window.tinymce,p="keyup input change undo redo SetContent",m=[],P=a=>{a?.on&&(a.on(p,r),m.push(a))};(c?.editors??[]).forEach(P);const I=a=>P(a?.editor);return c?.on?.("AddEditor",I),()=>{n=!0,e!==null&&(window.clearTimeout(e),e=null),f(document).off(`before-autosave${s}`),f(document).off(`after-autosave${s}`);for(const a of i)a.removeEventListener("input",r);for(const a of m)try{a.off?.(p,r)}catch{}c?.off?.("AddEditor",I)}}return null};window.addEventListener("message",w=>{if(w.origin!==l)return;const d=w?.data;if(!d||typeof d!="object")return;if(d.type==="os-editor-live-watch"&&typeof d.watchId=="string"){b.get(d.watchId)?.(),b.delete(d.watchId);const f=Math.min(3e4,Math.max(500,typeof d.debounceMs=="number"?d.debounceMs:1500));try{const e=A(d.watchId,f);e&&b.set(d.watchId,e)}catch{}return}if(d.type==="os-editor-live-unwatch"&&typeof d.watchId=="string"){try{b.get(d.watchId)?.()}catch{}b.delete(d.watchId);return}if(d.type!=="os-editor-autosave-request"||typeof d.requestId!="string")return;const E=d.requestId;let y=!1;const u=(f,e)=>{if(!y){y=!0;try{window.parent.postMessage({type:"os-editor-autosave-response",requestId:E,status:f,...e?{previewUrl:e}:{}},l)}catch{}}};try{const f=S(),e=f?.data?.select?.("core/editor");if(e){const o=f?.data?.dispatch?.("core/editor");if(typeof o?.__unstableSaveForPreview=="function"){Promise.resolve(o.__unstableSaveForPreview()).then(t=>{u("saved",_(t))}).catch(()=>u("error"));return}if(typeof e.isEditedPostAutosaveable=="function"&&!e.isEditedPostAutosaveable()){u("not-dirty");return}if(typeof o?.autosave=="function"&&typeof f?.data?.subscribe=="function"){let t=!1;const r=f.data.subscribe(()=>{if(e.isAutosavingPost?.()??!1){t=!0;return}t&&(r(),u("saved"))});window.setTimeout(()=>{r(),u("saved")},8e3),o.autosave();return}u("no-editor");return}const n=f?.autosave?.server?.triggerSave;if(typeof n=="function"){const t=window.jQuery;t&&t(document).one("after-autosave.os-editor-preview",()=>u("saved")),window.setTimeout(()=>u("saved"),5e3),n.call(f?.autosave?.server);return}u("no-editor")}catch{u("error")}})}return function(){if(!window.parent||window.parent===window)return;k();const h=window;if(h.wp?.os?.iframe)return;const l=window.location.origin,S={},_=[],M={};let b=null;const A=[],w=e=>{if(!e||b===e)return;b=e;const n=A.splice(0);for(const o of n)try{o(e)}catch{}},d={},E=(e,n,o)=>{try{window.parent.postMessage({type:"os-bridge-publish",connectionId:e,topic:n,payload:o},l)}catch{}};window.addEventListener("message",e=>{if(e.origin!==l)return;const n=e?.data;if(!(!n||typeof n!="object"||typeof n.type!="string")){if(n.type==="os-bridge-handshake"&&typeof n.connectionId=="string"){const o=n.targetWindowId;if(typeof o=="string"&&o!==""&&w(o),S[n.connectionId]){try{window.parent.postMessage({type:"os-bridge-handshake-ack",connectionId:n.connectionId},l)}catch{}return}const t={id:n.connectionId,topics:Array.isArray(n.topics)?n.topics.slice():[]};S[t.id]=t;try{window.parent.postMessage({type:"os-bridge-handshake-ack",connectionId:t.id},l)}catch{}for(const r of _)try{r({id:t.id,topics:t.topics.slice()})}catch{}return}if(n.type==="os-bridge-beforeunload-query"){let o=!1,t="";const r=i=>{const c=i;Object.defineProperty(i,"returnValue",{get(){return c._returnValue||""},set(p){c._returnValue=p}})},s=(i,c)=>{const p=i.returnValue,m=typeof c=="string"&&c!=="",P=typeof p=="string"&&p!=="";(i.defaultPrevented||m||P)&&(o=!0,m?t=c:P&&(t=p))};if(typeof window.onbeforeunload=="function"){const i=new Event("beforeunload",{cancelable:!0});r(i);const c=window.onbeforeunload(i);s(i,c)}if(!o){const i=new Event("beforeunload",{cancelable:!0});r(i),window.dispatchEvent(i),s(i,null)}try{window.parent.postMessage({type:"os-bridge-beforeunload-response",prevent:o,message:t},l)}catch{}return}if(n.type==="os-bridge-publish"&&typeof n.topic=="string"){const o={topic:n.topic,connectionId:n.connectionId},t=M[n.topic];if(t)for(const s of t)try{s(n.payload,o)}catch{}const r=M["*"];if(r)for(const s of r)try{s(n.payload,o)}catch{}return}if(n.type==="os-bridge-disconnect"&&typeof n.connectionId=="string"&&delete S[n.connectionId],n.type==="os-window-send"&&typeof n.channel=="string"){const o=n,t={channel:o.channel},r=d[o.channel];if(r)for(const i of r.slice())try{i(o.payload,t)}catch{}const s=d["*"];if(s)for(const i of s.slice())try{i(o.payload,t)}catch{}}}});const y={publish(e,n){if(typeof e!="string"||e==="")return;const o=Object.keys(S);if(o.length===0){console.warn('[openstation] wp.os.iframe.publish dropped: no open connection for topic "%s". The parent shell must call `wp.os.connect(windowId)` first.',e);return}for(const t of o)E(t,e,n)},subscribe(e,n){if(typeof e!="string"||e===""||typeof n!="function")return()=>{};let o=M[e];return o||(o=[],M[e]=o),o.push(n),()=>{const t=o.indexOf(n);t>=0&&o.splice(t,1)}},onConnection(e){if(typeof e!="function")return()=>{};_.push(e);for(const n of Object.keys(S))try{e({id:S[n].id,topics:S[n].topics.slice()})}catch{}return()=>{const n=_.indexOf(e);n>=0&&_.splice(n,1)}},chrome:{setTheme(e){try{window.parent.postMessage({type:"os-chrome-theme",tokens:e??{}},l)}catch{}},setControls(e){try{window.parent.postMessage({type:"os-chrome-controls",config:e??null},l)}catch{}},setSlot(e,n){if(!(typeof e!="string"||e===""))try{window.parent.postMessage({type:"os-chrome-slot",slot:e,html:typeof n=="string"?n:""},l)}catch{}}},requestConnection(e){const n=e??{},o=Array.isArray(n.topics)?n.topics.slice():[],t="wpdir-"+Math.random().toString(36).slice(2,10);return new Promise((r,s)=>{let i=!1;const c=typeof n.timeoutMs=="number"?n.timeoutMs:5e3,p=(I,a)=>{i||(i=!0,window.removeEventListener("message",m),clearTimeout(P),I?r(a):s(a))},m=I=>{if(I.origin!==l)return;const a=I?.data;if(!(!a||typeof a!="object"||a.type!=="os-bridge-connection-ack"||a.requestId!==t))if(a.accepted){const g={id:typeof a.connectionId=="string"?a.connectionId:"",topics:o.slice()};if(typeof n.onOpen=="function")try{n.onOpen(g)}catch{}p(!0,g)}else p(!1,new Error(a.reason||"rejected"))};window.addEventListener("message",m);const P=setTimeout(()=>{p(!1,new Error("timeout"))},c);try{window.parent.postMessage({type:"os-bridge-connection-request",requestId:t,topics:o},l)}catch(I){p(!1,I)}})},get windowId(){return b},whenWindowId(){return b!==null?Promise.resolve(b):new Promise(e=>{A.push(e)})},isParentReachable(){if(!window.parent||window.parent===window)return!1;try{return window.parent.location.origin===l}catch{return!1}}};h.wp||(h.wp={}),h.wp.os||(h.wp.os={}),h.wp.os.iframe=y,typeof h.wp.os.send!="function"&&(h.wp.os.send=(e,n)=>{if(!(typeof e!="string"||e===""))try{window.parent.postMessage({type:"os-window-publish",channel:e,payload:n},l)}catch{}}),typeof h.wp.os.on!="function"&&(h.wp.os.on=(e,n)=>{if(typeof e!="string"||e===""||typeof n!="function")return()=>{};let o=d[e];return o||(o=[],d[e]=o),o.push(n),()=>{const t=o.indexOf(n);t>=0&&o.splice(t,1)}});const u=window;if(u.__openStationScreenMetaInstalled||(u.__openStationScreenMetaInstalled=!0,f(l)),!u.__openStationOsFileDropForwarderInstalled){u.__openStationOsFileDropForwarderInstalled=!0;const e=t=>{const r=t.dataTransfer?.types;if(!r)return!1;const s=r;if(typeof s.includes=="function")return s.includes("Files");if(typeof s.contains=="function")return s.contains("Files");for(let i=0;i<s.length;i++)if(s[i]==="Files")return!0;return!1},n=[".components-drop-zone","[data-drop-zone]",".uploader-window",".media-frame-content"],o=t=>{const r=t;if(!r||!r.closest)return!1;for(const s of n)if(r.closest(s))return!0;return!1};document.addEventListener("dragover",t=>{e(t)&&(o(t.target)||t.defaultPrevented||(t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect="copy")))},!1),document.addEventListener("drop",t=>{if(!e(t)||o(t.target)||t.defaultPrevented)return;t.preventDefault(),t.stopPropagation();const r=[];if(t.dataTransfer?.files)for(let s=0;s<t.dataTransfer.files.length;s++)r.push(t.dataTransfer.files[s]);if(r.length!==0)try{window.parent.postMessage({type:"os-file-drop",files:r,x:t.clientX,y:t.clientY},l)}catch{}},!1)}if(!u.__openStationDragHoverForwarderInstalled){u.__openStationDragHoverForwarderInstalled=!0;const e=o=>{const t=o.dataTransfer?.types;if(!t)return!1;const r=t;return typeof r.includes=="function"?r.includes("Files"):typeof r.contains=="function"&&r.contains("Files")};let n=0;document.addEventListener("dragover",o=>{const t=Date.now();if(!(t-n<150)){n=t;try{window.parent.postMessage({type:"os-drag-hover",payloadType:e(o)?"os-file":"external"},l)}catch{}}},!0)}if(!u.__openStationPointerForwarderInstalled){u.__openStationPointerForwarderInstalled=!0;let e=!1,n=0;window.addEventListener("message",o=>{if(o.origin!==window.location.origin)return;const t=o.data;!t||t.type!=="os-pointer-track"||(e=t.enabled===!0)}),document.addEventListener("pointermove",o=>{if(!e)return;const t=Date.now();if(!(t-n<40)){n=t;try{window.parent.postMessage({type:"os-pointer-move",x:o.clientX,y:o.clientY},l)}catch{}}},{capture:!0,passive:!0})}try{window.parent&&window.parent!==window&&window.parent.postMessage({type:"os-ready"},l)}catch{}function f(e){const n=()=>{const r=document.getElementById("screen-options-wrap");return!!r&&!!r.querySelector('input:not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]), select, textarea')},o=()=>{const r=document.getElementById("contextual-help-wrap");if(!r)return!1;const s=r.querySelectorAll(".help-tab-content, .contextual-help-sidebar");for(let i=0;i<s.length;i++)if((s[i].textContent||"").trim()!=="")return!0;return!1},t=()=>{const r=document.getElementById("screen-meta-links"),s=r?document.getElementById("show-settings-link"):null,i=r?document.getElementById("contextual-help-link"):null,c=[];s&&n()&&c.push("screen-options"),i&&o()&&c.push("help");try{window.parent.postMessage({type:"os-screen-meta",panels:c},e)}catch{}if(c.length===0)return;const p=()=>s&&s.getAttribute("aria-expanded")==="true"?"screen-options":i&&i.getAttribute("aria-expanded")==="true"?"help":null,m=()=>{try{window.parent.postMessage({type:"os-screen-meta-state",open:p()},e)}catch{}};m();const P=new MutationObserver(m);s&&P.observe(s,{attributes:!0,attributeFilter:["aria-expanded"]}),i&&P.observe(i,{attributes:!0,attributeFilter:["aria-expanded"]});const I=a=>{if(!a||a.getAttribute("aria-expanded")!=="true")return;const g=a.getAttribute("aria-controls"),v=g?document.getElementById(g):null;if(!v)return;const F=window.jQuery;if(F)try{F(v).stop(!0,!1)}catch{}v.style.display="none",v.classList.add("hidden"),v.parentElement&&(v.parentElement.style.display="none"),a.classList.remove("screen-meta-active"),a.setAttribute("aria-expanded","false"),document.querySelectorAll(".screen-meta-toggle").forEach(L=>{L.style.visibility=""})};window.addEventListener("message",a=>{if(a.origin!==e)return;const g=a.data;if(!g||g.type!=="os-toggle-panel")return;let v=null;g.panel==="screen-options"&&s?v=s:g.panel==="help"&&i&&(v=i),v&&(v.getAttribute("aria-expanded")!=="true"&&I(v===s?i:s),v.click())})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}}(),T.installEditorAutosaveHandler=k,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"}),T}({});
2