Comparing version 0.0.1 to 0.0.2
@@ -1,2 +0,2 @@ | ||
/*! jullius v0.0.1 | (c) 2016 @pinceladasdaweb | https://github.com/pinceladasdaweb/jullius */ | ||
/*! jullius v0.0.2 | (c) 2016 @pinceladasdaweb | https://github.com/pinceladasdaweb/jullius */ | ||
(function (root, factory) { | ||
@@ -14,2 +14,19 @@ "use strict"; | ||
var generateCallback = function () { | ||
return 'jullius_' + Date.now() + '_' + Math.ceil(Math.random() * 100000); | ||
}; | ||
var clearFunction = function (fn) { | ||
try { | ||
delete window[fn]; | ||
} catch (e) { | ||
window[fn] = undefined; | ||
} | ||
}; | ||
var removeScript = function (id) { | ||
var script = document.getElementById(id); | ||
script.parentNode.removeChild(script); | ||
}; | ||
var jullius = function(url) { | ||
@@ -21,3 +38,3 @@ return new Promise(function(resolve, reject) { | ||
var name = 'jullius_' + Math.round(100000000000 * Math.random()), head, script, extScript; | ||
var name = generateCallback(), head, script, extScript; | ||
@@ -30,2 +47,3 @@ head = document.head || document.getElementsByTagName('head')[0]; | ||
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + name; | ||
script.id = name; | ||
script.async = true; | ||
@@ -37,10 +55,7 @@ | ||
resolve(data); | ||
try { | ||
delete window[name]; | ||
} catch(e) { | ||
window[name] = undefined; | ||
} | ||
clearFunction(name); | ||
} | ||
removeScript(name); | ||
script.addEventListener('error', reject); | ||
@@ -47,0 +62,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
/*! jullius v0.0.1 | (c) 2016 @pinceladasdaweb | https://github.com/pinceladasdaweb/jullius */ | ||
!function(e,t){"use strict";"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.jullius=t()}(this,function(){"use strict";var e=function(e){return new Promise(function(t,n){"string"!=typeof e&&n("You need pass a valid url!!!");var o,i,d,r="jullius_"+Math.round(1e11*Math.random());o=document.head||document.getElementsByTagName("head")[0],d=document.createElement("script"),d.type="text/javascript",i=d.cloneNode(),i.src=e+(e.indexOf("?")>=0?"&":"?")+"callback="+r,i.async=!0,o.appendChild(i),window[r]=function(e){t(e);try{delete window[r]}catch(n){window[r]=void 0}},i.addEventListener("error",n)})};return e}); | ||
/*! jullius v0.0.2 | (c) 2016 @pinceladasdaweb | https://github.com/pinceladasdaweb/jullius */ | ||
!function(e,t){"use strict";"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.jullius=t()}(this,function(){"use strict";var e=function(){return"jullius_"+Date.now()+"_"+Math.ceil(1e5*Math.random())},t=function(e){try{delete window[e]}catch(t){window[e]=void 0}},n=function(e){var t=document.getElementById(e);t.parentNode.removeChild(t)},o=function(o){return new Promise(function(i,d){"string"!=typeof o&&d("You need pass a valid url!!!");var r,c,a,u=e();r=document.head||document.getElementsByTagName("head")[0],a=document.createElement("script"),a.type="text/javascript",c=a.cloneNode(),c.src=o+(o.indexOf("?")>=0?"&":"?")+"callback="+u,c.id=u,c.async=!0,r.appendChild(c),window[u]=function(e){i(e),t(u)},n(u),c.addEventListener("error",d)})};return o}); |
{ | ||
"name": "jullius", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Light weight library to manage JSONP calls using Promises", | ||
@@ -5,0 +5,0 @@ "author": "@pinceladasdaweb", |
@@ -13,2 +13,19 @@ (function (root, factory) { | ||
var generateCallback = function () { | ||
return 'jullius_' + Date.now() + '_' + Math.ceil(Math.random() * 100000); | ||
}; | ||
var clearFunction = function (fn) { | ||
try { | ||
delete window[fn]; | ||
} catch (e) { | ||
window[fn] = undefined; | ||
} | ||
}; | ||
var removeScript = function (id) { | ||
var script = document.getElementById(id); | ||
script.parentNode.removeChild(script); | ||
}; | ||
var jullius = function(url) { | ||
@@ -20,3 +37,3 @@ return new Promise(function(resolve, reject) { | ||
var name = 'jullius_' + Math.round(100000000000 * Math.random()), head, script, extScript; | ||
var name = generateCallback(), head, script, extScript; | ||
@@ -29,2 +46,3 @@ head = document.head || document.getElementsByTagName('head')[0]; | ||
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + name; | ||
script.id = name; | ||
script.async = true; | ||
@@ -36,10 +54,7 @@ | ||
resolve(data); | ||
try { | ||
delete window[name]; | ||
} catch(e) { | ||
window[name] = undefined; | ||
} | ||
clearFunction(name); | ||
} | ||
removeScript(name); | ||
script.addEventListener('error', reject); | ||
@@ -46,0 +61,0 @@ }); |
10608
10
138