From 399e262f32c5d554697a4c148fd08e54d7650064 Mon Sep 17 00:00:00 2001 From: Roy Meissner Date: Fri, 28 Sep 2018 11:21:30 +0200 Subject: [PATCH 1/2] Fixed SWIK-2088 --- components/Deck/Presentation/Presentation.js | 38 +++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/components/Deck/Presentation/Presentation.js b/components/Deck/Presentation/Presentation.js index aeb4fa6cb..ea7803103 100644 --- a/components/Deck/Presentation/Presentation.js +++ b/components/Deck/Presentation/Presentation.js @@ -21,8 +21,41 @@ class Presentation extends React.Component{ this.id = props.currentRoute.query.id; } + //setting/reading a cookie is needed so SWIK-2088 is fixable + setCookie(name,value,seconds) { + let expires = ''; + if (seconds) { + let date = new Date(); + date.setTime(date.getTime() + (seconds*1000)); + expires = '; expires=' + date.toUTCString(); + } + document.cookie = name + '=' + (value || '') + expires + '; path=/'; + } + getCookie(name) { + let nameEQ = name + '='; + let ca = document.cookie.split(';'); + for(let i=0;i < ca.length;i++) { + let c = ca[i]; + while (c.charAt(0)===' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return undefined; + } + eraseCookie(name) { + document.cookie = name+'=; Max-Age=-99999999;'; + } + componentDidMount(){ if(process.env.BROWSER){ + + window.addEventListener('beforeunload', (event) => { + this.setCookie('lastHash',window.location.hash, 15); + }); + + let lastRevealHash = this.getCookie('lastHash'); + console.log(lastRevealHash); + this.eraseCookie('lastHash'); + //$('[style*="absolute"]').children().attr('tabindex', 0); //remove existing tabindices @@ -62,7 +95,10 @@ class Presentation extends React.Component{ pptxheight = '100%'; } - window.location.hash = '#slide-' + this.startingSlide; + if(lastRevealHash === undefined) + window.location.hash = '#slide-' + this.startingSlide; + else + window.location.hash = lastRevealHash; let multiplexFileToLoad = (this.secret) ? '/custom_modules/reveal.js/plugin/multiplex/master.js' : '/custom_modules/reveal.js/plugin/multiplex/client.js' ; multiplexFileToLoad = (this.id) ? multiplexFileToLoad : '' ; From a199c09ee80a242d280750ce00d1226b298f2d81 Mon Sep 17 00:00:00 2001 From: Roy Meissner Date: Fri, 28 Sep 2018 15:38:50 +0200 Subject: [PATCH 2/2] Moved from cookies to localstorage --- components/Deck/Presentation/Presentation.js | 44 +++++++------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/components/Deck/Presentation/Presentation.js b/components/Deck/Presentation/Presentation.js index ea7803103..de8feb77a 100644 --- a/components/Deck/Presentation/Presentation.js +++ b/components/Deck/Presentation/Presentation.js @@ -21,40 +21,28 @@ class Presentation extends React.Component{ this.id = props.currentRoute.query.id; } - //setting/reading a cookie is needed so SWIK-2088 is fixable - setCookie(name,value,seconds) { - let expires = ''; - if (seconds) { - let date = new Date(); - date.setTime(date.getTime() + (seconds*1000)); - expires = '; expires=' + date.toUTCString(); - } - document.cookie = name + '=' + (value || '') + expires + '; path=/'; - } - getCookie(name) { - let nameEQ = name + '='; - let ca = document.cookie.split(';'); - for(let i=0;i < ca.length;i++) { - let c = ca[i]; - while (c.charAt(0)===' ') c = c.substring(1,c.length); - if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); - } - return undefined; - } - eraseCookie(name) { - document.cookie = name+'=; Max-Age=-99999999;'; - } - componentDidMount(){ if(process.env.BROWSER){ window.addEventListener('beforeunload', (event) => { - this.setCookie('lastHash',window.location.hash, 15); + if(window.localStorage) + window.localStorage.setItem('lastHash', JSON.stringify({'hash': window.location.hash, 'time': new Date().getTime(), 'deckID': this.props.PresentationStore.selector.id}) );//safe current slide for page refresh }); - let lastRevealHash = this.getCookie('lastHash'); - console.log(lastRevealHash); - this.eraseCookie('lastHash'); + let lastRevealHash = undefined; + if(window.localStorage) { + lastRevealHash = window.localStorage.getItem('lastHash'); + lastRevealHash = (lastRevealHash) ? JSON.parse(lastRevealHash) : undefined; + if(lastRevealHash) { + if(lastRevealHash.deckID !== this.props.PresentationStore.selector.id){ //check that it is still the same deck, cause 15 secs is rather long + lastRevealHash = undefined; + } else { + let timePassed = (new Date().getTime()) - lastRevealHash.time; + lastRevealHash = (timePassed > 0 && timePassed <= 15*1000) ? lastRevealHash.hash : undefined;//not older than 15 secs ... just for reload of the page + } + } + window.localStorage.removeItem('lastHash'); + } //$('[style*="absolute"]').children().attr('tabindex', 0);