From 642314410eb8aca40c199ba230d075adc80bce25 Mon Sep 17 00:00:00 2001 From: Jan Rembold Date: Wed, 9 Dec 2015 14:09:55 +0100 Subject: [PATCH] added events for ready, all.ready, new.source --- build/jquery.responsiveImage.map | 2 +- build/jquery.responsiveImage.min.js | 4 ++-- src/jquery.responsiveImage.js | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/build/jquery.responsiveImage.map b/build/jquery.responsiveImage.map index 71b23ba..e4c881c 100644 --- a/build/jquery.responsiveImage.map +++ b/build/jquery.responsiveImage.map @@ -1 +1 @@ -{"version":3,"file":"jquery.responsiveImage.min.js","sources":["../src/jquery.responsiveImage.js"],"names":["$","window","document","undefined","Plugin","element","options","this","$element","extend","defaults","sources","dpr","getDpr","attributeCount","attributes","length","init","pluginName","source","container","minWidthDefault","maxWidthDefault","Number","MAX_VALUE","minDprDefault","resizeEvent","onGetWidth","prototype","loadSources","containerSelector","attr","$container","parents","loadResponsiveImage","initResizeEvent","self","find","each","$source","data","src","minWidth","maxWidth","minDpr","i","attribute","push","sort","a","b","newSource","targetWidth","getWidth","sourceCount","$currentSource","html","createImageWithAttributes","isFunction","call","width","innerWidth","documentElement","clientWidth","body","screen","systemXDPI","logicalXDPI","devicePixelRatio","image","createElement","setAttribute","on","proxy","fn","jQuery"],"mappings":";;;CAGA,SAAYA,EAAGC,EAAQC,EAAUC,GAC7B,YAmBA,SAASC,GAASC,EAASC,GACvBC,KAAKC,SAAWR,EAAEK,GAClBE,KAAKD,QAAUN,EAAES,UAAYC,EAAUJ,GAEvCC,KAAKI,WACLJ,KAAKK,IAAML,KAAKM,SAChBN,KAAKO,eAAiBP,KAAKD,QAAQS,WAAWC,OAE9CT,KAAKU,OAxBT,GAAIC,GAAa,kBACbR,GACIS,OAAoB,SACpBC,UAAoB,KAEpBC,gBAAoB,EACpBC,gBAAoBC,OAAOC,UAC3BC,cAAoB,EAEpBV,YAAqB,QAAS,MAAO,QAAS,QAAS,UACvDW,YAAoB,SAE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AYW,EAAY,GAAId,GAAQG,KAAMD,QAKpEqE,OAAQ1E,OAAQC"} \ No newline at end of file +{"version":3,"sources":["../src/jquery.responsiveImage.js"],"names":["$","window","document","undefined","Plugin","element","options","this","$element","extend","defaults","sources","dpr","getDpr","attributeCount","attributes","length","init","pluginName","source","container","minWidthDefault","maxWidthDefault","Number","MAX_VALUE","minDprDefault","resizeEvent","onGetWidth","prototype","loadSources","containerSelector","attr","$container","parents","loadResponsiveImage","initResizeEvent","self","find","each","$source","data","src","minWidth","maxWidth","minDpr","i","attribute","push","sort","a","b","newSource","targetWidth","getWidth","sourceCount","$currentSource","html","createImageWithAttributes","trigger","isFunction","call","width","innerWidth","documentElement","clientWidth","body","screen","systemXDPI","logicalXDPI","devicePixelRatio","image","createElement","setAttribute","on","proxy","fn","jQuery"],"mappings":";;;CAGA,SAAYA,EAAGC,EAAQC,EAAUC,GAC7B,YAmBA,SAASC,GAASC,EAASC,GACvBC,KAAKC,SAAWR,EAAEK,GAClBE,KAAKD,QAAUN,EAAES,UAAYC,EAAUJ,GAEvCC,KAAKI,WACLJ,KAAKK,IAAML,KAAKM,SAChBN,KAAKO,eAAiBP,KAAKD,QAAQS,WAAWC,OAE9CT,KAAKU,OAxBT,GAAIC,GAAa,kBACbR,GACIS,OAAoB,SACpBC,UAAoB,KAEpBC,gBAAoB,EACpBC,gBAAoBC,OAAOC,UAC3BC,cAAoB,EAEpBV,YAAqB,QAAS,MAAO,QAAS,QAAS,UACvDW,YAAoB,SAEpBC,WAAoB,KAgB5B3B,GAAES,OAAOL,EAAOwB,WACZX,KAAM,WAIF,GADAV,KAAKI,QAAUJ,KAAKsB,cACO,IAAxBtB,KAAKI,QAAQK,OAAhB,CAKA,GAAIc,GAAoBvB,KAAKC,SAASuB,KAAK,mBAAqBxB,KAAKD,QAAQc,SAC1EU,KACCvB,KAAKyB,WAAazB,KAAKC,SAASyB,QAAQH,IAI5CvB,KAAK2B,sBAGL3B,KAAK4B,oBAGTN,YAAa,WACT,G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,WAAWpD,KAAKD,QAAQqB,YAClBpB,KAAKD,QAAQqB,WAAWiC,KAAKrD,MAC9BA,KAAKyB,WACJzB,KAAKyB,WAAW6B,QAGpB5D,EAAO6D,YAAc5D,EAAS6D,gBAAgBC,aAAe9D,EAAS+D,KAAKD,aAGtFnD,OAAQ,WACJ,MAAIZ,GAAOiE,OAAOC,aAAehE,GAAaF,EAAOiE,OAAOE,cAAgBjE,GAAaF,EAAOiE,OAAOC,WAAalE,EAAOiE,OAAOE,YACvHnE,EAAOiE,OAAOC,WAAalE,EAAOiE,OAAOE,YAGhDnE,EAAOoE,mBAAqBlE,EACrBF,EAAOoE,iBAGX,GAGXZ,0BAA2B,SAAStC,GAEhC,GAAImD,GAAQpE,EAASqE,cAAc,MACnCD,GAAME,aAAa,MAAOrD,EAAOsB,IAGjC,KAAI,GAAII,GAAE,EAAGA,EAAEtC,KAAKO,eAAgB+B,IAAK,CACrC,GAAIC,GAAYvC,KAAKD,QAAQS,WAAW8B,EACP,oBAAvB1B,GAAO2B,IAAqD,KAAtB3B,EAAO2B,IACnDwB,EAAME,aAAa1B,EAAW3B,EAAO2B,IAI7C,MAAOwB,IAGXnC,gBAAiB,WAEbnC,EAAEC,GAAQwE,GAAGlE,KAAKD,QAAQoB,YAAa1B,EAAE0E,MAAMnE,KAAK2B,oBAAqB3B,UAIjFP,EAAE2E,GAAIzD,GAAe,SAAWZ,GAC5B,MAAOC,MAAK+B,KAAK,WACPtC,EAAEwC,KAAMjC,KAAM,UAAYW,KAC5BlB,EAAEwC,KAAMjC,KAAM,UAAYW,EAAY,GAAId,GAAQG,KAAMD,IACxDN,EAAEO,MAAMmD,QAAQ,SAASxC,IAE7BlB,EAAEC,GAAQyD,QAAQ,aAAaxC,OAIvC0D,OAAQ3E,OAAQC","file":"jquery.responsiveImage.min.js"} \ No newline at end of file diff --git a/build/jquery.responsiveImage.min.js b/build/jquery.responsiveImage.min.js index 79493b0..edae2b4 100644 --- a/build/jquery.responsiveImage.min.js +++ b/build/jquery.responsiveImage.min.js @@ -1,5 +1,5 @@ -/*! jquery-responsive-image - v1.1.0 - 2015-07-05 +/*! jquery-responsive-image - v1.2.0 - 2015-12-09 * Copyright (c) 2015 Jan Rembold ; License: MIT */ -!function(a,b,c,d){"use strict";function e(b,c){this.$element=a(b),this.options=a.extend({},g,c),this.sources=[],this.dpr=this.getDpr(),this.attributeCount=this.options.attributes.length,this.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",onGetWidth:null};a.extend(e.prototype,{init:function(){if(this.sources=this.loadSources(),0!==this.sources.length){var a=this.$element.attr("data-container")||this.options.container;a&&(this.$container=this.$element.parents(a)),this.loadResponsiveImage(),this.initResizeEvent()}},loadSources:function(){var b=this,c=[];return this.$element.find(this.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;fd;d++)if(this.sources[d].minWidth<=b&&this.sources[d].maxWidth>b&&this.sources[d].minDpr<=this.dpr){a=this.sources[d];break}a!==this.$currentSource&&(this.$currentSource=a,this.$element.html(this.createImageWithAttributes(a)))},getWidth:function(){return a.isFunction(this.options.onGetWidth)?this.options.onGetWidth.call(this):this.$container?this.$container.width():b.innerWidth||c.documentElement.clientWidth||c.body.clientWidth},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(a){var b=c.createElement("img");b.setAttribute("src",a.src);for(var d=0;d span",container:null,minWidthDefault:0,maxWidthDefault:Number.MAX_VALUE,minDprDefault:1,attributes:["title","alt","class","width","height"],resizeEvent:"resize",onGetWidth:null};a.extend(e.prototype,{init:function(){if(this.sources=this.loadSources(),0!==this.sources.length){var a=this.$element.attr("data-container")||this.options.container;a&&(this.$container=this.$element.parents(a)),this.loadResponsiveImage(),this.initResizeEvent()}},loadSources:function(){var b=this,c=[];return this.$element.find(this.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;fd;d++)if(this.sources[d].minWidth<=b&&this.sources[d].maxWidth>b&&this.sources[d].minDpr<=this.dpr){a=this.sources[d];break}a!==this.$currentSource&&(this.$currentSource=a,this.$element.html(this.createImageWithAttributes(a)),this.$element.trigger("new.source."+f))},getWidth:function(){return a.isFunction(this.options.onGetWidth)?this.options.onGetWidth.call(this):this.$container?this.$container.width():b.innerWidth||c.documentElement.clientWidth||c.body.clientWidth},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(a){var b=c.createElement("img");b.setAttribute("src",a.src);for(var d=0;d; License: MIT */ (function ( $, window, document, undefined ) { @@ -122,6 +122,9 @@ // append responsive image to target element this.$element.html( this.createImageWithAttributes(newSource) ); + + // trigger new source event + this.$element.trigger('new.source.'+pluginName); }, getWidth: function(){ @@ -172,7 +175,9 @@ return this.each(function() { if ( !$.data( this, 'plugin_' + pluginName ) ) { $.data( this, 'plugin_' + pluginName, new Plugin( this, options ) ); + $(this).trigger('ready.'+pluginName); } + $(window).trigger('all.ready.'+pluginName); }); };