From caacdf15c12e5ddd5b9ca7844ed480482c7aa3ee Mon Sep 17 00:00:00 2001 From: ramon183 Date: Sat, 21 Jan 2017 21:40:51 -0200 Subject: [PATCH] Hash changes binding resolved #4 resolved #22 --- static/js/webslides.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/static/js/webslides.js b/static/js/webslides.js index 9badf4c..0af5171 100644 --- a/static/js/webslides.js +++ b/static/js/webslides.js @@ -312,6 +312,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; + } + // Mouse wheel jQuery(window).bind('mousewheel DOMMouseScroll', function(event){ $slideshow.data('iswheel', true);