mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Activator: activated
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
import {Directive, ElementRef, Optional, Host, onDestroy, NgZone, Query, QueryList} from 'angular2/angular2';
|
||||
import {Directive} from 'angular2/angular2';
|
||||
|
||||
import {Icon} from '../icon/icon';
|
||||
import {IonicConfig} from '../../config/config';
|
||||
import {Activator} from '../../util/activator';
|
||||
import * as dom from '../../util/dom';
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -17,9 +13,7 @@ import * as dom from '../../util/dom';
|
||||
}
|
||||
})
|
||||
export class Button {
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
|
||||
constructor() {
|
||||
this.iconLeft = this.iconRight = this.iconOnly = false;
|
||||
}
|
||||
@@ -34,190 +28,3 @@ export class Button {
|
||||
this.iconOnly = icon.iconOnly;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
@Directive({
|
||||
selector: '[tap-disabled]'
|
||||
})
|
||||
export class TapDisabled {}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
@Directive({
|
||||
selector: 'button,[button],[tappable],ion-checkbox,ion-radio',
|
||||
host: {
|
||||
'(^touchstart)': 'touchStart($event)',
|
||||
'(^touchend)': 'touchEnd($event)',
|
||||
'(^touchcancel)': 'pointerCancel()',
|
||||
'(^mousedown)': 'mouseDown($event)',
|
||||
'(^mouseup)': 'mouseUp($event)',
|
||||
'(^click)': 'click($event)',
|
||||
}
|
||||
})
|
||||
export class TapClick {
|
||||
/**
|
||||
* TODO
|
||||
* @param {ElementRef} elementRef TODO
|
||||
* @param {IonicConfig} config TODO
|
||||
* @param {NgZone} ngZone TODO
|
||||
* @param {TapDisabled=} tapDisabled TODO
|
||||
*/
|
||||
constructor(
|
||||
elementRef: ElementRef,
|
||||
config: IonicConfig,
|
||||
ngZone: NgZone,
|
||||
@Optional() @Host() tapDisabled: TapDisabled
|
||||
) {
|
||||
this.ele = elementRef.nativeElement;
|
||||
this.tapEnabled = !tapDisabled;
|
||||
this.tapPolyfill = config.setting('tapPolyfill');
|
||||
this.zone = ngZone;
|
||||
|
||||
let self = this;
|
||||
self.pointerMove = function(ev) {
|
||||
let moveCoord = dom.pointerCoord(ev);
|
||||
console.log('pointerMove', moveCoord, self.start)
|
||||
|
||||
if ( dom.hasPointerMoved(10, self.start, moveCoord) ) {
|
||||
self.pointerCancel();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param {TODO} ev TODO
|
||||
*/
|
||||
touchStart(ev) {
|
||||
this.pointerStart(ev);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param {TODO} ev TODO
|
||||
*/
|
||||
touchEnd(ev) {
|
||||
let self = this;
|
||||
|
||||
if (this.tapPolyfill && this.tapEnabled) {
|
||||
|
||||
let endCoord = dom.pointerCoord(ev);
|
||||
|
||||
this.disableClick = true;
|
||||
this.zone.runOutsideAngular(() => {
|
||||
clearTimeout(self.disableTimer);
|
||||
self.disableTimer = setTimeout(() => {
|
||||
self.disableClick = false;
|
||||
}, 600);
|
||||
});
|
||||
|
||||
if ( this.start && !dom.hasPointerMoved(3, this.start, endCoord) ) {
|
||||
let clickEvent = document.createEvent('MouseEvents');
|
||||
clickEvent.initMouseEvent('click', true, true, window, 1, 0, 0, endCoord.x, endCoord.y, false, false, false, false, 0, null);
|
||||
clickEvent.isIonicTap = true;
|
||||
this.ele.dispatchEvent(clickEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.pointerEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param {TODO} ev TODO
|
||||
*/
|
||||
mouseDown(ev) {
|
||||
if (this.disableClick) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
} else {
|
||||
this.pointerStart(ev);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param {TODO} ev TODO
|
||||
*/
|
||||
mouseUp(ev) {
|
||||
if (this.disableClick) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
}
|
||||
|
||||
this.pointerEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param {TODO} ev TODO
|
||||
*/
|
||||
pointerStart(ev) {
|
||||
this.start = dom.pointerCoord(ev);
|
||||
|
||||
this.zone.runOutsideAngular(() => {
|
||||
Activator.start(ev.currentTarget);
|
||||
Activator.moveListeners(this.pointerMove, true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
pointerEnd() {
|
||||
this.zone.runOutsideAngular(() => {
|
||||
Activator.end();
|
||||
Activator.moveListeners(this.pointerMove, false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
pointerCancel() {
|
||||
this.start = null;
|
||||
|
||||
this.zone.runOutsideAngular(() => {
|
||||
Activator.clear();
|
||||
Activator.moveListeners(this.pointerMove, false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the supplied click event should be allowed or not.
|
||||
* @param {MouseEvent} ev The click event.
|
||||
* @return {boolean} True if click event should be allowed, otherwise false.
|
||||
*/
|
||||
allowClick(ev) {
|
||||
if (!ev.isIonicTap) {
|
||||
if (this.disableClick || !this.start) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param {MouseEvent} ev TODO
|
||||
*/
|
||||
click(ev) {
|
||||
if (!this.allowClick(ev)) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
onDestroy() {
|
||||
this.ele = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user