diff --git a/angular-carousel.js b/angular-carousel.js
index 6dbc9b5..5c897b9 100644
--- a/angular-carousel.js
+++ b/angular-carousel.js
@@ -166,7 +166,8 @@ angular.module('angular-carousel', [])
restrict: 'AE',
replace: true,
scope: {
- ngCarouselWatch: '='
+ ngCarouselWatch: '=',
+ ngCarousalNoDrag: '='
},
link: function(scope, element, attrs) {
// Options
@@ -271,8 +272,10 @@ angular.module('angular-carousel', [])
setNextSlideTimeout();
refreshVirtualSlides();
- };
- currentCarousel.onSlideChange(onSlideChangeCallback);
+ };
+ if(currentCarousel && currentCarousel.onSlideChange) {
+ currentCarousel.onSlideChange(onSlideChangeCallback);
+ }
// If new slide was out of range, move to the new assigned one
if(savedSlideIndex !== false && currentCarousel.currentSlide !== savedSlideIndex) {
@@ -301,7 +304,7 @@ angular.module('angular-carousel', [])
// On pan left/right
hammer.on("panleft panright", function(ev) {
- if(!ev.isFinal) carouselDrag(ev.deltaX);
+ if(!ev.isFinal && attrs.ngCarousalNoDrag !== 'true') carouselDrag(ev.deltaX);
});
} else {
console.log('ng-carousel error: No slidecontainer found')
@@ -353,7 +356,9 @@ angular.module('angular-carousel', [])
move(currentCarousel.currentSlide + 1 - deltaXFactor, false);
};
var carouselPress = function() {
- width = slideContainer[0].offsetWidth;
+ if(slideContainer && slideContainer[0]) {
+ width = slideContainer[0].offsetWidth;
+ }
};
var carouselRelease = function() {
if(Math.abs(deltaXFactor) > MOVE_TRESHOLD_PERCENTAGE / 100) {
@@ -396,11 +401,17 @@ angular.module('angular-carousel', [])
// Destroy all binded events on scope destroy
scope.$on('$destroy', function() {
$timeout.cancel(refreshInteractionWithDomTimer);
- element.off('mouseover mouseout');
+ if(element) {
+ element.off('mouseover mouseout');
+ }
$document.off(pressEvent);
- $document.off(releaseEvent);
- slideContainer.off('transitionend oTransitionEnd webkitTransitionEnd');
- currentCarousel.onSlideChangeCallbacks = [];
+ $document.off(releaseEvent);
+ if(slideContainer) {
+ slideContainer.off('transitionend oTransitionEnd webkitTransitionEnd');
+ }
+ if(currentCarousel && typeof currentCarousel === "object") {
+ currentCarousel.onSlideChangeCallbacks = [];
+ }
Carousel.remove(name);
});
diff --git a/angular-carousel.min.js b/angular-carousel.min.js
index 78764ec..f279189 100644
--- a/angular-carousel.min.js
+++ b/angular-carousel.min.js
@@ -1,6 +1,6 @@
/**
- * @license AngularJS v1.2.0
- * (c) 2015 Lifely
+ * @license AngularJS v1.2.6
+ * (c) 2015 Ashiv Gupta
* License: MIT
*/
-angular.module("angular-carousel",[]).factory("Carousel",function(){var n={};n.instances={},n.add=function(o,t,i,a){if(t=t||!1,!t)return"Error: no carousel name specified";o=o||0;var r=n.instances[t]||!1;if(r)return"Error: carousel instance already exists";var s=new e(o,i,a);return n.instances[t]=s,s},n.get=function(e){var o=n.instances[e]||!1;return o?o:"Error: carousel with name '"+e+"' does not exist"},n.remove=function(e){delete n.instances[e]};var e=function(n,e,o){o=o||{},"undefined"==typeof o.looping&&(o.looping=!0);var t=this;this.slidesCount=n,this.currentSlide=0,this.onSlideChangeCallbacks=[],this.toIndex=function(n,o){o=o||!1,this.currentSlide=n%this.slidesCount,angular.forEach(this.onSlideChangeCallbacks,function(n){"function"==typeof n&&n(t.currentSlide,o)}),setTimeout(function(){e.$apply()},0)},this.next=function(){var n=this.currentSlide+1,e=!1;return n>this.slidesCount-1&&(o.looping?(n=0,e="right"):n=this.slidesCount-1),this.toIndex(n,e),n},this.previous=function(){var n=this.currentSlide-1,e=!1;return 0>n&&(o.looping?(n=this.slidesCount-1,e="left"):n=0),this.toIndex(n,e),n},this.onSlideChange=function(n){return this.onSlideChangeCallbacks.push(n),this.onSlideChangeCallbacks.indexOf(n)},this.unbindOnSlideChangeCallback=function(n){"undefined"!=typeof this.onSlideChangeCallbacks[n]&&this.onSlideChangeCallbacks.splice(n,1)}};return n}).directive("ngCarousel",["Carousel","$compile","$document","$timeout",function(n,e,o,t){function i(){return"ontouchstart"in document.documentElement}var a=25;return{restrict:"AE",replace:!0,scope:{ngCarouselWatch:"="},link:function(e,r,s){function l(){p=angular.element(C[0].outerHTML),v=angular.element(C[C.length-1].outerHTML)}function u(){p=angular.element(''),v=angular.element('')}var c=!1,d=!1,f=!1,h="",g=!1;c="undefined"!=typeof s.ngCarouselTimer&&parseInt(s.ngCarouselTimer,10)>0?parseInt(s.ngCarouselTimer,10):!1,f="undefined"!=typeof s.ngCarouselRandom,g=!("false"===s.ngCarouselLoop);var C,m,p,v,S,b,h,y=function(){r.addClass("ng-carousel"),r.addClass(i()?"carousel-touch":"carousel-no-touch"),S=r.find("slidecontainer");var o=!1,t=!1;h&&(o=n.get(h).currentSlide,t=n.get(h).onSlideChangeCallbacks,n.remove(h));var a=function(){var n=angular.element(r[0].querySelectorAll(".carousel-slide-copy"));n.length>0&&n.remove()};if(a(),C=r.find("slide"),C.length>0){h=s.ngCarouselName,m=n.add(C.length,s.ngCarouselName,e,{looping:g}),angular.forEach(t,function(n){m.onSlideChange(n),m.unbindOnSlideChangeCallback(0)});var d=function(){a(),C=r.find("slide"),g?l():u(),p.addClass("carousel-slide-copy"),v.addClass("carousel-slide-copy"),S.append(p),S.prepend(v),S.addClass("carousel-ignore-first-slide")};d();var y=function(n,e){var o=n+1;"left"===e?o=0:"right"===e&&(o=C.length+1),E(o,!0,function(){"left"===e?E(C.length,!1):"right"===e&&E(1,!1)}),k(),d()};if(m.onSlideChange(y),o!==!1&&m.currentSlide!==o&&(y(m.currentSlide,!1),m.toIndex(o)),f){var T=Math.floor(Math.random()*m.slidesCount);m.toIndex(T)}c&&m.slidesCount>=2&&k()}else console.log("ng-carousel error: No slides found");S[0]?(b=new Hammer.Manager(S[0]),b.add(new Hammer.Pan({direction:Hammer.DIRECTION_HORIZONTAL,threshold:0})),b.on("panleft panright",function(n){n.isFinal||w(n.deltaX)})):console.log("ng-carousel error: No slidecontainer found")},k=function(){!c||m.slidesCount<2||(d&&t.cancel(d),d=t(function(){m.next()},c))},E=function(n,e,o){e?S.addClass("carousel-animate"):S.removeClass("carousel-animate");var t="translate(-"+100*n+"%, 0)";S.css({"-webkit-transform":t,"-moz-transform":t,"-ms-transform":t,"-o-transform":t,transform:t}),e&&S.on("transitionend oTransitionEnd webkitTransitionEnd",function(){"function"==typeof o&&o(),S.off("transitionend oTransitionEnd webkitTransitionEnd"),E(m.currentSlide+1,!1)})},T=0,x=0,w=function(n){T=n/x,T=T>1?1:-1>T?-1:T,E(m.currentSlide+1-T,!1)},I=function(){x=S[0].offsetWidth},$=function(){Math.abs(T)>a/100?(T>0?m.previous():m.next(),T=0):(T>0||0>T)&&E(m.currentSlide+1,!0,function(){T=0})},H=i()?"touchstart":"mousedown",M=i()?"touchend":"mouseup";o.on(H,I),o.on(M,$),r.on("mouseover",function(){d&&t.cancel(d)}),r.on("mouseout",k);var N=t(y,0);"undefined"!=typeof s.ngCarouselWatch&&e.$watch("ngCarouselWatch",function(){t(y)},!0),e.$on("$destroy",function(){t.cancel(N),r.off("mouseover mouseout"),o.off(H),o.off(M),S.off("transitionend oTransitionEnd webkitTransitionEnd"),m.onSlideChangeCallbacks=[],n.remove(h)})}}}]);
+angular.module("angular-carousel",[]).factory("Carousel",function(){var i={instances:{},add:function(n,e,o,t){if(!(e=e||!1))return"Error: no carousel name specified";if(n=n||0,i.instances[e]||!1)return"Error: carousel instance already exists";var a=new r(n,o,t);return i.instances[e]=a},get:function(n){var e=i.instances[n]||!1;return e||"Error: carousel with name '"+n+"' does not exist"},remove:function(n){delete i.instances[n]}},r=function(n,o,t){void 0===(t=t||{}).looping&&(t.looping=!0);var a=this;this.slidesCount=n,this.currentSlide=0,this.onSlideChangeCallbacks=[],this.toIndex=function(n,e){e=e||!1,this.currentSlide=n%this.slidesCount,angular.forEach(this.onSlideChangeCallbacks,function(n){"function"==typeof n&&n(a.currentSlide,e)}),setTimeout(function(){o.$apply()},0)},this.next=function(){var n=this.currentSlide+1,e=!1;return n>this.slidesCount-1&&(t.looping?(n=0,e="right"):n=this.slidesCount-1),this.toIndex(n,e),n},this.previous=function(){var n=this.currentSlide-1,e=!1;return n<0&&(t.looping?(n=this.slidesCount-1,e="left"):n=0),this.toIndex(n,e),n},this.onSlideChange=function(n){return this.onSlideChangeCallbacks.push(n),this.onSlideChangeCallbacks.indexOf(n)},this.unbindOnSlideChangeCallback=function(n){void 0!==this.onSlideChangeCallbacks[n]&&this.onSlideChangeCallbacks.splice(n,1)}};return i}).directive("ngCarousel",["Carousel","$compile","$document","$timeout",function(T,n,y,x){function w(){return"ontouchstart"in document.documentElement}return{restrict:"AE",replace:!0,scope:{ngCarouselWatch:"=",ngCarousalNoDrag:"="},link:function(r,s,l){var u,c,d,f,h,g,C,m,p,n=!1,v="";u=void 0!==l.ngCarouselTimer&&0'),angular.element('')),g.addClass("carousel-slide-copy"),C.addClass("carousel-slide-copy"),m.append(g),m.prepend(C),m.addClass("carousel-ignore-first-slide")}t();function a(n,e){var o=n+1;"left"===e?o=0:"right"===e&&(o=f.length+1),b(o,!0,function(){"left"===e?b(f.length,!1):"right"===e&&b(1,!1)}),S(),t()}if(h&&h.onSlideChange&&h.onSlideChange(a),!1!==n&&h.currentSlide!==n&&(a(h.currentSlide,!1),h.toIndex(n)),c){var i=Math.floor(Math.random()*h.slidesCount);h.toIndex(i)}u&&2<=h.slidesCount&&S()}else console.log("ng-carousel error: No slides found");m[0]?((p=new Hammer.Manager(m[0])).add(new Hammer.Pan({direction:Hammer.DIRECTION_HORIZONTAL,threshold:0})),p.on("panleft panright",function(n){n.isFinal||"true"===l.ngCarousalNoDrag||k(n.deltaX)})):console.log("ng-carousel error: No slidecontainer found")}var S=function(){!u||h.slidesCount<2||(n&&x.cancel(n),n=x(function(){h.next()},u))},b=function(n,e,o){e?m.addClass("carousel-animate"):m.removeClass("carousel-animate");var t="translate(-"+100*n+"%, 0)";m.css({"-webkit-transform":t,"-moz-transform":t,"-ms-transform":t,"-o-transform":t,transform:t}),e&&m.on("transitionend oTransitionEnd webkitTransitionEnd",function(){"function"==typeof o&&o(),m.off("transitionend oTransitionEnd webkitTransitionEnd"),b(h.currentSlide+1,!1)})},o=0,t=0,k=function(n){o=1<(o=n/t)?1:o<-1?-1:o,b(h.currentSlide+1-o,!1)},a=w()?"touchstart":"mousedown",i=w()?"touchend":"mouseup";y.on(a,function(){m&&m[0]&&(t=m[0].offsetWidth)}),y.on(i,function(){.25