parent
963bfce9cc
commit
036a58ce12
@ -1,189 +1,190 @@ |
|||||||
/** Global generic init */ |
/** Global generic init */ |
||||||
$.ready(function () { |
$.ready(function () { |
||||||
// Checkbox UI (checkbox CSS and hidden input with int value)
|
// Checkbox UI (checkbox CSS and hidden input with int value)
|
||||||
$('.Row.checkbox').forEach(function(x) { |
$('.Row.checkbox').forEach(function (x) { |
||||||
var inp = x.querySelector('input'); |
var inp = x.querySelector('input'); |
||||||
var box = x.querySelector('.box'); |
var box = x.querySelector('.box'); |
||||||
|
|
||||||
$(box).toggleClass('checked', inp.value); |
$(box).toggleClass('checked', inp.value); |
||||||
|
|
||||||
var hdl = function() { |
var hdl = function () { |
||||||
inp.value = 1 - inp.value; |
inp.value = 1 - inp.value; |
||||||
$(box).toggleClass('checked', inp.value) |
$(box).toggleClass('checked', inp.value) |
||||||
}; |
}; |
||||||
|
|
||||||
$(x).on('click', hdl).on('keypress', cr(hdl)); |
$(x).on('click', hdl).on('keypress', cr(hdl)); |
||||||
}); |
}); |
||||||
|
|
||||||
// Expanding boxes on mobile
|
// Expanding boxes on mobile
|
||||||
$('.Box.mobcol,.Box.fold').forEach(function(x) { |
$('.Box.mobcol,.Box.fold').forEach(function (x) { |
||||||
var h = x.querySelector('h2'); |
var h = x.querySelector('h2'); |
||||||
|
|
||||||
var hdl = function() { |
var hdl = function () { |
||||||
$(x).toggleClass('expanded'); |
$(x).toggleClass('expanded'); |
||||||
}; |
}; |
||||||
$(h).on('click', hdl).on('keypress', cr(hdl)); |
$(h).on('click', hdl).on('keypress', cr(hdl)); |
||||||
}); |
}); |
||||||
|
|
||||||
$('form').forEach(function(x) { |
$('form').forEach(function (x) { |
||||||
$(x).on('keypress', function(e) { |
$(x).on('keypress', function (e) { |
||||||
if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey) { |
if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey) { |
||||||
x.submit(); |
x.submit(); |
||||||
} |
} |
||||||
}) |
}) |
||||||
}); |
}); |
||||||
|
|
||||||
// loader dots...
|
// loader dots...
|
||||||
setInterval(function () { |
setInterval(function () { |
||||||
$('.anim-dots').each(function (x) { |
$('.anim-dots').each(function (x) { |
||||||
var $x = $(x); |
var $x = $(x); |
||||||
var dots = $x.html() + '.'; |
var dots = $x.html() + '.'; |
||||||
if (dots.length == 5) dots = '.'; |
if (dots.length == 5) dots = '.'; |
||||||
$x.html(dots); |
$x.html(dots); |
||||||
}); |
}); |
||||||
}, 1000); |
}, 1000); |
||||||
|
|
||||||
// flipping number boxes with the mouse wheel
|
// flipping number boxes with the mouse wheel
|
||||||
$('input[type=number]').on('mousewheel', function(e) { |
$('input[type=number]').on('mousewheel', function (e) { |
||||||
var $this = $(this); |
var $this = $(this); |
||||||
var val = +$this.val(); |
var val = +$this.val(); |
||||||
if (isNaN(val)) val = 1; |
if (isNaN(val)) val = 1; |
||||||
|
|
||||||
var step = +($this.attr('step') || 1); |
var step = +($this.attr('step') || 1); |
||||||
var min = +$this.attr('min'); |
var min = +$this.attr('min'); |
||||||
var max = +$this.attr('max'); |
var max = +$this.attr('max'); |
||||||
if(e.wheelDelta > 0) { |
if (e.wheelDelta > 0) { |
||||||
val += step; |
val += step; |
||||||
} else { |
} else { |
||||||
val -= step; |
val -= step; |
||||||
} |
} |
||||||
|
|
||||||
if (typeof min != 'undefined') val = Math.max(val, +min); |
if (typeof min != 'undefined') val = Math.max(val, +min); |
||||||
if (typeof max != 'undefined') val = Math.min(val, +max); |
if (typeof max != 'undefined') val = Math.min(val, +max); |
||||||
$this.val(val); |
$this.val(val); |
||||||
|
|
||||||
if ("createEvent" in document) { |
if ("createEvent" in document) { |
||||||
var evt = document.createEvent("HTMLEvents"); |
var evt = document.createEvent("HTMLEvents"); |
||||||
evt.initEvent("change", false, true); |
evt.initEvent("change", false, true); |
||||||
$this[0].dispatchEvent(evt); |
$this[0].dispatchEvent(evt); |
||||||
} else { |
} else { |
||||||
$this[0].fireEvent("onchange"); |
$this[0].fireEvent("onchange"); |
||||||
} |
} |
||||||
|
|
||||||
e.preventDefault(); |
e.preventDefault(); |
||||||
}); |
}); |
||||||
|
|
||||||
var errAt = location.search.indexOf('err='); |
var errAt = location.search.indexOf('err='); |
||||||
if (errAt !== -1 && qs('.Box.errors')) { |
if (errAt !== -1 && qs('.Box.errors')) { |
||||||
var errs = location.search.substr(errAt+4).split(','); |
var errs = location.search.substr(errAt + 4).split(','); |
||||||
var hres = []; |
var hres = []; |
||||||
errs.forEach(function(er) { |
errs.forEach(function (er) { |
||||||
var lbl = qs('label[for="'+er+'"]'); |
var lbl = qs('label[for="' + er + '"]'); |
||||||
if (lbl) { |
if (lbl) { |
||||||
lbl.classList.add('error'); |
lbl.classList.add('error'); |
||||||
hres.push(lbl.childNodes[0].textContent.trim().replace(/: ?$/, '')); |
hres.push(lbl.childNodes[0].textContent.trim().replace(/: ?$/, '')); |
||||||
} else { |
} else { |
||||||
hres.push(er); |
hres.push(er); |
||||||
} |
} |
||||||
}); |
}); |
||||||
|
|
||||||
qs('.Box.errors .list').innerHTML = hres.join(', '); |
qs('.Box.errors .list').innerHTML = hres.join(', '); |
||||||
qs('.Box.errors').classList.remove('hidden'); |
qs('.Box.errors').classList.remove('hidden'); |
||||||
} |
} |
||||||
|
|
||||||
Modal.init(); |
Modal.init(); |
||||||
Notify.init(); |
Notify.init(); |
||||||
|
|
||||||
// remove tabindixes from h2 if wide
|
// remove tabindixes from h2 if wide
|
||||||
if (window.innerWidth > 550) { |
if (window.innerWidth > 550) { |
||||||
$('.Box h2').forEach(function (x) { |
$('.Box h2').forEach(function (x) { |
||||||
x.removeAttribute('tabindex'); |
x.removeAttribute('tabindex'); |
||||||
}); |
}); |
||||||
|
|
||||||
// brand works as a link back to term in widescreen mode
|
// brand works as a link back to term in widescreen mode
|
||||||
var br = qs('#brand'); |
var br = qs('#brand'); |
||||||
br && br.addEventListener('click', function() { |
br && br.addEventListener('click', function () { |
||||||
location.href='/'; // go to terminal
|
location.href = '/'; // go to terminal
|
||||||
}); |
}); |
||||||
} |
} |
||||||
}); |
}); |
||||||
|
|
||||||
$._loader = function(vis) { |
$._loader = function (vis) { |
||||||
$('#loader').toggleClass('show', vis); |
$('#loader').toggleClass('show', vis); |
||||||
}; |
}; |
||||||
|
|
||||||
function showPage() { |
function showPage() { |
||||||
$('#content').addClass('load'); |
$('#content').addClass('load'); |
||||||
} |
} |
||||||
|
|
||||||
$.ready(function() { |
$.ready(function () { |
||||||
if (window.noAutoShow !== true) { |
if (window.noAutoShow !== true) { |
||||||
setTimeout(function () { |
setTimeout(function () { |
||||||
showPage(); |
showPage(); |
||||||
}, 1); |
}, 1); |
||||||
} |
} |
||||||
}); |
}); |
||||||
|
|
||||||
|
|
||||||
/*! http://mths.be/fromcodepoint v0.1.0 by @mathias */ |
/*! http://mths.be/fromcodepoint v0.1.0 by @mathias */ |
||||||
if (!String.fromCodePoint) { |
if (!String.fromCodePoint) { |
||||||
(function() { |
(function () { |
||||||
var defineProperty = (function() { |
var defineProperty = (function () { |
||||||
// IE 8 only supports `Object.defineProperty` on DOM elements
|
// IE 8 only supports `Object.defineProperty` on DOM elements
|
||||||
try { |
try { |
||||||
var object = {}; |
var object = {}; |
||||||
var $defineProperty = Object.defineProperty; |
var $defineProperty = Object.defineProperty; |
||||||
var result = $defineProperty(object, object, object) && $defineProperty; |
var result = $defineProperty(object, object, object) && $defineProperty; |
||||||
} catch(error) {} |
} catch (error) { |
||||||
return result; |
} |
||||||
}()); |
return result; |
||||||
var stringFromCharCode = String.fromCharCode; |
}()); |
||||||
var floor = Math.floor; |
var stringFromCharCode = String.fromCharCode; |
||||||
var fromCodePoint = function() { |
var floor = Math.floor; |
||||||
var MAX_SIZE = 0x4000; |
var fromCodePoint = function () { |
||||||
var codeUnits = []; |
var MAX_SIZE = 0x4000; |
||||||
var highSurrogate; |
var codeUnits = []; |
||||||
var lowSurrogate; |
var highSurrogate; |
||||||
var index = -1; |
var lowSurrogate; |
||||||
var length = arguments.length; |
var index = -1; |
||||||
if (!length) { |
var length = arguments.length; |
||||||
return ''; |
if (!length) { |
||||||
} |
return ''; |
||||||
var result = ''; |
} |
||||||
while (++index < length) { |
var result = ''; |
||||||
var codePoint = Number(arguments[index]); |
while (++index < length) { |
||||||
if ( |
var codePoint = Number(arguments[index]); |
||||||
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
|
if ( |
||||||
codePoint < 0 || // not a valid Unicode code point
|
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
|
||||||
codePoint > 0x10FFFF || // not a valid Unicode code point
|
codePoint < 0 || // not a valid Unicode code point
|
||||||
floor(codePoint) != codePoint // not an integer
|
codePoint > 0x10FFFF || // not a valid Unicode code point
|
||||||
) { |
floor(codePoint) != codePoint // not an integer
|
||||||
throw RangeError('Invalid code point: ' + codePoint); |
) { |
||||||
} |
throw RangeError('Invalid code point: ' + codePoint); |
||||||
if (codePoint <= 0xFFFF) { // BMP code point
|
} |
||||||
codeUnits.push(codePoint); |
if (codePoint <= 0xFFFF) { // BMP code point
|
||||||
} else { // Astral code point; split in surrogate halves
|
codeUnits.push(codePoint); |
||||||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
} else { // Astral code point; split in surrogate halves
|
||||||
codePoint -= 0x10000; |
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
||||||
highSurrogate = (codePoint >> 10) + 0xD800; |
codePoint -= 0x10000; |
||||||
lowSurrogate = (codePoint % 0x400) + 0xDC00; |
highSurrogate = (codePoint >> 10) + 0xD800; |
||||||
codeUnits.push(highSurrogate, lowSurrogate); |
lowSurrogate = (codePoint % 0x400) + 0xDC00; |
||||||
} |
codeUnits.push(highSurrogate, lowSurrogate); |
||||||
if (index + 1 == length || codeUnits.length > MAX_SIZE) { |
} |
||||||
result += stringFromCharCode.apply(null, codeUnits); |
if (index + 1 == length || codeUnits.length > MAX_SIZE) { |
||||||
codeUnits.length = 0; |
result += stringFromCharCode.apply(null, codeUnits); |
||||||
} |
codeUnits.length = 0; |
||||||
} |
} |
||||||
return result; |
} |
||||||
}; |
return result; |
||||||
if (defineProperty) { |
}; |
||||||
defineProperty(String, 'fromCodePoint', { |
if (defineProperty) { |
||||||
'value': fromCodePoint, |
defineProperty(String, 'fromCodePoint', { |
||||||
'configurable': true, |
'value': fromCodePoint, |
||||||
'writable': true |
'configurable': true, |
||||||
}); |
'writable': true |
||||||
} else { |
}); |
||||||
String.fromCodePoint = fromCodePoint; |
} else { |
||||||
} |
String.fromCodePoint = fromCodePoint; |
||||||
}()); |
} |
||||||
|
}()); |
||||||
} |
} |
||||||
|
@ -1,8 +1,8 @@ |
|||||||
// Generated from PHP locale file
|
// Generated from PHP locale file
|
||||||
var _tr = { |
var _tr = { |
||||||
"wifi.connected_ip_is": "Connected, IP is ", |
"wifi.connected_ip_is": "Connected, IP is ", |
||||||
"wifi.not_conn": "Not connected.", |
"wifi.not_conn": "Not connected.", |
||||||
"wifi.enter_passwd": "Enter password for \":ssid:\"" |
"wifi.enter_passwd": "Enter password for \":ssid:\"" |
||||||
}; |
}; |
||||||
|
|
||||||
function tr(key) { return _tr[key] || '?'+key+'?'; } |
function tr(key) { return _tr[key] || '?'+key+'?'; } |
||||||
|
@ -1,44 +1,44 @@ |
|||||||
/** Module for toggling a modal overlay */ |
/** Module for toggling a modal overlay */ |
||||||
(function () { |
(function () { |
||||||
var modal = {}; |
var modal = {}; |
||||||
var curCloseCb = null; |
var curCloseCb = null; |
||||||
|
|
||||||
modal.show = function (sel, closeCb) { |
modal.show = function (sel, closeCb) { |
||||||
var $m = $(sel); |
var $m = $(sel); |
||||||
$m.removeClass('hidden visible'); |
$m.removeClass('hidden visible'); |
||||||
setTimeout(function () { |
setTimeout(function () { |
||||||
$m.addClass('visible'); |
$m.addClass('visible'); |
||||||
}, 1); |
}, 1); |
||||||
curCloseCb = closeCb; |
curCloseCb = closeCb; |
||||||
}; |
}; |
||||||
|
|
||||||
modal.hide = function (sel) { |
modal.hide = function (sel) { |
||||||
var $m = $(sel); |
var $m = $(sel); |
||||||
$m.removeClass('visible'); |
$m.removeClass('visible'); |
||||||
setTimeout(function () { |
setTimeout(function () { |
||||||
$m.addClass('hidden'); |
$m.addClass('hidden'); |
||||||
if (curCloseCb) curCloseCb(); |
if (curCloseCb) curCloseCb(); |
||||||
}, 500); // transition time
|
}, 500); // transition time
|
||||||
}; |
}; |
||||||
|
|
||||||
modal.init = function () { |
modal.init = function () { |
||||||
// close modal by click outside the dialog
|
// close modal by click outside the dialog
|
||||||
$('.Modal').on('click', function () { |
$('.Modal').on('click', function () { |
||||||
if ($(this).hasClass('no-close')) return; // this is a no-close modal
|
if ($(this).hasClass('no-close')) return; // this is a no-close modal
|
||||||
modal.hide(this); |
modal.hide(this); |
||||||
}); |
}); |
||||||
|
|
||||||
$('.Dialog').on('click', function (e) { |
$('.Dialog').on('click', function (e) { |
||||||
e.stopImmediatePropagation(); |
e.stopImmediatePropagation(); |
||||||
}); |
}); |
||||||
|
|
||||||
// Hide all modals on esc
|
// Hide all modals on esc
|
||||||
$(window).on('keydown', function (e) { |
$(window).on('keydown', function (e) { |
||||||
if (e.which == 27) { |
if (e.which == 27) { |
||||||
modal.hide('.Modal'); |
modal.hide('.Modal'); |
||||||
} |
} |
||||||
}); |
}); |
||||||
}; |
}; |
||||||
|
|
||||||
window.Modal = modal; |
window.Modal = modal; |
||||||
})(); |
})(); |
||||||
|
@ -1,32 +1,32 @@ |
|||||||
(function (nt) { |
(function (nt) { |
||||||
var sel = '#notif'; |
var sel = '#notif'; |
||||||
|
|
||||||
var hideTmeo1; // timeout to start hiding (transition)
|
var hideTmeo1; // timeout to start hiding (transition)
|
||||||
var hideTmeo2; // timeout to add the hidden class
|
var hideTmeo2; // timeout to add the hidden class
|
||||||
|
|
||||||
nt.show = function (message, timeout) { |
nt.show = function (message, timeout) { |
||||||
$(sel).html(message); |
$(sel).html(message); |
||||||
Modal.show(sel); |
Modal.show(sel); |
||||||
|
|
||||||
clearTimeout(hideTmeo1); |
clearTimeout(hideTmeo1); |
||||||
clearTimeout(hideTmeo2); |
clearTimeout(hideTmeo2); |
||||||
|
|
||||||
if (undef(timeout)) timeout = 2500; |
if (undef(timeout)) timeout = 2500; |
||||||
|
|
||||||
hideTmeo1 = setTimeout(nt.hide, timeout); |
hideTmeo1 = setTimeout(nt.hide, timeout); |
||||||
}; |
}; |
||||||
|
|
||||||
nt.hide = function () { |
nt.hide = function () { |
||||||
var $m = $(sel); |
var $m = $(sel); |
||||||
$m.removeClass('visible'); |
$m.removeClass('visible'); |
||||||
hideTmeo2 = setTimeout(function () { |
hideTmeo2 = setTimeout(function () { |
||||||
$m.addClass('hidden'); |
$m.addClass('hidden'); |
||||||
}, 250); // transition time
|
}, 250); // transition time
|
||||||
}; |
}; |
||||||
|
|
||||||
nt.init = function() { |
nt.init = function () { |
||||||
$(sel).on('click', function() { |
$(sel).on('click', function () { |
||||||
nt.hide(this); |
nt.hide(this); |
||||||
}); |
}); |
||||||
}; |
}; |
||||||
})(window.Notify = {}); |
})(window.Notify = {}); |
||||||
|
@ -1,146 +1,146 @@ |
|||||||
/** File upload utility */ |
/** File upload utility */ |
||||||
var TermUpl = (function() { |
var TermUpl = (function () { |
||||||
var lines, // array of lines without newlines
|
var lines, // array of lines without newlines
|
||||||
line_i, // current line index
|
line_i, // current line index
|
||||||
fuTout, // timeout handle for line sending
|
fuTout, // timeout handle for line sending
|
||||||
send_delay_ms, // delay between lines (ms)
|
send_delay_ms, // delay between lines (ms)
|
||||||
nl_str, // newline string to use
|
nl_str, // newline string to use
|
||||||
curLine, // current line (when using fuOil)
|
curLine, // current line (when using fuOil)
|
||||||
inline_pos; // Offset in line (for long lines)
|
inline_pos; // Offset in line (for long lines)
|
||||||
|
|
||||||
// lines longer than this are split to chunks
|
// lines longer than this are split to chunks
|
||||||
// sending a super-ling string through the socket is not a good idea
|
// sending a super-ling string through the socket is not a good idea
|
||||||
var MAX_LINE_LEN = 128; |
var MAX_LINE_LEN = 128; |
||||||
|
|
||||||
function fuOpen() { |
function fuOpen() { |
||||||
fuStatus("Ready..."); |
fuStatus("Ready..."); |
||||||
Modal.show('#fu_modal', onClose); |
Modal.show('#fu_modal', onClose); |
||||||
$('#fu_form').toggleClass('busy', false); |
$('#fu_form').toggleClass('busy', false); |
||||||
Input.blockKeys(true); |
Input.blockKeys(true); |
||||||
} |
} |
||||||
|
|
||||||
function onClose() { |
function onClose() { |
||||||
console.log("Upload modal closed."); |
console.log("Upload modal closed."); |
||||||
clearTimeout(fuTout); |
clearTimeout(fuTout); |
||||||
line_i = 0; |
line_i = 0; |
||||||
Input.blockKeys(false); |
Input.blockKeys(false); |
||||||
} |
} |
||||||
|
|
||||||
function fuStatus(msg) { |
function fuStatus(msg) { |
||||||
qs('#fu_prog').textContent = msg; |
qs('#fu_prog').textContent = msg; |
||||||
} |
} |
||||||
|
|
||||||
function fuSend() { |
function fuSend() { |
||||||
var v = qs('#fu_text').value; |
var v = qs('#fu_text').value; |
||||||
if (!v.length) { |
if (!v.length) { |
||||||
fuClose(); |
fuClose(); |
||||||
return; |
return; |
||||||
} |
} |
||||||
|
|
||||||
lines = v.split('\n'); |
lines = v.split('\n'); |
||||||
line_i = 0; |
line_i = 0; |
||||||
inline_pos = 0; // offset in line
|
inline_pos = 0; // offset in line
|
||||||
send_delay_ms = qs('#fu_delay').value; |
send_delay_ms = qs('#fu_delay').value; |
||||||
|
|
||||||
// sanitize - 0 causes overflows
|
// sanitize - 0 causes overflows
|
||||||
if (send_delay_ms < 0) { |
if (send_delay_ms < 0) { |
||||||
send_delay_ms = 0; |
send_delay_ms = 0; |
||||||
qs('#fu_delay').value = send_delay_ms; |
qs('#fu_delay').value = send_delay_ms; |
||||||
} |
} |
||||||
|
|
||||||
nl_str = { |
nl_str = { |
||||||
'CR': '\r', |
'CR': '\r', |
||||||
'LF': '\n', |
'LF': '\n', |
||||||
'CRLF': '\r\n', |
'CRLF': '\r\n', |
||||||
}[qs('#fu_crlf').value]; |
}[qs('#fu_crlf').value]; |
||||||
|
|
||||||
$('#fu_form').toggleClass('busy', true); |
$('#fu_form').toggleClass('busy', true); |
||||||
fuStatus("Starting..."); |
fuStatus("Starting..."); |
||||||
fuSendLine(); |
fuSendLine(); |
||||||
} |
} |
||||||
|
|
||||||
function fuSendLine() { |
function fuSendLine() { |
||||||
if (!$('#fu_modal').hasClass('visible')) { |
if (!$('#fu_modal').hasClass('visible')) { |
||||||
// Modal is closed, cancel
|
// Modal is closed, cancel
|
||||||
return; |
return; |
||||||
} |
} |
||||||
|
|
||||||
if (!Conn.canSend()) { |
if (!Conn.canSend()) { |
||||||
// postpone
|
// postpone
|
||||||
fuTout = setTimeout(fuSendLine, 1); |
fuTout = setTimeout(fuSendLine, 1); |
||||||
return; |
return; |
||||||
} |
} |
||||||
|
|
||||||
if (inline_pos == 0) { |
if (inline_pos == 0) { |
||||||
curLine = lines[line_i++] + nl_str; |
curLine = lines[line_i++] + nl_str; |
||||||
} |
} |
||||||
|
|
||||||
var chunk; |
var chunk; |
||||||
if ((curLine.length - inline_pos) <= MAX_LINE_LEN) { |
if ((curLine.length - inline_pos) <= MAX_LINE_LEN) { |
||||||
chunk = curLine.substr(inline_pos, MAX_LINE_LEN); |
chunk = curLine.substr(inline_pos, MAX_LINE_LEN); |
||||||
inline_pos = 0; |
inline_pos = 0; |
||||||
} else { |
} else { |
||||||
chunk = curLine.substr(inline_pos, MAX_LINE_LEN); |
chunk = curLine.substr(inline_pos, MAX_LINE_LEN); |
||||||
inline_pos += MAX_LINE_LEN; |
inline_pos += MAX_LINE_LEN; |
||||||
} |
} |
||||||
|
|
||||||
if (!Input.sendString(chunk)) { |
if (!Input.sendString(chunk)) { |
||||||
fuStatus("FAILED!"); |
fuStatus("FAILED!"); |
||||||
return; |
return; |
||||||
} |
} |
||||||
|
|
||||||
var all = lines.length; |
var all = lines.length; |
||||||
|
|
||||||
fuStatus(line_i+" / "+all+ " ("+(Math.round((line_i/all)*1000)/10)+"%)"); |
fuStatus(line_i + " / " + all + " (" + (Math.round((line_i / all) * 1000) / 10) + "%)"); |
||||||
|
|
||||||
if (lines.length > line_i || inline_pos > 0) { |
if (lines.length > line_i || inline_pos > 0) { |
||||||
fuTout = setTimeout(fuSendLine, send_delay_ms); |
fuTout = setTimeout(fuSendLine, send_delay_ms); |
||||||
} else { |
} else { |
||||||
closeWhenReady(); |
closeWhenReady(); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
function closeWhenReady() { |
function closeWhenReady() { |
||||||
if (!Conn.canSend()) { |
if (!Conn.canSend()) { |
||||||
// stuck in XOFF still, wait to process...
|
// stuck in XOFF still, wait to process...
|
||||||
fuStatus("Waiting for Tx buffer..."); |
fuStatus("Waiting for Tx buffer..."); |
||||||
setTimeout(closeWhenReady, 100); |
setTimeout(closeWhenReady, 100); |
||||||
} else { |
} else { |
||||||
fuStatus("Done."); |
fuStatus("Done."); |
||||||
// delay to show it
|
// delay to show it
|
||||||
setTimeout(function() { |
setTimeout(function () { |
||||||
fuClose(); |
fuClose(); |
||||||
}, 100); |
}, 100); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
function fuClose() { |
function fuClose() { |
||||||
Modal.hide('#fu_modal'); |
Modal.hide('#fu_modal'); |
||||||
} |
} |
||||||
|
|
||||||
return { |
return { |
||||||
init: function() { |
init: function () { |
||||||
qs('#fu_file').addEventListener('change', function (evt) { |
qs('#fu_file').addEventListener('change', function (evt) { |
||||||
var reader = new FileReader(); |
var reader = new FileReader(); |
||||||
var file = evt.target.files[0]; |
var file = evt.target.files[0]; |
||||||
console.log("Selected file type: "+file.type); |
console.log("Selected file type: " + file.type); |
||||||
if (!file.type.match(/text\/.*|application\/(json|csv|.*xml.*|.*script.*)/)) { |
if (!file.type.match(/text\/.*|application\/(json|csv|.*xml.*|.*script.*)/)) { |
||||||
// Deny load of blobs like img - can crash browser and will get corrupted anyway
|
// Deny load of blobs like img - can crash browser and will get corrupted anyway
|
||||||
if (!confirm("This does not look like a text file: "+file.type+"\nReally load?")) { |
if (!confirm("This does not look like a text file: " + file.type + "\nReally load?")) { |
||||||
qs('#fu_file').value = ''; |
qs('#fu_file').value = ''; |
||||||
return; |
return; |
||||||
} |
} |
||||||
} |
} |
||||||
reader.onload = function(e) { |
reader.onload = function (e) { |
||||||
var txt = e.target.result.replace(/[\r\n]+/,'\n'); |
var txt = e.target.result.replace(/[\r\n]+/, '\n'); |
||||||
qs('#fu_text').value = txt; |
qs('#fu_text').value = txt; |
||||||
}; |
}; |
||||||
console.log("Loading file..."); |
console.log("Loading file..."); |
||||||
reader.readAsText(file); |
reader.readAsText(file); |
||||||
}, false); |
}, false); |
||||||
}, |
}, |
||||||
close: fuClose, |
close: fuClose, |
||||||
start: fuSend, |
start: fuSend, |
||||||
open: fuOpen, |
open: fuOpen, |
||||||
} |
} |
||||||
})(); |
})(); |
||||||
|
@ -1,163 +1,163 @@ |
|||||||
(function(w) { |
(function (w) { |
||||||
var authStr = ['Open', 'WEP', 'WPA', 'WPA2', 'WPA/WPA2']; |
var authStr = ['Open', 'WEP', 'WPA', 'WPA2', 'WPA/WPA2']; |
||||||
var curSSID; |
var curSSID; |
||||||
|
|
||||||
// Get XX % for a slider input
|
// Get XX % for a slider input
|
||||||
function rangePt(inp) { |
function rangePt(inp) { |
||||||
return Math.round(((inp.value / inp.max)*100)) + '%'; |
return Math.round(((inp.value / inp.max) * 100)) + '%'; |
||||||
} |
} |
||||||
|
|
||||||
// Display selected STA SSID etc
|
// Display selected STA SSID etc
|
||||||
function selectSta(name, password, ip) { |
function selectSta(name, password, ip) { |
||||||
$('#sta_ssid').val(name); |
$('#sta_ssid').val(name); |
||||||
$('#sta_password').val(password); |
$('#sta_password').val(password); |
||||||
|
|
||||||
$('#sta-nw').toggleClass('hidden', name.length == 0); |
$('#sta-nw').toggleClass('hidden', name.length == 0); |
||||||
$('#sta-nw-nil').toggleClass('hidden', name.length > 0); |
$('#sta-nw-nil').toggleClass('hidden', name.length > 0); |
||||||
|
|
||||||
$('#sta-nw .essid').html(e(name)); |
$('#sta-nw .essid').html(e(name)); |
||||||
var nopw = undef(password) || password.length == 0; |
var nopw = undef(password) || password.length == 0; |
||||||
$('#sta-nw .passwd').toggleClass('hidden', nopw); |
$('#sta-nw .passwd').toggleClass('hidden', nopw); |
||||||
$('#sta-nw .nopasswd').toggleClass('hidden', !nopw); |
$('#sta-nw .nopasswd').toggleClass('hidden', !nopw); |
||||||
$('#sta-nw .ip').html(ip.length>0 ? tr('wifi.connected_ip_is')+ip : tr('wifi.not_conn')); |
$('#sta-nw .ip').html(ip.length > 0 ? tr('wifi.connected_ip_is') + ip : tr('wifi.not_conn')); |
||||||
} |
} |
||||||
|
|
||||||
/** Update display for received response */ |
/** Update display for received response */ |
||||||
function onScan(resp, status) { |
function onScan(resp, status) { |
||||||
//var ap_json = {
|
//var ap_json = {
|
||||||
// "result": {
|
// "result": {
|
||||||
// "inProgress": "0",
|
// "inProgress": "0",
|
||||||
// "APs": [
|
// "APs": [
|
||||||
// {"essid": "Chlivek", "bssid": "88:f7:c7:52:b3:99", "rssi": "204", "enc": "4", "channel": "1"},
|
// {"essid": "Chlivek", "bssid": "88:f7:c7:52:b3:99", "rssi": "204", "enc": "4", "channel": "1"},
|
||||||
// {"essid": "TyNikdy", "bssid": "5c:f4:ab:0d:f1:1b", "rssi": "164", "enc": "3", "channel": "1"},
|
// {"essid": "TyNikdy", "bssid": "5c:f4:ab:0d:f1:1b", "rssi": "164", "enc": "3", "channel": "1"},
|
||||||
// ]
|
// ]
|
||||||
// }
|
// }
|
||||||
//};
|
//};
|
||||||
|
|
||||||
if (status != 200) { |
if (status != 200) { |
||||||
// bad response
|
// bad response
|
||||||
rescan(5000); // wait 5sm then retry
|
rescan(5000); // wait 5sm then retry
|
||||||
return; |
return; |
||||||
} |
} |
||||||
|
|
||||||
try { |
try { |
||||||
resp = JSON.parse(resp); |
resp = JSON.parse(resp); |
||||||
} catch (e) { |
} catch (e) { |
||||||
console.log(e); |
console.log(e); |
||||||
rescan(5000); |
rescan(5000); |
||||||
return; |
return; |
||||||
} |
} |
||||||
|
|
||||||
var done = !bool(resp.result.inProgress) && (resp.result.APs.length > 0); |
var done = !bool(resp.result.inProgress) && (resp.result.APs.length > 0); |
||||||
rescan(done ? 15000 : 1000); |
rescan(done ? 15000 : 1000); |
||||||
if (!done) return; // no redraw yet
|
if (!done) return; // no redraw yet
|
||||||
|
|
||||||
// clear the AP list
|
// clear the AP list
|
||||||
var $list = $('#ap-list'); |
var $list = $('#ap-list'); |
||||||
// remove old APs
|
// remove old APs
|
||||||
$('#ap-list .AP').remove(); |
$('#ap-list .AP').remove(); |
||||||
|
|
||||||
$list.toggleClass('hidden', !done); |
$list.toggleClass('hidden', !done); |
||||||
$('#ap-loader').toggleClass('hidden', done); |
$('#ap-loader').toggleClass('hidden', done); |
||||||
|
|
||||||
// scan done
|
// scan done
|
||||||
resp.result.APs.sort(function (a, b) { |
resp.result.APs.sort(function (a, b) { |
||||||
return b.rssi - a.rssi; |
return b.rssi - a.rssi; |
||||||
}).forEach(function (ap) { |
}).forEach(function (ap) { |
||||||
ap.enc = parseInt(ap.enc); |
ap.enc = parseInt(ap.enc); |
||||||
|
|
||||||
if (ap.enc > 4) return; // hide unsupported auths
|
if (ap.enc > 4) return; // hide unsupported auths
|
||||||
|
|
||||||
var item = mk('div'); |
var item = mk('div'); |
||||||
|
|
||||||
var $item = $(item) |
var $item = $(item) |
||||||
.data('ssid', ap.essid) |
.data('ssid', ap.essid) |
||||||
.data('pwd', ap.enc) |
.data('pwd', ap.enc) |
||||||
.attr('tabindex', 0) |
.attr('tabindex', 0) |
||||||
.addClass('AP'); |
.addClass('AP'); |
||||||
|
|
||||||
// mark current SSID
|
// mark current SSID
|
||||||
if (ap.essid == curSSID) { |
if (ap.essid == curSSID) { |
||||||
$item.addClass('selected'); |
$item.addClass('selected'); |
||||||
} |
} |
||||||
|
|
||||||
var inner = mk('div'); |
var inner = mk('div'); |
||||||
$(inner).addClass('inner') |
$(inner).addClass('inner') |
||||||
.htmlAppend('<div class="rssi">{0}</div>'.format(ap.rssi_perc)) |
.htmlAppend('<div class="rssi">{0}</div>'.format(ap.rssi_perc)) |
||||||
.htmlAppend('<div class="essid" title="{0}">{0}</div>'.format($.htmlEscape(ap.essid))) |
.htmlAppend('<div class="essid" title="{0}">{0}</div>'.format($.htmlEscape(ap.essid))) |
||||||
.htmlAppend('<div class="auth">{0}</div>'.format(authStr[ap.enc])); |
.htmlAppend('<div class="auth">{0}</div>'.format(authStr[ap.enc])); |
||||||
|
|
||||||
$item.on('click', function () { |
$item.on('click', function () { |
||||||
var $th = $(this); |
var $th = $(this); |
||||||
|
|
||||||
var conn_ssid = $th.data('ssid'); |
var conn_ssid = $th.data('ssid'); |
||||||
var conn_pass = ''; |
var conn_pass = ''; |
||||||
|
|
||||||
if (+$th.data('pwd')) { |
if (+$th.data('pwd')) { |
||||||
// this AP needs a password
|
// this AP needs a password
|
||||||
conn_pass = prompt(tr("wifi.enter_passwd").replace(":ssid:", conn_ssid)); |
conn_pass = prompt(tr("wifi.enter_passwd").replace(":ssid:", conn_ssid)); |
||||||
if (!conn_pass) return; |
if (!conn_pass) return; |
||||||
} |
} |
||||||
|
|
||||||
$('#sta_password').val(conn_pass); |
$('#sta_password').val(conn_pass); |
||||||
$('#sta_ssid').val(conn_ssid); |
$('#sta_ssid').val(conn_ssid); |
||||||
selectSta(conn_ssid, conn_pass, ''); |
selectSta(conn_ssid, conn_pass, ''); |
||||||
}); |
}); |
||||||
|
|
||||||
|
|
||||||
item.appendChild(inner); |
item.appendChild(inner); |
||||||
$list[0].appendChild(item); |
$list[0].appendChild(item); |
||||||
}); |
}); |
||||||
} |
} |
||||||
|
|
||||||
function startScanning() { |
function startScanning() { |
||||||
$('#ap-loader').removeClass('hidden'); |
$('#ap-loader').removeClass('hidden'); |
||||||
$('#ap-scan').addClass('hidden'); |
$('#ap-scan').addClass('hidden'); |
||||||
$('#ap-loader .anim-dots').html('.'); |
$('#ap-loader .anim-dots').html('.'); |
||||||
|
|
||||||
scanAPs(); |
scanAPs(); |
||||||
} |
} |
||||||
|
|
||||||
/** Ask the CGI what APs are visible (async) */ |
/** Ask the CGI what APs are visible (async) */ |
||||||
function scanAPs() { |
function scanAPs() { |
||||||
if (_demo) { |
if (_demo) { |
||||||
onScan(_demo_aps, 200); |
onScan(_demo_aps, 200); |
||||||
} else { |
} else { |
||||||
$.get('http://' + _root + '/cfg/wifi/scan', onScan); |
$.get('http://' + _root + '/cfg/wifi/scan', onScan); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
function rescan(time) { |
function rescan(time) { |
||||||
setTimeout(scanAPs, time); |
setTimeout(scanAPs, time); |
||||||
} |
} |
||||||
|
|
||||||
/** Set up the WiFi page */ |
/** Set up the WiFi page */ |
||||||
function wifiInit(cfg) { |
function wifiInit(cfg) { |
||||||
// Update slider value displays
|
// Update slider value displays
|
||||||
$('.Row.range').forEach(function(x) { |
$('.Row.range').forEach(function (x) { |
||||||
var inp = x.querySelector('input'); |
var inp = x.querySelector('input'); |
||||||
var disp1 = x.querySelector('.x-disp1'); |
var disp1 = x.querySelector('.x-disp1'); |
||||||
var disp2 = x.querySelector('.x-disp2'); |
var disp2 = x.querySelector('.x-disp2'); |
||||||
var t = rangePt(inp); |
var t = rangePt(inp); |
||||||
$(disp1).html(t); |
$(disp1).html(t); |
||||||
$(disp2).html(t); |
$(disp2).html(t); |
||||||
$(inp).on('input', function() { |
$(inp).on('input', function () { |
||||||
t = rangePt(inp); |
t = rangePt(inp); |
||||||
$(disp1).html(t); |
$(disp1).html(t); |
||||||
$(disp2).html(t); |
$(disp2).html(t); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
|
||||||
// Forget STA credentials
|
// Forget STA credentials
|
||||||
$('#forget-sta').on('click', function() { |
$('#forget-sta').on('click', function () { |
||||||
selectSta('', '', ''); |
selectSta('', '', ''); |
||||||
return false; |
return false; |
||||||
}); |
}); |
||||||
|
|
||||||
selectSta(cfg.sta_ssid, cfg.sta_password, cfg.sta_active_ip); |
selectSta(cfg.sta_ssid, cfg.sta_password, cfg.sta_active_ip); |
||||||
curSSID = cfg.sta_active_ssid; |
curSSID = cfg.sta_active_ssid; |
||||||
} |
} |
||||||
|
|
||||||
w.init = wifiInit; |
w.init = wifiInit; |
||||||
w.startScanning = startScanning; |
w.startScanning = startScanning; |
||||||
})(window.WiFi = {}); |
})(window.WiFi = {}); |
||||||
|
Loading…
Reference in new issue