FIX: Skrypt jquery.loggin.js nie działał w Safari 4.
[redakcja.git] / project / static / js / jquery.lazyload.js
index 25c9486..c15167b 100644 (file)
@@ -12,7 +12,7 @@
         }
         
         var container = this;
         }
         
         var container = this;
-        container.data('lastScroll', -10000);
+        container.data('lazyload:lastCheckedScrollTop', -10000);
         
         function aboveViewport(container, element, threshold) {
             return $(container).offset().top >= $(element).offset().top + $(element).height() + threshold;
         
         function aboveViewport(container, element, threshold) {
             return $(container).offset().top >= $(element).offset().top + $(element).height() + threshold;
         }
         
         function checkScroll() {
         }
         
         function checkScroll() {
-            if (Math.abs(container.scrollTop() - container.data('lastScroll')) > settings.scrollThreshold) {
-                container.data('lastScroll', container.scrollTop());
+            if (container.data('lazyload:lastCheckedScrollTop') == undefined) {
+                return;
+            }
+            if (Math.abs(container.scrollTop() - container.data('lazyload:lastCheckedScrollTop')) > settings.scrollThreshold) {
+                container.data('lazyload:lastCheckedScrollTop', container.scrollTop());
                 
                 $(pattern, container).each(function() {
                     if (aboveViewport(container, this, settings.threshold)
                         || belowViewport(container, this, settings.threshold)) {
                         $(this).html(settings.placeholder);
                     } else {
                 
                 $(pattern, container).each(function() {
                     if (aboveViewport(container, this, settings.threshold)
                         || belowViewport(container, this, settings.threshold)) {
                         $(this).html(settings.placeholder);
                     } else {
-                        $(this).html('<img src="' + $(this).attr('src') + '" width="' + $(this).width() + '" />');
+                        $(this).html('');
+                        var self = this;
+                        $('<img src="' + $(this).attr('src') + '" width="' + $(this).width() + '" />').load(function() {
+                            if ($(this).height() > $(self).height()) {
+                                $(self).height($(this).height());
+                            }
+                        }).appendTo(this);
                     }
                 })
             }
                     }
                 })
             }