Skip to content

Commit

Permalink
eslint all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
MightyPork committed Sep 10, 2017
1 parent 7e1611f commit 79664f5
Show file tree
Hide file tree
Showing 21 changed files with 2,371 additions and 1,224 deletions.
10 changes: 5 additions & 5 deletions .eslintrc
Expand Up @@ -45,7 +45,7 @@
"curly": ["error", "multi-line"],
"dot-location": ["error", "property"],
"eol-last": "error",
"eqeqeq": ["error", "always", { "null": "ignore" }],
"eqeqeq": ["off", "always", { "null": "ignore" }],
"func-call-spacing": ["error", "never"],
"generator-star-spacing": ["error", { "before": true, "after": true }],
"handle-callback-err": ["error", "^(err|error)$" ],
Expand All @@ -72,7 +72,7 @@
"no-empty-pattern": "error",
"no-eval": "error",
"no-ex-assign": "error",
"no-extend-native": "error",
"no-extend-native": "warn",
"no-extra-bind": "error",
"no-extra-boolean-cast": "error",
"no-extra-parens": ["error", "functions"],
Expand All @@ -87,7 +87,7 @@
"no-iterator": "error",
"no-label-var": "error",
"no-labels": ["error", { "allowLoop": false, "allowSwitch": false }],
"no-lone-blocks": "error",
"no-lone-blocks": "warn",
"no-mixed-operators": ["error", {
"groups": [
["==", "!=", "===", "!==", ">", ">=", "<", "<="],
Expand Down Expand Up @@ -134,8 +134,8 @@
"no-unreachable": "error",
"no-unsafe-finally": "error",
"no-unsafe-negation": "error",
"no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true, "allowTaggedTemplates": true }],
"no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": true }],
"no-unused-expressions": ["warn", { "allowShortCircuit": true, "allowTernary": true, "allowTaggedTemplates": true }],
"no-unused-vars": ["off", { "vars": "local", "args": "none", "ignoreRestSiblings": true }],
"no-use-before-define": ["error", { "functions": false, "classes": false, "variables": false }],
"no-useless-call": "error",
"no-useless-computed-key": "error",
Expand Down
36 changes: 20 additions & 16 deletions build.sh
@@ -1,25 +1,29 @@
#!/bin/bash

echo "Packing JS..."
echo 'Packing JS...'

cat jssrc/chibi.js \
jssrc/keymaster.js \
jssrc/utils.js \
jssrc/modal.js \
jssrc/notif.js \
jssrc/appcommon.js \
jssrc/lang.js \
jssrc/wifi.js \
jssrc/term_* \
jssrc/term.js \
jssrc/soft_keyboard.js | npm run --silent minify > js/app.js
echo ';' > ';'
cat jssrc/lib/chibi.js ';' \
jssrc/lib/keymaster.js ';' \
jssrc/lib/polyfills.js ';' \
jssrc/utils.js ';' \
jssrc/modal.js ';' \
jssrc/notif.js ';' \
jssrc/appcommon.js ';' \
jssrc/lang.js ';' \
jssrc/wifi.js ';' \
jssrc/term_* ';' \
jssrc/term.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

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'
File renamed without changes.
5 changes: 2 additions & 3 deletions dump_js_lang.php
Expand Up @@ -8,7 +8,6 @@
'wifi.connected_ip_is',
'wifi.not_conn',
'wifi.enter_passwd',
'wifi.passwd_saved',
];

$out = [];
Expand All @@ -18,6 +17,6 @@

file_put_contents(__DIR__. '/jssrc/lang.js',
"// Generated from PHP locale file\n" .
'var _tr = ' . json_encode($out, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE) . ";\n\n" .
"function tr(key) { return _tr[key] || '?'+key+'?'; }\n"
'let _tr = ' . json_encode($out, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE) . ";\n\n" .
"function tr (key) { return _tr[key] || '?' + key + '?' }\n"
);
195 changes: 65 additions & 130 deletions jssrc/appcommon.js
Expand Up @@ -2,189 +2,124 @@
$.ready(function () {
// Checkbox UI (checkbox CSS and hidden input with int value)
$('.Row.checkbox').forEach(function (x) {
var inp = x.querySelector('input');
var box = x.querySelector('.box');
let inp = x.querySelector('input')
let box = x.querySelector('.box')

$(box).toggleClass('checked', inp.value);
$(box).toggleClass('checked', inp.value)

var hdl = function () {
inp.value = 1 - inp.value;
let hdl = function () {
inp.value = 1 - 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
$('.Box.mobcol,.Box.fold').forEach(function (x) {
var h = x.querySelector('h2');
let h = x.querySelector('h2')

var hdl = function () {
$(x).toggleClass('expanded');
};
$(h).on('click', hdl).on('keypress', cr(hdl));
});
let hdl = function () {
$(x).toggleClass('expanded')
}
$(h).on('click', hdl).on('keypress', cr(hdl))
})

$('form').forEach(function (x) {
$(x).on('keypress', function (e) {
if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey) {
x.submit();
x.submit()
}
})
});
})

// loader dots...
setInterval(function () {
$('.anim-dots').each(function (x) {
var $x = $(x);
var dots = $x.html() + '.';
if (dots.length == 5) dots = '.';
$x.html(dots);
});
}, 1000);
let $x = $(x)
let dots = $x.html() + '.'
if (dots.length == 5) dots = '.'
$x.html(dots)
})
}, 1000)

