1
|
/*! UIkit 2.27.5 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
|
2
|
(function(UI){
|
3
|
|
4
|
"use strict";
|
5
|
|
6
|
var toggles = [];
|
7
|
|
8
|
UI.component('toggle', {
|
9
|
|
10
|
defaults: {
|
11
|
target : false,
|
12
|
cls : 'uk-hidden',
|
13
|
animation : false,
|
14
|
duration : 200
|
15
|
},
|
16
|
|
17
|
boot: function(){
|
18
|
|
19
|
// init code
|
20
|
UI.ready(function(context) {
|
21
|
|
22
|
UI.$('[data-uk-toggle]', context).each(function() {
|
23
|
var ele = UI.$(this);
|
24
|
|
25
|
if (!ele.data('toggle')) {
|
26
|
var obj = UI.toggle(ele, UI.Utils.options(ele.attr('data-uk-toggle')));
|
27
|
}
|
28
|
});
|
29
|
|
30
|
setTimeout(function(){
|
31
|
|
32
|
toggles.forEach(function(toggle){
|
33
|
toggle.getToggles();
|
34
|
});
|
35
|
|
36
|
}, 0);
|
37
|
});
|
38
|
},
|
39
|
|
40
|
init: function() {
|
41
|
|
42
|
var $this = this;
|
43
|
|
44
|
this.aria = (this.options.cls.indexOf('uk-hidden') !== -1);
|
45
|
|
46
|
this.on('click', function(e) {
|
47
|
|
48
|
if ($this.element.is('a[href="#"]')) {
|
49
|
e.preventDefault();
|
50
|
}
|
51
|
|
52
|
$this.toggle();
|
53
|
});
|
54
|
|
55
|
toggles.push(this);
|
56
|
},
|
57
|
|
58
|
toggle: function() {
|
59
|
|
60
|
this.getToggles();
|
61
|
|
62
|
if(!this.totoggle.length) return;
|
63
|
|
64
|
if (this.options.animation && UI.support.animation) {
|
65
|
|
66
|
var $this = this, animations = this.options.animation.split(',');
|
67
|
|
68
|
if (animations.length == 1) {
|
69
|
animations[1] = animations[0];
|
70
|
}
|
71
|
|
72
|
animations[0] = animations[0].trim();
|
73
|
animations[1] = animations[1].trim();
|
74
|
|
75
|
this.totoggle.css('animation-duration', this.options.duration+'ms');
|
76
|
|
77
|
this.totoggle.each(function(){
|
78
|
|
79
|
var ele = UI.$(this);
|
80
|
|
81
|
if (ele.hasClass($this.options.cls)) {
|
82
|
|
83
|
ele.toggleClass($this.options.cls);
|
84
|
|
85
|
UI.Utils.animate(ele, animations[0]).then(function(){
|
86
|
ele.css('animation-duration', '');
|
87
|
UI.Utils.checkDisplay(ele);
|
88
|
});
|
89
|
|
90
|
} else {
|
91
|
|
92
|
UI.Utils.animate(this, animations[1]+' uk-animation-reverse').then(function(){
|
93
|
ele.toggleClass($this.options.cls).css('animation-duration', '');
|
94
|
UI.Utils.checkDisplay(ele);
|
95
|
});
|
96
|
|
97
|
}
|
98
|
|
99
|
});
|
100
|
|
101
|
} else {
|
102
|
this.totoggle.toggleClass(this.options.cls);
|
103
|
UI.Utils.checkDisplay(this.totoggle);
|
104
|
}
|
105
|
|
106
|
this.updateAria();
|
107
|
|
108
|
},
|
109
|
|
110
|
getToggles: function() {
|
111
|
this.totoggle = this.options.target ? UI.$(this.options.target):[];
|
112
|
this.updateAria();
|
113
|
},
|
114
|
|
115
|
updateAria: function() {
|
116
|
if (this.aria && this.totoggle.length) {
|
117
|
this.totoggle.not('[aria-hidden]').each(function(){
|
118
|
UI.$(this).attr('aria-hidden', UI.$(this).hasClass('uk-hidden'));
|
119
|
});
|
120
|
}
|
121
|
}
|
122
|
});
|
123
|
|
124
|
})(UIkit2);
|