From 816a4653c0086eeaf57ba148864bb06678d9234c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20St=C4=99pniowski?= Date: Mon, 10 Aug 2009 12:07:03 +0200 Subject: [PATCH 1/1] =?utf8?q?Wydzielenie=20kodu=20jQuery=20obs=C5=82uguj?= =?utf8?q?=C4=85cego=20automatyczne=20=C5=82adowanie=20obrazk=C3=B3w=20do?= =?utf8?q?=20biblioteki=20jquery.lazyload.js.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- project/static/js/jquery.lazyload.js | 43 +++++++++++++++++++++++ project/templates/explorer/file_html.html | 33 ++--------------- project/templates/explorer/file_xml.html | 34 ++---------------- 3 files changed, 48 insertions(+), 62 deletions(-) create mode 100644 project/static/js/jquery.lazyload.js diff --git a/project/static/js/jquery.lazyload.js b/project/static/js/jquery.lazyload.js new file mode 100644 index 00000000..25c94869 --- /dev/null +++ b/project/static/js/jquery.lazyload.js @@ -0,0 +1,43 @@ +(function($) { + jQuery.fn.lazyload = function(pattern, options) { + var settings = { + threshold: 0, + scrollThreshold: 300, + placeholder: 'loading...', + checkInterval: 2000 + }; + + if (options) { + $.extend(settings, options); + } + + var container = this; + container.data('lastScroll', -10000); + + function aboveViewport(container, element, threshold) { + return $(container).offset().top >= $(element).offset().top + $(element).height() + threshold; + } + + function belowViewport(container, element, threshold) { + return $(container).offset().top + $(container).height() + threshold <= $(element).offset().top; + } + + function checkScroll() { + if (Math.abs(container.scrollTop() - container.data('lastScroll')) > settings.scrollThreshold) { + container.data('lastScroll', container.scrollTop()); + + $(pattern, container).each(function() { + if (aboveViewport(container, this, settings.threshold) + || belowViewport(container, this, settings.threshold)) { + $(this).html(settings.placeholder); + } else { + $(this).html(''); + } + }) + } + setTimeout(checkScroll, settings.checkInterval); + } + + checkScroll(); + }; +})(jQuery); diff --git a/project/templates/explorer/file_html.html b/project/templates/explorer/file_html.html index b0d16b6e..f3fe1876 100644 --- a/project/templates/explorer/file_html.html +++ b/project/templates/explorer/file_html.html @@ -3,43 +3,14 @@ {% block extrahead %} {% endblock extrahead %} diff --git a/project/templates/explorer/file_xml.html b/project/templates/explorer/file_xml.html index 08e42e4c..5c8dbf00 100644 --- a/project/templates/explorer/file_xml.html +++ b/project/templates/explorer/file_xml.html @@ -2,36 +2,8 @@ {% block extrahead %} + {% endblock extrahead %} -- 2.20.1