Comparing version 1.7.1 to 1.8.0
@@ -1,1 +0,1 @@ | ||
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.LoadAssets=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){b.exports=function(a,b,c){var d=this,e=(void 0!==c?c+"/":c)||"",f=[],g=[];d.count=0,d.get=function(a,b,c,d){d="boolean"==typeof d?d:!0;var e=new XMLHttpRequest;e.open("GET",a,d),e.onload=function(){"function"==typeof b&&b(e.responseText),"function"==typeof c&&c(e.responseText)},e.send()},d.validateObject=function(a){return"object"==typeof a&&-1!==Object.keys(a).indexOf("type")&&-1!==Object.keys(a).indexOf("filename")};var h=function(a,b){for(var c in a)"js"!=a[c].type&&"style"!=a[c].type||document.querySelector("head").appendChild(a[c].element);"function"==typeof b&&b(a)},i=function(b,c){"undefined"!=typeof b.order&&"number"==typeof b.order?f.push(b):g.push(b),f.concat(g).length==a.length&&(f.sort(function(a,b){return a.order-b.order}),"function"==typeof c&&c(f.concat(g)))};d.startLoad=function(){if("object"==typeof a&&a.length)for(var c in a){var e=a[c];if(d.validateObject(e))switch(e.type){case"image":d.loadImage(e,function(a){i(a,function(a){h(a,function(a){"function"==typeof b&&b(a)})})});break;case"svg":d.loadSVG(e,function(a){i(a,function(a){h(a,function(a){"function"==typeof b&&b(a)})})});break;case"js":d.loadScript(e,function(a){i(a,function(a){h(a,function(a){"function"==typeof b&&b(a)})})});break;case"style":d.loadCss(e,function(a){i(a,function(a){h(a,function(a){"function"==typeof b&&b(a)})})})}else console.alert("You need to pass the file name and type of "+e.filename)}else console.error("The first parameter of the constructor must be a list of objects")},d.loadScript=function(a,b){d.get(e+a.filename,function(c){var e=document.createElement("script");e.type="text/javascript",e.innerHTML=c,a.element=e,d.count++,"function"==typeof b&&b(a)})},d.loadImage=function(a,b){var c=new Image;c.onload=function(){a.element=c,d.count++,"function"==typeof b&&b(a)},c.src=e+a.filename},d.isSvgAble=function(){var a=document.createElement("div");return a.innerHTML="<svg/>","http://www.w3.org/2000/svg"==("undefined"!=typeof SVGRect&&a.firstChild&&a.firstChild.namespaceURI)},d.loadSVG=function(a,b){var c=document.querySelectorAll(a.target);d.isSvgAble()===!0?d.get(e+a.filename+".svg",function(e){for(var f=0;f<c.length;)c[f].insertAdjacentHTML("beforeend",e),f++;d.count++,"function"==typeof b&&b(a)}):a.hasFallback&&d.loadImage({type:"image",filename:e+a.filename+".png"},function(){console.log("dfjhdsfh");for(var f=0;f<c.length;)c[f].insertAdjacentHTML("beforeend",'<img src="'+e+a.filename+'.png">'),f++;d.count++,"function"==typeof b&&b(a)})},d.loadCss=function(a,b){d.get(e+a.filename,function(c){var e=document.createElement("style");e.type="text/css",e.innerHTML=c,a.element=e,d.count++,"function"==typeof b&&b(a)})}}},{}]},{},[1])(1)}); | ||
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.LoadAssets=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){b.exports=function(a,b,c){var d=this,e=(void 0!==c?c+"/":c)||"",f=[],g=[];d.count=0,d.get=function(a,b,c,d){d="boolean"==typeof d?d:!0;var e=new XMLHttpRequest;e.open("GET",a,d),e.onload=function(){"function"==typeof b&&b(e.responseText),"function"==typeof c&&c(e.responseText)},e.send()},d.validateObject=function(a){return"object"==typeof a&&-1!==Object.keys(a).indexOf("type")&&-1!==Object.keys(a).indexOf("filename")};var h=function(a,b){for(var c in a)"js"!=a[c].type&&"style"!=a[c].type||document.querySelector("head").appendChild(a[c].element);"function"==typeof b&&b(a)},i=function(b,c){"undefined"!=typeof b.order&&"number"==typeof b.order?f.push(b):g.push(b),f.concat(g).length==a.length&&(f.sort(function(a,b){return a.order-b.order}),"function"==typeof c&&c(f.concat(g)))};d.startLoad=function(){if("object"==typeof a&&a.length)for(var c in a){var e=a[c];if(d.validateObject(e))switch(e.type){case"image":d.loadImage(e,function(a){i(a,function(a){h(a,function(a){"function"==typeof b&&b(a)})})});break;case"svg":d.loadSVG(e,function(a){i(a,function(a){h(a,function(a){"function"==typeof b&&b(a)})})});break;case"js":d.loadScript(e,function(a){i(a,function(a){h(a,function(a){"function"==typeof b&&b(a)})})});break;case"style":d.loadCss(e,function(a){i(a,function(a){h(a,function(a){"function"==typeof b&&b(a)})})})}else console.alert("You need to pass the file name and type of "+e.filename)}else console.error("The first parameter of the constructor must be a list of objects")},d.loadScript=function(a,b){d.get(e+a.filename,function(c){var e=document.createElement("script");e.type="text/javascript",e.innerHTML=c,a.element=e,d.count++,"function"==typeof b&&b(a)})},d.loadImage=function(a,b){var c=new Image;c.onload=function(){a.element=c,d.count++,"function"==typeof b&&b(a)},c.src=e+a.filename},d.isSvgAble=function(){var a=document.createElement("div");return a.innerHTML="<svg/>","http://www.w3.org/2000/svg"==("undefined"!=typeof SVGRect&&a.firstChild&&a.firstChild.namespaceURI)},d.loadSVG=function(a,b){var c=document.querySelectorAll(a.target);d.isSvgAble()===!0?d.get(e+a.filename+".svg",function(e){for(var f=0;f<c.length;)c[f].insertAdjacentHTML("beforeend",e),f++;d.count++,"function"==typeof b&&b(a)}):a.hasFallback&&d.loadImage({type:"image",filename:e+a.filename+".png"},function(){for(var f=0;f<c.length;)c[f].insertAdjacentHTML("beforeend",'<img src="'+e+a.filename+'.png">'),f++;d.count++,"function"==typeof b&&b(a)})},d.loadCss=function(a,b){d.get(e+a.filename,function(c){var e=document.createElement("style");e.type="text/css",e.innerHTML=c,a.element=e,d.count++,"function"==typeof b&&b(a)})}}},{}]},{},[1])(1)}); |
{ | ||
"name": "loadassets", | ||
"version": "1.7.1", | ||
"version": "1.8.0", | ||
"description": "A library to load assets dinamically.", | ||
@@ -5,0 +5,0 @@ "main": "src/LoadAssets.js", |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
module.exports = function(listAssets, callbackLoad, assetsRoot){ | ||
module.exports = function(listAssets, callbackLoad, assetsRoot) { | ||
@@ -24,3 +24,3 @@ var self = this; | ||
*/ | ||
self.get = function(url, callback, errorCallback, async){ | ||
self.get = function(url, callback, errorCallback, async) { | ||
async = (typeof async == "boolean" ? async : true); | ||
@@ -40,3 +40,3 @@ var ajax = new XMLHttpRequest(); | ||
*/ | ||
self.validateObject = function(obj){ | ||
self.validateObject = function(obj) { | ||
return (typeof obj === "object" && Object.keys(obj).indexOf('type') !== -1 && Object.keys(obj).indexOf('filename') !== -1 ? true : false); | ||
@@ -50,5 +50,5 @@ }; | ||
*/ | ||
var injectElements = function(allElements, callback){ | ||
for(var el in allElements){ | ||
if(allElements[el].type == 'js' || allElements[el].type == 'style'){ | ||
var injectElements = function(allElements, callback) { | ||
for(var el in allElements) { | ||
if(allElements[el].type == 'js' || allElements[el].type == 'style') { | ||
document.querySelector('head').appendChild(allElements[el].element); | ||
@@ -64,10 +64,10 @@ } | ||
*/ | ||
var putInOrder = function(object, callback){ | ||
if(typeof object.order !== 'undefined' && typeof object.order == 'number'){ | ||
var putInOrder = function(object, callback) { | ||
if(typeof object.order !== 'undefined' && typeof object.order == 'number') { | ||
orderedList.push(object); | ||
}else { | ||
} else { | ||
unorderedList.push(object); | ||
} | ||
if(orderedList.concat(unorderedList).length == listAssets.length){ | ||
orderedList.sort(function(a, b){ | ||
if(orderedList.concat(unorderedList).length == listAssets.length) { | ||
orderedList.sort(function(a, b) { | ||
return a.order - b.order; | ||
@@ -121,4 +121,4 @@ }); | ||
self.loadCss(currentItem, function(object) { | ||
putInOrder(object, function(allElements){ | ||
injectElements(allElements, function(object){ | ||
putInOrder(object, function(allElements) { | ||
injectElements(allElements, function(object) { | ||
if(typeof callbackLoad == 'function') callbackLoad(object); | ||
@@ -144,4 +144,4 @@ }); | ||
*/ | ||
self.loadScript = function(object, callback){ | ||
self.get(baseUrl+object.filename, function(content){ | ||
self.loadScript = function(object, callback) { | ||
self.get(baseUrl+object.filename, function(content) { | ||
var newScript = document.createElement('script'); | ||
@@ -162,5 +162,5 @@ newScript.type = 'text/javascript'; | ||
*/ | ||
self.loadImage = function(object, callback){ | ||
self.loadImage = function(object, callback) { | ||
var newImage = new Image(); | ||
newImage.onload = function(){ | ||
newImage.onload = function() { | ||
object.element = newImage; | ||
@@ -180,3 +180,3 @@ | ||
div.innerHTML = '<svg/>'; | ||
if((typeof SVGRect != 'undefined' && div.firstChild && div.firstChild.namespaceURI) == 'http://www.w3.org/2000/svg') { | ||
if((typeof SVGRect != 'undefined' && div.firstChild && div.firstChild.namespaceURI) == 'http://www.w3.org/2000/svg') { // Thanks Modernizr | ||
return true; | ||
@@ -213,4 +213,3 @@ } else { | ||
filename: baseUrl + object.filename + '.png' | ||
}, function(){ | ||
console.log('dfjhdsfh') | ||
}, function() { | ||
var i = 0; | ||
@@ -227,3 +226,3 @@ while(i < target.length) { | ||
} | ||
}; | ||
@@ -230,0 +229,0 @@ /** |
696291
1435