From 89c1a1835b090408e571dbdfc07fe820d8474557 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Fri, 18 Nov 2016 14:34:58 +0800 Subject: webui: main.js: Extend jQuery with ".disable()" --- fg21sim/webui/static/js/main.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (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 64b65c1..5b0e7ec 100644 --- a/fg21sim/webui/static/js/main.js +++ b/fg21sim/webui/static/js/main.js @@ -26,8 +26,23 @@ $(document).ajaxError(function (event, jqxhr, settings, exception) { /** - * Common functions that will be used by other scripts + * Extend jQuery with the `disable()` function to enable/disable buttons, + * input, etc. + * + * Credit: https://stackoverflow.com/a/16788240/4856091 */ +jQuery.fn.extend({ + disable: function (state) { + return this.each(function () { + if ($(this).is("input, button, textarea, select")) { + this.disabled = state; + } else { + $(this).toggleClass("disabled", state); + } + }); + } +}); + /** * Get the value of a key stored in the cookie -- cgit v1.2.2