Skip to content

Commit

Permalink
feat($ionicSlideBoxDelegate): add enableSlide(true/false) method
Browse files Browse the repository at this point in the history
Closes #1122
  • Loading branch information
ajoslin committed Apr 30, 2014
1 parent 793b9f4 commit e003bf1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 7 additions & 0 deletions js/angular/service/slideBoxDelegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions js/views/sliderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e003bf1

Please sign in to comment.