You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by ru...@apache.org on 2017/10/02 13:48:41 UTC
[whimsy] branch master updated: touch: try to get the whole window;
reverse directions
This is an automated email from the ASF dual-hosted git repository.
rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new ff8ab1e touch: try to get the whole window; reverse directions
ff8ab1e is described below
commit ff8ab1eb003bd05143e228b667db4478109e6685
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Mon Oct 2 09:48:21 2017 -0400
touch: try to get the whole window; reverse directions
---
www/board/agenda/views/touch.js.rb | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/www/board/agenda/views/touch.js.rb b/www/board/agenda/views/touch.js.rb
index 3d95f5c..4dd746a 100644
--- a/www/board/agenda/views/touch.js.rb
+++ b/www/board/agenda/views/touch.js.rb
@@ -4,29 +4,36 @@
class Touch
def self.initEventHandlers()
+ # configuration
threshold = 150 # minimum distance required to be considered a swipe
limit = 100 # max distance in other direction
allowedTime = 500 # maximum time
+ # state
startX = 0
startY = 0
startTime = 0
- document.body.addEventListener :touchstart do |event|
+ # capture start of swipe
+ window.addEventListener :touchstart do |event|
touchobj = event.changedTouches[0]
startX = touchobj.pageX
startY = touchobj.pageY
startTime = Date.new().getTime()
end
- document.body.addEventListener :touchend do |event|
+ # process end of swipe
+ window.addEventListener :touchend do |event|
+ # ignore if a touch lasted too long
elapsed = Date.new().getTime() - startTime
return if elapsed > allowedTime
+ # compute distances
touchobj = event.changedTouches[0]
- distX = startX - touchobj.pageX
- distY = startY - touchobj.pageY
+ distX = touchobj.pageX - startX
+ distY = touchobj.pageY - startY
+ # compute direction
swipedir = 'none'
if Math.abs(distX) >= threshold and Math.abs(distY) <= limit
@@ -35,13 +42,14 @@ class Touch
swipedir = (distY < 0) ? 'up' : 'down'
end
+ # process swipe event
case swipedir
when 'left'
- link = document.querySelector("a[rel=prev]")
+ link = document.querySelector("a[rel=next]")
link.click() if link
when 'right'
- link = document.querySelector("a[rel=next]")
+ link = document.querySelector("a[rel=prev]")
link.click() if link
when 'up', 'down'
--
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <co...@whimsical.apache.org>'].