PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.6
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.6
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.1.6, at assets/js/iframe-bridge.min.js

2 lines 13.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var openStationIframeBridge=function(x){"use strict";function B(){const v=window;if(v.__openStationEditorAutosaveInstalled)return;v.__openStationEditorAutosaveInstalled=!0;const l=window.location.origin,_=()=>window.wp,A=y=>{if(!(typeof y!="string"||y===""))try{return new URL(y,l).origin===l?y:void 0}catch{return}},T=y=>{try{window.parent.postMessage(y,l)}catch{}},P=new Map,L=(y,d)=>{const M=_(),g=M?.data?.select?.("core/editor");if(g&&typeof M?.data?.subscribe=="function"){const u=M.data.select?.("core/block-editor"),f=M.data.dispatch?.("core/editor");let e=null,n=!1,o=u?.getBlocks?.(),t=g.getEditedPostAttribute?.("title"),r=!1;const i=()=>{if(e=null,!n){if((g.isSavingPost?.()??!1)||(g.isAutosavingPost?.()??!1)){e=window.setTimeout(i,1e3);return}if(!(typeof g.isEditedPostAutosaveable=="function"&&!g.isEditedPostAutosaveable())){if(typeof f?.__unstableSaveForPreview=="function"){Promise.resolve(f.__unstableSaveForPreview()).then(a=>{n||T({type:"os-editor-live-saved",watchId:y,...A(a)?{previewUrl:A(a)}:{}})}).catch(()=>{});return}typeof f?.autosave=="function"&&(f.autosave(),T({type:"os-editor-live-saved",watchId:y}))}}},s=M.data.subscribe(()=>{const a=u?.getBlocks?.(),w=g.getEditedPostAttribute?.("title");if((g.isSavingPost?.()??!1)||(g.isAutosavingPost?.()??!1)){o=a,t=w,r=!0;return}if(r){r=!1,o=a,t=w;return}a===o&&w===t||(o=a,t=w,!(typeof g.isEditedPostDirty=="function"&&!g.isEditedPostDirty())&&(e!==null&&window.clearTimeout(e),e=window.setTimeout(i,d)))});return()=>{n=!0,s(),e!==null&&(window.clearTimeout(e),e=null)}}if(M?.autosave?.server){const f=window.jQuery;if(!f)return null;let e=null,n=!1,o=!1;const t=window.tinymce,r=c=>{const E=document.getElementById(c);return!E||!("value"in E)?null:String(E.value)},i=()=>{const c=[];let E=!1;const W=r("title");W!==null&&(E=!0),c.push(W??"");for(const F of["content","excerpt"]){let q=null;try{const j=t?.get?.(F);j&&!j.isHidden?.()&&(q=j.getContent?.()??null)}catch{}q===null&&(q=r(F)),q!==null&&(E=!0),c.push(q??"")}return E?c.map(F=>`${F.length}:${F}`).join(""):null};let s=i(),a=null,w=!1;const I=()=>{if(e=null,n)return;if(o){e=window.setTimeout(I,1e3);return}const c=i();if(!(c!==null&&c===s))try{M.autosave?.server?.triggerSave?.()}catch{}},S=()=>{n||(w=!0,e!==null&&window.clearTimeout(e),e=window.setTimeout(I,d))},m=`.os-live-${y}`;f(document).on(`before-autosave${m}`,()=>{o=!0,a=i()}),f(document).on(`after-autosave${m}`,()=>{o=!1;const c=a;a=null;const E=c!==null&&c===s;c!==null&&(s=c),!(E||!w)&&(w=!1,T({type:"os-editor-live-saved",watchId:y}))});const p=[];for(const c of["title","content","excerpt"]){const E=document.getElementById(c);E&&(E.addEventListener("input",S),p.push(E))}const b="keyup input change undo redo SetContent ExecCommand",h=[],k=c=>{c?.on&&(c.on(b,S),h.push(c))};(t?.editors??[]).forEach(k);const O=c=>k(c?.editor);return t?.on?.("AddEditor",O),()=>{n=!0,e!==null&&(window.clearTimeout(e),e=null),f(document).off(`before-autosave${m}`),f(document).off(`after-autosave${m}`);for(const c of p)c.removeEventListener("input",S);for(const c of h)try{c.off?.(b,S)}catch{}t?.off?.("AddEditor",O)}}return null};window.addEventListener("message",y=>{if(y.origin!==l)return;const d=y?.data;if(!d||typeof d!="object")return;if(d.type==="os-editor-live-watch"&&typeof d.watchId=="string"){P.get(d.watchId)?.(),P.delete(d.watchId);const f=Math.min(3e4,Math.max(500,typeof d.debounceMs=="number"?d.debounceMs:1500));try{const e=L(d.watchId,f);e&&P.set(d.watchId,e)}catch{}return}if(d.type==="os-editor-live-unwatch"&&typeof d.watchId=="string"){try{P.get(d.watchId)?.()}catch{}P.delete(d.watchId);return}if(d.type!=="os-editor-autosave-request"||typeof d.requestId!="string")return;const M=d.requestId;let g=!1;const u=(f,e)=>{if(!g){g=!0;try{window.parent.postMessage({type:"os-editor-autosave-response",requestId:M,status:f,...e?{previewUrl:e}:{}},l)}catch{}}};try{const f=_(),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",A(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("not-dirty"),5e3)):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;B();const v=window;if(v.wp?.os?.iframe)return;const l=window.location.origin,_={},A=[],T={};let P=null;const L=[],y=e=>{if(!e||P===e)return;P=e;const n=L.splice(0);for(const o of n)try{o(e)}catch{}},d={},M=(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!==""&&y(o),_[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():[]};_[t.id]=t;try{window.parent.postMessage({type:"os-bridge-handshake-ack",connectionId:t.id},l)}catch{}for(const r of A)try{r({id:t.id,topics:t.topics.slice()})}catch{}return}if(n.type==="os-bridge-beforeunload-query"){let o=!1,t="";const r=s=>{const a=s;Object.defineProperty(s,"returnValue",{get(){return a._returnValue||""},set(w){a._returnValue=w}})},i=(s,a)=>{const w=s.returnValue,I=typeof a=="string"&&a!=="",S=typeof w=="string"&&w!=="";(s.defaultPrevented||I||S)&&(o=!0,I?t=a:S&&(t=w))};if(typeof window.onbeforeunload=="function"){const s=new Event("beforeunload",{cancelable:!0});r(s);const a=window.onbeforeunload(s);i(s,a)}if(!o){const s=new Event("beforeunload",{cancelable:!0});r(s),window.dispatchEvent(s),i(s,null)}try{const s={type:"os-bridge-beforeunload-response",prevent:o,message:t};typeof n.requestId=="string"&&n.requestId!==""&&(s.requestId=n.requestId),window.parent.postMessage(s,l)}catch{}return}if(n.type==="os-bridge-publish"&&typeof n.topic=="string"){const o={topic:n.topic,connectionId:n.connectionId},t=T[n.topic];if(t)for(const i of t)try{i(n.payload,o)}catch{}const r=T["*"];if(r)for(const i of r)try{i(n.payload,o)}catch{}return}if(n.type==="os-bridge-disconnect"&&typeof n.connectionId=="string"&&delete _[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 s of r.slice())try{s(o.payload,t)}catch{}const i=d["*"];if(i)for(const s of i.slice())try{s(o.payload,t)}catch{}}}});const g={publish(e,n){if(typeof e!="string"||e==="")return;const o=Object.keys(_);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)M(t,e,n)},subscribe(e,n){if(typeof e!="string"||e===""||typeof n!="function")return()=>{};let o=T[e];return o||(o=[],T[e]=o),o.push(n),()=>{const t=o.indexOf(n);t>=0&&o.splice(t,1)}},onConnection(e){if(typeof e!="function")return()=>{};A.push(e);for(const n of Object.keys(_))try{e({id:_[n].id,topics:_[n].topics.slice()})}catch{}return()=>{const n=A.indexOf(e);n>=0&&A.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,i)=>{let s=!1;const a=typeof n.timeoutMs=="number"?n.timeoutMs:5e3,w=(m,p)=>{s||(s=!0,window.removeEventListener("message",I),clearTimeout(S),m?r(p):i(p))},I=m=>{if(m.origin!==l)return;const p=m?.data;if(!(!p||typeof p!="object"||p.type!=="os-bridge-connection-ack"||p.requestId!==t))if(p.accepted){const b={id:typeof p.connectionId=="string"?p.connectionId:"",topics:o.slice()};if(typeof n.onOpen=="function")try{n.onOpen(b)}catch{}w(!0,b)}else w(!1,new Error(p.reason||"rejected"))};window.addEventListener("message",I);const S=setTimeout(()=>{w(!1,new Error("timeout"))},a);try{window.parent.postMessage({type:"os-bridge-connection-request",requestId:t,topics:o},l)}catch(m){w(!1,m)}})},get windowId(){return P},whenWindowId(){return P!==null?Promise.resolve(P):new Promise(e=>{L.push(e)})},isParentReachable(){if(!window.parent||window.parent===window)return!1;try{return window.parent.location.origin===l}catch{return!1}}};v.wp||(v.wp={}),v.wp.os||(v.wp.os={}),v.wp.os.iframe=g,typeof v.wp.os.send!="function"&&(v.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 v.wp.os.on!="function"&&(v.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 i=r;if(typeof i.includes=="function")return i.includes("Files");if(typeof i.contains=="function")return i.contains("Files");for(let s=0;s<i.length;s++)if(i[s]==="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 i of n)if(r.closest(i))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 i=0;i<t.dataTransfer.files.length;i++)r.push(t.dataTransfer.files[i]);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.addEventListener("pagehide",()=>{try{window.parent&&window.parent!==window&&window.parent.postMessage({type:"os-iframe-unloading"},l)}catch{}})}catch{}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 i=r.querySelectorAll(".help-tab-content, .contextual-help-sidebar");for(let s=0;s<i.length;s++)if((i[s].textContent||"").trim()!=="")return!0;return!1},t=()=>{const r=document.getElementById("screen-meta-links"),i=r?document.getElementById("show-settings-link"):null,s=r?document.getElementById("contextual-help-link"):null,a=[];i&&n()&&a.push("screen-options"),s&&o()&&a.push("help");try{window.parent.postMessage({type:"os-screen-meta",panels:a},e)}catch{}if(a.length===0)return;const w=()=>i&&i.getAttribute("aria-expanded")==="true"?"screen-options":s&&s.getAttribute("aria-expanded")==="true"?"help":null,I=()=>{try{window.parent.postMessage({type:"os-screen-meta-state",open:w()},e)}catch{}};I();const S=new MutationObserver(I);i&&S.observe(i,{attributes:!0,attributeFilter:["aria-expanded"]}),s&&S.observe(s,{attributes:!0,attributeFilter:["aria-expanded"]});const m=p=>{if(!p||p.getAttribute("aria-expanded")!=="true")return;const b=p.getAttribute("aria-controls"),h=b?document.getElementById(b):null;if(!h)return;const k=window.jQuery;if(k)try{k(h).stop(!0,!1)}catch{}h.style.display="none",h.classList.add("hidden"),h.parentElement&&(h.parentElement.style.display="none"),p.classList.remove("screen-meta-active"),p.setAttribute("aria-expanded","false"),document.querySelectorAll(".screen-meta-toggle").forEach(c=>{c.style.visibility=""})};window.addEventListener("message",p=>{if(p.origin!==e)return;const b=p.data;if(!b||b.type!=="os-toggle-panel")return;let h=null;b.panel==="screen-options"&&i?h=i:b.panel==="help"&&s&&(h=s),h&&(h.getAttribute("aria-expanded")!=="true"&&m(h===i?s:i),h.click())})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}}(),x.installEditorAutosaveHandler=B,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"}),x}({});
2