From c99af726e0c56d2db8d809d210da54ee06a1a33b Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Thu, 17 Nov 2016 14:13:56 +0800 Subject: webui: main.js: Refactor out the function "toggleBlock()" --- fg21sim/webui/static/js/main.js | 42 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'fg21sim/webui/static/js') 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); }); }); -- cgit v1.2.2