Código Javascript:
Ver original
var Asset = null; var CXMW = { //wapi secuency:0, widgets:{}, site:'#site#', queued:new Array, loading:{}, widget:function(options){ var loadwidget = function(){ options.id = CXMW.secuency++; var widget = options.widget; CXMW.getWidget(widget,options); return CXMW.widgets[options.id]; } var test_mootools = function(){ alert(window.mootools); if (typeof window.MooTools == "undefined") { var script_tag = document.createElement('script'); script_tag.setAttribute("type","text/javascript"); script_tag.setAttribute("src","https://ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools.js") if (window.addEventListener) window.addEventListener('load', loadwidget, false); else if (window.attachEvent) window.attachEvent('onload', loadwidget); document.getElementsByTagName("head")[0].appendChild(script_tag); } else { loadwidget(); } } test_mootools(); }, getWidget:function(widget,options){ if(CXMW[widget]){ // esta definido el widget en el API ?? CXMW.widgets[options.id] = (CXMW.widgets[options.id]) ? CXMW.widgets[options.id] : new CXMW[widget](options); }else{ if(CXMW.loading[widget]){CXMW.queued.push(options);} // voy encolando las peticiones hasta finalizar la carga else { CXMW.loading[widget] = true; CXMW.queued.push(options); console.log(Asset); Asset.javascript(CXMW.site + widget + ".js", { onLoad: function(){ alert("loadedd"); CXMW.queued.each(function(item,index){ if(item.widget == widget){ CXMW.widgets[item.id] = (CXMW.widgets[item.id]) ? CXMW.widgets[item.id] : new CXMW[widget](item); CXMW.queued.slice(index,1); } }); CXMW.loading[widget] = false; } }); } } } }; if(Asset==null){ Asset={javascript:function(d,b){if(!b){b={};}var a=new Element("script",{src:d,type:"text/javascript"}),e=b.document||document,c=b.onload||b.onLoad; delete b.onload;delete b.onLoad;delete b.document;if(c){if(typeof a.onreadystatechange!="undefined"){a.addEvent("readystatechange",function(){if(["loaded","complete"].contains(this.readyState)){c.call(this); }});}else{a.addEvent("load",c);}}return a.set(b).inject(e.head);},css:function(d,a){if(!a){a={};}var b=new Element("link",{rel:"stylesheet",media:"screen",type:"text/css",href:d}); var c=a.onload||a.onLoad,e=a.document||document;delete a.onload;delete a.onLoad;delete a.document;if(c){b.addEvent("load",c);}return b.set(a).inject(e.head); },image:function(c,b){if(!b){b={};}var d=new Image(),a=document.id(d)||new Element("img");["load","abort","error"].each(function(e){var g="on"+e,f="on"+e.capitalize(),h=b[g]||b[f]||function(){}; delete b[f];delete b[g];d[g]=function(){if(!d){return;}if(!a.parentNode){a.width=d.width;a.height=d.height;}d=d.onload=d.onabort=d.onerror=null;h.delay(1,a,a); a.fireEvent(e,a,1);};});d.src=a.src=c;if(d&&d.complete){d.onload.delay(1);}return a.set(b);},images:function(c,b){c=Array.from(c);var d=function(){},a=0; b=Object.merge({onComplete:d,onProgress:d,onError:d,properties:{}},b);return new Elements(c.map(function(f,e){return Asset.image(f,Object.append(b.properties,{onload:function(){a++; b.onProgress.call(this,a,e,f);if(a==c.length){b.onComplete();}},onerror:function(){a++;b.onError.call(this,a,e,f);if(a==c.length){b.onComplete();}}})); }));}}; }
Ojala podais ayudarme por que realmente me está matando este tema. Mil gracias por adelantado a los que almenos se molesten en leer este largo post.