<?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>
|