/*! * glidejs * Version: 2.0.9 * Glide is a responsive and touch-friendly jQuery slider. Based on CSS3 transitions with fallback to older broswers. It's simple, lightweight and fast. * Author: Jędrzej Chałubek * Site: http://http://glide.jedrzejchalubek.com/ * Licensed under the MIT license */ ;(function($, window, document, undefined){ /** * Animation module. * * @param {Object} Glide * @param {Object} Core * @return {Animation} */ var Animation = function(Glide, Core) { /** * Animation offset value. * * @var {Number} */ var offset; /** * Animation constructor. */ function Animation() { } /** * Make configured animation type. * * @param {Number} displacement * @return {self} */ Animation.prototype.make = function(displacement) { // Do not run if we have only one slide. if (! Core.Run.canProcess()) { return Core.Arrows.disable(); } // Parse displacement to integer before use. offset = (typeof displacement !== 'undefined') ? parseInt(displacement) : 0; // Animation actual translate animation this[Glide.options.type](); return this; }; /** * After animation callback. * * @param {Function} callback * @return {Integer} */ Animation.prototype.after = function(callback) { return setTimeout(function() { callback(); }, Glide.options.animationDuration + 20); }; /** * Slider animation type. * * @return {Void} */ Animation.prototype.slider = function() { var translate = Glide[Glide.size] * (Glide.current - 1); var shift = Core.Clones.shift - Glide.paddings; // If we are on the first slide. if (Core.Run.isStart()) { if (Glide.options.centered) { shift = Math.abs(shift); } // Shift is zero. else { shift = 0; } // Hide previous arrow. Core.Arrows.disable('prev'); } // If we are on the last slide. else if (Core.Run.isEnd()) { if (Glide.options.centered) { shift = Math.abs(shift); } // Double and absolute shift. else { shift = Math.abs(shift * 2); } // Hide next arrow. Core.Arrows.disable('next'); } // We are not on the edge cases. else { // Absolute shift shift = Math.abs(shift); // Show arrows. Core.Arrows.enable(); } // Apply translate to // the slider track. Glide.track.css({ 'transition': Core.Transition.get('all'), 'transform': Core.Translate.set(Glide.axis, translate - shift - offset) }); }; /** * Carousel animation type * * @return {Void} */ Animation.prototype.carousel = function() { // Get translate value by multiplying two // slider size and current slide number. var translate = Glide[Glide.size] * Glide.current; // Get animation shift. var shift; // Calculate animation shift. if (Glide.options.centered) { // Decrease clones shift with slider // paddings, because slider is centered. shift = Core.Clones.shift - Glide.paddings; } else { // Shif is only clones shift. shift = Core.Clones.shift; } // The flag is set and direction is previous, // so we are on the first slide and need // to make offset translate. if (Core.Run.isOffset('<')) { // Translate is 0 (left edge of the track). translate = 0; // Take off flag. Core.Run.flag = false; // Clear transition and jump to last slide, // after offset animation is done. this.after(function() { Glide.track.css({ 'transition': Core.Transition.clear('all'), 'transform': Core.Translate.set(Glide.axis, Glide[Glide.size] * Glide.length + shift) }); }); } // The flag is set and direction is next, // so we're on the last slide and need // to make offset translate. if (Core.Run.isOffset('>')) { // Translate is slides width * length with addtional // offset (right edge of the track). translate = (Glide[Glide.size] * Glide.length) + Glide[Glide.size]; // Reset flag Core.Run.flag = false; // Clear transition and jump to the first slide, // after offset animation is done. this.after(function() { Glide.track.css({ 'transition': Core.Transition.clear('all'), 'transform': Core.Translate.set(Glide.axis, Glide[Glide.size] + shift) }); }); } /** * Actual translate apply to wrapper * overwrite transition (can be pre-cleared) */ Glide.track.css({ 'transition': Core.Transition.get('all'), 'transform': Core.Translate.set(Glide.axis, translate + shift - offset) }); }; /** * Slideshow animation type. * * @return {Void} */ Animation.prototype.slideshow = function() { Glide.slides.css('transition', Core.Transition.get('opacity')) .eq(Glide.current - 1).css('opacity', 1) .siblings().css('opacity', 0); }; // Return class. return new Animation(); }; ;/** * Api module. * * @param {Object} Glide * @param {Object} Core * @return {Api} */ var Api = function(Glide, Core) { /** * Api constructor. */ function Api() { } /** * Api instance. * * @return {Object} */ Api.prototype.instance = function() { return { /** * Get current slide index. * * @return {Integer} */ current: function() { return Glide.current; }, /** * Go to specifed slide. * * @param {String} distance * @param {Function} callback * @return {Void} */ go: function(distance, callback) { Core.Run.pause(); Core.Run.make(distance, callback); Core.Run.play(); }, /** * Jump without animation to specifed slide * * @param {String} distance * @param {Function} callback * @return {Void} */ jump: function(distance, callback) { // Let know that we want jumping. Core.Transition.jumping = true; // Take off jumping flag, // after animation. Core.Animation.after(function() { Core.Transition.jumping = false; }); // Move slider. Core.Run.make(distance, callback); }, /** * Move slider by passed distance. * * @param {Integer} distance * @return {Void} */ move: function(distance) { Core.Transition.jumping = true; Core.Animation.make(distance); Core.Transition.jumping = false; }, /** * Start autoplay. * * @return {Void} */ start: function(interval) { // We want running, turn on flag. Core.Run.running = true; // Set autoplay duration. Glide.options.autoplay = parseInt(interval); // Run autoplay. Core.Run.play(); }, /** * Run autoplay. * * @return {Boolean} */ play: function() { return Core.Run.play(); }, /** * Pause autoplay. * * @return {Integer} */ pause: function() { return Core.Run.pause(); }, /** * Destroy slider. * * @return {Void} */ destroy: function() { Core.Run.pause(); Core.Clones.remove(); Core.Helper.removeStyles([Glide.track, Glide.slides]); Core.Bullets.remove(); Glide.slider.removeData('glide_api'); Core.Events.unbind(); Core.Touch.unbind(); Core.Arrows.unbind(); Core.Bullets.unbind(); Glide.destroyed = true; delete Glide.slider; delete Glide.track; delete Glide.slides; delete Glide.width; delete Glide.length; }, /** * Refresh slider. * * @return {Void} */ refresh: function() { Core.Run.pause(); Glide.collect(); Glide.setup(); Core.Clones.remove().init(); Core.Bullets.remove().init(); Core.Build.init(); Core.Run.make('=' + parseInt(Glide.options.startAt), Core.Run.play()); }, }; }; // Return class. return new Api(); }; ;/** * Arrows module. * * @param {Object} Glide * @param {Object} Core * @return {Arrows} */ var Arrows = function(Glide, Core) { /** * Arrows constructor. */ function Arrows() { this.build(); this.bind(); } /** * Build arrows. Gets DOM elements. * * @return {Void} */ Arrows.prototype.build = function() { this.wrapper = Glide.slider.find('.' + Glide.options.classes.arrows); this.items = this.wrapper.children(); }; /** * Disable next/previous arrow and enable another. * * @param {String} type * @return {Void} */ Arrows.prototype.disable = function(type) { var classes = Glide.options.classes; if (!type) { return this.disableBoth(); } this.items.filter('.' + classes['arrow' + Core.Helper.capitalise(type)]) .unbind('click.glide touchstart.glide') .addClass(classes.disabled) .siblings() .bind('click.glide touchstart.glide', this.click) .bind('mouseenter.glide', this.hover) .bind('mouseleave.glide', this.hover) .removeClass(classes.disabled); }; /** * Disable both arrows. * * @return {Void} */ Arrows.prototype.disableBoth = function() { this.items .unbind('click.glide touchstart.glide') .addClass(Glide.options.classes.disabled); }; /** * Show both arrows. * * @return {Void} */ Arrows.prototype.enable = function() { this.bind(); this.items.removeClass(Glide.options.classes.disabled); }; /** * Arrow click event. * * @param {Object} event * @return {Void} */ Arrows.prototype.click = function(event) { event.preventDefault(); if (!Core.Events.disabled) { Core.Run.pause(); Core.Run.make($(this).data('glide-dir')); Core.Animation.after(function() { Core.Run.play(); }); } }; /** * Arrows hover event. * * @param {Object} event * @return {Void} */ Arrows.prototype.hover = function(event) { if (!Core.Events.disabled) { switch (event.type) { // Start autoplay on mouse leave. case 'mouseleave': Core.Run.play(); break; // Pause autoplay on mouse enter. case 'mouseenter': Core.Run.pause(); break; } } }; /** * Bind arrows events. * * @return {Void} */ Arrows.prototype.bind = function() { this.items .on('click.glide touchstart.glide', this.click) .on('mouseenter.glide', this.hover) .on('mouseleave.glide', this.hover); }; /** * Unbind arrows events. * * @return {Void} */ Arrows.prototype.unbind = function() { this.items .off('click.glide touchstart.glide') .off('mouseenter.glide') .off('mouseleave.glide'); }; // Return class. return new Arrows(); }; ;/** * Build module. * * @param {[type]} Glide * @param {[type]} Core * @return {Build} */ var Build = function(Glide, Core) { // Build constructor. function Build() { this.init(); } /** * Init slider builder. * * @return {Void} */ Build.prototype.init = function() { // Build proper slider type this[Glide.options.type](); // Set slide active class this.active(); // Set slides height Core.Height.set(); }; /** * Check slider type. * * @param {String} name * @return {Boolean} */ Build.prototype.isType = function(name) { return Glide.options.type === name; }; /** * Check slider mode. * * @param {String} name * @return {Boolean} */ Build.prototype.isMode = function(name) { return Glide.options.mode === name; }; /** * Build slider type. * * @return {Void} */ Build.prototype.slider = function() { // Turn on jumping flag. Core.Transition.jumping = true; // Apply slides width. Glide.slides[Glide.size](Glide[Glide.size]); // Apply translate. Glide.track.css(Glide.size, Glide[Glide.size] * Glide.length); // If mode is vertical apply height. if (this.isMode('vertical')) { Core.Height.set(true); } // Go to startup position. Core.Animation.make(); // Turn off jumping flag. Core.Transition.jumping = false; }; /** * Build carousel type. * * @return {Void} */ Build.prototype.carousel = function() { // Turn on jumping flag. Core.Transition.jumping = true; // Update shift for carusel type. Core.Clones.shift = (Glide[Glide.size] * Core.Clones.items.length / 2) - Glide[Glide.size]; // Apply slides width. Glide.slides[Glide.size](Glide[Glide.size]); // Apply translate. Glide.track.css(Glide.size, (Glide[Glide.size] * Glide.length) + Core.Clones.getGrowth()); // If mode is vertical apply height. if (this.isMode('vertical')) { Core.Height.set(true); } // Go to startup position. Core.Animation.make(); // Append clones. Core.Clones.append(); // Turn off jumping flag. Core.Transition.jumping = false; }; /** * Build slideshow type. * * @return {Void} */ Build.prototype.slideshow = function() { // Turn on jumping flag Core.Transition.jumping = true; // Go to startup position Core.Animation.make(); // Turn off jumping flag Core.Transition.jumping = false; }; /** * Set active class to current slide. * * @return {Void} */ Build.prototype.active = function() { Glide.slides .eq(Glide.current - 1).addClass(Glide.options.classes.active) .siblings().removeClass(Glide.options.classes.active); }; // Return class. return new Build(); }; ;/** * Bullets module. * * @param {Object} Glide * @param {Object} Core * @return {Bullets} */ var Bullets = function(Glide, Core) { /** * Bullets constructor. */ function Bullets() { this.init(); this.bind(); } /** * Init bullets builder. * * @return {self} */ Bullets.prototype.init = function() { this.build(); this.active(); return this; }; /** * Get DOM and setup bullets. * * @return {Void} */ Bullets.prototype.build = function() { // Get bullets wrapper. this.wrapper = Glide.slider.children('.' + Glide.options.classes.bullets); // Set class and direction to each bullet. for (var i = 1; i <= Glide.length; i++) { $('