modify how elements remove active class

This commit is contained in:
Adam Bradley
2014-03-18 08:48:58 -05:00
parent 25f8829949
commit bd4c1f48a5

View File

@@ -8,17 +8,25 @@
function onStart(e) {
// when an element is touched/clicked, it climbs up a few
// parents to see if it is an .item or .button element
var x, ele = e.target;
ionic.requestAnimationFrame(function(){
var x, ele = e.target;
for(x=0; x<5; x++) {
if(!ele || ele.tagName === 'LABEL') break;
if( ele.classList.contains('item') || ele.classList.contains('button') ) {
keyId = (keyId > 99 ? 0 : keyId + 1);
// queue that this element should be set to active
queueElements[keyId] = ele;
setTimeout(activateElements, 32);
// in XX milliseconds, set the queued elements to active
setTimeout(activateElements, 60);
// add listeners to clear all queued/active elements onMove
document.body.addEventListener('mousemove', clear, false);
document.body.addEventListener('touchmove', clear, false);
keyId = (keyId > 19 ? 0 : keyId + 1);
break;
}
ele = ele.parentElement;
}
@@ -42,12 +50,22 @@
}
function clear() {
// clear out any active/queued elements immediately
// clear out any elements that are queued to be set to active
queueElements = {};
for(var key in activeElements) {
activeElements[key] && activeElements[key].classList.remove('active');
delete activeElements[key];
}
// in the next frame, remove the active class from all active elements
ionic.requestAnimationFrame(function(){
for(var key in activeElements) {
if(activeElements[key]) {
activeElements[key].classList.remove('active');
delete activeElements[key];
}
}
});
// remove onMove listeners that clear out active elements
document.body.removeEventListener('mousemove', clear);
document.body.removeEventListener('touchmove', clear);
}
// use window.onload because this doesn't need to run immediately
@@ -59,11 +77,7 @@
// clear all active elements after XX milliseconds
document.body.addEventListener('touchend', onEnd, false);
document.body.addEventListener('mouseup', onEnd, false);
// clear all active immediately
document.body.addEventListener('mousemove', clear, false);
document.body.addEventListener('touchmove', clear, false);
document.body.addEventListener('touchcancel', clear, false);
document.body.addEventListener('touchcancel', onEnd, false);
}, false);
})(document, ionic);