From a635f670b489f0dbb349f5277753d6851d2c03bd Mon Sep 17 00:00:00 2001 From: yama-dev Date: Thu, 4 Apr 2019 18:18:12 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Modify:=20=E3=83=87=E3=83=BC=E3=82=BF?= =?UTF-8?q?=E3=81=AB=E4=B8=8D=E5=82=99=E3=81=8C=E3=81=82=E3=82=8B=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E8=AA=BF=E6=95=B4?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js-multi-data-module.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/js-multi-data-module.js b/src/js-multi-data-module.js index d1aaae2..8baa76f 100644 --- a/src/js-multi-data-module.js +++ b/src/js-multi-data-module.js @@ -71,17 +71,24 @@ export default class MULTI_DATA_MODULE { let getDataFunc = ()=>{ let promise = new Promise((resolve, reject)=>{ + if(dataAry[count].url){ + let _script = document.createElement('script'); if(dataAry[count].url.match(/\?.*$/)){ _script.src = `${dataAry[count].url}&callback=${this.Config.jsonpCallback}&_=${param_ramd+count}`; } else { _script.src = `${dataAry[count].url}?callback=${this.Config.jsonpCallback}&_=${param_ramd+count}`; } + document.body.appendChild(_script); window.callback = (response)=>{ resolve(response); }; setTimeout(()=>{ reject('error'); }, this.Config.fetch_timeout); + + } else { + reject('error:not found data.'); + } }); promise @@ -149,6 +156,9 @@ export default class MULTI_DATA_MODULE { let getDataFunc = ()=>{ let promise = new Promise((resolve, reject)=>{ + + if(dataAry[count].url){ + let xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { @@ -170,6 +180,10 @@ export default class MULTI_DATA_MODULE { xhr.send(null); setTimeout(()=>{ reject('error'); }, this.Config.fetch_timeout); + + } else { + reject('error:not found data.'); + } }); promise From 65f7087214513d9a07dc18f0f03df90dd37a8d8e Mon Sep 17 00:00:00 2001 From: yama-dev Date: Thu, 4 Apr 2019 18:18:43 +0900 Subject: [PATCH 2/3] Update: version text. --- dist/js-multi-data-module.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/js-multi-data-module.js b/dist/js-multi-data-module.js index 21a126a..833457d 100644 --- a/dist/js-multi-data-module.js +++ b/dist/js-multi-data-module.js @@ -1,7 +1,7 @@ /*! * JS MULTI_DATA_MODULE (JavaScript Library) * js-multi-data-module - * Version 0.4.5 + * Version 0.4.7 * Repository https://github.com/yama-dev/js-multi-data-module * Copyright yama-dev * Licensed MIT diff --git a/package.json b/package.json index 3b5aac3..85584b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-multi-data-module", - "version": "0.4.5", + "version": "0.4.7", "description": "Get multi data library.", "keywords": [ "multi-data", From 7f99ba886d7654b0bf50250d2167468f090f7946 Mon Sep 17 00:00:00 2001 From: yama-dev Date: Thu, 4 Apr 2019 18:19:10 +0900 Subject: [PATCH 3/3] Adjust: console log. --- dist/js-multi-data-module.js | 2 +- src/js-multi-data-module.js | 62 ++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/dist/js-multi-data-module.js b/dist/js-multi-data-module.js index 833457d..19c8b1b 100644 --- a/dist/js-multi-data-module.js +++ b/dist/js-multi-data-module.js @@ -13,4 +13,4 @@ * @license Licensed under MIT license * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE * @version v4.2.5+7f2b526d - */var r;r=function(){"use strict";function t(t){return"function"==typeof t}var r=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},o=0,i=void 0,a=void 0,s=function(t,e){d[o]=t,d[o+1]=e,2===(o+=2)&&(a?a(y):b())},c="undefined"!=typeof window?window:void 0,u=c||{},l=u.MutationObserver||u.WebKitMutationObserver,f="undefined"==typeof self&&void 0!==e&&"[object process]"==={}.toString.call(e),h="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel;function p(){var t=setTimeout;return function(){return t(y,1)}}var d=new Array(1e3);function y(){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);if(!e.data_list||!Array.isArray(e.data_list)){try{throw new Error('Not config "data_list"')}catch(t){console.log(t.name+": "+t.message)}return!1}this.Config=i({data_type:"jsonp",data_list:null,order:"up",orderProperty:"date",filter:!1,empty:!1,jsonpCallback:"callback",fetch_timeout:1e4},e),this.Version="0.4.5",this.DataFix=[],this.DataList={},e.on||(e.on={}),this.On={Update:e.on.Update||"",Complete:e.on.Complete||""},"jsonp"===this.Config.data_type&&this.GetDataJsonp(this.Config.data_list),"json"===this.Config.data_type&&this.GetDataJson(this.Config.data_list),"html"!==this.Config.data_type&&"xml"!==this.Config.data_type||this.GetDataDocument(this.Config.data_list)}var e,n,r;return e=t,(n=[{key:"GetDataJsonp",value:function(t){var e=this,n=0,r=t.length,i=(new Date).getTime();!function a(){new o.a(function(r,o){var a=document.createElement("script");t[n].url.match(/\?.*$/)?a.src="".concat(t[n].url,"&callback=").concat(e.Config.jsonpCallback,"&_=").concat(i+n):a.src="".concat(t[n].url,"?callback=").concat(e.Config.jsonpCallback,"&_=").concat(i+n),document.body.appendChild(a),window.callback=function(t){r(t)},setTimeout(function(){o("error")},e.Config.fetch_timeout)}).then(function(o){var i=o;t[n].hierarchy.split(".").map(function(t){i=i[t]}),t[n].customFunction&&(i=e.CreateData(i,null,t[n].customFunction)),i?(e.DataFix=e.DataFix.concat(i),e.DataList[n]=i):e.Config.empty&&(e.DataFix=e.DataFix.concat([""]),e.DataList[n]=[]),e.OnUpdate(e.DataList[n]),++nn?1:0:-1:1}),"down"===this.Config.order&&this.DataFix.sort(function(e,n){return e[t.Config.orderProperty]?n[t.Config.orderProperty]?(e=new Date(e[t.Config.orderProperty].replace(/\./g,"/")))<(n=new Date(n[t.Config.orderProperty].replace(/\./g,"/")))?1:e>n?-1:0:-1:1}),this.OnComplete()}},{key:"OnUpdate",value:function(t){this.On.Update&&"function"==typeof this.On.Update&&this.On.Update(t)}},{key:"OnComplete",value:function(){this.On.Complete&&"function"==typeof this.On.Complete&&this.On.Complete(this.DataFix,this.DataList)}}])&&a(e.prototype,n),r&&a(e,r),t}()},function(t,e){var n,r,o=t.exports={};function i(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function s(t){if(n===setTimeout)return setTimeout(t,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(t){n=i}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(t){r=a}}();var c,u=[],l=!1,f=-1;function h(){l&&c&&(l=!1,c.length?u=c.concat(u):f=-1,u.length&&p())}function p(){if(!l){var t=s(h);l=!0;for(var e=u.length;e;){for(c=u,u=[];++f1)for(var n=1;n0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);if(!e.data_list||!Array.isArray(e.data_list)){try{throw new Error('Not config "data_list"')}catch(t){console.log(t.name+": "+t.message)}return!1}this.Config=i({data_type:"jsonp",data_list:null,order:"up",orderProperty:"date",filter:!1,empty:!1,jsonpCallback:"callback",fetch_timeout:1e4},e),this.Version="0.4.7",this.DataFix=[],this.DataList={},e.on||(e.on={}),this.On={Update:e.on.Update||"",Complete:e.on.Complete||""},"jsonp"===this.Config.data_type&&this.GetDataJsonp(this.Config.data_list),"json"===this.Config.data_type&&this.GetDataJson(this.Config.data_list),"html"!==this.Config.data_type&&"xml"!==this.Config.data_type||this.GetDataDocument(this.Config.data_list)}var e,n,r;return e=t,(n=[{key:"GetDataJsonp",value:function(t){var e=this,n=0,r=t.length,i=(new Date).getTime();!function a(){new o.a(function(r,o){if(t[n].url){var a=document.createElement("script");t[n].url.match(/\?.*$/)?a.src="".concat(t[n].url,"&callback=").concat(e.Config.jsonpCallback,"&_=").concat(i+n):a.src="".concat(t[n].url,"?callback=").concat(e.Config.jsonpCallback,"&_=").concat(i+n),document.body.appendChild(a),window.callback=function(t){r(t)},setTimeout(function(){o("error")},e.Config.fetch_timeout)}else o("error:not found data.")}).then(function(o){var i=o;t[n].hierarchy.split(".").map(function(t){i=i[t]}),t[n].customFunction&&(i=e.CreateData(i,null,t[n].customFunction)),i?(e.DataFix=e.DataFix.concat(i),e.DataList[n]=i):e.Config.empty&&(e.DataFix=e.DataFix.concat([""]),e.DataList[n]=[]),e.OnUpdate(e.DataList[n]),++nn?1:0:-1:1}),"down"===this.Config.order&&this.DataFix.sort(function(e,n){return e[t.Config.orderProperty]?n[t.Config.orderProperty]?(e=new Date(e[t.Config.orderProperty].replace(/\./g,"/")))<(n=new Date(n[t.Config.orderProperty].replace(/\./g,"/")))?1:e>n?-1:0:-1:1}),this.OnComplete()}},{key:"OnUpdate",value:function(t){this.On.Update&&"function"==typeof this.On.Update&&this.On.Update(t)}},{key:"OnComplete",value:function(){this.On.Complete&&"function"==typeof this.On.Complete&&this.On.Complete(this.DataFix,this.DataList)}}])&&a(e.prototype,n),r&&a(e,r),t}()},function(t,e){var n,r,o=t.exports={};function i(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function c(t){if(n===setTimeout)return setTimeout(t,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(t){n=i}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(t){r=a}}();var s,u=[],l=!1,f=-1;function h(){l&&s&&(l=!1,s.length?u=s.concat(u):f=-1,u.length&&p())}function p(){if(!l){var t=c(h);l=!0;for(var e=u.length;e;){for(s=u,u=[];++f1)for(var n=1;n{ if(dataAry[count].url){ - let _script = document.createElement('script'); - if(dataAry[count].url.match(/\?.*$/)){ - _script.src = `${dataAry[count].url}&callback=${this.Config.jsonpCallback}&_=${param_ramd+count}`; - } else { - _script.src = `${dataAry[count].url}?callback=${this.Config.jsonpCallback}&_=${param_ramd+count}`; - } + let _script = document.createElement('script'); + if(dataAry[count].url.match(/\?.*$/)){ + _script.src = `${dataAry[count].url}&callback=${this.Config.jsonpCallback}&_=${param_ramd+count}`; + } else { + _script.src = `${dataAry[count].url}?callback=${this.Config.jsonpCallback}&_=${param_ramd+count}`; + } - document.body.appendChild(_script); - window.callback = (response)=>{ - resolve(response); - }; - setTimeout(()=>{ reject('error'); }, this.Config.fetch_timeout); + document.body.appendChild(_script); + window.callback = (response)=>{ + resolve(response); + }; + setTimeout(()=>{ reject('error'); }, this.Config.fetch_timeout); } else { reject('error:not found data.'); @@ -126,7 +126,7 @@ export default class MULTI_DATA_MODULE { }) .catch((err)=>{ // Error. - console.log(err); + console.log('%c'+err,'color: red'); this.DataFix = this.DataFix.concat(['']); this.DataList[count] = []; @@ -159,27 +159,27 @@ export default class MULTI_DATA_MODULE { if(dataAry[count].url){ - let xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() { - if (xhr.readyState === 4) { - if (xhr.status == 200) { - resolve(JSON.parse(xhr.responseText)); + let xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + if (xhr.status == 200) { + resolve(JSON.parse(xhr.responseText)); + } + } + }; + let _url = ''; + if(dataAry[count].url.match(/\?.*$/)){ + _url = `${dataAry[count].url}&_=${param_ramd+count}`; + } else { + _url = `${dataAry[count].url}?_=${param_ramd+count}`; } - }; + xhr.onload = function() { }; + xhr.open('GET', _url, true); + xhr.send(null); - let _url = ''; - if(dataAry[count].url.match(/\?.*$/)){ - _url = `${dataAry[count].url}&_=${param_ramd+count}`; - } else { - _url = `${dataAry[count].url}?_=${param_ramd+count}`; - } - xhr.onload = function() { }; - xhr.open('GET', _url, true); - xhr.send(null); - - setTimeout(()=>{ reject('error'); }, this.Config.fetch_timeout); + setTimeout(()=>{ reject('error'); }, this.Config.fetch_timeout); } else { reject('error:not found data.'); @@ -221,7 +221,7 @@ export default class MULTI_DATA_MODULE { }) .catch((err)=>{ // Error. - console.log(err); + console.log('%c'+err,'color: red'); this.DataFix = this.DataFix.concat(['']); this.DataList[count] = []; @@ -331,7 +331,7 @@ export default class MULTI_DATA_MODULE { }) .catch((err)=>{ // Error. - console.log(err); + console.log('%c'+err,'color: red'); this.DataFix = this.DataFix.concat(['']); this.DataList[count] = [];