You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by su...@apache.org on 2020/12/02 15:47:46 UTC

[incubator-echarts-examples] 01/03: fix: thumbnail tool.

This is an automated email from the ASF dual-hosted git repository.

sushuang pushed a commit to branch next
in repository https://gitbox.apache.org/repos/asf/incubator-echarts-examples.git

commit e9575865b7c35f71bb0a022f4879cea300dbb37a
Author: 100pah <su...@gmail.com>
AuthorDate: Wed Dec 2 23:42:41 2020 +0800

    fix: thumbnail tool.
---
 public/screenshot.html | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/public/screenshot.html b/public/screenshot.html
index 18208c6..42d4971 100644
--- a/public/screenshot.html
+++ b/public/screenshot.html
@@ -47,7 +47,21 @@
         return myrng();
     };
 
+    var jqOriginal = {
+        getScript: $.getScript,
+        getJSON: $.getJSON,
+        get: $.get
+    };
+
+    function isRemoteURL(url) {
+        return url && url.indexOf('http') === 0;
+    }
+
     $.getJSON = function (url, cb) {
+        if (isRemoteURL(url)) {
+            return jqOriginal.getJSON.call($, url, cb);
+        }
+
         const deferred = $.Deferred();
         readLocalFile(url).then(data => {
             data = JSON.parse(data);
@@ -59,6 +73,10 @@
     }
 
     $.get = function (url, cb) {
+        if (isRemoteURL(url)) {
+            return jqOriginal.get.call($, url, cb);
+        }
+
         const deferred = $.Deferred();
         readLocalFile(url).then(data => {
             try {
@@ -66,12 +84,24 @@
             }
             catch(e) {}
 
-            cb(data);
+            cb && cb(data);
             deferred.resolve([data]);
         });
         return deferred;
     }
 
+    $.getScript = function (url, cb) {
+        if (isRemoteURL(url)) {
+            return jqOriginal.getScript.call($, url, cb);
+        }
+
+        return $.get(url).then(data => {
+            const scriptContent = data[0];
+            (new Function('window', scriptContent))(window);
+            cb && cb(data);
+        });
+    }
+
     function addComponentPadding(componentOpt) {
         if (!componentOpt) {
             return;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org