Browse Source

better event handling for desktop/mobile

pull/94/head
John Josef 12 years ago
parent
commit
07ea253be3
  1. 25
      dist/ratchet.js
  2. 13
      lib/js/popovers.js
  3. 3
      lib/js/push.js
  4. 5
      lib/js/segmented-controllers.js
  5. 2
      lib/js/sliders.js
  6. 2
      lib/js/toggles.js

25
dist/ratchet.js vendored

@ -6,6 +6,12 @@
* ==================================
*/
var clickEvent = 'click';
if(typeof window.ontouchmove !== 'undefined') {
var clickEvent = clickEvent;
$('body').removeClass('no-touch');
}
/* ----------------------------------
* POPOVER v1.0.0
* Licensed under The MIT License
@ -54,7 +60,8 @@
return popover;
}
window.addEventListener('touchend', function (e) {
window.addEventListener(clickEvent, function (e) {
e.preventDefault();
var popover = getPopover(e);
if (!popover) return;
@ -65,9 +72,7 @@
popover.parentNode.appendChild(backdrop);
});
window.addEventListener('click', function (e) { if (getPopover(e)) e.preventDefault(); });
}();
/* ----------------------------------
* PUSH v1.0.0
@ -481,8 +486,7 @@
window.addEventListener('touchstart', function () { isScrolling = false; });
window.addEventListener('touchmove', function () { isScrolling = true; })
window.addEventListener('touchend', touchend);
window.addEventListener('click', function (e) { if (getTarget(e)) e.preventDefault(); });
window.addEventListener(clickEvent, touchend);
window.addEventListener('popstate', popstate);
}();/* ----------------------------------
@ -499,7 +503,8 @@
}
};
window.addEventListener("touchend", function (e) {
window.addEventListener(clickEvent, function (e) {
e.preventDefault();
var activeTab;
var activeBody;
var targetBody;
@ -529,8 +534,6 @@
targetBody.classList.add(className)
});
window.addEventListener('click', function (e) { if (getTarget(e.target)) e.preventDefault(); });
}();/* ----------------------------------
* SLIDER v1.0.0
* Licensed under The MIT License
@ -642,7 +645,7 @@
window.addEventListener('touchstart', onTouchStart);
window.addEventListener('touchmove', onTouchMove);
window.addEventListener('touchend', onTouchEnd);
window.addEventListener(clickEvent, onTouchEnd);
}();
/* ----------------------------------
@ -712,7 +715,7 @@
toggle.classList[(distanceX > (toggleWidth/2 - handleWidth/2)) ? 'add' : 'remove']('active');
});
window.addEventListener('touchend', function (e) {
window.addEventListener(clickEvent, function (e) {
if (!toggle) return;
var handle = toggle.querySelector('.toggle-handle');

13
lib/js/popovers.js

@ -1,3 +1,9 @@
var clickEvent = 'click';
if(typeof window.ontouchmove !== 'undefined') {
var clickEvent = clickEvent;
$('body').removeClass('no-touch');
}
/* ----------------------------------
* POPOVER v1.0.0
* Licensed under The MIT License
@ -46,7 +52,8 @@
return popover;
}
window.addEventListener('touchend', function (e) {
window.addEventListener(clickEvent, function (e) {
e.preventDefault();
var popover = getPopover(e);
if (!popover) return;
@ -57,7 +64,5 @@
popover.parentNode.appendChild(backdrop);
});
window.addEventListener('click', function (e) { if (getPopover(e)) e.preventDefault(); });
}();

3
lib/js/push.js

@ -410,8 +410,7 @@
window.addEventListener('touchstart', function () { isScrolling = false; });
window.addEventListener('touchmove', function () { isScrolling = true; })
window.addEventListener('touchend', touchend);
window.addEventListener('click', function (e) { if (getTarget(e)) e.preventDefault(); });
window.addEventListener(clickEvent, touchend);
window.addEventListener('popstate', popstate);
}();

5
lib/js/segmented-controllers.js

@ -12,7 +12,8 @@
}
};
window.addEventListener("touchend", function (e) {
window.addEventListener(clickEvent, function (e) {
e.preventDefault();
var activeTab;
var activeBody;
var targetBody;
@ -42,6 +43,4 @@
targetBody.classList.add(className)
});
window.addEventListener('click', function (e) { if (getTarget(e.target)) e.preventDefault(); });
}();

2
lib/js/sliders.js

@ -109,6 +109,6 @@
window.addEventListener('touchstart', onTouchStart);
window.addEventListener('touchmove', onTouchMove);
window.addEventListener('touchend', onTouchEnd);
window.addEventListener(clickEvent, onTouchEnd);
}();

2
lib/js/toggles.js

@ -65,7 +65,7 @@
toggle.classList[(distanceX > (toggleWidth/2 - handleWidth/2)) ? 'add' : 'remove']('active');
});
window.addEventListener('touchend', function (e) {
window.addEventListener(clickEvent, function (e) {
if (!toggle) return;
var handle = toggle.querySelector('.toggle-handle');

Loading…
Cancel
Save