Skip to content
This repository was archived by the owner on May 4, 2022. It is now read-only.

Commit 43b8b4a

Browse files
committed
TapClick for a,button
1 parent fe5ce7b commit 43b8b4a

File tree

12 files changed

+77
-612
lines changed

12 files changed

+77
-612
lines changed

ionic/components.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
export * from 'ionic/components/app/app'
33
export * from 'ionic/components/action-menu/action-menu'
44
export * from 'ionic/components/aside/aside'
5+
export * from 'ionic/components/button/button'
56
export * from 'ionic/components/checkbox/checkbox'
67
export * from 'ionic/components/content/content'
78
export * from 'ionic/components/icon/icon'
89
export * from 'ionic/components/item/item'
910
export * from 'ionic/components/item/item-group'
10-
export * from 'ionic/components/form/form'
11+
export * from 'ionic/components/form/input'
1112
export * from 'ionic/components/form/text-input'
1213
export * from 'ionic/components/form/tap-input'
1314
export * from 'ionic/components/form/label'

ionic/components/action-menu/action-menu.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
import {View, Injectable, NgFor, NgIf} from 'angular2/angular2';
1010

11+
import {TapClick} from '../button/button';
1112
import {Overlay} from '../overlay/overlay';
1213
import {Animation} from '../../animations/animation';
1314
import * as util from 'ionic/util';
1415

1516

1617
@View({
1718
template: `
18-
<div class="action-menu-backdrop" (click)="_cancel()"></div>
19+
<div class="action-menu-backdrop" (click)="_cancel()" tappable></div>
1920
<div class="action-menu-wrapper">
2021
<div class="action-menu-container">
2122
<div class="action-menu-group action-menu-options">
@@ -28,7 +29,7 @@ import * as util from 'ionic/util';
2829
</div>
2930
</div>
3031
</div>`,
31-
directives: [NgFor, NgIf]
32+
directives: [NgFor, NgIf, TapClick]
3233
})
3334
class ActionMenuDirective {
3435

ionic/components/button/button.ts

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {Directive, ElementRef, Optional, Ancestor} from 'angular2/angular2';
2+
3+
import {IonicConfig} from '../../config/config';
4+
import {Gesture} from '../../gestures/gesture';
5+
import * as dom from '../../util/dom';
6+
7+
8+
@Directive({
9+
selector: '[tap-disabled]'
10+
})
11+
export class TapDisabled {}
12+
13+
14+
@Directive({
15+
selector: 'a,button,[tappable]'
16+
})
17+
export class TapClick {
18+
19+
constructor(
20+
elementRef: ElementRef,
21+
config: IonicConfig,
22+
@Optional() @Ancestor() tapDisabled: TapDisabled
23+
) {
24+
25+
if (config.setting('tapPolyfill') && !this.tapGesture && !tapDisabled) {
26+
this.tapGesture = new Gesture(elementRef.nativeElement);
27+
this.tapGesture.listen();
28+
29+
this.tapGesture.on('tap', (gestureEv) => {
30+
this.onTap(gestureEv.gesture.srcEvent);
31+
});
32+
}
33+
34+
}
35+
36+
onTap(ev) {
37+
if (ev && this.tapGesture) {
38+
ev.preventDefault();
39+
ev.stopPropagation();
40+
41+
let c = dom.pointerCoord(ev);
42+
43+
let clickEvent = document.createEvent("MouseEvents");
44+
clickEvent.initMouseEvent('click', true, true, window, 1, 0, 0, c.x, c.y, false, false, false, false, 0, null);
45+
clickEvent.isIonicTap = true;
46+
this.tapGesture.element.dispatchEvent(clickEvent);
47+
}
48+
}
49+
50+
onDestroy() {
51+
this.tapGesture && this.tapGesture.destroy();
52+
}
53+
54+
}

ionic/components/checkbox/checkbox.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from 'angular2/angular2';
99

1010
import {Ion} from '../ion';
11-
import {IonInputItem} from '../form/form';
11+
import {IonInputItem} from '../form/input';
1212
import {IonicConfig} from '../../config/config';
1313
import {IonicComponent, IonicView} from '../../config/annotations';
1414
import {Icon} from '../icon/icon';

ionic/components/form/focus-holder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Component, Directive, View, Parent, ElementRef, forwardRef} from 'angula
33
import {IonicConfig} from '../../config/config';
44
import * as dom from '../../util/dom';
55
import {Platform} from '../../platform/platform';
6-
import {IonInput} from './form';
6+
import {IonInput} from './input';
77

