Yay, CoffeeScript!
This commit is contained in:
25
js/frs.coffee
Normal file
25
js/frs.coffee
Normal file
@@ -0,0 +1,25 @@
|
||||
checkValidity = ->
|
||||
if @required
|
||||
optId = @selectedIndex
|
||||
selOpt = @options[optId]
|
||||
if selOpt.value is ''
|
||||
@parentNode.classList.add 'is-invalid'
|
||||
else
|
||||
@parentNode.classList.remove 'is-invalid'
|
||||
|
||||
document.addEventListener 'DOMContentLoaded', (event) ->
|
||||
all_selects = document.getElementsByTagName 'select'
|
||||
for own i, xsel of all_selects
|
||||
xvalue = xsel.dataset.value
|
||||
#console.log 'Value of %o = %o', xsel, xvalue
|
||||
# Walk all options, compare to desired value and set if matches
|
||||
for o, ov of xsel.options
|
||||
if ov.value is xvalue
|
||||
xsel.selectedIndex = o
|
||||
break
|
||||
|
||||
# Add eventlistener to change is-invalid state and run once
|
||||
xsel.addEventListener 'change', checkValidity
|
||||
event = document.createEvent 'HTMLEvents'
|
||||
event.initEvent 'change', true, true
|
||||
xsel.dispatchEvent event
|
||||
36
js/frs.js
36
js/frs.js
@@ -1,36 +0,0 @@
|
||||
function checkValidity() {
|
||||
if (this.required) {
|
||||
var optId = this.selectedIndex;
|
||||
var selOpt = this.options[optId];
|
||||
if (selOpt.value == '') {
|
||||
this.parentNode.classList.add('is-invalid');
|
||||
} else {
|
||||
this.parentNode.classList.remove('is-invalid');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
var all_selects = document.getElementsByTagName('select');
|
||||
for (var i in all_selects) {
|
||||
if (!all_selects.hasOwnProperty(i)) {
|
||||
continue;
|
||||
}
|
||||
var xsel = all_selects[i];
|
||||
var xvalue = xsel.dataset.value;
|
||||
//console.log('Value of %o = %o', xsel, xvalue);
|
||||
// Walk all options, compare to desired value and set if matches
|
||||
for (var o in xsel.options) {
|
||||
if (xsel.options[o].value == xvalue) {
|
||||
xsel.selectedIndex = o;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Add eventlistener to change is-invalid state and run once
|
||||
xsel.addEventListener('change', checkValidity);
|
||||
var event = document.createEvent('HTMLEvents');
|
||||
event.initEvent('change', true, true);
|
||||
xsel.dispatchEvent(event);
|
||||
}
|
||||
});
|
||||
16
js/session.coffee
Normal file
16
js/session.coffee
Normal file
@@ -0,0 +1,16 @@
|
||||
window.page_load_time = Math.floor(Date.now() / 1000);
|
||||
window.expire_time = window.page_load_time + window.seconds_left;
|
||||
|
||||
window.updateTimeLeft = ->
|
||||
now = Math.floor Date.now() / 1000
|
||||
time_left = window.expire_time - now
|
||||
obj = document.getElementById 'session_expires'
|
||||
minutes = Math.floor time_left / 60
|
||||
seconds = time_left % 60
|
||||
if minutes+seconds > 0
|
||||
obj.innerHTML = ' (' + ('0' + minutes).slice(-2) + ':' + ('0' + seconds).slice(-2) + ')'
|
||||
else
|
||||
obj?.innerHTML = ''
|
||||
window.clearInterval window.updateTimer
|
||||
|
||||
window.updateTimer = window.setInterval 'updateTimeLeft();', 1000
|
||||
Reference in New Issue
Block a user