pass 2 at trying to get swipe handler for resources, a=chris
pass 2 at trying to get swipe handler for resources, a=chris
diff --git a/src/controllers/components/SocialComponent.php b/src/controllers/components/SocialComponent.php
index d242407ef..e99dc85fb 100644
--- a/src/controllers/components/SocialComponent.php
+++ b/src/controllers/components/SocialComponent.php
@@ -2188,7 +2188,7 @@ class SocialComponent extends Component implements CrawlConstants
$folder_prefix .= "&sf=" . $data['SUB_PATH'];
$data['UP_LINK'] = $folder_prefix;
$up_link = html_entity_decode($data['UP_LINK']);
- $data['SCRIPT'] .= 'swipeListen("up", function(evt) {'.
+ $data['SCRIPT'] .= 'upSwipe("left", function(evt) {'.
'window.location="'.$up_link.'";})'."\n";
}
$url_prefix = $folder_prefix . "&arg=media";
@@ -2204,13 +2204,13 @@ class SocialComponent extends Component implements CrawlConstants
if (!empty($prev_name)) {
$data['PREV_LINK'] = "$url_prefix&n=$prev_name";
$prev_link = html_entity_decode($data['PREV_LINK']);
- $data['SCRIPT'] .= 'swipeListen("right", function(evt) {'.
+ $data['SCRIPT'] .= 'rightSwipe(function(evt) {'.
'window.location="'.$prev_link.'";})'."\n";
}
if (!empty($next_name)) {
$data['NEXT_LINK'] = "$url_prefix&n=$next_name";
$next_link = html_entity_decode($data['NEXT_LINK']);
- $data['SCRIPT'] .= 'swipeListen("left", function(evt) {'.
+ $data['SCRIPT'] .= 'leftSwipe(function(evt) {'.
'window.location="'.$next_link.'";})'."\n";
}
$page_string .= "<div class='media-container'>";
diff --git a/src/scripts/basic.js b/src/scripts/basic.js
index 9a3136255..327f2fa54 100755
--- a/src/scripts/basic.js
+++ b/src/scripts/basic.js
@@ -166,9 +166,8 @@ function listen(object, event_type, handler)
/*
*
*/
-function swipeListen(direction, handler)
+function leftSwipe(handler)
{
- var self = this;
listen(document, 'touchstart', start);
listen(document, 'touchmove', move);
var x_begin = null;
@@ -189,26 +188,116 @@ function swipeListen(direction, handler)
var delta_y = y_end - y_begin;
// check whether moved more in x or y direction
if ( Math.abs( delta_x ) > Math.abs( delta_y ) ) {
- //check minimum swipe distance
- if (Math.abs( delta_x ) > 20) {
- if ( delta_x > 0 && direction=="right" ) {
- handler(evt);
- } else if (direction=="left") {
- handler(evt);
- }
+ if (delta_x < 0) {
+ handler(evt);
}
- } else {
- if (Math.abs( delta_x ) > 20) {
- if ( delta_y > 0 && direction=="down") {
- handler(evt);
- } else if (direction=="up") {
- handler(evt);
- }
+ }
+ /* reset values */
+ x_begin = null;
+ y_begin = null;
+ }
+}
+/*
+ *
+ */
+function rightSwipe(handler)
+{
+ listen(document, 'touchstart', start);
+ listen(document, 'touchmove', move);
+ var x_begin = null;
+ var y_begin = null;
+ function start(evt)
+ {
+ x_begin = evt.touches[0].clientX;
+ y_begin = evt.touches[0].clientY;
+ }
+ function move(evt)
+ {
+ if ( !x_begin || !y_begin ) {
+ return;
+ }
+ var x_end = evt.touches[0].clientX;
+ var y_end = evt.touches[0].clientY;
+ var delta_x = x_end - x_begin;
+ var delta_y = y_end - y_begin;
+ // check whether moved more in x or y direction
+ if ( Math.abs( delta_x ) > Math.abs( delta_y ) ) {
+ if (delta_x > 0) {
+ handler(evt);
+ }
+ }
+ /* reset values */
+ x_begin = null;
+ y_begin = null;
+ }
+}
+/*
+ *
+ */
+function upSwipe(handler)
+{
+ listen(document, 'touchstart', start);
+ listen(document, 'touchmove', move);
+ var x_begin = null;
+ var y_begin = null;
+ function start(evt)
+ {
+ x_begin = evt.touches[0].clientX;
+ y_begin = evt.touches[0].clientY;
+ }
+ function move(evt)
+ {
+ if ( !x_begin || !y_begin ) {
+ return;
+ }
+ var x_end = evt.touches[0].clientX;
+ var y_end = evt.touches[0].clientY;
+ var delta_x = x_end - x_begin;
+ var delta_y = y_end - y_begin;
+ // check whether moved more in x or y direction
+ if ( Math.abs( delta_x ) < Math.abs( delta_y ) ) {
+ if (delta_y < 0) {
+ handler(evt);
+ }
+ }
+ /* reset values */
+ x_begin = null;
+ y_begin = null;
+ }
+}
+/*
+ *
+ */
+function downSwipe(handler)
+{
+ listen(document, 'touchstart', start);
+ listen(document, 'touchmove', move);
+ var x_begin = null;
+ var y_begin = null;
+ function start(evt)
+ {
+ x_begin = evt.touches[0].clientX;
+ y_begin = evt.touches[0].clientY;
+ }
+ function move(evt)
+ {
+ if ( !x_begin || !y_begin ) {
+ return;
+ }
+ var x_end = evt.touches[0].clientX;
+ var y_end = evt.touches[0].clientY;
+ var delta_x = x_end - x_begin;
+ var delta_y = y_end - y_begin;
+ // check whether moved more in x or y direction
+ if ( Math.abs( delta_x ) < Math.abs( delta_y ) ) {
+
+ if (delta_y > 0) {
+ handler(evt);
}
}
/* reset values */
- x = null;
- y = null;
+ x_begin = null;
+ y_begin = null;
}
}
/*