Menu
Is there a way in JavaScript to find out which portion of your HTML called the onload event.
For example i have 7 images all can fire the onload event. But is there a way to find out which img triggered the event?
<i>
</i>/* ---Element Utility Section--- */
/*
(DOMElement)create(tagName Type)
(DOMElement)create(urlString imageUrl, function onLoadCallback)
(function)makeEventListenerData(urlString imageUrl, function onLoadCallback)
(eventListener)makeEventListenerData(function callback, variant callbackData)
*/
var Element={};
<i> </i> Element.fatalError=function(advanced){
<i> </i> alert("We're terribly sorry, but there has been an error. Most likely, you're simply using an outdated browser.n Do yourself a favor and get Firefox at getfirefox.comnnError:n"+advanced);
<i> </i> }
<i> </i> Element.create=function(type){
<i> </i> return document.createElement(type);
<i> </i> }
<i> </i> Element.createImage=function(url,callback){
<i> </i> var imageEl=document.createElement("img");
<i> </i> if(callback!=undefined) Element.addEventListener(imageEl,"load",callback,imageEl);
<i> </i> if(url!=undefined) imageEl.src=url;
<i> </i> return imageEl;
<i> </i> }
<i> </i> Element.getWindowInnerSize=function(){
<i> </i> if(window.innerWidth!=undefined){
<i> </i> return {"x":window.innerWidth,"y":window.innerHeight};
<i> </i> }else if(document.body.clientWidth!=undefined){
<i> </i> return {"x":document.body.clientWidth,"y":document.body.clientHeight};
<i> </i> }else if(document.documentElement.clientWidth!=undefined){
<i> </i> return {"x":document.documentElement.clientWidth,"y":document.documentElement.clientHeight};
<i> </i> }else Element.fatalError("Can't get inner Window size.");
<i> </i> return {"x":640,"y":480};
<i> </i> }
<i> </i> Element.makeEventListenerData=function(callback,data,el){
<i> </i> return (function(evt){ callback(evt,data); });
<i> </i> }
<i> </i> Element.makeEventListenerDataIEModel=function(callback,data,el){
<i> </i> return (function(evt){ callback.call(el,evt,data); });
<i> </i> }
<i> </i> Element.addEventListener=function(el,type,callback,data){
<i> </i> if(el.addEventListener!=undefined) return el.addEventListener(type,Element.makeEventListenerData(callback,data,el),false);
<i> </i> else if(el.attachEvent!=undefined) {var cb=false; el.attachEvent("on"+type,cb=Element.makeEventListenerDataIEModel(callback,data,el),false); return cb;}
<i> </i> else Element.fatalError("Can't setup EventListener");
<i> </i> return null;
<i> </i> }
<i> </i> Element.sizeToDocumentOnce=function(evt,data){
<i> </i> data.style.width=Element.getWindowInnerSize().x+"px";
<i> </i> data.style.height=Element.getWindowInnerSize().y+"px";
<i> </i> }
<i> </i> Element.sizeToDocument=function(el){
<i> </i> el.style.top="0px";
<i> </i> el.style.left="0px";
<i> </i> el.style.position="absolute";
<i> </i> Element.sizeToDocumentOnce(undefined,el);
<i> </i> el.sizeToDocumentListener=Element.addEventListener(window,"resize",Element.sizeToDocumentOnce,el);
<i> </i> }
<i> </i> Element.appendToDocument=function(el){
<i> </i> document.getElementsByTagName("body")[0].appendChild(el);
<i> </i> }
<i> </i> Element.remove=function(el){
<i> </i> if(el.parentNode!=undefined)el.parentNode.removeChild(el);
<i> </i> }
<i> </i> Element.scaledPositionOnce=function(evt,data){
<i> </i> data.el.style.left=Math.floor((Element.getWindowInnerSize().x*data.x/100 -data.el.clientWidth/2))+"px";
<i> </i> data.el.style.top=Math.floor((Element.getWindowInnerSize().y*data.y/100-data.el.clientHeight/2))+"px";
<i> </i> }
<i> </i> Element.centerElement=function(el){
<i> </i> Element.scaledPosition(el,50,50);
<i> </i> }
<i> </i> Element.scaledPosition=function(el,x,y){
<i> </i> el.style.top="0px";
<i> </i> el.style.left="0px";
<i> </i> el.style.position="absolute";
<i> </i> Element.scaledPositionOnce(undefined,{"el":el,"x":x,"y":y});
<i> </i> el.scaledPositionElementListener=Element.addEventListener(window,"resize",Element.scaledPositionOnce,{"el":el,"x":x,"y":y});
<i> </i> }
<i> </i> Element.createCenteredImage=function(url){
<i> </i> return Element.createImage(url,function(evt,data){
<i> </i> Element.appendToDocument(data);
<i> </i> Element.centerElement(data);
<i> </i> });
<i> </i> }
/* ---Widget Section--- */
/* --- widgetFullScreenLayer ---
constructor(CSScolor backgroundColor)
destroy()
*/
function widgetFullScreenLayer(color){
this.layer=document.createElement("div");
this.layer.style.backgroundColor=color;
Element.sizeToDocument(this.layer);
Element.appendToDocument(this.layer);
}
<i> </i> widgetFullScreenLayer.prototype.destroy=function(){
<i> </i> Element.remove(this.layer);
<i> </i> }
/* --- widgetProgressBar ---
constructor(imageUrl backgroundImage, imageUrl foregroundImage,zIndex position)
set(integer percentage)
destroy()
*/
function widgetProgressBar(url1,url2,depth){
this.parent=Element.create("div");
this.parent.style.zIndex=depth;
this.layer2=Element.create("div");
this.layer2.style.backgroundImage="url("+url2+")";
this.layer1=document.createElement("img");
this.loadListener=Element.addEventListener(this.layer1,"load",function(evt,data){
data.layer2.style.position=data.layer1.style.position="absolute";
data.layer2.style.left=data.layer1.style.left="0px";
data.layer2.style.top=data.layer1.style.top="0px";
<i> </i> data.parent.style.position="absolute";
<i> </i> data.layer2.style.width="0px";
<i> </i> data.parent.style.width=data.layer1.width+"px";
<i> </i> data.layer2.style.height=data.parent.style.height=data.layer1.height+"px";
<i> </i> data.parent.appendChild(data.layer1);
<i> </i> data.parent.appendChild(data.layer2);
<i> </i> Element.appendToDocument(data.parent);
<i> </i> Element.centerElement(data.parent);
<i> </i> },this);
<i> </i> this.layer1.src=url1;
<i> </i> }
<i> </i> widgetProgressBar.prototype.set=function(percentage){
<i> </i> if(percentage>100) percentage=100;
<i> </i> this.layer2.style.width=Math.round(this.layer1.clientWidth/100*percentage)+"px";
<i> </i> }
<i> </i> widgetProgressBar.prototype.destroy=function(){
<i> </i> Element.remove(this.layer2);
<i> </i> Element.remove(this.layer1);
<i> </i> Element.remove(this.parent);
<i> </i> }
/* --- widgetPreloader ---
constructor(imageUrl backgroundImage, imageUrl foregroundImage,CSScolor backgroundColor,array UrlList,function ondone)
*/
function widgetPreloader(url1,url2,color,list,ondone,timeout){
this.background=new widgetFullScreenLayer(color);
this.progress=new widgetProgressBar(url1,url2,999);
this.imgs=new Array();
this.tcount=list.length;
this.ccount=0;
this.forceEnd=false;
this.ondone=ondone;
this.done=false;
this.end=function(data){
if(!data.done){
data.done=true;
data.ondone();
data.background.destroy();
data.progress.destroy();
}
}
<i> </i> this.checker=function(evt,data){
<i> </i> if(!data.done){
<i> </i> data.ccount++;
<i> </i> data.progress.set(Math.floor(data.ccount/data.tcount*100));
<i> </i> if(data.ccount>=data.tcount){
<i> </i> data.end(data);
<i> </i> }
<i> </i> }
<i> </i> }
<i> </i> for(var i=0;i<list.length;i++){
<i> </i> this.imgs[i]=document.createElement("img");
<i> </i> Element.addEventListener(this.imgs[i],"load",this.checker,this);
<i> </i> this.imgs[i].src=list[i];
<i> </i> }
<i> </i> this.timeout=window.setTimeout(Element.makeEventListenerData(function(evt,data){data.forceEnd=true;data.end(data);},this),timeout*1000);
<i> </i> }
[CODE] imageCounter: function(el) {/*{{{*/
var clean = this.clean(this.current);
var duration = this.options.durations.active;
var callingImage = el.getAttribute('src');
// var callingImage = document.getElementById('preloadedImage').src;
if (this.counter > this.products[clean]['images'][duration].length){
this.counter = 0;
}
if( this.imageArray.indexOf(callingImage) == -1 ){
this.imageArray.push(callingImage);
this.counter ++;
this.imageInfoText();
}
// if(this.products[clean]['isPlaying'] == true) {
// this.counter ++;
// this.imageInfoText();
// }
// alert("Counter : <" + (this.counter) + "> <" + this.products[clean]['images'][duration].length + "> <" + callingImage + ">");
return this.counter;
},/*}}}*/
[/CODE]
[CODE]
animateOnce: function(){/*{{{*/
// alert(this.products[clean]['images'][duration][i].src);
var clean = this.clean(this.current);
var duration = this.options.durations.active;
var period = this.getPeriod();
this.products[clean]['isPlaying'] = true;
newDiv = document.createElement("div");
newDiv.setAttribute('id','hidden-Preloaded-Images');
newImgArray = [];
for(i = 0; i < this.products[clean]['images'][duration].length; i++){
newImgArray[i] = document.createElement("img");
newImgArray[i].setAttribute('onload','animator.imageCounter(this);');
newImgArray[i].setAttribute('id','preloadedImage')
newImgArray[i].src = this.products[clean]['images'][duration][i].src;
newDiv.appendChild(newImgArray[i]);
}
animationImage = document.getElementById(this.options.ids.imageWrapper);
animationImage.appendChild(newDiv);
/* for(i = 0; i < this.products[clean]['images'][duration].length; i++){
if (this.products[clean]['timer']) window.clearTimeout(this.products[clean]['timer']);
this.next();
if (this.isLastFrame()) period = this.getPeriod() * 4;
this.products[clean]['timer'] = window.setTimeout(this.animate.bind(this),period);
}
*/
var animateInterval = window.setInterval( function(){
if ((this.counter) == this.products[clean]['images'][duration].length){
this.animate();
clearInterval(animateInterval);
}
}.bind(this),300);
},/*}}}*/
[/CODE]
<i>
</i>function methodize(methodize_func,methodize_scope){
var methodize_args=new Array();
for(var i=2;i<arguments.length;i++) methodize_args.push(arguments[i]);
return (function(evt){methodize_func.call(methodize_scope,evt,methodize_args);});
}
newImgArray[i].onload=methodize(this.imageCounter,this,newImgArray[i]);
<i>
</i>imageCounter: function(evt,args) {
var el=args[0];
[CODE]
var overlayImages = document.getElementById('overlayLayer');
overlayImages.onload = this.methodize(this.countOverlays, this, overlayImages);
[/CODE]
0.1.9 — BETA 5.13