2018-05-05 13:35:10 +00:00
|
|
|
/*! UIkit 2.27.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
|
2016-03-06 00:50:22 +00:00
|
|
|
(function(UI){
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var toggles = [];
|
|
|
|
|
|
|
|
UI.component('toggle', {
|
|
|
|
|
|
|
|
defaults: {
|
|
|
|
target : false,
|
|
|
|
cls : 'uk-hidden',
|
|
|
|
animation : false,
|
|
|
|
duration : 200
|
|
|
|
},
|
|
|
|
|
|
|
|
boot: function(){
|
|
|
|
|
|
|
|
// init code
|
|
|
|
UI.ready(function(context) {
|
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
UI.$('[data-uk-toggle]', context).each(function() {
|
2016-03-06 00:50:22 +00:00
|
|
|
var ele = UI.$(this);
|
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
if (!ele.data('toggle')) {
|
|
|
|
var obj = UI.toggle(ele, UI.Utils.options(ele.attr('data-uk-toggle')));
|
2016-03-06 00:50:22 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(function(){
|
|
|
|
|
|
|
|
toggles.forEach(function(toggle){
|
|
|
|
toggle.getToggles();
|
|
|
|
});
|
|
|
|
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
|
|
|
|
var $this = this;
|
|
|
|
|
|
|
|
this.aria = (this.options.cls.indexOf('uk-hidden') !== -1);
|
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
this.on('click', function(e) {
|
|
|
|
|
|
|
|
if ($this.element.is('a[href="#"]')) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2016-03-06 00:50:22 +00:00
|
|
|
|
|
|
|
$this.toggle();
|
|
|
|
});
|
|
|
|
|
|
|
|
toggles.push(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle: function() {
|
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
this.getToggles();
|
|
|
|
|
2016-03-06 00:50:22 +00:00
|
|
|
if(!this.totoggle.length) return;
|
|
|
|
|
|
|
|
if (this.options.animation && UI.support.animation) {
|
|
|
|
|
|
|
|
var $this = this, animations = this.options.animation.split(',');
|
|
|
|
|
|
|
|
if (animations.length == 1) {
|
|
|
|
animations[1] = animations[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
animations[0] = animations[0].trim();
|
|
|
|
animations[1] = animations[1].trim();
|
|
|
|
|
|
|
|
this.totoggle.css('animation-duration', this.options.duration+'ms');
|
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
this.totoggle.each(function(){
|
|
|
|
|
|
|
|
var ele = UI.$(this);
|
|
|
|
|
|
|
|
if (ele.hasClass($this.options.cls)) {
|
2016-03-06 00:50:22 +00:00
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
ele.toggleClass($this.options.cls);
|
2016-03-06 00:50:22 +00:00
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
UI.Utils.animate(ele, animations[0]).then(function(){
|
|
|
|
ele.css('animation-duration', '');
|
|
|
|
UI.Utils.checkDisplay(ele);
|
2016-03-06 00:50:22 +00:00
|
|
|
});
|
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
} else {
|
2016-03-06 00:50:22 +00:00
|
|
|
|
|
|
|
UI.Utils.animate(this, animations[1]+' uk-animation-reverse').then(function(){
|
2018-05-05 13:35:10 +00:00
|
|
|
ele.toggleClass($this.options.cls).css('animation-duration', '');
|
|
|
|
UI.Utils.checkDisplay(ele);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2016-03-06 00:50:22 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
this.totoggle.toggleClass(this.options.cls);
|
|
|
|
UI.Utils.checkDisplay(this.totoggle);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateAria();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
getToggles: function() {
|
|
|
|
this.totoggle = this.options.target ? UI.$(this.options.target):[];
|
|
|
|
this.updateAria();
|
|
|
|
},
|
|
|
|
|
|
|
|
updateAria: function() {
|
|
|
|
if (this.aria && this.totoggle.length) {
|
2018-05-05 13:35:10 +00:00
|
|
|
this.totoggle.not('[aria-hidden]').each(function(){
|
2016-03-06 00:50:22 +00:00
|
|
|
UI.$(this).attr('aria-hidden', UI.$(this).hasClass('uk-hidden'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-05 13:35:10 +00:00
|
|
|
})(UIkit2);
|