aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/webui/static/js/main.js
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-28 12:28:12 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-28 12:28:12 +0800
commit39dc175b88fe7e76770708c96bad9915c1eaa893 (patch)
tree5f55846073cd8c8cebb4a00b529da4be8ec49757 /fg21sim/webui/static/js/main.js
parentc26aa54d45d9ae089e65f046ec06b4e21ca6d166 (diff)
downloadfg21sim-39dc175b88fe7e76770708c96bad9915c1eaa893.tar.bz2
webui: Some JavaScript cleanups and refactors
Credit: "JavaScript: The Good Parts" by Douglas Crockford
Diffstat (limited to 'fg21sim/webui/static/js/main.js')
-rw-r--r--fg21sim/webui/static/js/main.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/fg21sim/webui/static/js/main.js b/fg21sim/webui/static/js/main.js
index c725803..0383365 100644
--- a/fg21sim/webui/static/js/main.js
+++ b/fg21sim/webui/static/js/main.js
@@ -37,7 +37,7 @@ var dirname = function (path) {
* FIXME: only support "/" as the path separator
*/
var joinPath = function (path1, path2) {
- var p = null;
+ var p;
// Strip the trailing path separator
path1 = path1.replace(/\/$/, "");
if (path1 === "") {
@@ -47,8 +47,8 @@ var joinPath = function (path1, path2) {
}
// Both "path1" and "path2" are empty
if (p === "/") {
- console.error("Both 'path1' and 'path2' are empty");
p = null;
+ console.error("Both 'path1' and 'path2' are empty");
}
return p;
};
@@ -203,10 +203,11 @@ var toggleBlock = function (toggle, targetBlock) {
* To close the modal, use `$.modal.close()`
*/
var showModal = function (modalBox, data) {
+ var p;
modalBox = $(modalBox);
// Empty previous contents
modalBox.html("");
- var p = $("<p>");
+ p = $("<p>");
if (data.icon) {
$("<span>").addClass("icon fa")
.addClass("fa-" + data.icon).appendTo(p);
@@ -271,10 +272,11 @@ $(document).ready(function () {
toggleBlock(toggle, body);
});
- // Prevent from submitting form by "Enter"
+ // Prevent from submitting form on "Enter" keypress
// Credit; https://stackoverflow.com/a/11235672/4856091
$("form").on("keypress", function (e) {
if (e.which === 13) {
+ // Disable the default submit action
e.preventDefault();
return false;
}