[ Index ]

PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10)

title

Body

[close]

/template/lib/mootools/more/Core/ -> Depender.js (source)

   1  //MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License.
   2  
   3  var Depender={options:{loadedSources:[],loadedScripts:["Core","Browser","Array","String","Function","Number","Hash","Element","Event","Element.Event","Class","DomReady","Class.Extras","Request","JSON","Request.JSON","More","Depender","Log"],useScriptInjection:true},loaded:[],sources:{},libs:{},include:function(b){this.log("include: ",b);this.mapLoaded=false;var a=function(c){this.libs=$merge(this.libs,c);$each(this.libs,function(d,e){if(d.scripts){this.loadSource(e,d.scripts)}},this)}.bind(this);if($type(b)=="string"){this.log("fetching libs ",b);this.request(b,a)}else{a(b)}return this},required:[],require:function(b){var a=function(){var c=this.calculateDependencies(b.scripts);if(b.sources){b.sources.each(function(d){c.combine(this.libs[d].files)},this)}if(b.serial){c.combine(this.getLoadedScripts())}b.scripts=c;this.required.push(b);this.fireEvent("require",b);this.loadScripts(b.scripts)};if(this.mapLoaded){a.call(this)}else{this.addEvent("mapLoaded",a.bind(this))}return this},cleanDoubleSlash:function(b){if(!b){return b}var a="";if(b.test(/^http:\/\//)){a="http://";b=b.substring(7,b.length)}b=b.replace(/\/\//g,"/");return a+b},request:function(a,b){new Request.JSON({url:a,secure:false,onSuccess:b}).send()},loadSource:function(b,a){if(this.libs[b].files){this.dataLoaded();return}this.log("loading source: ",a);this.request(this.cleanDoubleSlash(a+"/scripts.json"),function(c){this.log("loaded source: ",a);this.libs[b].files=c;this.dataLoaded()}.bind(this))},dataLoaded:function(){var a=true;$each(this.libs,function(c,b){if(!this.libs[b].files){a=false}},this);if(a){this.mapTree();this.mapLoaded=true;this.calculateLoaded();this.lastLoaded=this.getLoadedScripts().getLength();this.fireEvent("mapLoaded");this.removeEvents("mapLoaded")}},calculateLoaded:function(){var a=function(b){this.scriptsState[b]=true}.bind(this);if(this.options.loadedScripts){this.options.loadedScripts.each(a)}if(this.options.loadedSources){this.options.loadedSources.each(function(b){$each(this.libs[b].files,function(c){$each(c,function(e,d){a(d)},this)},this)},this)}},deps:{},pathMap:{},mapTree:function(){$each(this.libs,function(b,a){$each(b.files,function(c,d){$each(c,function(f,e){var g=a+":"+d+":"+e;if(this.deps[g]){return}this.deps[g]=f.deps;this.pathMap[e]=g},this)},this)},this)},getDepsForScript:function(a){return this.deps[this.pathMap[a]]||[]},calculateDependencies:function(a){var b=[];$splat(a).each(function(c){if(c=="None"||!c){return}var d=this.getDepsForScript(c);if(!d){if(window.console&&console.warn){console.warn("dependencies not mapped: script: %o, map: %o, :deps: %o",c,this.pathMap,this.deps)}}else{d.each(function(e){if(e==c||e=="None"||!e){return}if(!b.contains(e)){b.combine(this.calculateDependencies(e))}b.include(e)},this)}b.include(c)},this);return b},getPath:function(a){try{var f=this.pathMap[a].split(":");var d=this.libs[f[0]];var b=(d.path||d.scripts)+"/";f.shift();return this.cleanDoubleSlash(b+f.join("/")+".js")}catch(c){return a}},loadScripts:function(a){a=a.filter(function(b){if(!this.scriptsState[b]&&b!="None"){this.scriptsState[b]=false;return true}},this);if(a.length){a.each(function(b){this.loadScript(b)},this)}else{this.check()}},toLoad:[],loadScript:function(b){if(this.scriptsState[b]&&this.toLoad.length){this.loadScript(this.toLoad.shift());return}else{if(this.loading){this.toLoad.push(b);return}}var e=function(){this.loading=false;this.scriptLoaded(b);if(this.toLoad.length){this.loadScript(this.toLoad.shift())}}.bind(this);var d=function(){this.log("could not load: ",a)}.bind(this);this.loading=true;var a=this.getPath(b);if(this.options.useScriptInjection){this.log("injecting script: ",a);var c=function(){this.log("loaded script: ",a);e()}.bind(this);new Element("script",{src:a+(this.options.noCache?"?noCache="+new Date().getTime():""),events:{load:c,readystatechange:function(){if(["loaded","complete"].contains(this.readyState)){c()}},error:d}}).inject(this.options.target||document.head)}else{this.log("requesting script: ",a);new Request({url:a,noCache:this.options.noCache,onComplete:function(f){this.log("loaded script: ",a);$exec(f);e()}.bind(this),onFailure:d,onException:d}).send()}},scriptsState:$H(),getLoadedScripts:function(){return this.scriptsState.filter(function(a){return a})},scriptLoaded:function(a){this.log("loaded script: ",a);this.scriptsState[a]=true;this.check();var b=this.getLoadedScripts();var d=b.getLength();var c=this.scriptsState.getLength();this.fireEvent("scriptLoaded",{script:a,totalLoaded:(d/c*100).round(),currentLoaded:((d-this.lastLoaded)/(c-this.lastLoaded)*100).round(),loaded:b});if(d==c){this.lastLoaded=d}},lastLoaded:0,check:function(){var a=[];this.required.each(function(c){var b=[];c.scripts.each(function(d){if(this.scriptsState[d]){b.push(d)}},this);if(c.onStep){c.onStep({percent:b.length/c.scripts.length*100,scripts:b})}if(c.scripts.length!=b.length){return}c.callback();this.required.erase(c);this.fireEvent("requirementLoaded",[b,c])},this)}};$extend(Depender,new Events);$extend(Depender,new Options);$extend(Depender,new Log);Depender._setOptions=Depender.setOptions;Depender.setOptions=function(){Depender._setOptions.apply(Depender,arguments);if(this.options.log){Depender.enableLog()}return this};


Generated: Tue Nov 16 22:51:00 2010 Cross-referenced by PHPXref 0.7