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


The following commit(s) were added to refs/heads/gh-pages by this push:
     new 38bd4ee7 fix(explore): use seedrandom to keep the same CDN subdomain & 
extract some library URLs into common config
38bd4ee7 is described below

commit 38bd4ee769e489110ab5e0b58a1e1a794fb77b8c
Author: plainheart <[email protected]>
AuthorDate: Mon Oct 9 03:03:48 2023 +0800

    fix(explore): use seedrandom to keep the same CDN subdomain & extract some 
library URLs into common config
---
 src/common/config.js                  |  3 +++
 src/editor/downloadExample.js         |  2 +-
 src/editor/sandbox/index.js           | 10 +++++++---
 src/editor/sandbox/openwith/helper.js |  3 ++-
 src/editor/sandbox/srcdoc.html        |  4 ----
 src/explore/ExampleCard.vue           |  4 +++-
 src/explore/Explore.vue               | 23 ++++++++++++++++-------
 7 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/src/common/config.js b/src/common/config.js
index ab20fe27..caa565b9 100644
--- a/src/common/config.js
+++ b/src/common/config.js
@@ -132,6 +132,9 @@ export const SCRIPT_URLS = {
   aceDir: `${CDN_ROOT}[email protected]/src-min-noconflict`,
   prettierDir: `${CDN_ROOT}[email protected]`,
   highlightjsDir: 
`https://fastly.jsdelivr.net/gh/highlightjs/[email protected]/build`,
+  seedrandomJS: `${CDN_ROOT}[email protected]/seedrandom.min.js`,
+  jQueryJS: `${CDN_ROOT}[email protected]/dist/jquery.min.js`,
+  acornJS: `${CDN_ROOT}[email protected]/dist/acorn.min.js`,
 
   bmapLibJS:
     'https://api.map.baidu.com/api?v=3.0&ak=KOmVjPVUAey1G2E8zNhPiuQ6QiEmAwZu',
diff --git a/src/editor/downloadExample.js b/src/editor/downloadExample.js
index 78252d03..ae80e72d 100644
--- a/src/editor/downloadExample.js
+++ b/src/editor/downloadExample.js
@@ -9,7 +9,7 @@ export function download(sourceHeader) {
 
   const hasJQueryJS = /\$[\.\(]+/g.test(store.sourceCode);
   const jqueryScriptCode = hasJQueryJS
-    ? '<script type="text/javascript" 
src="https://fastly.jsdelivr.net/npm/jquery";></script>'
+    ? `<script type="text/javascript" src="${SCRIPT_URLS.jQueryJS}"></script>`
     : '';
 
   const echartsDir = SCRIPT_URLS[
diff --git a/src/editor/sandbox/index.js b/src/editor/sandbox/index.js
index ab4fbc5e..0dc3d816 100644
--- a/src/editor/sandbox/index.js
+++ b/src/editor/sandbox/index.js
@@ -5,6 +5,7 @@ import handleLoop from './handleLoop?raw-minify';
 import showDebugDirtyRect from '../../dep/showDebugDirtyRect?raw-minify';
 import setup from './setup?raw-minify';
 import { store } from '../../common/store';
+import { SCRIPT_URLS } from '../../common/config';
 
 function prepareSetupScript(isShared) {
   const isProd = process.env.NODE_ENV === 'production';
@@ -31,9 +32,12 @@ export function createSandbox(
   onOptionUpdated,
   onCSSParsed
 ) {
-  scripts = ((scripts && scripts.slice()) || []).concat(
-    prepareSetupScript(isShared)
-  );
+  const commonLibs = [
+    SCRIPT_URLS.jQueryJS,
+    SCRIPT_URLS.seedrandomJS,
+    SCRIPT_URLS.acornJS
+  ].map((src) => ({ src }));
+  scripts = commonLibs.concat(scripts, prepareSetupScript(isShared));
 
   const sandbox = document.createElement('iframe');
   const allow = [
diff --git a/src/editor/sandbox/openwith/helper.js 
b/src/editor/sandbox/openwith/helper.js
index 62463991..5e4019f6 100644
--- a/src/editor/sandbox/openwith/helper.js
+++ b/src/editor/sandbox/openwith/helper.js
@@ -1,4 +1,5 @@
 import { store } from '../../../common/store';
+import { SCRIPT_URLS } from '../../../common/config';
 
 /**
  * Get templates
@@ -16,7 +17,7 @@ export function getTemplates(title, scripts, css) {
   const hasJQuery = /\$[\.\(]+/g.test(store.sourceCode);
   hasJQuery &&
     scripts.unshift({
-      src: 'https://fastly.jsdelivr.net/npm/jquery'
+      src: SCRIPT_URLS.jQueryJS
     });
 
   const htmlTpl = `<!DOCTYPE html>
diff --git a/src/editor/sandbox/srcdoc.html b/src/editor/sandbox/srcdoc.html
index d32f99e7..3dc3d807 100644
--- a/src/editor/sandbox/srcdoc.html
+++ b/src/editor/sandbox/srcdoc.html
@@ -3,7 +3,6 @@
   <head>
     <meta charset="utf-8" />
     <meta http-equiv="Content-Security-Policy" content="__CSP__" />
-    <link rel="dns-prefetch" href="https://fastly.jsdelivr.net"; />
     <style>
       * {
         margin: 0;
@@ -65,9 +64,6 @@
         });
       })();
     </script>
-    <script src="https://fastly.jsdelivr.net/npm/jquery";></script>
-    <script 
src="https://fastly.jsdelivr.net/npm/[email protected]/seedrandom.min.js";></script>
-    <script 
src="https://fastly.jsdelivr.net/npm/[email protected]/dist/acorn.min.js";></script>
     __SCRIPTS__
   </body>
 </html>
diff --git a/src/explore/ExampleCard.vue b/src/explore/ExampleCard.vue
index 57105245..c11026e4 100644
--- a/src/explore/ExampleCard.vue
+++ b/src/explore/ExampleCard.vue
@@ -75,7 +75,9 @@ export default {
       const cdnRoot = store.cdnRoot;
       const acceleratorCDN =
         this.enableImgAcceleration &&
-        IMG_ACCELERATOR_CDN[~~(Math.random() * IMG_ACCELERATOR_CDN.length)];
+        IMG_ACCELERATOR_CDN[
+          ~~(window.ec_math_random() * IMG_ACCELERATOR_CDN.length)
+        ];
       return acceleratorCDN
         ? acceleratorCDN + '/' + cdnRoot.slice(cdnRoot.indexOf('//') + 2)
         : cdnRoot;
diff --git a/src/explore/Explore.vue b/src/explore/Explore.vue
index f397a521..3d79da37 100644
--- a/src/explore/Explore.vue
+++ b/src/explore/Explore.vue
@@ -66,9 +66,12 @@
 <script>
 import CHART_LIST from '../data/chart-list-data';
 import CHART_LIST_GL from '../data/chart-list-data-gl';
-import { EXAMPLE_CATEGORIES, BLACK_MAP } from '../common/config';
+import { EXAMPLE_CATEGORIES, BLACK_MAP, SCRIPT_URLS } from '../common/config';
 import { store } from '../common/store';
-import { shouldEnableImgAcceleration } from '../common/helper';
+import {
+  loadScriptsAsync,
+  shouldEnableImgAcceleration
+} from '../common/helper';
 import ExampleCard from './ExampleCard.vue';
 import LazyLoad from 'vanilla-lazyload/dist/lazyload.esm';
 
@@ -253,12 +256,18 @@ export default {
       return onDone();
     }
 
-    $.getJSON(`${store.cdnRoot}/thumb-hash.json?_v_=${store.version}`).always(
-      (data) => {
+    $.getJSON(`${store.cdnRoot}/thumb-hash.json?_v_=${store.version}`)
+      .done((data) => {
         window.ec_thumb_hash = data;
-        onDone();
-      }
-    );
+      })
+      .always(() => {
+        loadScriptsAsync([SCRIPT_URLS.seedrandomJS]).finally(() => {
+          window.ec_math_random = Math.seedrandom
+            ? new Math.seedrandom('echarts-examples')
+            : Math.random;
+          onDone();
+        });
+      });
   },
 
   methods: {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to