Project

General

Profile

1
/*! UIkit 2.27.5 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
2
(function(UI) {
3

    
4
    "use strict";
5

    
6
    UI.component('buttonRadio', {
7

    
8
        defaults: {
9
            activeClass: 'uk-active',
10
            target: '.uk-button'
11
        },
12

    
13
        boot: function() {
14

    
15
            // init code
16
            UI.$html.on('click.buttonradio.uikit', '[data-uk-button-radio]', function(e) {
17

    
18
                var ele = UI.$(this);
19

    
20
                if (!ele.data('buttonRadio')) {
21

    
22
                    var obj    = UI.buttonRadio(ele, UI.Utils.options(ele.attr('data-uk-button-radio'))),
23
                        target = UI.$(e.target);
24

    
25
                    if (target.is(obj.options.target)) {
26
                        target.trigger('click');
27
                    }
28
                }
29
            });
30
        },
31

    
32
        init: function() {
33

    
34
            var $this = this;
35

    
36
            // Init ARIA
37
            this.find($this.options.target).attr('aria-checked', 'false').filter('.' + $this.options.activeClass).attr('aria-checked', 'true');
38

    
39
            this.on('click', this.options.target, function(e) {
40

    
41
                var ele = UI.$(this);
42

    
43
                if (ele.is('a[href="#"]')) e.preventDefault();
44

    
45
                $this.find($this.options.target).not(ele).removeClass($this.options.activeClass).blur();
46
                ele.addClass($this.options.activeClass);
47

    
48
                // Update ARIA
49
                $this.find($this.options.target).not(ele).attr('aria-checked', 'false');
50
                ele.attr('aria-checked', 'true');
51

    
52
                $this.trigger('change.uk.button', [ele]);
53
            });
54

    
55
        },
56

    
57
        getSelected: function() {
58
            return this.find('.' + this.options.activeClass);
59
        }
60
    });
61

    
62
    UI.component('buttonCheckbox', {
63

    
64
        defaults: {
65
            activeClass: 'uk-active',
66
            target: '.uk-button'
67
        },
68

    
69
        boot: function() {
70

    
71
            UI.$html.on('click.buttoncheckbox.uikit', '[data-uk-button-checkbox]', function(e) {
72
                var ele = UI.$(this);
73

    
74
                if (!ele.data('buttonCheckbox')) {
75

    
76
                    var obj    = UI.buttonCheckbox(ele, UI.Utils.options(ele.attr('data-uk-button-checkbox'))),
77
                        target = UI.$(e.target);
78

    
79
                    if (target.is(obj.options.target)) {
80
                        target.trigger('click');
81
                    }
82
                }
83
            });
84
        },
85

    
86
        init: function() {
87

    
88
            var $this = this;
89

    
90
            // Init ARIA
91
            this.find($this.options.target).attr('aria-checked', 'false').filter('.' + $this.options.activeClass).attr('aria-checked', 'true');
92

    
93
            this.on('click', this.options.target, function(e) {
94
                var ele = UI.$(this);
95

    
96
                if (ele.is('a[href="#"]')) e.preventDefault();
97

    
98
                ele.toggleClass($this.options.activeClass).blur();
99

    
100
                // Update ARIA
101
                ele.attr('aria-checked', ele.hasClass($this.options.activeClass));
102

    
103
                $this.trigger('change.uk.button', [ele]);
104
            });
105

    
106
        },
107

    
108
        getSelected: function() {
109
            return this.find('.' + this.options.activeClass);
110
        }
111
    });
112

    
113

    
114
    UI.component('button', {
115

    
116
        defaults: {},
117

    
118
        boot: function() {
119

    
120
            UI.$html.on('click.button.uikit', '[data-uk-button]', function(e) {
121
                var ele = UI.$(this);
122

    
123
                if (!ele.data('button')) {
124

    
125
                    var obj = UI.button(ele, UI.Utils.options(ele.attr('data-uk-button')));
126
                    ele.trigger('click');
127
                }
128
            });
129
        },
130

    
131
        init: function() {
132

    
133
            var $this = this;
134

    
135
            // Init ARIA
136
            this.element.attr('aria-pressed', this.element.hasClass("uk-active"));
137

    
138
            this.on('click', function(e) {
139

    
140
                if ($this.element.is('a[href="#"]')) e.preventDefault();
141

    
142
                $this.toggle();
143
                $this.trigger('change.uk.button', [$this.element.blur().hasClass('uk-active')]);
144
            });
145

    
146
        },
147

    
148
        toggle: function() {
149
            this.element.toggleClass('uk-active');
150

    
151
            // Update ARIA
152
            this.element.attr('aria-pressed', this.element.hasClass('uk-active'));
153
        }
154
    });
155

    
156
})(UIkit2);
(3-3/32)