jsdoc for invisible image functions, polyfill for rAF

This commit is contained in:
Ivan Malopinsky
2015-01-25 00:00:00 -05:00
parent 41c9258802
commit e61a67134d
2 changed files with 63 additions and 18 deletions

View File

@@ -869,28 +869,36 @@ Holder.js - client side image placeholders
}
}
//todo jsdoc
/**
* Iterates through all current invisible images, and if they're visible, renders them and removes them from further checks. Runs every animation frame.
*
* @private
*/
function visibilityCheck() {
var renderableImages = [];
var keys = Object.keys(App.vars.invisibleImages);
var el;
for (var i = 0, l = keys.length; i < l; i++) {
el = App.vars.invisibleImages[keys[i]];
if (dimensionCheck(el) && el.nodeName.toLowerCase() == 'img') {
renderableImages.push(el);
delete App.vars.invisibleImages[keys[i]];
}
var renderableImages = [];
var keys = Object.keys(App.vars.invisibleImages);
var el;
for (var i = 0, l = keys.length; i < l; i++) {
el = App.vars.invisibleImages[keys[i]];
if (dimensionCheck(el) && el.nodeName.toLowerCase() == 'img') {
renderableImages.push(el);
delete App.vars.invisibleImages[keys[i]];
}
}
if (renderableImages.length) {
Holder.run({
images: renderableImages
});
}
global.requestAnimationFrame(visibilityCheck);
if (renderableImages.length) {
Holder.run({
images: renderableImages
});
}
global.requestAnimationFrame(visibilityCheck);
}
//todo jsdoc
/**
* Starts checking for invisible placeholders if not doing so yet. Does nothing otherwise.
*
* @private
*/
function startVisibilityCheck() {
if (!App.vars.visibilityCheckStarted) {
global.requestAnimationFrame(visibilityCheck);
@@ -898,7 +906,12 @@ Holder.js - client side image placeholders
}
}
//todo jsdoc
/**
* Sets a unique ID for an image detected to be invisible and adds it to the map of invisible images checked by visibilityCheck
*
* @private
* @param el Invisible DOM element
*/
function setInvisible(el) {
if (!el.holderData.invisibleId) {
App.vars.invisibleId += 1;

View File

@@ -257,3 +257,35 @@ if (!Object.prototype.hasOwnProperty){
}
/*jshint +W001, +W103 */
}
//requestAnimationFrame polyfill for older Firefox/Chrome versions
if (!window.requestAnimationFrame) {
if (window.webkitRequestAnimationFrame) {
//https://github.com/Financial-Times/polyfill-service/blob/master/polyfills/requestAnimationFrame/polyfill-webkit.js
(function (global) {
// window.requestAnimationFrame
global.requestAnimationFrame = function (callback) {
return webkitRequestAnimationFrame(function () {
callback(performance.now());
});
};
// window.cancelAnimationFrame
global.cancelAnimationFrame = webkitCancelAnimationFrame;
}(this));
} else if (window.mozRequestAnimationFrame) {
//https://github.com/Financial-Times/polyfill-service/blob/master/polyfills/requestAnimationFrame/polyfill-moz.js
(function (global) {
// window.requestAnimationFrame
global.requestAnimationFrame = function (callback) {
return mozRequestAnimationFrame(function () {
callback(performance.now());
});
};
// window.cancelAnimationFrame
global.cancelAnimationFrame = mozCancelAnimationFrame;
}(this));
}
}