xsdot_onvisible_js
var EventListener = function(element, callback) {
this._top = getElementYPos(element)+60;
this._el = element;
this._cb = callback;
this._at = false;
this._hasBeenVisible = false;
this._hasBeenInvisible = true;
var _me = this;
testPosition(_me);
window.onscroll = function() {
for (q in EventListener.queue.onvisible) {
EventListener.queue.onvisible[q].call();
}
};
return {
onvisible: function() {
EventListener.queue.onvisible.push(function() {
testPosition(_me);
});
}
};
}
EventListener.queue = {
onvisible: []
};
function addOnVisibleEvent(element, event, fn) {
if (typeof element == 'string')
element = document.getElementById(element);
var listener = new EventListener(element, fn);
if (listener['on' + event.toLowerCase()])
return listener['on' + event.toLowerCase()].call();
}
function testPosition(o) {
if (!o._at && o._hasBeenInvisible && (window.pageYOffset + window.innerHeight) > o._top ) {
o._at = true;
o._hasBeenVisible = true;
o._cb(o._el);
}
}
var onVisIdCounter = 0;
var onVisDelay = 0;
function initOnVisible(e) {
// + 1. only if out of page
// + 2. only on page load
// - 4. delays between objects
// - 5. clear class?
var vt = e.getAttribute("data-vt");
if(vt!=null) {
var et = getElementYPos(e);
if((window.pageYOffset + window.innerHeight) < et) {
var type = "anitop";
if(vt=="b")
type = "anibot";
else if(vt=="l")
type = "anileft";
else if(vt=="r")
type = "aniright";
var cc = e.getAttribute("class");
setAttribute(e, "class", cc+" "+type);
addOnVisibleEvent(e, 'visible', function(ee) {
var isLR = false;
var nc = ee.getAttribute("class");
if(nc.indexOf("anileft")>0) {
nc = nc.replace(" anileft", "");
isLR = true;
}
else if(nc.indexOf("aniright")>0) {
nc = nc.replace(" aniright", "");
isLR = true;
}
else {
nc = nc.replace(" anitop", "");
nc = nc.replace(" anibot", "");
}
var id = ee.id;
if(id==null)
id = "";
if(id=="") {
onVisIdCounter++;
ee.id = "visid"+onVisIdCounter;
id = ee.id;
}
var del = 1;
if(onVisDelay>0)
del = onVisDelay * 160;
var ncl = nc+" ani";
window.setTimeout("onVisFireElement('"+id+"', '"+ncl+"', "+isLR+");", del);
if(!isLR)
onVisDelay++;
});
}
}
}
function onVisFireElement(id, cl, isLR) {
var e = $(id);
setAttribute(e, "class", cl);
if((onVisDelay>0) & (!isLR))
onVisDelay--;
}