parent
7e1611ff7a
commit
79664f56a6
@ -1,25 +1,29 @@ |
|||||||
#!/bin/bash |
#!/bin/bash |
||||||
|
|
||||||
echo "Packing JS..." |
echo 'Packing JS...' |
||||||
|
|
||||||
cat jssrc/chibi.js \ |
echo ';' > ';' |
||||||
jssrc/keymaster.js \ |
cat jssrc/lib/chibi.js ';' \ |
||||||
jssrc/utils.js \ |
jssrc/lib/keymaster.js ';' \ |
||||||
jssrc/modal.js \ |
jssrc/lib/polyfills.js ';' \ |
||||||
jssrc/notif.js \ |
jssrc/utils.js ';' \ |
||||||
jssrc/appcommon.js \ |
jssrc/modal.js ';' \ |
||||||
jssrc/lang.js \ |
jssrc/notif.js ';' \ |
||||||
jssrc/wifi.js \ |
jssrc/appcommon.js ';' \ |
||||||
jssrc/term_* \ |
jssrc/lang.js ';' \ |
||||||
jssrc/term.js \ |
jssrc/wifi.js ';' \ |
||||||
|
jssrc/term_* ';' \ |
||||||
|
jssrc/term.js ';' \ |
||||||
jssrc/soft_keyboard.js | npm run --silent minify > js/app.js |
jssrc/soft_keyboard.js | npm run --silent minify > js/app.js |
||||||
|
rm ';' |
||||||
|
|
||||||
echo "Building CSS..." |
echo 'Building CSS...' |
||||||
|
|
||||||
npm run sass -- --output-style compressed sass/app.scss css/app.css |
npm run sass -- --output-style compressed sass/app.scss css/app.css |
||||||
|
|
||||||
echo "Building HTML..." |
echo 'Building HTML...' |
||||||
|
|
||||||
php ./build_html.php |
php ./dump_js_lang.php |
||||||
|
php ./compile_html.php |
||||||
|
|
||||||
echo "ESPTerm front-end ready" |
echo 'ESPTerm front-end ready' |
||||||
|
@ -1,8 +1,8 @@ |
|||||||
// Generated from PHP locale file
|
// Generated from PHP locale file
|
||||||
var _tr = { |
let _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 + '?' } |
||||||
|
@ -0,0 +1,63 @@ |
|||||||
|
/*! http://mths.be/fromcodepoint v0.1.0 by @mathias */ |
||||||
|
if (!String.fromCodePoint) { |
||||||
|
(function () { |
||||||
|
var defineProperty = (function () { |
||||||
|
// IE 8 only supports `Object.defineProperty` on DOM elements
|
||||||
|
try { |
||||||
|
var object = {}; |
||||||
|
var $defineProperty = Object.defineProperty; |
||||||
|
var result = $defineProperty(object, object, object) && $defineProperty; |
||||||
|
} catch (error) { |
||||||
|
} |
||||||
|
return result; |
||||||
|
}()); |
||||||
|
var stringFromCharCode = String.fromCharCode; |
||||||
|
var floor = Math.floor; |
||||||
|
var fromCodePoint = function () { |
||||||
|
var MAX_SIZE = 0x4000; |
||||||
|
var codeUnits = []; |
||||||
|
var highSurrogate; |
||||||
|
var lowSurrogate; |
||||||
|
var index = -1; |
||||||
|
var length = arguments.length; |
||||||
|
if (!length) { |
||||||
|
return ''; |
||||||
|
} |
||||||
|
var result = ''; |
||||||
|
while (++index < length) { |
||||||
|
var codePoint = Number(arguments[index]); |
||||||
|
if ( |
||||||
|
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
|
||||||
|
codePoint < 0 || // not a valid Unicode code point
|
||||||
|
codePoint > 0x10FFFF || // not a valid Unicode code point
|
||||||
|
floor(codePoint) != codePoint // not an integer
|
||||||
|
) { |
||||||
|
throw RangeError('Invalid code point: ' + codePoint); |
||||||
|
} |
||||||
|
if (codePoint <= 0xFFFF) { // BMP code point
|
||||||
|
codeUnits.push(codePoint); |
||||||
|
} else { // Astral code point; split in surrogate halves
|
||||||
|
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
||||||
|
codePoint -= 0x10000; |
||||||
|
highSurrogate = (codePoint >> 10) + 0xD800; |
||||||
|
lowSurrogate = (codePoint % 0x400) + 0xDC00; |
||||||
|
codeUnits.push(highSurrogate, lowSurrogate); |
||||||
|
} |
||||||
|
if (index + 1 == length || codeUnits.length > MAX_SIZE) { |
||||||
|
result += stringFromCharCode.apply(null, codeUnits); |
||||||
|
codeUnits.length = 0; |
||||||
|
} |
||||||
|
} |
||||||
|
return result; |
||||||
|
}; |
||||||
|
if (defineProperty) { |
||||||
|
defineProperty(String, 'fromCodePoint', { |
||||||
|
'value': fromCodePoint, |
||||||
|
'configurable': true, |
||||||
|
'writable': true |
||||||
|
}); |
||||||
|
} else { |
||||||
|
String.fromCodePoint = fromCodePoint; |
||||||
|
} |
||||||
|
}()); |
||||||
|
} |
@ -1,44 +1,44 @@ |
|||||||
/** Module for toggling a modal overlay */ |
/** Module for toggling a modal overlay */ |
||||||
(function () { |
(function () { |
||||||
var modal = {}; |
let modal = {} |
||||||
var curCloseCb = null; |
let curCloseCb = null |
||||||
|
|
||||||
modal.show = function (sel, closeCb) { |
modal.show = function (sel, closeCb) { |
||||||
var $m = $(sel); |
let $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); |
let $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,35 @@ |
|||||||
(function (nt) { |
window.Notify = (function () { |
||||||
var sel = '#notif'; |
let nt = {} |
||||||
|
const sel = '#notif' |
||||||
|
|
||||||
var hideTmeo1; // timeout to start hiding (transition)
|
let hideTmeo1 // timeout to start hiding (transition)
|
||||||
var hideTmeo2; // timeout to add the hidden class
|
let 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); |
let $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 = {}); |
|
||||||
|
return nt |
||||||
|
})() |
||||||
|
@ -1,87 +1,87 @@ |
|||||||
$.ready(() => { |
$.ready(() => { |
||||||
const input = qs('#softkb-input'); |
const input = qs('#softkb-input') |
||||||
if (!input) return; // abort, we're not on the terminal page
|
if (!input) return // abort, we're not on the terminal page
|
||||||
|
|
||||||
let keyboardOpen = false; |
let keyboardOpen = false |
||||||
|
|
||||||
let updateInputPosition = function () { |
let updateInputPosition = function () { |
||||||
if (!keyboardOpen) return; |
if (!keyboardOpen) return |
||||||
|
|
||||||
let [x, y] = Screen.gridToScreen(Screen.cursor.x, Screen.cursor.y); |
let [x, y] = Screen.gridToScreen(Screen.cursor.x, Screen.cursor.y) |
||||||
input.style.transform = `translate(${x}px, ${y}px)` |
input.style.transform = `translate(${x}px, ${y}px)` |
||||||
}; |
} |
||||||
|
|
||||||
input.addEventListener('focus', () => { |
input.addEventListener('focus', () => { |
||||||
keyboardOpen = true; |
keyboardOpen = true |
||||||
updateInputPosition() |
updateInputPosition() |
||||||
}); |
}) |
||||||
input.addEventListener('blur', () => (keyboardOpen = false)); |
input.addEventListener('blur', () => (keyboardOpen = false)) |
||||||
Screen.on('cursor-moved', updateInputPosition); |
Screen.on('cursor-moved', updateInputPosition) |
||||||
|
|
||||||
window.kbOpen = function openSoftKeyboard (open) { |
window.kbOpen = function openSoftKeyboard (open) { |
||||||
keyboardOpen = open; |
keyboardOpen = open |
||||||
updateInputPosition(); |
updateInputPosition() |
||||||
if (open) input.focus(); |
if (open) input.focus() |
||||||
else input.blur() |
else input.blur() |
||||||
}; |
} |
||||||
|
|
||||||
let lastCompositionString = ''; |
let lastCompositionString = '' |
||||||
let compositing = false; |
let compositing = false |
||||||
|
|
||||||
let sendInputDelta = function (newValue) { |
let sendInputDelta = function (newValue) { |
||||||
let resend = false; |
let resend = false |
||||||
if (newValue.length > lastCompositionString.length) { |
if (newValue.length > lastCompositionString.length) { |
||||||
if (newValue.startsWith(lastCompositionString)) { |
if (newValue.startsWith(lastCompositionString)) { |
||||||
// characters have been added at the end
|
// characters have been added at the end
|
||||||
Input.sendString(newValue.substr(lastCompositionString.length)) |
Input.sendString(newValue.substr(lastCompositionString.length)) |
||||||
} else resend = true; |
} else resend = true |
||||||
} else if (newValue.length < lastCompositionString.length) { |
} else if (newValue.length < lastCompositionString.length) { |
||||||
if (lastCompositionString.startsWith(newValue)) { |
if (lastCompositionString.startsWith(newValue)) { |
||||||
// characters have been removed at the end
|
// characters have been removed at the end
|
||||||
Input.sendString('\b'.repeat(lastCompositionString.length - |
Input.sendString('\b'.repeat(lastCompositionString.length - |
||||||
newValue.length)) |
newValue.length)) |
||||||
} else resend = true; |
} else resend = true |
||||||
} else if (newValue !== lastCompositionString) resend = true; |
} else if (newValue !== lastCompositionString) resend = true |
||||||
|
|
||||||
if (resend) { |
if (resend) { |
||||||
// the entire string changed; resend everything
|
// the entire string changed; resend everything
|
||||||
Input.sendString('\b'.repeat(lastCompositionString.length) + |
Input.sendString('\b'.repeat(lastCompositionString.length) + |
||||||
newValue) |
newValue) |
||||||
} |
} |
||||||
lastCompositionString = newValue; |
lastCompositionString = newValue |
||||||
}; |
} |
||||||
|
|
||||||
input.addEventListener('keydown', e => { |
input.addEventListener('keydown', e => { |
||||||
if (e.key === 'Unidentified') return; |
if (e.key === 'Unidentified') return |
||||||
|
|
||||||
e.preventDefault(); |
e.preventDefault() |
||||||
input.value = ''; |
input.value = '' |
||||||
|
|
||||||
if (e.key === 'Backspace') Input.sendString('\b'); |
if (e.key === 'Backspace') Input.sendString('\b') |
||||||
else if (e.key === 'Enter') Input.sendString('\x0d') |
else if (e.key === 'Enter') Input.sendString('\x0d') |
||||||
}); |
}) |
||||||
input.addEventListener('input', e => { |
input.addEventListener('input', e => { |
||||||
e.stopPropagation(); |
e.stopPropagation() |
||||||
|
|
||||||
if (e.isComposing) { |
if (e.isComposing) { |
||||||
sendInputDelta(e.data); |
sendInputDelta(e.data) |
||||||
} else { |
} else { |
||||||
if (e.data) Input.sendString(e.data); |
if (e.data) Input.sendString(e.data) |
||||||
else if (e.inputType === 'deleteContentBackward') { |
else if (e.inputType === 'deleteContentBackward') { |
||||||
lastCompositionString = ''; |
lastCompositionString = '' |
||||||
sendInputDelta(''); |
sendInputDelta('') |
||||||
} |
} |
||||||
} |
} |
||||||
}); |
}) |
||||||
input.addEventListener('compositionstart', e => { |
input.addEventListener('compositionstart', e => { |
||||||
lastCompositionString = ''; |
lastCompositionString = '' |
||||||
compositing = true; |
compositing = true |
||||||
}); |
}) |
||||||
input.addEventListener('compositionend', e => { |
input.addEventListener('compositionend', e => { |
||||||
lastCompositionString = ''; |
lastCompositionString = '' |
||||||
compositing = false; |
compositing = false |
||||||
input.value = ''; |
input.value = '' |
||||||
}); |
}) |
||||||
|
|
||||||
Screen.on('open-soft-keyboard', () => input.focus()) |
Screen.on('open-soft-keyboard', () => input.focus()) |
||||||
}); |
}) |
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@ |
|||||||
/** Init the terminal sub-module - called from HTML */ |
/** Init the terminal sub-module - called from HTML */ |
||||||
window.termInit = function () { |
window.termInit = function () { |
||||||
Conn.init(); |
Conn.init() |
||||||
Input.init(); |
Input.init() |
||||||
TermUpl.init(); |
TermUpl.init() |
||||||
}; |
} |
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,146 +1,146 @@ |
|||||||
/** File upload utility */ |
/** File upload utility */ |
||||||
var TermUpl = (function () { |
window.TermUpl = (function () { |
||||||
var lines, // array of lines without newlines
|
let 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; |
const 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; |
let 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; |
let 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; |
let 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(); |
let reader = new FileReader() |
||||||
var file = evt.target.files[0]; |
let 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'); |
const 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 |
||||||
} |
} |
||||||
})(); |
})() |
||||||
|
Loading…
Reference in new issue