aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/webui
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-23 19:15:39 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-23 19:15:39 +0800
commit3beef01f36214973008d980b2da997b053eb4fd8 (patch)
treede45b56423febd467bf0a9beccf6238b56207711 /fg21sim/webui
parenta993ae58f3c848bbf46c90f217d1dbc1f44828c1 (diff)
downloadfg21sim-3beef01f36214973008d980b2da997b053eb4fd8.tar.bz2
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.
Diffstat (limited to 'fg21sim/webui')
-rw-r--r--fg21sim/webui/static/js/configs.js29
1 files changed, 15 insertions, 14 deletions
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");
+ }
});
});