vendor/assets/javascripts/uikit/core/switcher.js in uikit2-rails-0.1.9 vs vendor/assets/javascripts/uikit/core/switcher.js in uikit2-rails-0.1.10
- old
+ new
@@ -1,17 +1,17 @@
-/*! UIkit 2.26.3 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
+/*! UIkit 2.27.2 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
(function(UI) {
"use strict";
var Animations;
UI.component('switcher', {
defaults: {
connect : false,
- toggle : ">*",
+ toggle : '>*',
active : 0,
animation : false,
duration : 200,
swiping : true
},
@@ -21,108 +21,108 @@
boot: function() {
// init code
UI.ready(function(context) {
- UI.$("[data-uk-switcher]", context).each(function() {
+ UI.$('[data-uk-switcher]', context).each(function() {
var switcher = UI.$(this);
- if (!switcher.data("switcher")) {
- var obj = UI.switcher(switcher, UI.Utils.options(switcher.attr("data-uk-switcher")));
+ if (!switcher.data('switcher')) {
+ var obj = UI.switcher(switcher, UI.Utils.options(switcher.attr('data-uk-switcher')));
}
});
});
},
init: function() {
var $this = this;
- this.on("click.uk.switcher", this.options.toggle, function(e) {
+ this.on('click.uk.switcher', this.options.toggle, function(e) {
e.preventDefault();
$this.show(this);
});
- if (this.options.connect) {
+ if (!this.options.connect) {
+ return;
+ }
- this.connect = UI.$(this.options.connect);
+ this.connect = UI.$(this.options.connect);
- this.connect.children().removeClass("uk-active");
+ if (!this.connect.length) {
+ return;
+ }
- // delegate switch commands within container content
- if (this.connect.length) {
+ this.connect.on('click.uk.switcher', '[data-uk-switcher-item]', function(e) {
- // Init ARIA for connect
- this.connect.children().attr('aria-hidden', 'true');
+ e.preventDefault();
- this.connect.on("click", '[data-uk-switcher-item]', function(e) {
+ var item = UI.$(this).attr('data-uk-switcher-item');
- e.preventDefault();
+ if ($this.index == item) return;
- var item = UI.$(this).attr('data-uk-switcher-item');
+ switch(item) {
+ case 'next':
+ case 'previous':
+ $this.show($this.index + (item=='next' ? 1:-1));
+ break;
+ default:
+ $this.show(parseInt(item, 10));
+ }
+ });
- if ($this.index == item) return;
+ if (this.options.swiping) {
- switch(item) {
- case 'next':
- case 'previous':
- $this.show($this.index + (item=='next' ? 1:-1));
- break;
- default:
- $this.show(parseInt(item, 10));
- }
- });
+ this.connect.on('swipeRight swipeLeft', function(e) {
+ e.preventDefault();
+ if (!window.getSelection().toString()) {
+ $this.show($this.index + (e.type == 'swipeLeft' ? 1 : -1));
+ }
+ });
+ }
- if (this.options.swiping) {
+ this.update();
+ },
- this.connect.on('swipeRight swipeLeft', function(e) {
- e.preventDefault();
- if(!window.getSelection().toString()) {
- $this.show($this.index + (e.type == 'swipeLeft' ? 1 : -1));
- }
- });
- }
- }
+ update: function() {
- var toggles = this.find(this.options.toggle),
- active = toggles.filter(".uk-active");
+ this.connect.children().removeClass('uk-active').attr('aria-hidden', 'true');
- if (active.length) {
- this.show(active, false);
- } else {
+ var toggles = this.find(this.options.toggle),
+ active = toggles.filter('.uk-active');
- if (this.options.active===false) return;
+ if (active.length) {
+ this.show(active, false);
+ } else {
- active = toggles.eq(this.options.active);
- this.show(active.length ? active : toggles.eq(0), false);
- }
+ if (this.options.active===false) return;
- // Init ARIA for toggles
- toggles.not(active).attr('aria-expanded', 'false');
- active.attr('aria-expanded', 'true');
+ active = toggles.eq(this.options.active);
+ this.show(active.length ? active : toggles.eq(0), false);
}
+ // Init ARIA for toggles
+ toggles.not(active).attr('aria-expanded', 'false');
+ active.attr('aria-expanded', 'true');
},
show: function(tab, animate) {
if (this.animating) {
return;
}
+ var toggles = this.find(this.options.toggle);
+
if (isNaN(tab)) {
tab = UI.$(tab);
} else {
-
- var toggles = this.find(this.options.toggle);
-
tab = tab < 0 ? toggles.length-1 : tab;
tab = toggles.eq(toggles[tab] ? tab : 0);
}
var $this = this,
- toggles = this.find(this.options.toggle),
active = UI.$(tab),
animation = Animations[this.options.animation] || function(current, next) {
if (!$this.options.animation) {
return Animations.none.apply($this);
@@ -271,10 +271,12 @@
if (current) current.hide().removeClass('uk-active '+clsOut+' uk-animation-reverse');
next.addClass(clsIn).one(UI.support.animation.end, function() {
- next.removeClass(''+clsIn+'').css({opacity:'', display:''});
+ setTimeout(function () {
+ next.removeClass(''+clsIn+'').css({opacity:'', display:''});
+ }, 0);
d.resolve();
UI.$body.css('overflow-x', '');