Committer: vvasin
LJSUP-13603: Preload next comment's page when user is about to finish reading current one. Add ability preload on scroll.U trunk/htdocs/js/jquery_fn.js
Modified: trunk/htdocs/js/jquery_fn.js =================================================================== --- trunk/htdocs/js/jquery_fn.js 2012-09-17 11:32:30 UTC (rev 22904) +++ trunk/htdocs/js/jquery_fn.js 2012-09-17 12:13:03 UTC (rev 22905) @@ -413,3 +413,36 @@ } }); }; + +/** + * Provide ability to check if element is on the screen + * @author Valeriy Vasin (valeriy.vasin@sup.com) + */ +;(function ($) { + 'use strict'; + // cache window object + var $win = $(window); + $.expr[':'].screenable = function (element) { + var win = {}, + el = {}, + $el = $(element); + + // window coordinates + win.width = $win.width(), + win.height = $win.height(), + win.top = $win.scrollTop(), + win.bottom = win.top + win.height, + win.left = $win.scrollLeft(), + win.right = win.left + win.width, + + // element coordinates + el.width = $el.width(); + el.height = $el.height(); + el.top = $el.offset().top; + el.bottom = el.top + el.height; + el.left = $el.offset().left; + el.right = el.left + el.width; + + return (el.bottom > win.top && el.top < win.bottom) && (el.right > win.left && el.left < win.right); + }; +}(jQuery)); \ No newline at end of file