Skip to content

Commit

Permalink
Merge branch 'canvas-babel' into canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
MightyPork committed Sep 10, 2017
2 parents c354ec8 + d1fd0b9 commit c07a616
Show file tree
Hide file tree
Showing 10 changed files with 907 additions and 55 deletions.
18 changes: 18 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"presets": [
["env", {
"targets": {
"browsers": [
"last 2 versions",
"> 4%",
"ie 11",
"safari 8",
"android 4.4"
]
}
}],
["minify", {
"mergeVars": false
}]
]
}
28 changes: 13 additions & 15 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#!/bin/bash

echo 'Packing 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 ';'
npm run babel -- -o js/app.js --source-maps jssrc/lib \
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

echo 'Building CSS...'

Expand Down
4 changes: 2 additions & 2 deletions jssrc/appcommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ $.ready(function () {
val -= step
}

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

if ('createEvent' in document) {
Expand Down
3 changes: 2 additions & 1 deletion jssrc/lib/keymaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,5 @@

if(typeof module !== 'undefined') module.exports = assignKey;

})(this);
})(window);

14 changes: 6 additions & 8 deletions jssrc/term_screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ for (let gray = 0; gray < 24; gray++) {

class TermScreen {
constructor () {
this.canvas = document.createElement('canvas')
this.canvas = mk('canvas')
this.ctx = this.canvas.getContext('2d')

if ('AudioContext' in window || 'webkitAudioContext' in window) {
Expand Down Expand Up @@ -587,7 +587,7 @@ class TermScreen {
let selectedText = this.getSelectedText()
// don't copy anything if nothing is selected
if (!selectedText) return
let textarea = document.createElement('textarea')
let textarea = mk('textarea')
document.body.appendChild(textarea)
textarea.value = selectedText
textarea.select()
Expand Down Expand Up @@ -717,10 +717,10 @@ class TermScreen {
const FONT_MASK = 0b101

// Map of (attrs & FONT_MASK) -> Array of cell indices
const fontGroups = new Map()
let fontGroups = new Map()

// Map of (cell index) -> boolean, whether or not a cell has updated
const updateMap = new Map()
let updateMap = new Map()

for (let cell = 0; cell < screenLength; cell++) {
let x = cell % width
Expand Down Expand Up @@ -994,9 +994,7 @@ class TermScreen {
this.screenAttrs = new Array(screenLength).fill(' ')
}

let strArray = typeof Array.from !== 'undefined'
? Array.from(str)
: str.split('')
let strArray = !undef(Array.from) ? Array.from(str) : str.split('')

const MASK_LINE_ATTR = 0xC8
const MASK_BLINK = 1 << 4
Expand Down Expand Up @@ -1084,7 +1082,7 @@ class TermScreen {
let label = pieces[i + 1].trim()
// if empty string, use the "dim" effect and put nbsp instead to
// stretch the button vertically
button.innerHTML = label ? e(label) : '&nbsp;'
button.innerHTML = label ? esc(label) : '&nbsp;'
button.style.opacity = label ? 1 : 0.2
})
}
Expand Down
2 changes: 1 addition & 1 deletion jssrc/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Math.log10 = Math.log10 || function (x) {
}

/** HTML escape */
function e (str) {
function esc (str) {
return $.htmlEscape(str)
}

Expand Down
2 changes: 1 addition & 1 deletion jssrc/wifi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$('#sta-nw').toggleClass('hidden', name.length === 0)
$('#sta-nw-nil').toggleClass('hidden', name.length > 0)

$('#sta-nw .essid').html(e(name))
$('#sta-nw .essid').html(esc(name))
const nopw = undef(password) || password.length === 0
$('#sta-nw .passwd').toggleClass('hidden', nopw)
$('#sta-nw .nopasswd').toggleClass('hidden', !nopw)
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
"description": "ESPTerm web interface",
"license": "MPL-2.0",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-minify": "^0.2.0",
"babel-preset-env": "^1.6.0",
"node-sass": "^4.5.3",
"standard": "^10.0.3"
"standard": "^10.0.3"
},
"scripts": {
"babel": "babel $@",
"minify": "babel-minify $@",
"sass": "node-sass $@"
}
Expand Down
2 changes: 1 addition & 1 deletion pages/_head.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
var _root = <?= JS_WEB_ROOT ?>;
var _demo = <?= (int)ESP_DEMO ?>;
<?php if($_GET['page']=='term'): ?>var _demo_screen = <?= ESP_DEMO ? DEMO_SCREEN : 0 ?>;<?php endif; ?>
<?php if($_GET['page']=='cfg_wifi'): ?>var _demo_aps = <?= ESP_DEMO ? json_encode(DEMO_APS) : '' ?>;<?php endif; ?>
<?php if($_GET['page']=='cfg_wifi'): ?>var _demo_aps = <?= ESP_DEMO ? json_encode(DEMO_APS) : '""' ?>;<?php endif; ?>
</script>
</head>
<body class="<?= $_GET['BODYCLASS'] ?>">
Expand Down
Loading

0 comments on commit c07a616

Please sign in to comment.