You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by wa...@apache.org on 2023/10/11 01:02:35 UTC
[echarts-examples] 01/02: reuse jQuery lib from parent context if possible & fix the typo of `handleMessage`
This is an automated email from the ASF dual-hosted git repository.
wangzx pushed a commit to branch gh-pages
in repository https://gitbox.apache.org/repos/asf/echarts-examples.git
commit 007749385bfcc99266c25d5401691f5be2f5a629
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Wed Oct 11 08:55:12 2023 +0800
reuse jQuery lib from parent context if possible & fix the typo of `handleMessage`
---
src/editor/sandbox/index.js | 36 ++++++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 8 deletions(-)
diff --git a/src/editor/sandbox/index.js b/src/editor/sandbox/index.js
index 0dc3d816..6019cffa 100644
--- a/src/editor/sandbox/index.js
+++ b/src/editor/sandbox/index.js
@@ -32,11 +32,31 @@ export function createSandbox(
onOptionUpdated,
onCSSParsed
) {
- const commonLibs = [
- SCRIPT_URLS.jQueryJS,
- SCRIPT_URLS.seedrandomJS,
- SCRIPT_URLS.acornJS
- ].map((src) => ({ src }));
+ const commonLibs = [SCRIPT_URLS.seedrandomJS, SCRIPT_URLS.acornJS].map(
+ (src) => ({ src })
+ );
+ commonLibs.unshift({
+ content: `
+ (() => {
+ let _win = window;
+ while (_win) {
+ if (_win.jQuery) {
+ if (_win !== window) {
+ window.jQuery = window.$ = _win.jQuery;
+ }
+ return;
+ }
+ if (_win === top) {
+ break;
+ }
+ _win = _win.parent;
+ }
+ const jqLib = document.createElement('script');
+ jqLib.src = '${SCRIPT_URLS.jQueryJS}';
+ document.head.appendChild(jqLib);
+ })();
+ `
+ });
scripts = commonLibs.concat(scripts, prepareSetupScript(isShared));
const sandbox = document.createElement('iframe');
@@ -133,7 +153,7 @@ export function createSandbox(
sandbox.onerror = onerror;
container.appendChild(sandbox);
- function hanldeMessage(e) {
+ function handleMessage(e) {
if (e.source !== sandbox.contentWindow) {
return;
}
@@ -162,12 +182,12 @@ export function createSandbox(
sandbox.contentWindow.postMessage({ action, ...argumentMap }, '*');
}
- window.addEventListener('message', hanldeMessage, false);
+ window.addEventListener('message', handleMessage, false);
return {
dispose() {
sendMessage('dispose');
- window.removeEventListener('message', hanldeMessage);
+ window.removeEventListener('message', handleMessage);
container.removeChild(sandbox);
},
run(store, recreateInstance) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org