[ Index ]

PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12)

title

Body

[close]

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

   1  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(c){this.log("include: ",c);this.mapLoaded=false;var d=function(a){this.libs=$merge(this.libs,a);$each(this.libs,function(f,b){if(f.scripts){this.loadSource(b,f.scripts)}},this)}.bind(this);if($type(c)=="string"){this.log("fetching libs ",c);this.request(c,d)}else{d(c)}return this},required:[],require:function(c){var d=function(){var a=this.calculateDependencies(c.scripts);if(c.sources){c.sources.each(function(b){a.combine(this.libs[b].files)},this)}if(c.serial){a.combine(this.getLoadedScripts())}c.scripts=a;this.required.push(c);this.fireEvent("require",c);this.loadScripts(c.scripts)};if(this.mapLoaded){d.call(this)}else{this.addEvent("mapLoaded",d.bind(this))}return this},cleanDoubleSlash:function(c){if(!c){return c}var d="";if(c.test(/^http:\/\//)){d="http://";c=c.substring(7,c.length)}c=c.replace(/\/\//g,"/");return d+c},request:function(d,c){new Request.JSON({url:d,secure:false,onSuccess:c}).send()},loadSource:function(c,d){if(this.libs[c].files){this.dataLoaded();return}this.log("loading source: ",d);this.request(this.cleanDoubleSlash(d+"/scripts.json"),function(a){this.log("loaded source: ",d);this.libs[c].files=a;this.dataLoaded()}.bind(this))},dataLoaded:function(){var b=true;$each(this.libs,function(d,a){if(!this.libs[a].files){b=false}},this);if(b){this.mapTree();this.mapLoaded=true;this.calculateLoaded();this.lastLoaded=this.getLoadedScripts().getLength();this.fireEvent("mapLoaded");this.removeEvents("mapLoaded")}},calculateLoaded:function(){var b=function(a){this.scriptsState[a]=true}.bind(this);if(this.options.loadedScripts){this.options.loadedScripts.each(b)}if(this.options.loadedSources){this.options.loadedSources.each(function(a){$each(this.libs[a].files,function(d){$each(d,function(c,f){b(f)},this)},this)},this)}},deps:{},pathMap:{},mapTree:function(){$each(this.libs,function(c,d){$each(c.files,function(b,a){$each(b,function(i,j){var h=d+":"+a+":"+j;if(this.deps[h]){return}this.deps[h]=i.deps;this.pathMap[j]=h},this)},this)},this)},getDepsForScript:function(b){return this.deps[this.pathMap[b]]||[]},calculateDependencies:function(d){var c=[];$splat(d).each(function(b){if(b=="None"||!b){return}var a=this.getDepsForScript(b);if(!a){if(window.console&&console.warn){console.warn("dependencies not mapped: script: %o, map: %o, :deps: %o",b,this.pathMap,this.deps)}}else{a.each(function(f){if(f==b||f=="None"||!f){return}if(!c.contains(f)){c.combine(this.calculateDependencies(f))}c.include(f)},this)}c.include(b)},this);return c},getPath:function(g){try{var h=this.pathMap[g].split(":");var i=this.libs[h[0]];var e=(i.path||i.scripts)+"/";h.shift();return this.cleanDoubleSlash(e+h.join("/")+".js")}catch(j){return g}},loadScripts:function(b){b=b.filter(function(a){if(!this.scriptsState[a]&&a!="None"){this.scriptsState[a]=false;return true}},this);if(b.length){b.each(function(a){this.loadScript(a)},this)}else{this.check()}},toLoad:[],loadScript:function(f){if(this.scriptsState[f]&&this.toLoad.length){this.loadScript(this.toLoad.shift());return}else{if(this.loading){this.toLoad.push(f);return}}var h=function(){this.loading=false;this.scriptLoaded(f);if(this.toLoad.length){this.loadScript(this.toLoad.shift())}}.bind(this);var i=function(){this.log("could not load: ",g)}.bind(this);this.loading=true;var g=this.getPath(f);if(this.options.useScriptInjection){this.log("injecting script: ",g);var j=function(){this.log("loaded script: ",g);h()}.bind(this);new Element("script",{src:g+(this.options.noCache?"?noCache="+new Date().getTime():""),events:{load:j,readystatechange:function(){if(["loaded","complete"].contains(this.readyState)){j()}},error:i}}).inject(this.options.target||document.head)}else{this.log("requesting script: ",g);new Request({url:g,noCache:this.options.noCache,onComplete:function(a){this.log("loaded script: ",g);$exec(a);h()}.bind(this),onFailure:i,onException:i}).send()}},scriptsState:$H(),getLoadedScripts:function(){return this.scriptsState.filter(function(b){return b})},scriptLoaded:function(f){this.log("loaded script: ",f);this.scriptsState[f]=true;this.check();var e=this.getLoadedScripts();var g=e.getLength();var h=this.scriptsState.getLength();this.fireEvent("scriptLoaded",{script:f,totalLoaded:(g/h*100).round(),currentLoaded:((g-this.lastLoaded)/(h-this.lastLoaded)*100).round(),loaded:e});if(g==h){this.lastLoaded=g}},lastLoaded:0,check:function(){var b=[];this.required.each(function(d){var a=[];d.scripts.each(function(c){if(this.scriptsState[c]){a.push(c)}},this);if(d.onStep){d.onStep({percent:a.length/d.scripts.length*100,scripts:a})}if(d.scripts.length!=a.length){return}d.callback();this.required.erase(d);this.fireEvent("requirementLoaded",[a,d])},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: Sun Jan 29 16:31:14 2012 Cross-referenced by PHPXref 0.7.1