/*! uikit 2.25.0 | http://www.getuikit.com | (c) 2014 yootheme | mit license */ (function(addon) { var component; if (window.uikit) { component = addon(uikit); } if (typeof define == "function" && define.amd) { define("uikit-slideset", ["uikit"], function(){ return component || addon(uikit); }); } })(function(ui){ "use strict"; var animations; ui.component('slideset', { defaults: { default : 1, animation : 'fade', duration : 200, filter : '', delay : false, controls : false, autoplay : false, autoplayinterval : 7000, pauseonhover : true }, sets: [], boot: function() { // auto init ui.ready(function(context) { ui.$("[data-uk-slideset]", context).each(function(){ var ele = ui.$(this); if(!ele.data("slideset")) { ui.slideset(ele, ui.utils.options(ele.attr("data-uk-slideset"))); } }); }); }, init: function() { var $this = this; this.activeset = false; this.list = this.element.find('.uk-slideset'); this.nav = this.element.find('.uk-slideset-nav'); this.controls = this.options.controls ? ui.$(this.options.controls) : this.element; ui.$win.on("resize load", ui.utils.debounce(function() { $this.updatesets(); }, 100)); $this.list.addclass('uk-grid-width-1-'+$this.options.default); ['xlarge', 'large', 'medium', 'small'].foreach(function(bp) { if (!$this.options[bp]) { return; } $this.list.addclass('uk-grid-width-'+bp+'-1-'+$this.options[bp]); }); this.on("click.uk.slideset", '[data-uk-slideset-item]', function(e) { e.preventdefault(); if ($this.animating) { return; } var set = ui.$(this).attr('data-uk-slideset-item'); if ($this.activeset === set) return; switch(set) { case 'next': case 'previous': $this[set=='next' ? 'next':'previous'](); break; default: $this.show(parseint(set, 10)); } }); this.controls.on('click.uk.slideset', '[data-uk-filter]', function(e) { var ele = ui.$(this); if (ele.parent().hasclass('uk-slideset')) { return; } e.preventdefault(); if ($this.animating || $this.currentfilter == ele.attr('data-uk-filter')) { return; } $this.updatefilter(ele.attr('data-uk-filter')); $this._hide().then(function(){ $this.updatesets(true, true); }); }); this.on('swiperight swipeleft', function(e) { $this[e.type=='swipeleft' ? 'next' : 'previous'](); }); this.updatefilter(this.options.filter); this.updatesets(); this.element.on({ mouseenter: function() { if ($this.options.pauseonhover) $this.hovering = true; }, mouseleave: function() { $this.hovering = false; } }); // set autoplay if (this.options.autoplay) { this.start(); } }, updatesets: function(animate, force) { var visible = this.visible, i; this.visible = this.getvisibleoncurrenbreakpoint(); if (visible == this.visible && !force) { return; } this.children = this.list.children().hide(); this.items = this.getitems(); this.sets = array_chunk(this.items, this.visible); for (i=0;i'); } this.nav[this.nav.children().length==1 ? 'addclass':'removeclass']('uk-invisible'); } this.activeset = false; this.show(0, !animate); }, updatefilter: function(currentfilter) { var $this = this, filter; this.currentfilter = currentfilter; this.controls.find('[data-uk-filter]').each(function(){ filter = ui.$(this); if (!filter.parent().hasclass('uk-slideset')) { if (filter.attr('data-uk-filter') == $this.currentfilter) { filter.addclass('uk-active'); } else { filter.removeclass('uk-active'); } } }); }, getvisibleoncurrenbreakpoint: function() { var breakpoint = null, tmp = ui.$('
').appendto('body'), testdiv = tmp.children().eq(0), breakpoints = this.options; ['xlarge', 'large', 'medium', 'small'].foreach(function(bp) { if (!breakpoints[bp] || breakpoint) { return; } tmp.attr('class', 'uk-grid-width-'+bp+'-1-2').width(); if (testdiv.width() == 50) { breakpoint = bp; } }); tmp.remove(); return this.options[breakpoint] || this.options['default']; }, getitems: function() { var items = [], filter; if (this.currentfilter) { filter = this.currentfilter || []; if (typeof(filter) === 'string') { filter = filter.split(/,/).map(function(item){ return item.trim(); }); } this.children.each(function(index){ var ele = ui.$(this), f = ele.attr('data-uk-filter'), infilter = filter.length ? false : true; if (f) { f = f.split(/,/).map(function(item){ return item.trim(); }); filter.foreach(function(item){ if (f.indexof(item) > -1) infilter = true; }); } if(infilter) items.push(ele[0]); }); items = ui.$(items); } else { items = this.list.children(); } return items; }, show: function(setindex, noanimate, dir) { var $this = this; if (this.activeset === setindex || this.animating) { return; } dir = dir || (setindex < this.activeset ? -1:1); var current = this.sets[this.activeset] || [], next = this.sets[setindex], animation = this._getanimation(); if (noanimate || !ui.support.animation) { animation = animations.none; } this.animating = true; if (this.nav.length) { this.nav.children().removeclass('uk-active').eq(setindex).addclass('uk-active'); } animation.apply($this, [current, next, dir]).then(function(){ ui.utils.checkdisplay(next, true); $this.children.hide().removeclass('uk-active'); next.addclass('uk-active').css({'display': '', 'opacity':''}); $this.animating = false; $this.activeset = setindex; ui.utils.checkdisplay(next, true); $this.trigger('show.uk.slideset', [next]); }); }, _getanimation: function() { var animation = animations[this.options.animation] || animations.none; if (!ui.support.animation) { animation = animations.none; } return animation; }, _hide: function() { var $this = this, current = this.sets[this.activeset] || [], animation = this._getanimation(); this.animating = true; return animation.apply($this, [current, [], 1]).then(function(){ $this.animating = false; }); }, next: function() { this.show(this.sets[this.activeset + 1] ? (this.activeset + 1) : 0, false, 1); }, previous: function() { this.show(this.sets[this.activeset - 1] ? (this.activeset - 1) : (this.sets.length - 1), false, -1); }, start: function() { this.stop(); var $this = this; this.interval = setinterval(function() { if (!$this.hovering && !$this.animating) $this.next(); }, this.options.autoplayinterval); }, stop: function() { if (this.interval) clearinterval(this.interval); } }); animations = { 'none': function() { var d = ui.$.deferred(); d.resolve(); return d.promise(); }, 'fade': function(current, next) { return coreanimation.apply(this, ['uk-animation-fade', current, next]); }, 'slide-bottom': function(current, next) { return coreanimation.apply(this, ['uk-animation-slide-bottom', current, next]); }, 'slide-top': function(current, next) { return coreanimation.apply(this, ['uk-animation-slide-top', current, next]); }, 'slide-vertical': function(current, next, dir) { var anim = ['uk-animation-slide-top', 'uk-animation-slide-bottom']; if (dir == -1) { anim.reverse(); } return coreanimation.apply(this, [anim, current, next]); }, 'slide-horizontal': function(current, next, dir) { var anim = ['uk-animation-slide-right', 'uk-animation-slide-left']; if (dir == -1) { anim.reverse(); } return coreanimation.apply(this, [anim, current, next, dir]); }, 'scale': function(current, next) { return coreanimation.apply(this, ['uk-animation-scale-up', current, next]); } }; ui.slideset.animations = animations; // helpers function coreanimation(cls, current, next, dir) { var d = ui.$.deferred(), delay = (this.options.delay === false) ? math.floor(this.options.duration/2) : this.options.delay, $this = this, clsin, clsout, release, i; dir = dir || 1; this.element.css('min-height', this.element.height()); if (next[0]===current[0]) { d.resolve(); return d.promise(); } if (typeof(cls) == 'object') { clsin = cls[0]; clsout = cls[1] || cls[0]; } else { clsin = cls; clsout = clsin; } release = function() { if (current && current.length) { current.hide().removeclass(clsout+' uk-animation-reverse').css({'opacity':'', 'animation-delay': '', 'animation':''}); } if (!next.length) { d.resolve(); return; } for (i=0;i