From f37c2a228e418b8facfb429704edaf15fb6c2f1b Mon Sep 17 00:00:00 2001 From: Jan Rembold Date: Thu, 28 Jan 2016 20:17:20 +0100 Subject: [PATCH] added option to disable resize event added documentation --- README.md | 1 + build/jquery.responsiveImage.map | 2 +- build/jquery.responsiveImage.min.js | 2 +- src/jquery.responsiveImage.js | 4 +++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4f162a1..6acb3f9 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ Setting this parameter is recommended because it optimizes the target size for t This is the resize event used to detect the resize of the viewport. You can set any event that can be used inside jQuery's `.on()` function. +Set `resizeEvent` to empty string to disable image calculation on resize. It defaults to the `resize` event, which is not recommended because of the high amount of fired events. diff --git a/build/jquery.responsiveImage.map b/build/jquery.responsiveImage.map index 8369731..482d10c 100644 --- a/build/jquery.responsiveImage.map +++ b/build/jquery.responsiveImage.map @@ -1 +1 @@ -{"version":3,"sources":["../src/jquery.responsiveImage.js"],"names":["$","window","document","undefined","Plugin","element","options","self","this","$element","extend","defaults","sources","dpr","getDpr","attributeCount","attributes","length","init","pluginName","source","container","minWidthDefault","maxWidthDefault","Number","MAX_VALUE","minDprDefault","resizeEvent","preload","autoDpr","onGetWidth","prototype","loadSources","containerSelector","attr","$container","parents","loadResponsiveImage","initResizeEvent","find","each","$source","data","src","minWidth","maxWidth","minDpr","i","attribute","push","sort","a","b","newSource","targetWidth","getWidth","sourceCount","$currentSource","$image","createImageWithAttributes","setNewSource","html","trigger","width","isFunction","call","innerWidth","documentElement","clientWidth","body","screen","systemXDPI","logicalXDPI","devicePixelRatio","one","get","complete","on","proxy","fn","jQuery"],"mappings":";;;CAGA,SAAYA,EAAGC,EAAQC,EAAUC,GAC7B,YAqBA,SAASC,GAASC,EAASC,GACvB,GAAIC,GAAOC,IACXD,GAAKE,SAAWT,EAAEK,GAClBE,EAAKD,QAAUN,EAAEU,UAAYC,EAAUL,GAEvCC,EAAKK,WACLL,EAAKM,IAAM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d,0BAA2B,SAASvC,GAMhC,IAAI,GAJAb,GAAOC,KACPkD,EAAS1D,EAAE,UAGP+C,EAAE,EAAGA,EAAExC,EAAKQ,eAAgBgC,IAAK,CACrC,GAAIC,GAAYzC,EAAKD,QAAQU,WAAW+B,EACP,oBAAvB3B,GAAO4B,IAAqD,KAAtB5B,EAAO4B,IACnDU,EAAOxB,KAAKc,EAAW5B,EAAO4B,IAoBtC,MAfAU,GAAOgB,IAAI,OAAQ,WACfnE,EAAKE,SAASqD,QAAQ,+BAGlBvD,EAAKD,QAAQsB,SACbrB,EAAKqD,aAAcF,KAG1BxB,KAAK,MAAOd,EAAOuB,KAGhBe,EAAOiB,IAAI,GAAGC,UACdlB,EAAOI,QAAQ,QAGZJ,GAGXpB,gBAAiB,WACb,GAAI/B,GAAOC,IAGXR,GAAEC,GAAQ4E,GAAGtE,EAAKD,QAAQqB,YAAa3B,EAAE8E,MAAMvE,EAAK8B,oBAAqB9B,OAIjFP,EAAE+E,GAAI5D,GAAe,SAAWb,GAC5B,MAAOE,MAAKgC,KAAK,WACPxC,EAAE0C,KAAMlC,KAAM,UAAYW,KAC5BnB,EAAE0C,KAAMlC,KAAM,UAAYW,EAAY,GAAIf,GAAQI,KAAMF,IACxDN,EAAEQ,MAAMsD,QAAQ,SAAS3C,IAE7BnB,EAAEC,GAAQ6D,QAAQ,aAAa3C,OAIvC6D,OAAQ/E,OAAQC","file":"jquery.responsiveImage.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/jquery.responsiveImage.js"],"names":["$","window","document","undefined","Plugin","element","options","self","this","$element","extend","defaults","sources","dpr","getDpr","attributeCount","attributes","length","init","pluginName","source","container","minWidthDefault","maxWidthDefault","Number","MAX_VALUE","minDprDefault","resizeEvent","preload","autoDpr","onGetWidth","prototype","loadSources","containerSelector","attr","$container","parents","loadResponsiveImage","initResizeEvent","find","each","$source","data","src","minWidth","maxWidth","minDpr","i","attribute","push","sort","a","b","newSource","targetWidth","getWidth","sourceCount","$currentSource","$image","createImageWithAttributes","setNewSource","html","trigger","width","isFunction","call","innerWidth","documentElement","clientWidth","body","screen","systemXDPI","logicalXDPI","devicePixelRatio","one","get","complete","on","proxy","fn","jQuery"],"mappings":";;;CAGA,SAAYA,EAAGC,EAAQC,EAAUC,GAC7B,YAqBA,SAASC,GAASC,EAASC,GACvB,GAAIC,GAAOC,IACXD,GAAKE,SAAWT,EAAEK,GAClBE,EAAKD,QAAUN,EAAEU,UAAYC,EAAUL,GAEvCC,EAAKK,WACLL,EAAKM,IAAMN,EAAKO,SAChBP,EAAKQ,eAAiBR,EAAKD,QAAQU,WAAWC,OAE9CV,EAAKW,OA3BT,GAAIC,GAAa,kBACbR,GACIS,OAAoB,SACpBC,UAAoB,KAEpBC,gBAAoB,EACpBC,gBAAoBC,OAAOC,UAC3BC,cAAoB,EAEpBV,YAAqB,QAAS,MAAO,QAAS,QAAS,UACvDW,YAAoB,SACpBC,SAAoB,EACpBC,SAAoB,EAEpBC,WAAoB,KAiB5B9B,GAAEU,OAAON,EAAO2B,WACZb,KAAM,WACF,GAAIX,GAAOC,IAIX,IADAD,EAAKK,QAAUL,EAAKyB,cACO,IAAxBzB,EAAKK,QAAQK,OAAhB,CAKA,GAAIgB,GAAoB1B,EAAKE,SAASyB,KAAK,mBAAqB3B,EAAKD,QAAQe,SAC1EY,KACC1B,EAAK4B,WAAa5B,EAAKE,SAAS2B,QAAQH,IAI5C1B,EAAK8B,sBAGL9B,EAAK+B,oBAGTN,YAAa,WACT,GAAIzB,GAAOC,KACPI,IAoCJ,OAjCAL,GAAKE,SAAS8B,KAAKhC,EAAKD,QAAQc,QAAQoB,KAAK,WACzC,GAAIC,GAAUzC,EAAEQ,KAGhB,IAAGiC,EAAQC,KAAK,OAAQ,CASpB,IAAI,GARAA,IACAC,IAAYF,EAAQC,KAAK,OACzBE,SAAYH,EAAQC,KAAK,cAAgBnC,EAAKD,QAAQgB,gBACtDuB,SAAYJ,EAAQC,KAAK,cAAgBnC,EAAKD,QAAQiB,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ery.responsiveImage.min.js"} \ No newline at end of file diff --git a/build/jquery.responsiveImage.min.js b/build/jquery.responsiveImage.min.js index 42d31b6..cc5eec6 100644 --- a/build/jquery.responsiveImage.min.js +++ b/build/jquery.responsiveImage.min.js @@ -1,5 +1,5 @@ /*! jquery-responsive-image - v1.3.0 - 2016-01-28 * Copyright (c) 2016 Jan Rembold ; License: MIT */ -!function(a,b,c,d){"use strict";function e(b,c){var d=this;d.$element=a(b),d.options=a.extend({},g,c),d.sources=[],d.dpr=d.getDpr(),d.attributeCount=d.options.attributes.length,d.init()}var f="responsiveImage",g={source:"> span",container:null,minWidthDefault:0,maxWidthDefault:Number.MAX_VALUE,minDprDefault:1,attributes:["title","alt","class","width","height"],resizeEvent:"resize",preload:!1,autoDpr:!1,onGetWidth:null};a.extend(e.prototype,{init:function(){var a=this;if(a.sources=a.loadSources(),0!==a.sources.length){var b=a.$element.attr("data-container")||a.options.container;b&&(a.$container=a.$element.parents(b)),a.loadResponsiveImage(),a.initResizeEvent()}},loadSources:function(){var b=this,c=[];return b.$element.find(b.options.source).each(function(){var d=a(this);if(d.data("src")){for(var e={src:d.data("src"),minWidth:d.data("min-width")||b.options.minWidthDefault,maxWidth:d.data("max-width")||b.options.maxWidthDefault,minDpr:d.data("min-dpr")||b.options.minDprDefault},f=0;fe;e++)if(b.sources[e].minWidth<=c&&b.sources[e].maxWidth>c&&b.sources[e].minDpr<=b.dpr){a=b.sources[e];break}if(a!==b.$currentSource){b.$currentSource=a;var f=b.createImageWithAttributes(a);b.options.preload||b.setNewSource(f)}},setNewSource:function(a){var b=this;b.$element.html(a),b.$element.trigger("new.source."+f)},getWidth:function(){var d,e=this;return d=a.isFunction(e.options.onGetWidth)?e.options.onGetWidth.call(this):e.$container?e.$container.width():b.innerWidth||c.documentElement.clientWidth||c.body.clientWidth,e.options.autoDpr&&(d*=e.dpr),d},getDpr:function(){return b.screen.systemXDPI!==d&&b.screen.logicalXDPI!==d&&b.screen.systemXDPI>b.screen.logicalXDPI?b.screen.systemXDPI/b.screen.logicalXDPI:b.devicePixelRatio!==d?b.devicePixelRatio:1},createImageWithAttributes:function(b){for(var c=this,d=a(""),e=0;e span",container:null,minWidthDefault:0,maxWidthDefault:Number.MAX_VALUE,minDprDefault:1,attributes:["title","alt","class","width","height"],resizeEvent:"resize",preload:!1,autoDpr:!1,onGetWidth:null};a.extend(e.prototype,{init:function(){var a=this;if(a.sources=a.loadSources(),0!==a.sources.length){var b=a.$element.attr("data-container")||a.options.container;b&&(a.$container=a.$element.parents(b)),a.loadResponsiveImage(),a.initResizeEvent()}},loadSources:function(){var b=this,c=[];return b.$element.find(b.options.source).each(function(){var d=a(this);if(d.data("src")){for(var e={src:d.data("src"),minWidth:d.data("min-width")||b.options.minWidthDefault,maxWidth:d.data("max-width")||b.options.maxWidthDefault,minDpr:d.data("min-dpr")||b.options.minDprDefault},f=0;fe;e++)if(b.sources[e].minWidth<=c&&b.sources[e].maxWidth>c&&b.sources[e].minDpr<=b.dpr){a=b.sources[e];break}if(a!==b.$currentSource){b.$currentSource=a;var f=b.createImageWithAttributes(a);b.options.preload||b.setNewSource(f)}},setNewSource:function(a){var b=this;b.$element.html(a),b.$element.trigger("new.source."+f)},getWidth:function(){var d,e=this;return d=a.isFunction(e.options.onGetWidth)?e.options.onGetWidth.call(this):e.$container?e.$container.width():b.innerWidth||c.documentElement.clientWidth||c.body.clientWidth,e.options.autoDpr&&(d*=e.dpr),d},getDpr:function(){return b.screen.systemXDPI!==d&&b.screen.logicalXDPI!==d&&b.screen.systemXDPI>b.screen.logicalXDPI?b.screen.systemXDPI/b.screen.logicalXDPI:b.devicePixelRatio!==d?b.devicePixelRatio:1},createImageWithAttributes:function(b){for(var c=this,d=a(""),e=0;e