// flipping number boxes with the mouse wheel
$('input[type=number]').on('mousewheel', function (e) {
var $this = $(this);
var val = +$this.val();
if (isNaN(val)) val = 1;
let $this = $(this)
let val = +$this.val()
if (isNaN(val)) val = 1

var step = +($this.attr('step') || 1);
var min = +$this.attr('min');
var max = +$this.attr('max');
const step = +($this.attr('step') || 1)
const min = +$this.attr('min')
const max = +$this.attr('max')
if (e.wheelDelta > 0) {
val += step;
val += step
} else {
val -= step;
val -= step
}

if (typeof min != 'undefined') val = Math.max(val, +min);
if (typeof max != 'undefined') val = Math.min(val, +max);
$this.val(val);
if (typeof min != 'undefined') val = Math.max(val, +min)
if (typeof max != 'undefined') val = Math.min(val, +max)
$this.val(val)

if ("createEvent" in document) {
var evt = document.createEvent("HTMLEvents");
evt.initEvent("change", false, true);
$this[0].dispatchEvent(evt);
if ('createEvent' in document) {
let evt = document.createEvent('HTMLEvents')
evt.initEvent('change', false, true)
$this[0].dispatchEvent(evt)
} else {
$this[0].fireEvent("onchange");
$this[0].fireEvent('onchange')
}

e.preventDefault();
});
e.preventDefault()
})

var errAt = location.search.indexOf('err=');
let errAt = location.search.indexOf('err=')
if (errAt !== -1 && qs('.Box.errors')) {
var errs = location.search.substr(errAt + 4).split(',');
var hres = [];
let errs = location.search.substr(errAt + 4).split(',')
let hres = []
errs.forEach(function (er) {
var lbl = qs('label[for="' + er + '"]');
let lbl = qs('label[for="' + er + '"]')
if (lbl) {
lbl.classList.add('error');
hres.push(lbl.childNodes[0].textContent.trim().replace(/: ?$/, ''));
lbl.classList.add('error')
hres.push(lbl.childNodes[0].textContent.trim().replace(/: ?$/, ''))
} else {
hres.push(er);
hres.push(er)
}
});
})

qs('.Box.errors .list').innerHTML = hres.join(', ');
qs('.Box.errors').classList.remove('hidden');
qs('.Box.errors .list').innerHTML = hres.join(', ')
qs('.Box.errors').classList.remove('hidden')
}

Modal.init();
Notify.init();
Modal.init()
Notify.init()

// remove tabindixes from h2 if wide
if (window.innerWidth > 550) {
$('.Box h2').forEach(function (x) {
x.removeAttribute('tabindex');
});
x.removeAttribute('tabindex')
})

// brand works as a link back to term in widescreen mode
var br = qs('#brand');
let br = qs('#brand')
br && br.addEventListener('click', function () {
location.href = '/'; // go to terminal
});
location.href = '/' // go to terminal
})
}
});
})

$._loader = function (vis) {
$('#loader').toggleClass('show', vis);
};
$('#loader').toggleClass('show', vis)
}

function showPage() {
$('#content').addClass('load');
function showPage () {
$('#content').addClass('load')
}

$.ready(function () {
if (window.noAutoShow !== true) {
setTimeout(function () {
showPage();
}, 1);
showPage()
}, 1)
}
});


/*! 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;
}
}());
}
})
10 changes: 5 additions & 5 deletions jssrc/lang.js
@@ -1,8 +1,8 @@
// Generated from PHP locale file
var _tr = {
"wifi.connected_ip_is": "Connected, IP is ",
"wifi.not_conn": "Not connected.",
"wifi.enter_passwd": "Enter password for \":ssid:\""
let _tr = {
"wifi.connected_ip_is": "Connected, IP is ",
"wifi.not_conn": "Not connected.",
"wifi.enter_passwd": "Enter password for \":ssid:\""
};

function tr(key) { return _tr[key] || '?'+key+'?'; }
function tr (key) { return _tr[key] || '?' + key + '?' }
File renamed without changes.
File renamed without changes.

0 comments on commit 79664f5

Please sign in to comment.