diff --git a/js/angular/service/slideBoxDelegate.js b/js/angular/service/slideBoxDelegate.js index 7d0b29d6648..a066c4f8d3b 100644 --- a/js/angular/service/slideBoxDelegate.js +++ b/js/angular/service/slideBoxDelegate.js @@ -52,6 +52,13 @@ IonicModule * @param {number=} speed The number of milliseconds for the change to take. */ 'slide', + /** + * @ngdoc method + * @name $ionicSlideBoxDelegate#enableSlide + * @param {boolean=} shouldEnable Whether to enable sliding the slidebox. + * @returns {boolean} Whether sliding is enabled. + */ + 'enableSlide', /** * @ngdoc method * @name $ionicSlideBoxDelegate#previous diff --git a/js/views/sliderView.js b/js/views/sliderView.js index 59e06ead280..a4910741556 100644 --- a/js/views/sliderView.js +++ b/js/views/sliderView.js @@ -11,6 +11,8 @@ ionic.views.Slider = ionic.views.View.inherit({ initialize: function (options) { + var slider = this; + // utilities var noop = function() {}; // simple no operation function var offloadFn = function(fn) { setTimeout(fn || noop, 0) }; // offload a functions execution @@ -254,8 +256,8 @@ ionic.views.Slider = ionic.views.View.inherit({ switch (event.type) { case 'mousedown': this.start(event); break; case 'touchstart': this.start(event); break; - case 'touchmove': this.move(event); break; - case 'mousemove': this.move(event); break; + case 'touchmove': this.touchmove(event); break; + case 'mousemove': this.touchmove(event); break; case 'touchend': offloadFn(this.end(event)); break; case 'mouseup': offloadFn(this.end(event)); break; case 'webkitTransitionEnd': @@ -301,10 +303,15 @@ ionic.views.Slider = ionic.views.View.inherit({ document.addEventListener('mouseup', this, false); } }, - move: function(event) { + touchmove: function(event) { // ensure swiping with one touch and not pinching - if ( event.touches.length > 1 || event.scale && event.scale !== 1) return + // ensure sliding is enabled + if (event.touches.length > 1 || + event.scale && event.scale !== 1 || + slider.slideIsDisabled) { + return; + } if (options.disableScroll) event.preventDefault(); @@ -468,6 +475,12 @@ ionic.views.Slider = ionic.views.View.inherit({ setup(); }; + this.enableSlide = function(shouldEnable) { + if (arguments.length) { + this.slideIsDisabled = !shouldEnable; + } + return !this.slideIsDisabled; + }, this.slide = function(to, speed) { // cancel slideshow stop();