diff --git a/README.md b/README.md index dc99355..3dd3e67 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,8 @@ Turn on/off bubbles. *** # Touch support -- swipe right and left to change images +- swipe right for prev +- swipe left for next - doubletap to close gallery > Touch will be enabled only if `hammer.js` file is added. diff --git a/dist/ng-image-gallery.js b/dist/ng-image-gallery.js index c8f2578..10ed131 100644 --- a/dist/ng-image-gallery.js +++ b/dist/ng-image-gallery.js @@ -312,12 +312,12 @@ // Swipe events if(window.Hammer){ var hammerElem = new Hammer(elem[0]); - hammerElem.on('swipeleft', function(ev){ + hammerElem.on('swiperight', function(ev){ $timeout(function(){ scope.methods.prev(); }); }); - hammerElem.on('swiperight', function(ev){ + hammerElem.on('swipeleft', function(ev){ $timeout(function(){ scope.methods.next(); }); diff --git a/dist/ng-image-gallery.min.js b/dist/ng-image-gallery.min.js index c5f6ac0..baf4555 100644 --- a/dist/ng-image-gallery.min.js +++ b/dist/ng-image-gallery.min.js @@ -1,2 +1,2 @@ -!function(){"use strict";var e={enter:13,esc:27,left:37,right:39};angular.module("thatisuday.ng-image-gallery",["ngAnimate"]).directive("ngImageGallery",["$timeout","$document","$q",function(i,n,a){return{replace:!0,transclude:!1,restrict:"AE",scope:{images:"=",methods:"=?",thumbnails:"=?",inline:"=?",bubbles:"=?",imgBubbles:"=?",bgClose:"=?",onOpen:"&?",onClose:"&?"},template:'',link:function(s,l,g){s.showLoader=function(){s.imgLoading=!0},s.hideLoader=function(){s.imgLoading=!1},s.loadImg=function(e){var i=a.defer();e.hasOwnProperty("cached")||s.showLoader();var n=new Image;return n.src=e.url,n.onload=function(){return e.hasOwnProperty("cached")||s.hideLoader(),e.hasOwnProperty("cached")||(e.cached=!0),i.resolve(e)},i.promise},s.setActiveImg=function(e){s.loadImg(e).then(function(e){s.activeImg=e})},s.images=s.images?s.images:[],s.methods=s.methods?s.methods:{},s.thumbnails=!s.thumbnails||s.thumbnails,s.inline=!!s.inline&&s.inline,s.bubbles=!s.bubbles||s.bubbles,s.imgBubbles=!!s.imgBubbles&&s.imgBubbles,s.bgClose=!!s.bgClose&&s.bgClose,s.onOpen=s.onOpen?s.onOpen:angular.noop,s.onClose=s.onClose?s.onClose:angular.noop;var t=!0;s.$watch("images",function(){t?t=!1:s.images.length&&s.setActiveImg(s.images[s.activeImageIndex||0])});var c=!0;if(s.$watch("activeImageIndex",function(e){c?c=!1:s.images.length&&s.setActiveImg(s.images[e])}),s.$watch("inline",function(){i(function(){s.inline&&s.methods.open()})}),s.methods.open=function(e){s.activeImageIndex=e?e:0,s.opened=!0,i(function(){s.onOpen()},300)},s.methods.close=function(){s.opened=!1,i(function(){s.onClose(),s.activeImageIndex=0},300)},s.methods.next=function(){s.activeImageIndex==s.images.length-1?s.activeImageIndex=0:s.activeImageIndex=s.activeImageIndex+1},s.methods.prev=function(){0==s.activeImageIndex?s.activeImageIndex=s.images.length-1:s.activeImageIndex--},s.backgroundClose=function(e){if(s.bgClose&&!s.inline)for(var i=["galleria-image","destroy-icons-container","ext-url","close","next","prev","galleria-bubble"],n=0;n',link:function(s,l,g){s.showLoader=function(){s.imgLoading=!0},s.hideLoader=function(){s.imgLoading=!1},s.loadImg=function(e){var i=a.defer();e.hasOwnProperty("cached")||s.showLoader();var n=new Image;return n.src=e.url,n.onload=function(){return e.hasOwnProperty("cached")||s.hideLoader(),e.hasOwnProperty("cached")||(e.cached=!0),i.resolve(e)},i.promise},s.setActiveImg=function(e){s.loadImg(e).then(function(e){s.activeImg=e})},s.images=s.images?s.images:[],s.methods=s.methods?s.methods:{},s.thumbnails=!s.thumbnails||s.thumbnails,s.inline=!!s.inline&&s.inline,s.bubbles=!s.bubbles||s.bubbles,s.imgBubbles=!!s.imgBubbles&&s.imgBubbles,s.bgClose=!!s.bgClose&&s.bgClose,s.onOpen=s.onOpen?s.onOpen:angular.noop,s.onClose=s.onClose?s.onClose:angular.noop;var t=!0;s.$watch("images",function(){t?t=!1:s.images.length&&s.setActiveImg(s.images[s.activeImageIndex||0])});var c=!0;if(s.$watch("activeImageIndex",function(e){c?c=!1:s.images.length&&s.setActiveImg(s.images[e])}),s.$watch("inline",function(){i(function(){s.inline&&s.methods.open()})}),s.methods.open=function(e){s.activeImageIndex=e?e:0,s.opened=!0,i(function(){s.onOpen()},300)},s.methods.close=function(){s.opened=!1,i(function(){s.onClose(),s.activeImageIndex=0},300)},s.methods.next=function(){s.activeImageIndex==s.images.length-1?s.activeImageIndex=0:s.activeImageIndex=s.activeImageIndex+1},s.methods.prev=function(){0==s.activeImageIndex?s.activeImageIndex=s.images.length-1:s.activeImageIndex--},s.backgroundClose=function(e){if(s.bgClose&&!s.inline)for(var i=["galleria-image","destroy-icons-container","ext-url","close","next","prev","galleria-bubble"],n=0;n'+\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t// Thumbnails container\r\n\t\t\t\t\t\t\t// Hide for inline gallery\r\n\t\t\t\t\t\t\t''+\r\n\r\n\t\t\t\t\t\t\t// Modal container\r\n\t\t\t\t\t\t\t// (inline container for inline modal)\r\n\t\t\t\t\t\t\t''+\r\n\t\t\t\t\t\t'',\r\n\t\t\t\t\t\t\r\n\t\t\tlink : function(scope, elem, attr){\r\n\t\t\t\t\r\n\t\t\t\t/*\r\n\t\t\t\t *\tOperational functions\r\n\t\t\t\t**/\r\n\r\n\t\t\t\t// Show gallery loader\r\n\t\t\t\tscope.showLoader = function(){\r\n\t\t\t\t\tscope.imgLoading = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Hide gallery loader\r\n\t\t\t\tscope.hideLoader = function(){\r\n\t\t\t\t\tscope.imgLoading = false;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Image load complete promise\r\n\t\t\t\tscope.loadImg = function(imgObj){\r\n\t\t\t\t\tvar deferred = $q.defer();\r\n\r\n\t\t\t\t\t// Show loder\r\n\t\t\t\t\tif(!imgObj.hasOwnProperty('cached')) scope.showLoader();\r\n\r\n\t\t\t\t\t// Process image\r\n\t\t\t\t\tvar img = new Image();\r\n\t\t\t\t\timg.src = imgObj.url;\r\n\t\t\t\t\timg.onload = function(){\r\n\t\t\t\t\t\t// Hide loder\r\n\t\t\t\t\t\tif(!imgObj.hasOwnProperty('cached')) scope.hideLoader();\r\n\r\n\t\t\t\t\t\t// Cache image\r\n\t\t\t\t\t\tif(!imgObj.hasOwnProperty('cached')) imgObj.cached = true;\r\n\r\n\t\t\t\t\t\treturn deferred.resolve(imgObj);\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\treturn deferred.promise;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tscope.setActiveImg = function(imgObj){\r\n\t\t\t\t\t// Load image\r\n\t\t\t\t\tscope.loadImg(imgObj).then(function(imgObj){\r\n\t\t\t\t\t\tscope.activeImg = imgObj;\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\r\n\r\n\t\t\t\t/***************************************************/\r\n\t\t\t\t\r\n\r\n\t\t\t\t/*\r\n\t\t\t\t *\tGallery settings\r\n\t\t\t\t**/\r\n\r\n\t\t\t\t// Modify scope models\r\n\t\t\t\tscope.images \t \t = \t(scope.images) \t\t ? scope.images \t\t: \t[];\r\n\t\t\t\tscope.methods \t \t = \t(scope.methods) \t ? scope.methods \t\t: \t{};\r\n\r\n\t\t\t\tscope.thumbnails \t = \t(scope.thumbnails) \t ? scope.thumbnails \t: \ttrue;\r\n\t\t\t\tscope.inline \t \t = \t(scope.inline) \t\t ? scope.inline \t\t: \tfalse;\r\n\t\t\t\tscope.bubbles \t \t = \t(scope.bubbles) \t ? scope.bubbles \t\t: \ttrue;\r\n\t\t\t\tscope.imgBubbles \t = \t(scope.imgBubbles) \t ? scope.imgBubbles \t: \tfalse;\r\n\t\t\t\tscope.bgClose \t \t = \t(scope.bgClose) \t ? scope.bgClose \t\t: \tfalse;\r\n\r\n\t\t\t\tscope.onOpen \t \t = \t(scope.onOpen) \t\t ? scope.onOpen \t\t: \tangular.noop;\r\n\t\t\t\tscope.onClose \t \t = \t(scope.onClose) \t ? scope.onClose \t\t: \tangular.noop;\r\n\r\n\r\n\t\t\t\t// If images populate dynamically, reset gallery\r\n\t\t\t\tvar imagesFirstWatch = true;\r\n\t\t\t\tscope.$watch('images', function(){\r\n\t\t\t\t\tif(imagesFirstWatch){\r\n\t\t\t\t\t\timagesFirstWatch = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if(scope.images.length) scope.setActiveImg(\r\n\t\t\t\t\t\tscope.images[scope.activeImageIndex || 0]\r\n\t\t\t\t\t);\r\n\t\t\t\t});\r\n\r\n\t\t\t\t// Watch index of visible/active image\r\n\t\t\t\t// If index changes, make sure to load/change image\r\n\t\t\t\tvar activeImageIndexFirstWatch = true;\r\n\t\t\t\tscope.$watch('activeImageIndex', function(newImgIndex){\r\n\t\t\t\t\tif(activeImageIndexFirstWatch){\r\n\t\t\t\t\t\tactiveImageIndexFirstWatch = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if(scope.images.length){\r\n\t\t\t\t\t\tscope.setActiveImg(\r\n\t\t\t\t\t\t\tscope.images[newImgIndex]\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t}\r\n\t\t\t\t});\r\n\r\n\t\t\t\t// Open modal automatically if inline\r\n\t\t\t\tscope.$watch('inline', function(){\r\n\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\tif(scope.inline) scope.methods.open();\r\n\t\t\t\t\t});\r\n\t\t\t\t});\r\n\t\t\t\t\r\n\r\n\t\t\t\t/***************************************************/\r\n\r\n\r\n\t\t\t\t/*\r\n\t\t\t\t *\tMethods\r\n\t\t\t\t**/\r\n\r\n\t\t\t\t// Open gallery modal\r\n\t\t\t\tscope.methods.open = function(imgIndex){\r\n\t\t\t\t\t// Open modal from an index if one passed\r\n\t\t\t\t\tscope.activeImageIndex = (imgIndex) ? imgIndex : 0;\r\n\r\n\t\t\t\t\tscope.opened = true; \r\n\r\n\t\t\t\t\t// call open event after transition\r\n\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\tscope.onOpen();\r\n\t\t\t\t\t}, 300);\r\n\t\t\t\t}\r\n\r\n\r\n\t\t\t\t// Close gallery modal\r\n\t\t\t\tscope.methods.close = function(){\r\n\t\t\t\t\tscope.opened = false; // Model closed\r\n\r\n\t\t\t\t\t// call close event after transition\r\n\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\tscope.onClose();\r\n\t\t\t\t\t\tscope.activeImageIndex = 0; // Reset index\r\n\t\t\t\t\t}, 300);\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Change image to next\r\n\t\t\t\tscope.methods.next = function(){\r\n\t\t\t\t\tif(scope.activeImageIndex == (scope.images.length - 1)){\r\n\t\t\t\t\t\tscope.activeImageIndex = 0;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse{\r\n\t\t\t\t\t\tscope.activeImageIndex = scope.activeImageIndex + 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Change image to prev\r\n\t\t\t\tscope.methods.prev = function(){\r\n\t\t\t\t\tif(scope.activeImageIndex == 0){\r\n\t\t\t\t\t\tscope.activeImageIndex = scope.images.length - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse{\r\n\t\t\t\t\t\tscope.activeImageIndex--;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\r\n\t\t\t\t// Close gallery on background click\r\n\t\t\t\tscope.backgroundClose = function(e){\r\n\t\t\t\t\tif(!scope.bgClose || scope.inline) return;\r\n\r\n\t\t\t\t\tvar noCloseClasses = [\r\n\t\t\t\t\t\t'galleria-image',\r\n\t\t\t\t\t\t'destroy-icons-container',\r\n\t\t\t\t\t\t'ext-url',\r\n\t\t\t\t\t\t'close',\r\n\t\t\t\t\t\t'next',\r\n\t\t\t\t\t\t'prev',\r\n\t\t\t\t\t\t'galleria-bubble'\r\n\t\t\t\t\t];\r\n\r\n\t\t\t\t\t// check if clicked element has a class that\r\n\t\t\t\t\t// belongs to `noCloseClasses`\r\n\t\t\t\t\tfor(var i = 0; i < e.target.classList.length; i++){\r\n\t\t\t\t\t\tif(noCloseClasses.indexOf(e.target.classList[i]) != -1){\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse{\r\n\t\t\t\t\t\t\tscope.methods.close();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\r\n\t\t\t\t/***************************************************/\r\n\r\n\r\n\t\t\t\t/*\r\n\t\t\t\t *\tUser interactions\r\n\t\t\t\t**/\r\n\r\n\t\t\t\t// Key events\r\n\t\t\t\t$document.bind('keyup', function(event){\r\n\t\t\t\t\t// If inline modal, do not interact\r\n\t\t\t\t\tif(scope.inline) return;\r\n\r\n\t\t\t\t\tif(event.which == keys.right || event.which == keys.enter){\r\n\t\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\t\tscope.methods.next();\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if(event.which == keys.left){\r\n\t\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\t\tscope.methods.prev();\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if(event.which == keys.esc){\r\n\t\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\t\tscope.methods.close();\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t}\r\n\t\t\t\t});\r\n\r\n\t\t\t\t// Swipe events\r\n\t\t\t\tif(window.Hammer){\r\n\t\t\t\t\tvar hammerElem = new Hammer(elem[0]);\r\n\t\t\t\t\thammerElem.on('swipeleft', function(ev){\r\n\t\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\t\tscope.methods.prev();\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t});\r\n\t\t\t\t\thammerElem.on('swiperight', function(ev){\r\n\t\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\t\tscope.methods.next();\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t});\r\n\t\t\t\t\thammerElem.on('doubletap', function(ev){\r\n\t\t\t\t\t\tif(scope.inline) return;\r\n\r\n\t\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\t\tscope.methods.close();\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}]);\r\n })();"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["ng-image-gallery.min.js"],"names":["keys","enter","esc","left","right","angular","module","directive","$timeout","$document","$q","replace","transclude","restrict","scope","images","methods","thumbnails","inline","bubbles","imgBubbles","bgClose","onOpen","onClose","template","link","elem","attr","showLoader","imgLoading","hideLoader","loadImg","imgObj","deferred","defer","hasOwnProperty","img","Image","src","url","onload","cached","resolve","promise","setActiveImg","then","activeImg","noop","imagesFirstWatch","$watch","length","activeImageIndex","activeImageIndexFirstWatch","newImgIndex","open","imgIndex","opened","close","next","prev","backgroundClose","e","noCloseClasses","i","target","classList","indexOf","bind","event","which","window","Hammer","hammerElem","on","ev"],"mappings":"CAAC,WACA,YAGA,IAAIA,IACHC,MAAQ,GACRC,IAAQ,GACRC,KAAQ,GACRC,MAAQ,GAGTC,SACCC,OAAO,+BAAgC,cACvCC,UAAU,kBAAmB,WAAY,YAAa,KAAM,SAASC,EAAUC,EAAWC,GAC1F,OACCC,SAAU,EACVC,YAAa,EACbC,SAAW,KACXC,OACCC,OAAa,IACbC,QAAa,KAEbC,WAAgB,KAChBC,OAAa,KACbC,QAAa,KACbC,WAAgB,KAChBC,QAAa,KAEbC,OAAa,KACbC,QAAa,MAEdC,SAAY,08DAsEZC,KAAO,SAASX,EAAOY,EAAMC,GAO5Bb,EAAMc,WAAa,WAClBd,EAAMe,YAAa,GAIpBf,EAAMgB,WAAa,WAClBhB,EAAMe,YAAa,GAIpBf,EAAMiB,QAAU,SAASC,GACxB,GAAIC,GAAYvB,EAAGwB,OAGfF,GAAOG,eAAe,WAAWrB,EAAMc,YAG3C,IAAIQ,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\t'use strict';\r\n\t\r\n\t// Key codes\r\n\tvar keys = {\r\n\t\tenter : 13,\r\n\t\tesc : 27,\r\n\t\tleft : 37,\r\n\t\tright : 39\r\n\t};\r\n\r\n\tangular\r\n\t.module('thatisuday.ng-image-gallery', ['ngAnimate'])\r\n\t.directive('ngImageGallery', ['$timeout', '$document', '$q', function($timeout, $document, $q){\r\n\t\treturn {\r\n\t\t\treplace : true,\r\n\t\t\ttransclude : false,\r\n\t\t\trestrict : 'AE',\r\n\t\t\tscope : {\r\n\t\t\t\timages \t\t\t: \t'=',\t\t// []\r\n\t\t\t\tmethods \t\t: \t'=?',\t\t// {}\r\n\r\n\t\t\t\tthumbnails \t\t: \t'=?',\t\t// true|false\r\n\t\t\t\tinline \t\t\t: \t'=?',\t\t// true|flase\r\n\t\t\t\tbubbles \t\t: \t'=?',\t\t// true|flase\r\n\t\t\t\timgBubbles \t\t: \t'=?',\t\t// true|flase\r\n\t\t\t\tbgClose \t\t: \t'=?',\t\t// true|flase\r\n\r\n\t\t\t\tonOpen \t\t\t: \t'&?',\t\t// function\r\n\t\t\t\tonClose \t\t: \t'&?'\t\t// function\r\n\t\t\t},\r\n\t\t\ttemplate : \t'
'+\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t// Thumbnails container\r\n\t\t\t\t\t\t\t// Hide for inline gallery\r\n\t\t\t\t\t\t\t''+\r\n\r\n\t\t\t\t\t\t\t// Modal container\r\n\t\t\t\t\t\t\t// (inline container for inline modal)\r\n\t\t\t\t\t\t\t''+\r\n\t\t\t\t\t\t'
',\r\n\t\t\t\t\t\t\r\n\t\t\tlink : function(scope, elem, attr){\r\n\t\t\t\t\r\n\t\t\t\t/*\r\n\t\t\t\t *\tOperational functions\r\n\t\t\t\t**/\r\n\r\n\t\t\t\t// Show gallery loader\r\n\t\t\t\tscope.showLoader = function(){\r\n\t\t\t\t\tscope.imgLoading = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Hide gallery loader\r\n\t\t\t\tscope.hideLoader = function(){\r\n\t\t\t\t\tscope.imgLoading = false;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Image load complete promise\r\n\t\t\t\tscope.loadImg = function(imgObj){\r\n\t\t\t\t\tvar deferred = $q.defer();\r\n\r\n\t\t\t\t\t// Show loder\r\n\t\t\t\t\tif(!imgObj.hasOwnProperty('cached')) scope.showLoader();\r\n\r\n\t\t\t\t\t// Process image\r\n\t\t\t\t\tvar img = new Image();\r\n\t\t\t\t\timg.src = imgObj.url;\r\n\t\t\t\t\timg.onload = function(){\r\n\t\t\t\t\t\t// Hide loder\r\n\t\t\t\t\t\tif(!imgObj.hasOwnProperty('cached')) scope.hideLoader();\r\n\r\n\t\t\t\t\t\t// Cache image\r\n\t\t\t\t\t\tif(!imgObj.hasOwnProperty('cached')) imgObj.cached = true;\r\n\r\n\t\t\t\t\t\treturn deferred.resolve(imgObj);\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\treturn deferred.promise;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tscope.setActiveImg = function(imgObj){\r\n\t\t\t\t\t// Load image\r\n\t\t\t\t\tscope.loadImg(imgObj).then(function(imgObj){\r\n\t\t\t\t\t\tscope.activeImg = imgObj;\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\r\n\r\n\t\t\t\t/***************************************************/\r\n\t\t\t\t\r\n\r\n\t\t\t\t/*\r\n\t\t\t\t *\tGallery settings\r\n\t\t\t\t**/\r\n\r\n\t\t\t\t// Modify scope models\r\n\t\t\t\tscope.images \t \t = \t(scope.images) \t\t ? scope.images \t\t: \t[];\r\n\t\t\t\tscope.methods \t \t = \t(scope.methods) \t ? scope.methods \t\t: \t{};\r\n\r\n\t\t\t\tscope.thumbnails \t = \t(scope.thumbnails) \t ? scope.thumbnails \t: \ttrue;\r\n\t\t\t\tscope.inline \t \t = \t(scope.inline) \t\t ? scope.inline \t\t: \tfalse;\r\n\t\t\t\tscope.bubbles \t \t = \t(scope.bubbles) \t ? scope.bubbles \t\t: \ttrue;\r\n\t\t\t\tscope.imgBubbles \t = \t(scope.imgBubbles) \t ? scope.imgBubbles \t: \tfalse;\r\n\t\t\t\tscope.bgClose \t \t = \t(scope.bgClose) \t ? scope.bgClose \t\t: \tfalse;\r\n\r\n\t\t\t\tscope.onOpen \t \t = \t(scope.onOpen) \t\t ? scope.onOpen \t\t: \tangular.noop;\r\n\t\t\t\tscope.onClose \t \t = \t(scope.onClose) \t ? scope.onClose \t\t: \tangular.noop;\r\n\r\n\r\n\t\t\t\t// If images populate dynamically, reset gallery\r\n\t\t\t\tvar imagesFirstWatch = true;\r\n\t\t\t\tscope.$watch('images', function(){\r\n\t\t\t\t\tif(imagesFirstWatch){\r\n\t\t\t\t\t\timagesFirstWatch = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if(scope.images.length) scope.setActiveImg(\r\n\t\t\t\t\t\tscope.images[scope.activeImageIndex || 0]\r\n\t\t\t\t\t);\r\n\t\t\t\t});\r\n\r\n\t\t\t\t// Watch index of visible/active image\r\n\t\t\t\t// If index changes, make sure to load/change image\r\n\t\t\t\tvar activeImageIndexFirstWatch = true;\r\n\t\t\t\tscope.$watch('activeImageIndex', function(newImgIndex){\r\n\t\t\t\t\tif(activeImageIndexFirstWatch){\r\n\t\t\t\t\t\tactiveImageIndexFirstWatch = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if(scope.images.length){\r\n\t\t\t\t\t\tscope.setActiveImg(\r\n\t\t\t\t\t\t\tscope.images[newImgIndex]\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t}\r\n\t\t\t\t});\r\n\r\n\t\t\t\t// Open modal automatically if inline\r\n\t\t\t\tscope.$watch('inline', function(){\r\n\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\tif(scope.inline) scope.methods.open();\r\n\t\t\t\t\t});\r\n\t\t\t\t});\r\n\t\t\t\t\r\n\r\n\t\t\t\t/***************************************************/\r\n\r\n\r\n\t\t\t\t/*\r\n\t\t\t\t *\tMethods\r\n\t\t\t\t**/\r\n\r\n\t\t\t\t// Open gallery modal\r\n\t\t\t\tscope.methods.open = function(imgIndex){\r\n\t\t\t\t\t// Open modal from an index if one passed\r\n\t\t\t\t\tscope.activeImageIndex = (imgIndex) ? imgIndex : 0;\r\n\r\n\t\t\t\t\tscope.opened = true; \r\n\r\n\t\t\t\t\t// call open event after transition\r\n\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\tscope.onOpen();\r\n\t\t\t\t\t}, 300);\r\n\t\t\t\t}\r\n\r\n\r\n\t\t\t\t// Close gallery modal\r\n\t\t\t\tscope.methods.close = function(){\r\n\t\t\t\t\tscope.opened = false; // Model closed\r\n\r\n\t\t\t\t\t// call close event after transition\r\n\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\tscope.onClose();\r\n\t\t\t\t\t\tscope.activeImageIndex = 0; // Reset index\r\n\t\t\t\t\t}, 300);\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Change image to next\r\n\t\t\t\tscope.methods.next = function(){\r\n\t\t\t\t\tif(scope.activeImageIndex == (scope.images.length - 1)){\r\n\t\t\t\t\t\tscope.activeImageIndex = 0;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse{\r\n\t\t\t\t\t\tscope.activeImageIndex = scope.activeImageIndex + 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Change image to prev\r\n\t\t\t\tscope.methods.prev = function(){\r\n\t\t\t\t\tif(scope.activeImageIndex == 0){\r\n\t\t\t\t\t\tscope.activeImageIndex = scope.images.length - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse{\r\n\t\t\t\t\t\tscope.activeImageIndex--;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\r\n\t\t\t\t// Close gallery on background click\r\n\t\t\t\tscope.backgroundClose = function(e){\r\n\t\t\t\t\tif(!scope.bgClose || scope.inline) return;\r\n\r\n\t\t\t\t\tvar noCloseClasses = [\r\n\t\t\t\t\t\t'galleria-image',\r\n\t\t\t\t\t\t'destroy-icons-container',\r\n\t\t\t\t\t\t'ext-url',\r\n\t\t\t\t\t\t'close',\r\n\t\t\t\t\t\t'next',\r\n\t\t\t\t\t\t'prev',\r\n\t\t\t\t\t\t'galleria-bubble'\r\n\t\t\t\t\t];\r\n\r\n\t\t\t\t\t// check if clicked element has a class that\r\n\t\t\t\t\t// belongs to `noCloseClasses`\r\n\t\t\t\t\tfor(var i = 0; i < e.target.classList.length; i++){\r\n\t\t\t\t\t\tif(noCloseClasses.indexOf(e.target.classList[i]) != -1){\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse{\r\n\t\t\t\t\t\t\tscope.methods.close();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\r\n\t\t\t\t/***************************************************/\r\n\r\n\r\n\t\t\t\t/*\r\n\t\t\t\t *\tUser interactions\r\n\t\t\t\t**/\r\n\r\n\t\t\t\t// Key events\r\n\t\t\t\t$document.bind('keyup', function(event){\r\n\t\t\t\t\t// If inline modal, do not interact\r\n\t\t\t\t\tif(scope.inline) return;\r\n\r\n\t\t\t\t\tif(event.which == keys.right || event.which == keys.enter){\r\n\t\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\t\tscope.methods.next();\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if(event.which == keys.left){\r\n\t\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\t\tscope.methods.prev();\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if(event.which == keys.esc){\r\n\t\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\t\tscope.methods.close();\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t}\r\n\t\t\t\t});\r\n\r\n\t\t\t\t// Swipe events\r\n\t\t\t\tif(window.Hammer){\r\n\t\t\t\t\tvar hammerElem = new Hammer(elem[0]);\r\n\t\t\t\t\thammerElem.on('swiperight', function(ev){\r\n\t\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\t\tscope.methods.prev();\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t});\r\n\t\t\t\t\thammerElem.on('swipeleft', function(ev){\r\n\t\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\t\tscope.methods.next();\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t});\r\n\t\t\t\t\thammerElem.on('doubletap', function(ev){\r\n\t\t\t\t\t\tif(scope.inline) return;\r\n\r\n\t\t\t\t\t\t$timeout(function(){\r\n\t\t\t\t\t\t\tscope.methods.close();\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}]);\r\n })();"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/ng-image-gallery.min.js.map.gz b/dist/ng-image-gallery.min.js.map.gz index 6df3ff0..f831380 100644 Binary files a/dist/ng-image-gallery.min.js.map.gz and b/dist/ng-image-gallery.min.js.map.gz differ diff --git a/src/js/directive.js b/src/js/directive.js index c8f2578..10ed131 100644 --- a/src/js/directive.js +++ b/src/js/directive.js @@ -312,12 +312,12 @@ // Swipe events if(window.Hammer){ var hammerElem = new Hammer(elem[0]); - hammerElem.on('swipeleft', function(ev){ + hammerElem.on('swiperight', function(ev){ $timeout(function(){ scope.methods.prev(); }); }); - hammerElem.on('swiperight', function(ev){ + hammerElem.on('swipeleft', function(ev){ $timeout(function(){ scope.methods.next(); });