in tapestry-framework/src/js/dojo-0.4.3-custom-4.1.6/src/widget/html/loader.js [281:608]
this.hookUp=function(_45){
var _46=_45.widget;
if(dojo.lang.isString(_46)){
if(_45.mixin){
dojo.raise(this.toString()+", cant use mixin when widget is a string");
}
_46=dojo.evalObjPath(_46);
}
if(!_46||!(_46 instanceof dojo.widget.HtmlWidget)){
dojo.raise(this.toString()+" Widget isn't defined or isn't a HtmlWidget instance");
}
if(_46.loader&&_46.setUrl){
return;
}
var _47=(_45.mixin)?_46:_46.constructor.prototype;
_46.loader={isLoaded:false,styleNodes:[],addOnLoads:[],addOnUnLoads:[],callOnUnLoad:(function(_48){
return function(_49){
this.abort();
if(_48){
this.onUnLoad();
}
_48=_49;
};
})(false),bindObj:null,unHook:(function(w,wg){
var _4c={isContainer:w.isContainer,adjustPats:w.adjustPaths,href:w.href,extractContent:w.extractContent,parseContent:w.parseContent,cacheContent:w.cacheContent,bindArgs:w.bindArgs,preload:w.preload,refreshOnShow:w.refreshOnShow,handler:w.handler,trackHistory:w.trackHistory,executeScripts:w.executeScripts,scriptScope:w.scriptScope,postCreate:w.postCreate,show:w.show,refresh:w.refresh,loadContents:w.loadContents,abort:w.abort,destroy:w.destroy,onLoad:w.onLoad,onUnLoad:w.onUnLoad,addOnLoad:w.addOnLoad,addOnUnLoad:w.addOnUnLoad,onDownloadStart:w.onDownloadStart,onDownloadEnd:w.onDownloadEnd,onDownloadError:w.onDownloadError,onContentError:w.onContentError,onExecError:w.onExecError,onSetContent:w.onSetContent,setUrl:w.setUrl,setContent:w.setContent,onContentParse:w.onContentParse,onExecScript:w.onExecScript,setHandler:w.setHandler};
return function(){
if(wg.abort){
wg.abort();
}
if((w!=wg)&&(dojo.widget.byType(wg.widgetType).length>1)){
return;
}
for(var x in _4c){
if(_4c[x]===undefined){
delete w[x];
continue;
}
w[x]=_4c[x];
}
delete wg._loader_defined;
delete wg.loader;
};
})(_47,_46)};
if(_47._loader_defined||_46._loader_defined){
return;
}
dojo.mixin(_47,{isContainer:true,adjustPaths:_d(_47.adjustPaths)?true:_47.adjustPaths,href:_d(_47.href)?"":_47.href,extractContent:_d(_47.extractContent)?true:_47.extractContent,parseContent:_d(_47.parseContent)?true:_47.parseContent,cacheContent:_d(_47.cacheContent)?true:_47.cacheContent,bindArgs:_d(_47.bindArgs)?{}:_47.bindArgs,preload:_d(_47.preload)?false:_47.preload,refreshOnShow:_d(_47.refreshOnShow)?false:_47.refreshOnShow,handler:_d(_47.handler)?"":_47.handler,executeScripts:_d(_47.executeScripts)?false:_47.executeScripts,trackHistory:_d(_47.tracHistory)?false:_47.trackHistory,scriptScope:null});
_47.postCreate=(function(_4e){
return function(){
if(_47.constructor.superclass.postCreate!=_4e){
_4e.apply(this,arguments);
}else{
_47.constructor.superclass.postCreate.apply(this,arguments);
}
if(this.handler!==""){
this.setHandler(this.handler);
}
if(this.isShowing()||this.preload){
this.loadContents();
if(!this.href){
_1._log(this,(this.domNode||this.containerNode).innerHTML);
}
}
};
})(_47.postCreate);
_47.show=(function(_4f){
return function(){
if(this.refreshOnShow){
this.refresh();
}else{
this.loadContents();
}
if((_47.constructor.superclass.show==_4f)||!_e(_4f)){
_47.constructor.superclass.show.apply(this,arguments);
}else{
_4f.apply(this,arguments);
}
};
})(_47.show);
_47.destroy=(function(_50){
return function(_51){
this.onUnLoad();
this.abort();
this.loader.unHook();
if((_47.constructor.superclass.destroy!=_51)&&_e(_51)){
_51.apply(this,arguments);
}else{
_47.constructor.superclass.destroy.apply(this,arguments);
}
};
})(_47.destroy);
if(!_47.refresh){
_47.refresh=function(){
this.loader.isLoaded=false;
this.loadContents();
};
}
if(!_47.loadContents){
_47.loadContents=function(){
if(this.loader.isLoaded){
return;
}
if(_e(this.handler)){
runHandler.call(this);
}else{
if(this.href!==""){
handleDefaults.call(this,"Loading...","onDownloadStart");
var _52=this,url=this.href;
downloader.call(this,{url:url,load:function(_54,_55,xhr){
_52.onDownloadEnd.call(_52,url,_55);
},error:function(_57,err,xhr){
var e={responseText:xhr.responseText,status:xhr.status,statusText:xhr.statusText,responseHeaders:(xhr.getAllResponseHeaders)?xhr.getAllResponseHeaders():[],_text:"Error loading '"+url+"' ("+xhr.status+" "+xhr.statusText+")"};
handleDefaults.call(_52,e,"onDownloadError");
_52.onLoad();
}});
}
}
};
}
if(!_47.abort){
_47.abort=function(){
if(!this.loader||!this.loader.bindObj||!this.loader.bindObj.abort){
return;
}
this.loader.bindObj.abort();
this.loader.bindObj=null;
};
}
if(!_47.onLoad){
_47.onLoad=function(){
stackRunner.call(this,this.loader.addOnLoads);
this.loader.isLoaded=true;
};
}
if(!_47.onUnLoad){
_47.onUnLoad=function(){
stackRunner.call(this,this.loader.addOnUnLoads);
delete this.scriptScope;
};
}
if(!_47.addOnLoad){
_47.addOnLoad=function(obj,_5c){
stackPusher.call(this,this.loader.addOnLoads,obj,_5c);
};
}
if(!_47.addOnUnLoad){
_47.addOnUnLoad=function(obj,_5e){
stackPusher.call(this,this.loader.addOnUnLoads,obj,_5e);
};
}
if(!_47.onExecError){
_47.onExecError=function(){
};
}
if(!_47.onContentError){
_47.onContentError=function(){
};
}
if(!_47.onDownloadError){
_47.onDownloadError=function(){
};
}
if(!_47.onDownloadStart){
_47.onDownloadStart=function(_5f){
};
}
if(!_47.onDownloadEnd){
_47.onDownloadEnd=function(url,_61){
var _62={content:_61,url:url,adjustPaths:this.adjustPaths,collectScripts:this.executeScripts,collectRequires:this.parseContent,bodyExtract:this.extractContent};
_61=_1.splitAndFixPaths.call(this,_62);
this.setContent(_61);
};
}
if(!_47.onSetContent){
_47.onSetContent=function(_63){
this.destroyChildren();
var _64=this.loader.styleNodes;
while(_64.length){
var st=_64.pop();
if(st&&st.parentNode){
st.parentNode.removeChild(st);
}
}
var _66=this.containerNode||this.domNode;
while(_66.firstChild){
try{
dojo.event.browser.clean(_66.firstChild);
}
catch(e){
}
_66.removeChild(_66.firstChild);
}
try{
if(typeof _63!="string"){
_66.appendChild(_63);
}else{
try{
_66.innerHTML=_63;
}
catch(e){
var tmp;
(tmp=dojo.doc().createElement("div")).innerHTML=_63;
while(tmp.firstChild){
_66.appendChild(tmp.removeChild(tmp.firstChild));
}
}
}
}
catch(e){
e._text="Could'nt load content: "+e;
var _68=(this.loader._onSetContent_err==e._text);
this.loader._onSetContent_err=e._text;
handleDefaults.call(this,e,"onContentError",_68);
}
};
}
if(!_47.setUrl){
_47.setUrl=function(url){
this.href=url;
this.loader.isLoaded=false;
if(this.preload||this.isShowing()){
this.loadContents();
}
};
}
if(!_47.setContent){
_47.setContent=function(_6a,_6b){
this.loader.callOnUnLoad.call(this,true);
if(!_6a||dojo.html.isNode(_6a)){
this.onSetContent(_6a);
refreshed.call(this);
}else{
if(typeof _6a.xml!="string"){
this.href="";
var _6c={content:_6a,url:this.href,adjustPaths:this.adjustPaths,collectScripts:this.executeScripts,collectRequires:this.parseContent,bodyExtract:this.extractContent};
_6a=_1.splitAndFixPaths.call(this,_6c);
}else{
if(_6a.url!="./"){
this.url=_6a.url;
}
}
this.onSetContent(_6a.xml);
for(var i=0,_6e=_6a.styles;i<_6e.length;i++){
if(_6e[i].path){
this.loader.styleNodes.push(dojo.html.insertCssFile(_6e[i].path));
}else{
this.loader.styleNodes.push(dojo.html.insertCssText(_6e[i]));
}
}
if(this.parseContent){
for(var i=0,_6f=_6a.requires;i<_6f.length;i++){
try{
eval(_6f[i]);
}
catch(e){
e._text="dojo.widget.html.loader.hookUp: error in package loading calls, "+(e.description||e);
handleDefaults.call(this,e,"onContentError",true);
}
}
}
if(dojo.hostenv.isXDomain&&_6a.requires.length){
dojo.addOnLoad(function(){
asyncParse.call(this,_6a);
if(!_6b){
_1._log(this,_6a);
}
});
_6b=true;
}else{
asyncParse.call(this,_6a);
}
}
if(!_6b){
}
};
}
if(!_47.onContentParse){
_47.onContentParse=function(){
var _70=this.containerNode||this.domNode;
var _71=new dojo.xml.Parse();
var _72=_71.parseElement(_70,null,true);
dojo.widget.getParser().createSubComponents(_72,this);
};
}
if(!_47.onExecScript){
_47.onExecScript=function(_73){
var _74=this,tmp="",_76="";
for(var i=0;i<_73.length;i++){
if(_73[i].path){
var url=_73[i].path;
downloader.call(this,{"url":url,"load":function(_79,_7a){
(function(){
tmp=_7a;
_73[i]=_7a;
}).call(_74);
},"error":function(_7b,_7c){
_7c._text=_7b+" downloading remote script";
handleDefaults.call(_74,_7c,"onExecError",true);
},"mimetype":"text/plain","sync":true});
_76+=tmp;
}else{
_76+=_73[i];
}
}
try{
delete this.scriptScope;
this.scriptScope=new (new Function("_container_",_76+"; return this;"))(_74);
}
catch(e){
e._text="Error running scripts from content:\n"+(e.description||e.toString());
handleDefaults.call(this,e,"onExecError",true);
}
};
}
if(!_47.setHandler){
_47.setHandler=function(_7d){
var fcn=dojo.lang.isFunction(_7d)?_7d:window[_7d];
if(!_e(fcn)){
handleDefaults.call(this,"Unable to set handler, '"+_7d+"' not a function.","onExecError",true);
return;
}
this.handler=function(){
return fcn.apply(this,arguments);
};
};
}
_47._loader_defined=true;
};