aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-17 14:13:56 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-17 14:13:56 +0800
commitc99af726e0c56d2db8d809d210da54ee06a1a33b (patch)
treec1ca6019780b17f7c4d3e5ad02cd6b595bfaab43
parenta5a45795b3380b58c6c966cca33c87dfa1b9b8b2 (diff)
downloadfg21sim-c99af726e0c56d2db8d809d210da54ee06a1a33b.tar.bz2
webui: main.js: Refactor out the function "toggleBlock()"
-rw-r--r--fg21sim/webui/static/js/main.js42
1 files changed, 20 insertions, 22 deletions
diff --git a/fg21sim/webui/static/js/main.js b/fg21sim/webui/static/js/main.js
index 6db99e0..ea29e0f 100644
--- a/fg21sim/webui/static/js/main.js
+++ b/fg21sim/webui/static/js/main.js
@@ -76,6 +76,24 @@ var scrollTarget = function (height) {
};
+/**
+ * Toggle the display of the target block
+ */
+var toggleBlock = function (toggle, targetBlock) {
+ if (targetBlock.is(":visible")) {
+ targetBlock.slideUp("fast");
+ toggle.removeClass("fa-chevron-circle-up")
+ .addClass("fa-chevron-circle-down")
+ .attr("title", "Expand contents");
+ } else {
+ targetBlock.slideDown("fast");
+ toggle.removeClass("fa-chevron-circle-down")
+ .addClass("fa-chevron-circle-up")
+ .attr("title", "Collapse contents");
+ }
+};
+
+
$(document).ready(function () {
// Scroll the page to adjust for the fixed navigation banner
$(window).on("hashchange", function () {
@@ -87,33 +105,13 @@ $(document).ready(function () {
$(".heading > .toggle").on("click", function () {
var toggle = $(this);
var body = toggle.closest(".heading").next(".body");
- if (body.is(":visible")) {
- body.slideUp("fast");
- toggle.removeClass("fa-chevron-circle-up")
- .addClass("fa-chevron-circle-down")
- .attr("title", "Expand contents");
- } else {
- body.slideDown("fast");
- toggle.removeClass("fa-chevron-circle-down")
- .addClass("fa-chevron-circle-up")
- .attr("title", "Collapse contents");
- }
+ toggleBlock(toggle, body);
});
// Panel toggle control
$(".panel-title > .toggle").on("click", function () {
var toggle = $(this);
var body = toggle.closest(".panel").find(".panel-body");
- if (body.is(":visible")) {
- body.slideUp("fast");
- toggle.removeClass("fa-chevron-circle-up")
- .addClass("fa-chevron-circle-down")
- .attr("title", "Expand contents");
- } else {
- body.slideDown("fast");
- toggle.removeClass("fa-chevron-circle-down")
- .addClass("fa-chevron-circle-up")
- .attr("title", "Collapse contents");
- }
+ toggleBlock(toggle, body);
});
});