Skip to content

Instantly share code, notes, and snippets.

@KarneAsada
Created August 13, 2018 17:28
Show Gist options
  • Save KarneAsada/cfaed2a30c73492c22260dc1ed4ee090 to your computer and use it in GitHub Desktop.
Save KarneAsada/cfaed2a30c73492c22260dc1ed4ee090 to your computer and use it in GitHub Desktop.
diff --git a/src/player.js b/src/player.js
index ddb6037..4201d0b 100644
--- a/src/player.js
+++ b/src/player.js
@@ -1,6 +1,5 @@
import Swiper from 'swiper'
import 'swiper/dist/css/swiper.css'
-import 'url-search-params-polyfill'
import config from './config'
import logger from './components/logger'
@@ -15,6 +14,7 @@ const ArturoPlayer = ((document, window) => {
items : document.getElementById('arturo-circles'),
stories : []
}
+ const arturoSearchParam = 'arturo_story'
const imageWidth = 720
const titleMax = 40
let stories = []
@@ -58,17 +58,18 @@ const ArturoPlayer = ((document, window) => {
elements.swiperContainer = Utils.create('div', 'swiper-container', elements.content)
elements.swiperWrapper = Utils.create('div', 'swiper-wrapper', elements.swiperContainer)
- // listen for hash url changes
- window.addEventListener('hashchange', checkHash)
-
// support deep links using search params
- const params = new URLSearchParams(window.location.search)
- if (params.has('arturo_story')) {
- window.history.pushState({}, 'remove params', window.location.pathname)
- window.location.hash = '#/' + params.get('arturo_story')
- } else {
- checkHash()
+ const searchRegExp = new RegExp(`&?${arturoSearchParam}=(\\w+)`)
+ const searchMatch = window.location.search.match(searchRegExp)
+ if (searchMatch) {
+ const storyId = searchMatch[1]
+ const newPath = window.location.href.replace(searchRegExp, '')
+ window.history.pushState({}, `remove ${arturoSearchParam}`, `${newPath}#/${storyId}`)
}
+
+ // listen for hash url changes
+ window.addEventListener('hashchange', checkHash)
+ checkHash()
}
function checkHash() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment