Sha256: 59d4a685dfbe4cd6494c6799c08c6f60780a4493fd0474a654ce7e5ca9a8175d

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 KB

Contents

//= require instant_upload/angular/angular

//= require instant_upload/single
//= require instant_upload/multi

/**
 * jQuery Unveil
 * A very lightweight jQuery plugin to lazy load images
 * http://luis-almeida.github.com/unveil
 *
 * Licensed under the MIT license.
 * Copyright 2013 Luís Almeida
 * https://github.com/luis-almeida
 */

;(function($) {

  $.fn.unveil = function(threshold) {

    var $w = $(window),
        th = threshold || 0,
        retina = window.devicePixelRatio > 1,
        attrib = retina? "data-src-retina" : "data-src",
        images = this,
        loaded,
        inview,
        source;

    this.one("unveil", function() {
      source = this.getAttribute(attrib);
      source = source || this.getAttribute("data-src");
      if (source) this.setAttribute("src", source);
    });

    function unveil() {
      inview = images.filter(function() {
        var $e = $(this),
            wt = $w.scrollTop(),
            wb = wt + $w.height(),
            et = $e.offset().top,
            eb = et + $e.height();

        return eb >= wt - th && et <= wb + th;
      });

      loaded = inview.trigger("unveil");
      images = images.not(loaded);
    }

    $w.scroll(unveil);
    $w.resize(unveil);

    unveil();

    return this;

  };

})(jQuery);

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
instant-upload-1.1.0 app/assets/javascripts/instant_upload.js
instant-upload-1.0.9 app/assets/javascripts/instant_upload.js
instant-upload-1.0.8 app/assets/javascripts/instant_upload.js
instant-upload-1.0.7 app/assets/javascripts/instant_upload.js