PHP Classes

PHP Touch Swipe Emulator: Track swipe events when user moves the mouse

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 98 All time: 9,796 This week: 182Up
Version License PHP version Categories
swiper 0.1Public Domain5HTML, PHP 5
Description 

Author

This class can be used to track swipe events when user uses the mouse.

It generate HTML attributes for a given HTML element that will track mouse over and mouse out events and redirect to a specific URL.

The URL is of the current page but takes parameters that determine the direction of the swipe events (left, right, up, down), as well the identifier of the page element on which the swipe events happened.

Innovation Award
PHP Programming Innovation award nominee
December 2016
Number 6
Swipe movements are usually performed by users of touch devices. However, if a site is accessed from a computer device without a touch screen, it is not be possible to detect swipe movements performed with the mouse directly.

This class provides means to emulate the detection of swipe movements performed with the mouse. It generates JavaScript to perform the movement detection and then sends HTTP requests to the server side to notify about the detected movements.

Manuel Lemos
Picture of Dave Smith
  Performance   Level  
Name: Dave Smith is available for providing paid consulting. Contact Dave Smith .
Classes: 51 packages by
Country: United States United States
Age: 58
All time rank: 618 in United States United States
Week rank: 11 Up3 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x

Example

<?php
/*
This example will place 3 elements on the page and increase or decrease
the value contained within depending on the swipe direction
*/
session_start();

require(
'swiper.class.php');
$swiper = new swiper();

if( isset(
$_REQUEST['swipe']) ){
   
   
//request key/value pairs returned
   
$swipe = $_REQUEST['swipe'];
   
$elem = $_REQUEST['elem'];
   
   
//action to take for swipe on element
   
switch($swipe){
        case
'l':
            switch(
$elem){
                case
'elem0':
                   
$_SESSION['swiper']['elem0Value']--;
                    break;
                case
'elem1':
                   
$_SESSION['swiper']['elem1Value']--;
                    break;
                case
'elem2':
                   
$_SESSION['swiper']['elem2Value']--;
                    break;
            }
            break;
        case
'r':
            switch(
$elem){
                case
'elem0':
                   
$_SESSION['swiper']['elem0Value']++;
                    break;
                case
'elem1':
                   
$_SESSION['swiper']['elem1Value']++;
                    break;
                case
'elem2':
                   
$_SESSION['swiper']['elem2Value']++;
                    break;
            }
            break;
        case
'u':
            switch(
$elem){
                case
'elem0':
                   
$_SESSION['swiper']['elem0Value'] -= 10;
                    break;
                case
'elem1':
                   
$_SESSION['swiper']['elem1Value'] -= 10;
                    break;
                case
'elem2':
                   
$_SESSION['swiper']['elem2Value'] -= 10;
                    break;
            }
            break;
        case
'd':
            switch(
$elem){
                case
'elem0':
                   
$_SESSION['swiper']['elem0Value'] += 10;
                    break;
                case
'elem1':
                   
$_SESSION['swiper']['elem1Value'] += 10;
                    break;
                case
'elem2':
                   
$_SESSION['swiper']['elem2Value'] += 10;
                    break;
            }
            break;
    }
   
header('location: example.php');
    exit;
}elseif( empty(
$_SESSION['swiper']) ){
   
//initializing session variables
   
$_SESSION['swiper']['elem0Value'] = 0;
   
$_SESSION['swiper']['elem1Value'] = 0;
   
$_SESSION['swiper']['elem2Value'] = 0;
}

?>
<html>
    <head>
        <title>Swiper Exampe</title>
        <?php echo $swiper->script(); //adding script to head?>
<style>
            div {
                height: 100px;
                width: 100px;
                text-align: center;
                font-size: 24pt;
                margin-top: 40px;
                margin-left: 40px;
                border: solid thin black;
            }
        </style>
    </head>
    <body>
        <p>Using your mouse, swipe across an element. Left swipe decreases number by 1, right swipe increases number by 1, swipe up decreases number by 10 and swipe down increases number by 10. Moving the mouse too quickly will not register the swipe.</p>
        <div <?php echo $swiper->element('elem0'); //adding mouse events to element?>><?php echo $_SESSION['swiper']['elem0Value'];?></div>
        <div <?php echo $swiper->element('elem1');?>><?php echo $_SESSION['swiper']['elem1Value'];?></div>
        <div <?php echo $swiper->element('elem2');?>><?php echo $_SESSION['swiper']['elem2Value'];?></div>
    </body>
</html>


  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example Usage Example
Plain text file swiper.class.php Class Main Class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:98
This week:0
All time:9,796
This week:182Up