-
Notifications
You must be signed in to change notification settings - Fork 0
/
garfield.min.js
1 lines (1 loc) · 1.16 KB
/
garfield.min.js
1
+function(t){"use strict";function e(e,r){return this.each(function(){var r=t(this),i=r.data("garfield"),o=t.extend({},a.DEFAULTS,r.data(),"object"==typeof e&&e);i||r.data("garfield",i=new a(this,o)),i.prepare()})}var a=function(e,a){this.options=a,this.$body=t(document.body),this.$element=t(e),this.loaded=!1};a.VERSION="0.1.2",a.DEFAULTS={offsets:{top:400,bottom:400},dataSrcSetAttribute:"data-srcset",dataSrcAttribute:"data-src",unloadedCssClass:"garfield",loadedCssClass:"garfielded"},a.prototype.prepare=function(){this.options;var t=this.$element,e=t,a=this,r=t.parent()[0];"PICTURE"==r.tagName&&(e=r),scrollMonitor.create(e,this.options.offsets).enterViewport(function(){!1===a.loaded&&a.loadImage()})},a.prototype.loadImage=function(){var t=this.options,e=this.$element,a=e.attr(t.dataSrcAttribute),r=e.attr(t.dataSrcSetAttribute);e.attr("src",a),e.attr("srcset",r),this.loaded=!0};var r=t.fn.garfield;t.fn.garfield=e,t.fn.garfield.Constructor=a,t.fn.garfield.noConflict=function(){return t.fn.garfield=r,this},t(document).ready(function(){t("["+a.DEFAULTS.dataSrcAttribute+"], ["+a.DEFAULTS.dataSrcSetAttribute+"]").each(function(){var a=t(this);e.call(a,a.data())})})}(jQuery);