diff options
Diffstat (limited to 'js/components/form-select.js')
| -rwxr-xr-x | js/components/form-select.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/js/components/form-select.js b/js/components/form-select.js new file mode 100755 index 0000000..8f081fb --- /dev/null +++ b/js/components/form-select.js | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | /*! UIkit 2.26.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ | ||
| 2 | (function(addon) { | ||
| 3 | |||
| 4 | var component; | ||
| 5 | |||
| 6 | if (window.UIkit) { | ||
| 7 | component = addon(UIkit); | ||
| 8 | } | ||
| 9 | |||
| 10 | if (typeof define == "function" && define.amd) { | ||
| 11 | define("uikit-form-select", ["uikit"], function(){ | ||
| 12 | return component || addon(UIkit); | ||
| 13 | }); | ||
| 14 | } | ||
| 15 | |||
| 16 | })(function(UI){ | ||
| 17 | |||
| 18 | "use strict"; | ||
| 19 | |||
| 20 | UI.component('formSelect', { | ||
| 21 | |||
| 22 | defaults: { | ||
| 23 | 'target': '>span:first', | ||
| 24 | 'activeClass': 'uk-active' | ||
| 25 | }, | ||
| 26 | |||
| 27 | boot: function() { | ||
| 28 | // init code | ||
| 29 | UI.ready(function(context) { | ||
| 30 | |||
| 31 | UI.$("[data-uk-form-select]", context).each(function(){ | ||
| 32 | |||
| 33 | var ele = UI.$(this); | ||
| 34 | |||
| 35 | if (!ele.data("formSelect")) { | ||
| 36 | UI.formSelect(ele, UI.Utils.options(ele.attr("data-uk-form-select"))); | ||
| 37 | } | ||
| 38 | }); | ||
| 39 | }); | ||
| 40 | }, | ||
| 41 | |||
| 42 | init: function() { | ||
| 43 | var $this = this; | ||
| 44 | |||
| 45 | this.target = this.find(this.options.target); | ||
| 46 | this.select = this.find('select'); | ||
| 47 | |||
| 48 | // init + on change event | ||
| 49 | this.select.on("change", (function(){ | ||
| 50 | |||
| 51 | var select = $this.select[0], fn = function(){ | ||
| 52 | |||
| 53 | try { | ||
| 54 | if($this.options.target === 'input') | ||
| 55 | { | ||
| 56 | $this.target.val(select.options[select.selectedIndex].text); | ||
| 57 | } | ||
| 58 | else | ||
| 59 | { | ||
| 60 | $this.target.text(select.options[select.selectedIndex].text); | ||
| 61 | } | ||
| 62 | } catch(e) {} | ||
| 63 | |||
| 64 | $this.element[$this.select.val() ? 'addClass':'removeClass']($this.options.activeClass); | ||
| 65 | |||
| 66 | return fn; | ||
| 67 | }; | ||
| 68 | |||
| 69 | return fn(); | ||
| 70 | })()); | ||
| 71 | |||
| 72 | this.element.data("formSelect", this); | ||
| 73 | } | ||
| 74 | }); | ||
| 75 | |||
| 76 | return UI.formSelect; | ||
| 77 | }); | ||
