Skip to content

Commit

Permalink
fix: select initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Idered committed Feb 14, 2018
1 parent 6dc21fd commit 87c3837
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions docs/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,27 @@
plugins: [
function (hook, vm) {
hook.ready(function() {
const version = window.location.host.match(/^[0-9\.|master|legacy]+/) || 'master';
[].forEach.call(document.querySelectorAll('.app-nav a'), a => {
a.setAttribute('href', a.getAttribute('href').replace('https://', `https://${version}-`))
})
const $select = document.querySelector('[data-version]')
const $options = document.querySelectorAll(`[data-version] option`)
const $selectedOption = document.querySelector(`option[value="${version}"]`)
const selectedOptionIndex = Array.prototype.indexOf.call($options, $selectedOption)
$select.selectedIndex = selectedOptionIndex >= 0 ? selectedOptionIndex : 0
$select.addEventListener('change', event => {
const version = event.target.value
const url = event.target.options[event.target.selectedIndex].dataset.url
window.location.href = url || `https://${version}-docs.syncano.io`
})
setTimeout(() => {
const version = window.location.host.match(/^[0-9\.|master|legacy]+/) || 'master';

[].forEach.call(document.querySelectorAll('.app-nav a'), a => {
a.setAttribute('href', a.getAttribute('href').replace('https://', `https://${version}-`))
})

const $select = document.querySelector('[data-version]')
const $options = document.querySelectorAll(`[data-version] option`)
const $selectedOption = document.querySelector(`option[value="${version}"]`)
const selectedOptionIndex = Array.prototype.indexOf.call($options, $selectedOption)

$select.selectedIndex = selectedOptionIndex >= 0 ? selectedOptionIndex : 0

$select.addEventListener('change', event => {
const version = event.target.value
const url = event.target.options[event.target.selectedIndex].dataset.url

window.location.href = url || `https://${version}-docs.syncano.io`
})
}, 100);
})
}
]
Expand Down

0 comments on commit 87c3837

Please sign in to comment.