From c94fb32c7a3c28b18a27460aa2447eeec1fac1de Mon Sep 17 00:00:00 2001 From: Pascal Szewczyk Date: Mon, 18 Jul 2016 23:23:54 +0200 Subject: uikit added --- js/components/form-select.js | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 js/components/form-select.js (limited to 'js/components/form-select.js') 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 @@ +/*! UIkit 2.26.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ +(function(addon) { + + var component; + + if (window.UIkit) { + component = addon(UIkit); + } + + if (typeof define == "function" && define.amd) { + define("uikit-form-select", ["uikit"], function(){ + return component || addon(UIkit); + }); + } + +})(function(UI){ + + "use strict"; + + UI.component('formSelect', { + + defaults: { + 'target': '>span:first', + 'activeClass': 'uk-active' + }, + + boot: function() { + // init code + UI.ready(function(context) { + + UI.$("[data-uk-form-select]", context).each(function(){ + + var ele = UI.$(this); + + if (!ele.data("formSelect")) { + UI.formSelect(ele, UI.Utils.options(ele.attr("data-uk-form-select"))); + } + }); + }); + }, + + init: function() { + var $this = this; + + this.target = this.find(this.options.target); + this.select = this.find('select'); + + // init + on change event + this.select.on("change", (function(){ + + var select = $this.select[0], fn = function(){ + + try { + if($this.options.target === 'input') + { + $this.target.val(select.options[select.selectedIndex].text); + } + else + { + $this.target.text(select.options[select.selectedIndex].text); + } + } catch(e) {} + + $this.element[$this.select.val() ? 'addClass':'removeClass']($this.options.activeClass); + + return fn; + }; + + return fn(); + })()); + + this.element.data("formSelect", this); + } + }); + + return UI.formSelect; +}); -- cgit v1.2.3