Browse Source

better event handling for desktop/mobile

pull/94/head
John Josef 12 years ago
parent
commit
07ea253be3
  1. 23
      dist/ratchet.js
  2. 11
      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

23
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 * POPOVER v1.0.0
* Licensed under The MIT License * Licensed under The MIT License
@ -54,7 +60,8 @@
return popover; return popover;
} }
window.addEventListener('touchend', function (e) { window.addEventListener(clickEvent, function (e) {
e.preventDefault();
var popover = getPopover(e); var popover = getPopover(e);
if (!popover) return; if (!popover) return;
@ -66,8 +73,6 @@
popover.parentNode.appendChild(backdrop); popover.parentNode.appendChild(backdrop);
}); });
window.addEventListener('click', function (e) { if (getPopover(e)) e.preventDefault(); });
}(); }();
/* ---------------------------------- /* ----------------------------------
* PUSH v1.0.0 * PUSH v1.0.0
@ -481,8 +486,7 @@
window.addEventListener('touchstart', function () { isScrolling = false; }); window.addEventListener('touchstart', function () { isScrolling = false; });
window.addEventListener('touchmove', function () { isScrolling = true; }) window.addEventListener('touchmove', function () { isScrolling = true; })
window.addEventListener('touchend', touchend); window.addEventListener(clickEvent, touchend);
window.addEventListener('click', function (e) { if (getTarget(e)) e.preventDefault(); });
window.addEventListener('popstate', popstate); window.addEventListener('popstate', popstate);
}();/* ---------------------------------- }();/* ----------------------------------
@ -499,7 +503,8 @@
} }
}; };
window.addEventListener("touchend", function (e) { window.addEventListener(clickEvent, function (e) {
e.preventDefault();
var activeTab; var activeTab;
var activeBody; var activeBody;
var targetBody; var targetBody;
@ -529,8 +534,6 @@
targetBody.classList.add(className) targetBody.classList.add(className)
}); });
window.addEventListener('click', function (e) { if (getTarget(e.target)) e.preventDefault(); });
}();/* ---------------------------------- }();/* ----------------------------------
* SLIDER v1.0.0 * SLIDER v1.0.0
* Licensed under The MIT License * Licensed under The MIT License
@ -642,7 +645,7 @@
window.addEventListener('touchstart', onTouchStart); window.addEventListener('touchstart', onTouchStart);
window.addEventListener('touchmove', onTouchMove); 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'); toggle.classList[(distanceX > (toggleWidth/2 - handleWidth/2)) ? 'add' : 'remove']('active');
}); });
window.addEventListener('touchend', function (e) { window.addEventListener(clickEvent, function (e) {
if (!toggle) return; if (!toggle) return;
var handle = toggle.querySelector('.toggle-handle'); var handle = toggle.querySelector('.toggle-handle');

11
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 * POPOVER v1.0.0
* Licensed under The MIT License * Licensed under The MIT License
@ -46,7 +52,8 @@
return popover; return popover;
} }
window.addEventListener('touchend', function (e) { window.addEventListener(clickEvent, function (e) {
e.preventDefault();
var popover = getPopover(e); var popover = getPopover(e);
if (!popover) return; if (!popover) return;
@ -58,6 +65,4 @@
popover.parentNode.appendChild(backdrop); 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('touchstart', function () { isScrolling = false; });
window.addEventListener('touchmove', function () { isScrolling = true; }) window.addEventListener('touchmove', function () { isScrolling = true; })
window.addEventListener('touchend', touchend); window.addEventListener(clickEvent, touchend);
window.addEventListener('click', function (e) { if (getTarget(e)) e.preventDefault(); });
window.addEventListener('popstate', popstate); 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 activeTab;
var activeBody; var activeBody;
var targetBody; var targetBody;
@ -42,6 +43,4 @@
targetBody.classList.add(className) 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('touchstart', onTouchStart);
window.addEventListener('touchmove', onTouchMove); 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'); toggle.classList[(distanceX > (toggleWidth/2 - handleWidth/2)) ? 'add' : 'remove']('active');
}); });
window.addEventListener('touchend', function (e) { window.addEventListener(clickEvent, function (e) {
if (!toggle) return; if (!toggle) return;
var handle = toggle.querySelector('.toggle-handle'); var handle = toggle.querySelector('.toggle-handle');

Loading…
Cancel
Save