mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
the activator
This commit is contained in:
61
ionic/util/activator.ts
Normal file
61
ionic/util/activator.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import {raf} from './dom';
|
||||
|
||||
var queueElements = {}; // elements that should get an active state in XX milliseconds
|
||||
var activeElements = {}; // elements that are currently active
|
||||
var keyId = 0; // a counter for unique keys for the above ojects
|
||||
var ACTIVATED_CLASS = 'activated';
|
||||
var DEACTIVATE_TIMEOUT = 180;
|
||||
|
||||
|
||||
export class Activator {
|
||||
|
||||
static start(ele) {
|
||||
queueElements[++keyId] = ele;
|
||||
if (keyId > 9) keyId = 0;
|
||||
raf(Activator.activate);
|
||||
}
|
||||
|
||||
static activate() {
|
||||
// activate all elements in the queue
|
||||
for (var key in queueElements) {
|
||||
if (queueElements[key]) {
|
||||
queueElements[key].classList.add(ACTIVATED_CLASS);
|
||||
activeElements[key] = queueElements[key];
|
||||
}
|
||||
}
|
||||
queueElements = {};
|
||||
}
|
||||
|
||||
static end() {
|
||||
setTimeout(Activator.clear, DEACTIVATE_TIMEOUT);
|
||||
}
|
||||
|
||||
static clear() {
|
||||
// clear out any elements that are queued to be set to active
|
||||
queueElements = {};
|
||||
|
||||
// in the next frame, remove the active class from all active elements
|
||||
raf(Activator.deactivate);
|
||||
}
|
||||
|
||||
static deactivate() {
|
||||
|
||||
for (var key in activeElements) {
|
||||
if (activeElements[key]) {
|
||||
activeElements[key].classList.remove(ACTIVATED_CLASS);
|
||||
}
|
||||
delete activeElements[key];
|
||||
}
|
||||
}
|
||||
|
||||
static moveListeners(pointerMove, shouldAdd) {
|
||||
document.removeEventListener('touchmove', pointerMove);
|
||||
document.removeEventListener('mousemove', pointerMove);
|
||||
|
||||
if (shouldAdd) {
|
||||
document.addEventListener('touchmove', pointerMove);
|
||||
document.addEventListener('mousemove', pointerMove);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -174,9 +174,9 @@ export function pointerCoord(ev) {
|
||||
return c;
|
||||
}
|
||||
|
||||
export function hasPointerMoved(tolerance, startCoord, endCoord) {
|
||||
export function hasPointerMoved(threshold, startCoord, endCoord) {
|
||||
return startCoord && endCoord &&
|
||||
(Math.abs(startCoord.x - endCoord.x) > tolerance || Math.abs(startCoord.y - endCoord.y) > tolerance);
|
||||
(Math.abs(startCoord.x - endCoord.x) > threshold || Math.abs(startCoord.y - endCoord.y) > threshold);
|
||||
}
|
||||
|
||||
export function hasFocus(ele) {
|
||||
|
||||
Reference in New Issue
Block a user