diff options
author | Aaron LI <aaronly.me@outlook.com> | 2016-11-18 14:34:58 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2016-11-18 14:34:58 +0800 |
commit | 89c1a1835b090408e571dbdfc07fe820d8474557 (patch) | |
tree | f676ee99ad214e868ed86274dce473e226b341d6 /fg21sim/webui/static/js | |
parent | fbdcbcd78779cde5cdebd28106abf904f6d026e2 (diff) | |
download | fg21sim-89c1a1835b090408e571dbdfc07fe820d8474557.tar.bz2 |
webui: main.js: Extend jQuery with ".disable()"
Diffstat (limited to 'fg21sim/webui/static/js')
-rw-r--r-- | fg21sim/webui/static/js/main.js | 17 |
1 files changed, 16 insertions, 1 deletions
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 |