Solstice
view release on metacpan or search on metacpan
javascript/yui/build/imageloader/imageloader-experimental.js view on Meta::CPAN
var wrappedFetch = function() {
this.fetch();
};
this._triggers.push([trigEl, trigAct, wrappedFetch]);
YAHOO.util.Event.addListener(trigEl, trigAct, wrappedFetch, this, true);
};
/**
* Setup to do in the window's onload
* Initiates time limit for group; executes the fold check for the images
* @method _onloadTasks
* @private
*/
YAHOO.util.ImageLoader.group.prototype._onloadTasks = function() {
if (this.timeoutLen && typeof(this.timeoutLen) == 'number' && this.timeoutLen > 0) {
this._timeout = setTimeout(this._getFetchTimeout(), this.timeoutLen * 1000);
}
if (this.foldConditional) {
this._foldCheck();
}
};
/**
* Returns the group's fetch method, with the proper closure, for use with setTimeout
* @method _getFetchTimeout
* @return {Function} group's fetch method
* @private
*/
YAHOO.util.ImageLoader.group.prototype._getFetchTimeout = function() {
var self = this;
return function() { self.fetch(); };
};
/**
* Registers a background image with the group
* @method registerBgImage
* @param {String} domId HTML DOM id of the image element
* @param {String} url URL for the image
* @return {Object} bgImgObj that was registered, for modifying any attributes in the object
*/
YAHOO.util.ImageLoader.group.prototype.registerBgImage = function(domId, url) {
this._imgObjs[domId] = new YAHOO.util.ImageLoader.bgImgObj(domId, url);
return this._imgObjs[domId];
};
/**
* Registers a src image with the group
* @method registerSrcImage
* @param {String} domId HTML DOM id of the image element
* @param {String} url URL for the image
* @param {Int} width pixel width of the image - defaults to image's natural size
* @param {Int} height pixel height of the image - defaults to image's natural size
* @return {Object} srcImgObj that was registered, for modifying any attributes in the object
*/
YAHOO.util.ImageLoader.group.prototype.registerSrcImage = function(domId, url, width, height) {
this._imgObjs[domId] = new YAHOO.util.ImageLoader.srcImgObj(domId, url, width, height);
return this._imgObjs[domId];
};
/**
* Registers an alpha-channel-type png background image with the group
* @method registerPngBgImage
* @param {String} domId HTML DOM id of the image element
* @param {String} url URL for the image
* @return {Object} pngBgImgObj that was registered, for modifying any attributes in the object
*/
YAHOO.util.ImageLoader.group.prototype.registerPngBgImage = function(domId, url) {
this._imgObjs[domId] = new YAHOO.util.ImageLoader.pngBgImgObj(domId, url);
return this._imgObjs[domId];
};
/**
* Displays the images in the group
* @method fetch
*/
YAHOO.util.ImageLoader.group.prototype.fetch = function() {
YAHOO.log('Fetching images in group: "' + this.name + '".', 'info', 'imageloader');
clearTimeout(this._timeout);
// remove all listeners
for (var i=0; i < this._triggers.length; i++) {
YAHOO.util.Event.removeListener(this._triggers[i][0], this._triggers[i][1], this._triggers[i][2]);
}
// fetch whatever we need to by className
this._fetchByClass();
// fetch registered images
for (var id in this._imgObjs) {
if (YAHOO.lang.hasOwnProperty(this._imgObjs, id)) {
this._imgObjs[id].fetch();
}
}
};
/**
* Checks the position of each image in the group. If any part of the image is within the client viewport, shows the image immediately.
* @method _foldCheck
* @private
*/
YAHOO.util.ImageLoader.group.prototype._foldCheck = function() {
YAHOO.log('Checking for images above the fold in group: "' + this.name + '"', 'info', 'imageloader');
var scrollTop = (document.compatMode != 'CSS1Compat') ? document.body.scrollTop : document.documentElement.scrollTop;
var viewHeight = YAHOO.util.Dom.getViewportHeight();
var hLimit = scrollTop + viewHeight;
var scrollLeft = (document.compatMode != 'CSS1Compat') ? document.body.scrollLeft : document.documentElement.scrollLeft;
var viewWidth = YAHOO.util.Dom.getViewportWidth();
var wLimit = scrollLeft + viewWidth;
for (var id in this._imgObjs) {
if (YAHOO.lang.hasOwnProperty(this._imgObjs, id)) {
var elPos = YAHOO.util.Dom.getXY(this._imgObjs[id].domId);
if (elPos[1] < hLimit && elPos[0] < wLimit) {
YAHOO.log('Image with id "' + this._imgObjs[id].domId + '" is above the fold. Fetching image.', 'info', 'imageloader');
this._imgObjs[id].fetch();
}
}
}
// and by class
if (this.className) {
this._classImageEls = YAHOO.util.Dom.getElementsByClassName(this.className);
for (var i=0; i < this._classImageEls.length; i++) {
var elPos = YAHOO.util.Dom.getXY(this._classImageEls[i]);
if (elPos[1] < hLimit && elPos[0] < wLimit) {
YAHOO.log('Image with id "' + this._classImageEls[i].id + '" is above the fold. Fetching image. (Image registered by class name with the group - may not have an id.)', 'info', 'imageloader');
YAHOO.util.Dom.removeClass(this._classImageEls[i], this.className);
}
}
( run in 3.196 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )