1
0
mirror of https://github.com/webslides/WebSlides.git synced 2025-08-19 19:31:46 +02:00

Back and forward buttons on browser

Wonderful work by Ramon https://github.com/ramon-src
This commit is contained in:
José Luis Antúnez
2017-01-22 08:53:46 +01:00
committed by GitHub
parent f8ecd299b5
commit 8bb9e1c475

View File

@@ -311,8 +311,45 @@ jQuery(document).ready(function($){
} }
} }
}); });
/**
* Bind the event HashChange when the prev/next history button was clicked
*/
jQuery(window).bind("hashchange", function () {
if (hasHash()) {
goToSlideIfSlideHashChange();
} else {
window.location.reload();
}
});
function hasHash() {
return window.location.hash ? true : false;
}
function goToSlideIfSlideHashChange() {
var paramsArr = getArrayOfHashParams();
var slideObj = $.grep(paramsArr, function (e) {
return (e.key == "slide");
});
if (slideObj.length == 1) {
goToSlide(slideObj[0].value);
}
}
function getArrayOfHashParams() {
var hash = window.location.hash.replace('#', '').split('&');
var paramsArr = new Array();
for (var i = 0; i < hash.length; i++) {
var itemArray = hash[i].split('=');
var action = new Object();
action.key = itemArray[0];
action.value = itemArray[1];
paramsArr.push(action);
}
return paramsArr;
}
// Tabs // Tabs
jQuery('ul.tabs li').click(function(){ jQuery('ul.tabs li').click(function(){
var $this = jQuery(this); var $this = jQuery(this);
@@ -331,4 +368,4 @@ jQuery(document).ready(function($){
$('body').toggleClass('baseline').css('height', $(document).height()); $('body').toggleClass('baseline').css('height', $(document).height());
} }
}); });