88

99
@Component({

ionic/components/form/tap-input.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Parent, Ancestor, Optional, ElementRef, Attribute, Directive} from 'angular2/angular2';
22

3-
import {IonInput} from './form';
3+
import {IonInput} from './input';
44
import {IonicApp} from '../app/app';
55
import {IonicConfig} from '../../config/config';
66
import {Content} from '../content/content';

ionic/components/form/text-input.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Directive, View, Parent, Ancestor, Optional, ElementRef, Attribute, forw
22

33
import {IonicDirective} from '../../config/annotations';
44
import {IonicConfig} from '../../config/config';
5-
import {IonInput, IonInputItem} from './form';
5+
import {IonInput, IonInputItem} from './input';
66
import {IonicApp} from '../app/app';
77
import {Content} from '../content/content';
88
import {ClickBlock} from '../../util/click-block';

ionic/components/nav/swipe-handle.ts

+4
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,8 @@ export class SwipeHandle {
9393
return (this.viewCtrl ? this.viewCtrl.swipeBackEnabled() : false);
9494
}
9595

96+
onDestroy() {
97+
this.gesture && self.gesture.destroy();
98+
}
99+
96100
}

ionic/config/annotations.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
Segment, SegmentButton, SegmentControlValueAccessor,
1717
RadioGroup, RadioButton, SearchBar,
1818
Nav, NavbarTemplate, Navbar, NavPush, NavPop,
19+
TapClick, TapDisabled,
1920
Register
2021
} from '../ionic';
2122

@@ -71,7 +72,11 @@ export const IonicDirectives = [
7172
forwardRef(() => Navbar),
7273
forwardRef(() => NavPush),
7374
forwardRef(() => NavPop),
74-
forwardRef(() => Register)
75+
forwardRef(() => Register),
76+
77+
// Gestures
78+
forwardRef(() => TapClick),
79+
forwardRef(() => TapDisabled),
7580
];
7681

7782
class IonicViewImpl extends View {

ionic/gestures/gesture.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as util from 'ionic/util';
22
import {Hammer} from 'ionic/gestures/hammer';
33

4+
45
export class Gesture {
56
constructor(element, opts = {}) {
67
util.defaults(opts, {
@@ -18,6 +19,7 @@ export class Gesture {
1819
this._callbacks = {};
1920

2021
}
22+
2123
options(opts = {}) {
2224
util.extend(this._options, opts);
2325
}
@@ -31,6 +33,7 @@ export class Gesture {
3133
listen() {
3234
this.hammertime = Hammer(this.element, this._options);
3335
}
36+
3437
unlisten() {
3538
this.hammertime.destroy();
3639
this.hammertime = null;
@@ -41,6 +44,7 @@ export class Gesture {
4144
}
4245
this._callbacks = {}
4346
}
47+
4448
destroy() {
4549
this.unlisten()
4650
}

ionic/ionic.ts

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export * from 'ionic/routing/url-state'
1616

1717
export * from 'ionic/util/click-block'
1818
export * from 'ionic/util/focus'
19-
export * from 'ionic/util/tap'
2019

2120
export * from 'ionic/animations/animation'
2221
export * from 'ionic/animations/builtins'

0 commit comments

Comments
 (0)