From 3beef01f36214973008d980b2da997b053eb4fd8 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Wed, 23 Nov 2016 19:15:39 +0800 Subject: webui: configs.js: Trigger "Enter" after page load on "common/nside" Refactor the "click" event handler on "common/nside" to avoid the duplicated code on resolution calculation. --- fg21sim/webui/static/js/configs.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'fg21sim/webui') diff --git a/fg21sim/webui/static/js/configs.js b/fg21sim/webui/static/js/configs.js index c4fd317..a8ba933 100644 --- a/fg21sim/webui/static/js/configs.js +++ b/fg21sim/webui/static/js/configs.js @@ -557,20 +557,7 @@ $(document).ready(function () { .done(function () { updateFormConfigStatus(); }); }); - // When field "common/nside" changed, update the resolution note, as well - // as the maximum multiple "common/lmax" - $("#conf-form input[name='common/nside']").on("change", function (e) { - var nside = parseInt($(this).val()); - // Update the resolution note (unit: arcmin) - var resolution = Math.sqrt(3/Math.PI) * 3600 / nside; - $(this).closest(".form-group").find(".note > .value") - .text(resolution.toFixed(2)); - // Also update the maximum multipole "common/lmax" - if (! isNaN(nside)) { - var lmax = 3 * nside - 1; - $("#conf-form input[name='common/lmax']").val(lmax).trigger("change"); - } - }); + // Update the resolution note for field "common/nside" when press "Enter" $("#conf-form input[name='common/nside']").keypress(function (e) { if (e.which === 13) { var nside = parseInt($(this).val()); @@ -579,5 +566,19 @@ $(document).ready(function () { $(this).closest(".form-group").find(".note > .value") .text(resolution.toFixed(2)); } + }).trigger( + // Manually trigger the "Enter" keypress event after loading page + $.Event("keypress", {which: 13}) + ); + + // Update the maximum multiple "common/lmax" when "common/nside" changed + $("#conf-form input[name='common/nside']").on("change", function (e) { + // Update the resolution note + $(this).trigger($.Event("keypress", {which: 13})); + var nside = parseInt($(this).val()); + if (! isNaN(nside)) { + var lmax = 3 * nside - 1; + $("#conf-form input[name='common/lmax']").val(lmax).trigger("change"); + } }); }); -- cgit v1.2.2