| 1 |
window.addEventListener("load", (event) => { |
| 2 |
var serviceConfig = window.WSCServiceConfig || {}; |
| 3 |
var bundlePath = serviceConfig.bundleUrl || 'https://svc.webspellchecker.net/spellcheck31/wscbundle/wscbundle.js'; |
| 4 |
|
| 5 |
function loadScript(doc, src) { |
| 6 |
// One bundle copy per document. This script runs both in the top frame |
| 7 |
// and inside the editor-canvas iframe, and the top copy also injects |
| 8 |
// into the iframe, so without the flag the bundle could load twice. |
| 9 |
var win = doc.defaultView; |
| 10 |
if (!win || win.__wscBundleRequested) { |
| 11 |
return; |
| 12 |
} |
| 13 |
win.__wscBundleRequested = true; |
| 14 |
|
| 15 |
const script = doc.createElement('script'); |
| 16 |
const appendTo = doc.head || doc.documentElement; |
| 17 |
|
| 18 |
script.type = 'text/javascript'; |
| 19 |
script.async = false; |
| 20 |
script.src = src; |
| 21 |
|
| 22 |
appendTo.appendChild(script); |
| 23 |
} |
| 24 |
|
| 25 |
if (!window.WEBSPELLCHECKER_CONFIG) { |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
window.gutenbergIframe = document.querySelector('[name=editor-canvas]'); |
| 30 |
|
| 31 |
if (window.gutenbergIframe) { |
| 32 |
// The iframe document hosts the editable content and shows the badge; |
| 33 |
// the top frame keeps a badge-less SDK for classic metabox fields. |
| 34 |
const iframeConfig = window.gutenbergIframe.contentWindow.WEBSPELLCHECKER_CONFIG; |
| 35 |
if (iframeConfig && window.WEBSPELLCHECKER_CONFIG.globalBadge) { |
| 36 |
window.WEBSPELLCHECKER_CONFIG.globalBadge = false; |
| 37 |
} |
| 38 |
loadScript(window.gutenbergIframe.contentWindow.document, bundlePath); |
| 39 |
window.gutenbergIframe = null; |
| 40 |
} |
| 41 |
|
| 42 |
loadScript(document, bundlePath); |
| 43 |
}); |
| 44 |
|