|
|
@ -8,6 +8,8 @@ function goToTrain(number) { |
|
|
|
window.location.href = url.toString() |
|
|
|
window.location.href = url.toString() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var focusedElement = null |
|
|
|
|
|
|
|
|
|
|
|
var _rebuildDebounce = null |
|
|
|
var _rebuildDebounce = null |
|
|
|
var _rebuildRequested = false |
|
|
|
var _rebuildRequested = false |
|
|
|
function rebuildSuggestions() { |
|
|
|
function rebuildSuggestions() { |
|
|
@ -55,6 +57,9 @@ function rebuildSuggestions() { |
|
|
|
onAction(e) |
|
|
|
onAction(e) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
suggestionLi.addEventListener('focus', function (e) { |
|
|
|
|
|
|
|
focusedElement = suggestionLi |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
var trainNameP = document.createElement('p') |
|
|
|
var trainNameP = document.createElement('p') |
|
|
|
suggestionLi.appendChild(trainNameP) |
|
|
|
suggestionLi.appendChild(trainNameP) |
|
|
@ -82,12 +87,26 @@ function lsk() { |
|
|
|
document.getElementById('trainNumber').focus() |
|
|
|
document.getElementById('trainNumber').focus() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function csk() { |
|
|
|
|
|
|
|
if (focusedElement == null) { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (focusedElement.id === 'trainNumber') { |
|
|
|
|
|
|
|
goToTrain(document.activeElement.value.trim()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
focusedElement.click() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('load', function (e) { |
|
|
|
window.addEventListener('load', function (e) { |
|
|
|
var trainNumber = document.getElementById('trainNumber') |
|
|
|
var trainNumber = document.getElementById('trainNumber') |
|
|
|
trainNumber.addEventListener('input', function (e) { |
|
|
|
trainNumber.addEventListener('input', function (e) { |
|
|
|
rebuildSuggestions() |
|
|
|
rebuildSuggestions() |
|
|
|
}) |
|
|
|
}) |
|
|
|
trainNumber.addEventListener('focus', function (e) { |
|
|
|
trainNumber.addEventListener('focus', function (e) { |
|
|
|
|
|
|
|
focusedElement = trainNumber |
|
|
|
document.getElementsByClassName('lsk')[0].textContent = '' |
|
|
|
document.getElementsByClassName('lsk')[0].textContent = '' |
|
|
|
document.getElementsByClassName('csk')[0].textContent = 'Search' |
|
|
|
document.getElementsByClassName('csk')[0].textContent = 'Search' |
|
|
|
}) |
|
|
|
}) |
|
|
@ -106,10 +125,18 @@ window.addEventListener('load', function (e) { |
|
|
|
lsk() |
|
|
|
lsk() |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
document.querySelectorAll('.csk').forEach(function (cskElem) { |
|
|
|
|
|
|
|
cskElem.addEventListener('click', function (e) { |
|
|
|
|
|
|
|
csk() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
document.body.addEventListener('keydown', function (e) { |
|
|
|
document.body.addEventListener('keydown', function (e) { |
|
|
|
if (e.key == 'SoftLeft') { |
|
|
|
if (e.key == 'SoftLeft') { |
|
|
|
lsk() |
|
|
|
lsk() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (e.key == 'Enter') { |
|
|
|
|
|
|
|
csk() |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
fetch('https://scraper.infotren.dcdev.ro/v2/trains') |
|
|
|
fetch('https://scraper.infotren.dcdev.ro/v2/trains') |
|
|
|