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/core/button.js | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100755 js/core/button.js (limited to 'js/core/button.js') diff --git a/js/core/button.js b/js/core/button.js new file mode 100755 index 0000000..9ebe57a --- /dev/null +++ b/js/core/button.js @@ -0,0 +1,157 @@ +/*! UIkit 2.26.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ +(function(UI) { + + "use strict"; + + UI.component('buttonRadio', { + + defaults: { + "activeClass": 'uk-active', + "target": ".uk-button" + }, + + boot: function() { + + // init code + UI.$html.on("click.buttonradio.uikit", "[data-uk-button-radio]", function(e) { + + var ele = UI.$(this); + + if (!ele.data("buttonRadio")) { + + var obj = UI.buttonRadio(ele, UI.Utils.options(ele.attr("data-uk-button-radio"))), + target = UI.$(e.target); + + if (target.is(obj.options.target)) { + target.trigger("click"); + } + } + }); + }, + + init: function() { + + var $this = this; + + // Init ARIA + this.find($this.options.target).attr('aria-checked', 'false').filter('.' + $this.options.activeClass).attr('aria-checked', 'true'); + + this.on("click", this.options.target, function(e) { + + var ele = UI.$(this); + + if (ele.is('a[href="#"]')) e.preventDefault(); + + $this.find($this.options.target).not(ele).removeClass($this.options.activeClass).blur(); + ele.addClass($this.options.activeClass); + + // Update ARIA + $this.find($this.options.target).not(ele).attr('aria-checked', 'false'); + ele.attr('aria-checked', 'true'); + + $this.trigger("change.uk.button", [ele]); + }); + + }, + + getSelected: function() { + return this.find('.' + this.options.activeClass); + } + }); + + UI.component('buttonCheckbox', { + + defaults: { + "activeClass": 'uk-active', + "target": ".uk-button" + }, + + boot: function() { + + UI.$html.on("click.buttoncheckbox.uikit", "[data-uk-button-checkbox]", function(e) { + var ele = UI.$(this); + + if (!ele.data("buttonCheckbox")) { + + var obj = UI.buttonCheckbox(ele, UI.Utils.options(ele.attr("data-uk-button-checkbox"))), + target = UI.$(e.target); + + if (target.is(obj.options.target)) { + target.trigger("click"); + } + } + }); + }, + + init: function() { + + var $this = this; + + // Init ARIA + this.find($this.options.target).attr('aria-checked', 'false').filter('.' + $this.options.activeClass).attr('aria-checked', 'true'); + + this.on("click", this.options.target, function(e) { + var ele = UI.$(this); + + if (ele.is('a[href="#"]')) e.preventDefault(); + + ele.toggleClass($this.options.activeClass).blur(); + + // Update ARIA + ele.attr('aria-checked', ele.hasClass($this.options.activeClass)); + + $this.trigger("change.uk.button", [ele]); + }); + + }, + + getSelected: function() { + return this.find('.' + this.options.activeClass); + } + }); + + + UI.component('button', { + + defaults: {}, + + boot: function() { + + UI.$html.on("click.button.uikit", "[data-uk-button]", function(e) { + var ele = UI.$(this); + + if (!ele.data("button")) { + + var obj = UI.button(ele, UI.Utils.options(ele.attr("data-uk-button"))); + ele.trigger("click"); + } + }); + }, + + init: function() { + + var $this = this; + + // Init ARIA + this.element.attr('aria-pressed', this.element.hasClass("uk-active")); + + this.on("click", function(e) { + + if ($this.element.is('a[href="#"]')) e.preventDefault(); + + $this.toggle(); + $this.trigger("change.uk.button", [$this.element.blur().hasClass("uk-active")]); + }); + + }, + + toggle: function() { + this.element.toggleClass("uk-active"); + + // Update ARIA + this.element.attr('aria-pressed', this.element.hasClass("uk-active")); + } + }); + +})(UIkit); + -- cgit v1.2.3