Sha256: 76b6a51f648f7f0ae71922ab7ec5b4e1cac9ef67e4a1ab0b2aecb59bdb63d412

Contents?: true

Size: 1.98 KB

Versions: 3

Compression:

Stored size: 1.98 KB

Contents

/*! UIkit 2.26.3 | 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;
});

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
uikit2-rails-0.1.9 vendor/assets/javascripts/uikit/components/form-select.js
blazer-rails-0.1.1 vendor/assets/components/uikit/js/components/form-select.js
blazer-rails-0.1.0 vendor/assets/components/uikit/js/components/form-select.js