From 39dc175b88fe7e76770708c96bad9915c1eaa893 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Mon, 28 Nov 2016 12:28:12 +0800 Subject: webui: Some JavaScript cleanups and refactors Credit: "JavaScript: The Good Parts" by Douglas Crockford --- fg21sim/webui/static/js/main.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'fg21sim/webui/static/js/main.js') 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 = $("

"); if (data.icon) { $("").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; } -- cgit v1.2.2