aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/webui
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-18 14:34:58 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-18 14:34:58 +0800
commit89c1a1835b090408e571dbdfc07fe820d8474557 (patch)
treef676ee99ad214e868ed86274dce473e226b341d6 /fg21sim/webui
parentfbdcbcd78779cde5cdebd28106abf904f6d026e2 (diff)
downloadfg21sim-89c1a1835b090408e571dbdfc07fe820d8474557.tar.bz2
webui: main.js: Extend jQuery with ".disable()"
Diffstat (limited to 'fg21sim/webui')
-rw-r--r--fg21sim/webui/static/js/main.js17
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