Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tidying.

  • Loading branch information...
commit 004dbdfe76a09f12ace6192281a00e29eb8cd4d4 1 parent 7d36993
@joseph authored
Showing with 25 additions and 36 deletions.
  1. +0 −1  .jshintrc
  2. +25 −35 src/compat/gala.js
View
1  .jshintrc
@@ -14,7 +14,6 @@
"globals" : {
"Monocle" : true,
"Gala" : true,
- "BU" : true,
"console" : true
},
View
60 src/compat/gala.js
@@ -136,57 +136,47 @@ Gala.replaceGroup = function (elem, listeners, newListeners, useCapture) {
Gala.onTap = function (elem, fn, tapClass) {
elem = Gala.$(elem);
if (typeof tapClass == 'undefined') { tapClass = Gala.TAPPING_CLASS; }
- var tapping = false,
- maxContactDistance = Gala.TAP_MAX_CONTACT_DISTANCE,
- startEvent,
-
- tapIsValid = function (evt) {
- evt = Gala.Cursor(evt)
-
- var xDelta = Math.abs(evt.pageX - startEvent.pageX),
- yDelta = Math.abs(evt.pageY - startEvent.pageY),
- maxContact = Math.max(xDelta, yDelta),
- isValid = maxContactDistance >= maxContact;
-
- /*
- console.log(
- 'isTapValid=', isValid,
- ',maxContact=', maxContact
- );
- */
- return isValid;
- };
+
+ var tapStartingCoords = {};
+
+ // If the tap extends beyond a few pixels, it's no longer a tap.
+ var tapIsValid = function (evt) {
+ var cur = Gala.Cursor(evt);
+ var xDelta = Math.abs(cur.pageX - tapStartingCoords.x);
+ var yDelta = Math.abs(cur.pageY - tapStartingCoords.y);
+ var maxContact = Math.max(xDelta, yDelta);
+ return Gala.TAP_MAX_CONTACT_DISTANCE >= maxContact;
+ }
+
+ // This ensures the element is considered 'clickable' by browsers
+ // like on the Kindle 3.
+ var noopOnClick = function (listeners) {
+ Gala.listen(elem, 'click', listeners.click = fns.noop);
+ }
var fns = {
start: function (evt) {
- startEvent = Gala.Cursor(evt);
- tapping = true;
+ var cur = Gala.Cursor(evt);
+ tapStartingCoords = { x: cur.pageX, y: cur.pageY };
if (tapClass) { elem.classList.add(tapClass); }
},
move: function (evt) {
- if (!tapping) { return }
-
- if (!tapIsValid(evt)) {
- fns.cancel(evt);
- }
+ if (!tapStartingCoords) { return; }
+ if (!tapIsValid(evt)) { fns.cancel(evt); }
},
end: function (evt) {
- if (!tapping) { return; }
+ if (!tapStartingCoords) { return; }
fns.cancel(evt);
evt.currentTarget = evt.currentTarget || evt.srcElement;
fn(evt);
},
noop: function () {},
cancel: function () {
- if (!tapping) { return; }
- tapping = false;
- startEvent = null;
+ if (!tapStartingCoords) { return; }
+ tapStartingCoords = null;
if (tapClass) { elem.classList.remove(tapClass); }
}
- }
- var noopOnClick = function (listeners) {
- Gala.listen(elem, 'click', listeners.click = fns.noop);
- }
+ };
Gala.listen(window, Gala.CONTACT_CANCEL, fns.cancel);
return Gala.onContact(elem, fns, false, noopOnClick);
}
Please sign in to comment.
Something went wrong with that request. Please try again.