aboutsummaryrefslogtreecommitdiffstats
path: root/uikit/static/js/components/form-select.js
diff options
context:
space:
mode:
authorValentin Heinz <inktrap@users.noreply.github.com>2017-04-08 14:03:25 +0200
committerAlexis Metaireau <alexis@notmyidea.org>2017-04-08 14:03:25 +0200
commit5c231ceade17e7f5b1bba90e845dd2d17e54da1c (patch)
treef4f07dbbac2c51c8a0af1e1a24f11e030a2e4155 /uikit/static/js/components/form-select.js
parent00986ab80df4b6be2d1306671907e2b2378e487f (diff)
downloadpelican-themes-5c231ceade17e7f5b1bba90e845dd2d17e54da1c.tar.gz
uikit demo theme ported to pelican (#385)
Diffstat (limited to 'uikit/static/js/components/form-select.js')
-rw-r--r--uikit/static/js/components/form-select.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/uikit/static/js/components/form-select.js b/uikit/static/js/components/form-select.js
new file mode 100644
index 0000000..ddafff8
--- /dev/null
+++ b/uikit/static/js/components/form-select.js
@@ -0,0 +1,70 @@
+/*! UIkit 2.21.0 | 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")) {
+ var obj = 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 {
+ $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;
+});