Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added swipeL + swipeR + arrowL + arrowR events to DailyCharts form #1034

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions homepage/views.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,60 @@ function setLiveStreamVolume(vol) {
audioelement.volume = 1
}
}

function getTheDate(increment) {
var theDate = "<?php echo $theDate;?>";

d = new Date(theDate);
d.setDate(d.getDate(theDate) + increment);
yyyy = d.getFullYear();
mm = d.getMonth() + 1; if (mm < 10) mm = "0" + mm;
dd = d.getDate(); if (dd < 10) dd = "0" + dd;

swipeSpinner=document.getElementById("SwipeSpinner");
swipeSpinner.setAttribute("src","images/spinner.gif");

window.location = "/views.php?date="+yyyy+"-"+mm+"-"+dd+"&view=Daily+Charts";
}

function installKeyAndSwipeEventHandler() {
for (var i = 0; i < topbuttons.length; i++) {
if (topbuttons[i].textContent == "Daily Charts" &&
topbuttons[i].className == "button-hover") {

document.onkeydown = function(event) {
switch (event.keyCode) {
case 37: //Left key
getTheDate(-1);
break;
case 39: //Right key
getTheDate(+1);
break;
}
}

// https://stackoverflow.com/questions/2264072/detect-a-finger-swipe-through-javascript-on-the-iphone-and-android
let touchstartX = 0
let touchendX = 0

function checkDirection() {
if (touchendX < touchstartX) getTheDate(+1);
if (touchendX > touchstartX) getTheDate(-1);
}

document.addEventListener('touchstart', e => {
touchstartX = e.changedTouches[0].screenX
})

document.addEventListener('touchend', e => {
touchendX = e.changedTouches[0].screenX
checkDirection()
})
}
}
}

installKeyAndSwipeEventHandler();
</script>
</div>
</body>
1 change: 1 addition & 0 deletions scripts/history.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function submitID() {
<tr>
<th>Total Detections For The Day</th>
<td><?php echo $totalcount['COUNT(*)'];?></td>
<td><img id="SwipeSpinner" style="height:30px;"></td>
</tr>
</table>
<?php // <br><button type="button" onclick="showDialog()">Export as CSV for eBird</button><br><br> ?>
Expand Down