File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Injectable } from '@angular/core' ;
2+ import { MdGestureConfig } from '../../core/gestures/MdGestureConfig' ;
3+ // import {MdGestureConfig} from '@angular2-material/core/gestures/MdGestureConfig';
4+
5+ /**
6+ * To test the dragging behavior on the slider, we need to be able to access the hammer instances
7+ * to emit events for a drag.
8+ *
9+ */
10+ @Injectable ( )
11+ export class TestGestureConfig extends MdGestureConfig {
12+ /**
13+ * A map of Hammer instances to element.
14+ * Used to emit events over instances for an element.
15+ */
16+ hammerInstances : Map < HTMLElement , HammerManager [ ] > = new Map < HTMLElement , HammerManager [ ] > ( ) ;
17+
18+ /**
19+ * Create a mapping of Hammer instances to element so that events can be emitted during testing.
20+ */
21+ buildHammer ( element : HTMLElement ) {
22+ let mc = super . buildHammer ( element ) ;
23+
24+ if ( ! this . hammerInstances . get ( element ) ) {
25+ this . hammerInstances . set ( element , [ mc ] ) ;
26+ } else {
27+ this . hammerInstances . get ( element ) . push ( mc ) ;
28+ }
29+
30+ return mc ;
31+ }
32+
33+ /**
34+ * Hammer creates a new instance for every listener so we need to apply our event on all instances
35+ * to hit the correct listener.
36+ */
37+ emitEventForElement ( eventType : string , element : HTMLElement , eventData : Object ) {
38+ let instances = this . hammerInstances . get ( element ) ;
39+ instances . forEach ( instance => instance . emit ( eventType , eventData ) ) ;
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments