v8.3p_2012-11-21/PowerEdition Deployment
I am using cacheFiles to load an image in the background. I have a callback that then displays it to the user once it has loaded.
My problem is that if the image fails to load, I want to detect that and do some error handling. This got me digging:
onload, onerror and onabort all are handled by the same callback. Looking further downstream in the code, it seems there is no way to detect which one of those conditions triggered the callback.
fileLoaded currently takes four arguments:
My solution was to add a fifth argument to fileLoaded called loadStatus.
I changed _cacheImages to pass either "success", "error" or "abort" as the loadStatus when it calls fileLoaded.
Finally, I made fileLoaded set a loadStatus property on the fileConfig and that's all I need.
fileLoaded calls _completeLoad. Which in turn calls the onload callback from my original call to FileLoader.cacheFiles, passing it the fileConfig object.
I now have the loadStatus available within the onload callback.
Observations: I did it this way around because it involved the fewest changes to the obfuscated code, but I would love to see a proper Isomorphic solution for handling failed cacheFiles calls!
I am using cacheFiles to load an image in the background. I have a callback that then displays it to the user once it has loaded.
My problem is that if the image fails to load, I want to detect that and do some error handling. This got me digging:
Code:
... _cacheImages:function(){ var html=""; while(this._imageQueue.length){ var fileID=this._imageQueue.shift(); var URL=this._fileConfig[fileID].URL; var callback="if(window.isc)isc.FileLoader.fileLoaded(\""+fileID+"\")"; html+="<IMG SRC='"+URL+"' onload='"+callback+"' onerror='"+callback+"' onabort='"+callback +(isc.Browser.isOpera?"' STYLE=visibility:hidden;position:absolute;top:-1000px'>" :"' STYLE='display:none'>"); } this._insertHTML(html); }, ...
fileLoaded currently takes four arguments:
Code:
... fileLoaded:function(fileID,fileContents,ignoreThisArg,delayed){ ...
I changed _cacheImages to pass either "success", "error" or "abort" as the loadStatus when it calls fileLoaded.
Finally, I made fileLoaded set a loadStatus property on the fileConfig and that's all I need.
Code:
_completeLoad:function(fileID){ var fileConfig=this._fileConfig[fileID]; this._checkISCInit(); if(fileConfig.onload){ if(this.isAString(fileConfig.onload))isc.evalSA(fileConfig.onload); else fileConfig.onload(fileConfig); } ...
I now have the loadStatus available within the onload callback.
Observations: I did it this way around because it involved the fewest changes to the obfuscated code, but I would love to see a proper Isomorphic solution for handling failed cacheFiles calls!
Comment