Comparing version 0.0.2 to 0.0.3
@@ -1,2 +0,2 @@ | ||
/*! jullius v0.0.2 | (c) 2016 @pinceladasdaweb | https://github.com/pinceladasdaweb/jullius */ | ||
/*! jullius v0.0.3 | (c) 2016 @pinceladasdaweb | https://github.com/pinceladasdaweb/jullius */ | ||
(function (root, factory) { | ||
@@ -31,3 +31,15 @@ "use strict"; | ||
var jullius = function(url) { | ||
var buildQuery = function (params) { | ||
var query = '', key; | ||
for (key in params) { | ||
if(params.hasOwnProperty(key)) { | ||
query += encodeURIComponent(key) + "=" + encodeURIComponent(params[key]) + "&" | ||
} | ||
}; | ||
return query; | ||
}; | ||
var jullius = function(url, params) { | ||
return new Promise(function(resolve, reject) { | ||
@@ -45,3 +57,3 @@ if (typeof url !== 'string') { | ||
script = extScript.cloneNode(); | ||
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + name; | ||
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + buildQuery(params) + 'callback=' + name; | ||
script.id = name; | ||
@@ -48,0 +60,0 @@ script.async = true; |
@@ -1,2 +0,2 @@ | ||
/*! 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}); | ||
/*! jullius v0.0.3 | (c) 2016 @pinceladasdaweb | https://github.com/pinceladasdaweb/jullius */ | ||
!function(e,n){"use strict";"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?module.exports=n():e.jullius=n()}(this,function(){"use strict";var e=function(){return"jullius_"+Date.now()+"_"+Math.ceil(1e5*Math.random())},n=function(e){try{delete window[e]}catch(n){window[e]=void 0}},t=function(e){var n=document.getElementById(e);n.parentNode.removeChild(n)},o=function(e){var n,t="";for(n in e)e.hasOwnProperty(n)&&(t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n])+"&");return t},i=function(i,r){return new Promise(function(d,c){"string"!=typeof i&&c("You need pass a valid url!!!");var a,u,s,f=e();a=document.head||document.getElementsByTagName("head")[0],s=document.createElement("script"),s.type="text/javascript",u=s.cloneNode(),u.src=i+(i.indexOf("?")>=0?"&":"?")+o(r)+"callback="+f,u.id=f,u.async=!0,a.appendChild(u),window[f]=function(e){d(e),n(f)},t(f),u.addEventListener("error",c)})};return i}); |
{ | ||
"name": "jullius", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Light weight library to manage JSONP calls using Promises", | ||
@@ -5,0 +5,0 @@ "author": "@pinceladasdaweb", |
@@ -26,3 +26,6 @@ # jullius | ||
<script> | ||
jullius('http://www.pinceladasdaweb.com.br/blog/?json=get_recent_posts') | ||
jullius('http://www.pinceladasdaweb.com.br/blog/', { | ||
json: 'get_recent_posts', | ||
count: 5 | ||
}) | ||
.then(function(data) { | ||
@@ -47,2 +50,6 @@ console.dir(data); | ||
##Options | ||
* url: (string) (required) URL for the JSONP resource. | ||
* params: (object) (optional) Object used to generate GET query parameters for the JSONP resource. | ||
##Browser Support | ||
@@ -49,0 +56,0 @@ |
@@ -30,3 +30,15 @@ (function (root, factory) { | ||
var jullius = function(url) { | ||
var buildQuery = function (params) { | ||
var query = '', key; | ||
for (key in params) { | ||
if(params.hasOwnProperty(key)) { | ||
query += encodeURIComponent(key) + "=" + encodeURIComponent(params[key]) + "&" | ||
} | ||
}; | ||
return query; | ||
}; | ||
var jullius = function(url, params) { | ||
return new Promise(function(resolve, reject) { | ||
@@ -44,3 +56,3 @@ if (typeof url !== 'string') { | ||
script = extScript.cloneNode(); | ||
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + name; | ||
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + buildQuery(params) + 'callback=' + name; | ||
script.id = name; | ||
@@ -47,0 +59,0 @@ script.async = true; |
11587
156
70