mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
feat($ionicSlideBoxDelegate): add enableSlide(true/false) method
Closes #1122
This commit is contained in:
7
js/angular/service/slideBoxDelegate.js
vendored
7
js/angular/service/slideBoxDelegate.js
vendored
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user