ionic-angular
Version:
A powerful framework for building mobile and progressive web apps with JavaScript and Angular
66 lines • 2.24 kB
JavaScript
import { defaults } from '../util/util';
import { DIRECTION_HORIZONTAL, DIRECTION_VERTICAL, Hammer } from './hammer';
/**
* @hidden
* A gesture recognizer class.
*
* TODO(mlynch): Re-enable the DOM event simulation that was causing issues (or verify hammer does this already, it might);
*/
var Gesture = (function () {
function Gesture(element, opts) {
if (opts === void 0) { opts = {}; }
this._callbacks = {};
this.isListening = false;
defaults(opts, {
domEvents: true
});
this.element = element;
// Map 'x' or 'y' string to hammerjs opts
this.direction = opts.direction || 'x';
opts.direction = this.direction === 'x' ?
DIRECTION_HORIZONTAL :
DIRECTION_VERTICAL;
this._options = opts;
}
Gesture.prototype.options = function (opts) {
Object.assign(this._options, opts);
};
Gesture.prototype.on = function (type, cb) {
if (type === 'pinch' || type === 'rotate') {
this._hammer.get(type).set({ enable: true });
}
this._hammer.on(type, cb);
(this._callbacks[type] || (this._callbacks[type] = [])).push(cb);
};
Gesture.prototype.off = function (type, cb) {
this._hammer.off(type, this._callbacks[type] ? cb : null);
};
Gesture.prototype.listen = function () {
if (!this.isListening) {
this._hammer = Hammer(this.element, this._options);
}
this.isListening = true;
};
Gesture.prototype.unlisten = function () {
var eventType;
var i;
if (this._hammer && this.isListening) {
for (eventType in this._callbacks) {
for (i = 0; i < this._callbacks[eventType].length; i++) {
this._hammer.off(eventType, this._callbacks[eventType]);
}
}
this._hammer.destroy();
}
this._callbacks = {};
this._hammer = null;
this.isListening = false;
};
Gesture.prototype.destroy = function () {
this.unlisten();
this.element = this._options = null;
};
return Gesture;
}());
export { Gesture };
//# sourceMappingURL=gesture.js.map