UNPKG

@angular2-material/core

Version:
85 lines (83 loc) 3.94 kB
var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Injectable } from '@angular/core'; import { HammerGestureConfig } from '@angular/platform-browser'; /* Adjusts configuration of our gesture library, Hammer. */ export var MdGestureConfig = (function (_super) { __extends(MdGestureConfig, _super); function MdGestureConfig() { _super.apply(this, arguments); /* List of new event names to add to the gesture support list */ this.events = [ 'drag', 'dragstart', 'dragend', 'dragright', 'dragleft', 'longpress', 'slide', 'slidestart', 'slideend', 'slideright', 'slideleft' ]; } /* * Builds Hammer instance manually to add custom recognizers that match the Material Design spec. * * Our gesture names come from the Material Design gestures spec: * https://www.google.com/design/spec/patterns/gestures.html#gestures-touch-mechanics * * More information on default recognizers can be found in Hammer docs: * http://hammerjs.github.io/recognizer-pan/ * http://hammerjs.github.io/recognizer-press/ * * TODO: Confirm threshold numbers with Material Design UX Team * */ MdGestureConfig.prototype.buildHammer = function (element) { var mc = new Hammer(element); // Default Hammer Recognizers. var pan = new Hammer.Pan(); var swipe = new Hammer.Swipe(); var press = new Hammer.Press(); // Notice that a HammerJS recognizer can only depend on one other recognizer once. // Otherwise the previous `recognizeWith` will be dropped. var slide = this._createRecognizer(pan, { event: 'slide', threshold: 0 }, swipe); var drag = this._createRecognizer(slide, { event: 'drag', threshold: 6 }, swipe); var longpress = this._createRecognizer(press, { event: 'longpress', time: 500 }); // Overwrite the default `pan` event to use the swipe event. pan.recognizeWith(swipe); // Add customized gestures to Hammer manager mc.add([swipe, press, pan, drag, slide, longpress]); return mc; }; /** Creates a new recognizer, without affecting the default recognizers of HammerJS */ MdGestureConfig.prototype._createRecognizer = function (base, options) { var inheritances = []; for (var _i = 2; _i < arguments.length; _i++) { inheritances[_i - 2] = arguments[_i]; } var recognizer = new base.constructor(options); inheritances.push(base); inheritances.forEach(function (item) { return recognizer.recognizeWith(item); }); return recognizer; }; MdGestureConfig = __decorate([ Injectable(), __metadata('design:paramtypes', []) ], MdGestureConfig); return MdGestureConfig; }(HammerGestureConfig)); //# sourceMappingURL=MdGestureConfig.js.map