the activator

This commit is contained in:
Adam Bradley
2015-07-23 00:51:29 -05:00
parent d67ba6f7c1
commit 96a84e593b
10 changed files with 274 additions and 34 deletions

61
ionic/util/activator.ts Normal file
View 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);
}
}
}

View File

@@ -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) {