From c1a9cbb2f24af907b442ff51e9a2c7686b33bfe2 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Tue, 30 Jun 2015 18:43:55 +1000 Subject: [PATCH] Split input controls to their own docs --- modules/system/assets/ui/docs/input.hotkey.md | 15 ++++++ modules/system/assets/ui/docs/input.md | 42 ---------------- .../system/assets/ui/docs/input.monitor.md | 6 +++ modules/system/assets/ui/docs/input.preset.md | 11 ++++ .../system/assets/ui/docs/input.trigger.md | 50 +++++++++++++++++++ modules/system/assets/ui/js/input.trigger.js | 11 ++-- 6 files changed, 86 insertions(+), 49 deletions(-) create mode 100644 modules/system/assets/ui/docs/input.hotkey.md delete mode 100644 modules/system/assets/ui/docs/input.md create mode 100644 modules/system/assets/ui/docs/input.monitor.md create mode 100644 modules/system/assets/ui/docs/input.preset.md create mode 100644 modules/system/assets/ui/docs/input.trigger.md diff --git a/modules/system/assets/ui/docs/input.hotkey.md b/modules/system/assets/ui/docs/input.hotkey.md new file mode 100644 index 000000000..d8d435324 --- /dev/null +++ b/modules/system/assets/ui/docs/input.hotkey.md @@ -0,0 +1,15 @@ +# Input Hotkey API + +Scripts that manage user input events. + +# Example + + + + + + diff --git a/modules/system/assets/ui/docs/input.md b/modules/system/assets/ui/docs/input.md deleted file mode 100644 index 7484b5a92..000000000 --- a/modules/system/assets/ui/docs/input.md +++ /dev/null @@ -1,42 +0,0 @@ -# Input - -Scripts that manage user input events. - -# Example - -

Example: input.hotkey

- - - - - -
- -

Example: input.preset

- - - - -
- -

Example: input.trigger

- - - - -
- -

Example: input.monitor

- diff --git a/modules/system/assets/ui/docs/input.monitor.md b/modules/system/assets/ui/docs/input.monitor.md new file mode 100644 index 000000000..a2c019b26 --- /dev/null +++ b/modules/system/assets/ui/docs/input.monitor.md @@ -0,0 +1,6 @@ +# Input Monitoring + +Scripts that manage user input events. + +# Example + diff --git a/modules/system/assets/ui/docs/input.preset.md b/modules/system/assets/ui/docs/input.preset.md new file mode 100644 index 000000000..b5b8807ec --- /dev/null +++ b/modules/system/assets/ui/docs/input.preset.md @@ -0,0 +1,11 @@ +# Input Preset API + +Scripts that manage user input events. + +# Example + + + \ No newline at end of file diff --git a/modules/system/assets/ui/docs/input.trigger.md b/modules/system/assets/ui/docs/input.trigger.md new file mode 100644 index 000000000..bf27e124b --- /dev/null +++ b/modules/system/assets/ui/docs/input.trigger.md @@ -0,0 +1,50 @@ +# Input Trigger API + +The API allows to change elements' visibility or status (enabled/disabled) basing on other elements' statuses. Example: enable a button if any checkbox inside another element is checked. + +### Supported data attributes: + +- data-trigger-action, values: show, hide, enable, disable, empty +- data-trigger: a CSS selector for elements that trigger the action (checkboxes) +- data-trigger-condition, values: + - checked: determines the condition the elements specified in the data-trigger should satisfy in order the condition to be considered as "true". + - value[somevalue]: determines if the value of data-trigger equals the specified value (somevalue) the condition is considered "true". +- data-trigger-closest-parent: optional, specifies a CSS selector for a closest common parent for the source and destination input elements. + +Example code: + + + +### Supported events: + +- oc.triggerOn.update - triggers the update. Trigger this event on the element the plugin is bound to to + force it to check the condition and update itself. This is useful when the page content is updated with AJAX. + +### JavaScript API: + + $('#mybutton').triggerOn({ + triggerCondition: 'checked', + trigger: '#cblist input[type=checkbox]', + triggerAction: 'enable' + }) + +# Example + + + + + + diff --git a/modules/system/assets/ui/js/input.trigger.js b/modules/system/assets/ui/js/input.trigger.js index f9af7a5a9..e27d967f8 100644 --- a/modules/system/assets/ui/js/input.trigger.js +++ b/modules/system/assets/ui/js/input.trigger.js @@ -78,13 +78,10 @@ this.updateTarget($(this.options.trigger + ':checked', this.triggerParent).length > 0) } else if (this.triggerCondition == 'value') { - var trigger = $(this.options.trigger + ':checked', this.triggerParent); - if (trigger.length) { - this.updateTarget(trigger.val() == this.triggerConditionValue) - } - else { - this.updateTarget($(this.options.trigger, this.triggerParent).val() == this.triggerConditionValue) - } + var trigger = $(this.options.trigger + ':checked', this.triggerParent), + needle = trigger.length ? trigger.val() : $(this.options.trigger, this.triggerParent).val() + + this.updateTarget($.inArray(needle, this.triggerConditionValue) != -1) } }