/** * jquery.gridrotator.js v1.1.0 * http://www.codrops.com * * Licensed under the MIT license. * http://www.opensource.org/licenses/mit-license.php * * Copyright 2012, Codrops * http://www.codrops.com */ ; (function($, window, undefined) { 'use strict'; /* * debouncedresize: special jQuery event that happens once after a window resize * * latest version and complete README available on Github: * https://github.com/louisremi/jquery-smartresize/blob/master/jquery.debouncedresize.js * * Copyright 2011 @louis_remi * Licensed under the MIT license. */ var $event = $.event, $special, resizeTimeout; $special = $event.special.debouncedresize = { setup: function() { $(this).on("resize", $special.handler); }, teardown: function() { $(this).off("resize", $special.handler); }, handler: function(event, execAsap) { // Save the context var context = this, args = arguments, dispatch = function() { // set correct event type event.type = "debouncedresize"; $event.dispatch.apply(context, args); }; if (resizeTimeout) { clearTimeout(resizeTimeout); } execAsap ? dispatch() : resizeTimeout = setTimeout(dispatch, $special.threshold); }, threshold: 100 }; // http://www.hardcode.nl/subcategory_1/article_317-array-shuffle-function Array.prototype.shuffle = function() { var i = this.length, p, t; while (i--) { p = Math.floor(Math.random() * i); t = this[i]; this[i] = this[p]; this[p] = t; } return this; }; // HTML5 PageVisibility API // http://www.html5rocks.com/en/tutorials/pagevisibility/intro/ // by Joe Marini (@joemarini) function getHiddenProp() { var prefixes = ['webkit', 'moz', 'ms', 'o']; // if 'hidden' is natively supported just return it if ('hidden' in document) return 'hidden'; // otherwise loop over all the known prefixes until we find one for (var i = 0; i < prefixes.length; i++) { if ((prefixes[i] + 'Hidden') in document) return prefixes[i] + 'Hidden'; } // otherwise it's not supported return null; } function isHidden() { var prop = getHiddenProp(); if (!prop) return false; return document[prop]; } function isEmpty(obj) { return Object.keys(obj).length === 0; } // global var $window = $(window), Modernizr = window.Modernizr; $.GridRotator = function(options, element) { this.$el = $(element); if (Modernizr.backgroundsize) { var self = this; this.$el.addClass('ri-grid-loading'); this._init(options); } }; // the options $.GridRotator.defaults = { // number of rows rows: 4, // number of columns columns: 10, w992: { rows: 3, columns: 8 }, w768: { rows: 3, columns: 7 }, w480: { rows: 3, columns: 5 }, w320: { rows: 2, columns: 4 }, w240: { rows: 2, columns: 3 }, // step: number of items that are replaced at the same time // random || [some number] // note: for performance issues, the number "can't" be > options.maxStep step: 'random', // change it as you wish.. maxStep: 3, // prevent user to click the items preventClick: true, // animation type // showHide || fadeInOut || // slideLeft || slideRight || slideTop || slideBottom || // rotateBottom || rotateLeft || rotateRight || rotateTop || // scale || // rotate3d || // rotateLeftScale || rotateRightScale || rotateTopScale || rotateBottomScale || // random animType: 'random', // animation speed animSpeed: 800, // animation easings animEasingOut: 'linear', animEasingIn: 'linear', // the item(s) will be replaced every 3 seconds // note: for performance issues, the time "can't" be < 300 ms interval: 3000, // if false the animations will not start // use false if onhover is true for example slideshow: true, // if true the items will switch when hovered onhover: false, // ids of elements that shouldn't change nochange: [] }; $.GridRotator.prototype = { _init: function(options) { // options this.options = $.extend(true, {}, $.GridRotator.defaults, options); // cache some elements + variables this._config(); }, _config: function() { var self = this, transEndEventNames = { 'WebkitTransition': 'webkitTransitionEnd', 'MozTransition': 'transitionend', 'OTransition': 'oTransitionEnd', 'msTransition': 'MSTransitionEnd', 'transition': 'transitionend' }; // support CSS transitions and 3d transforms this.supportTransitions = Modernizr.csstransitions; this.supportTransforms3D = Modernizr.csstransforms3d; this.transEndEventName = transEndEventNames[Modernizr.prefixed('transition')] + '.gridrotator'; // all animation types for the random option this.animTypes = this.supportTransforms3D ? [ 'fadeInOut', 'slideLeft', 'slideRight', 'slideTop', 'slideBottom', 'rotateLeft', 'rotateRight', 'rotateTop', 'rotateBottom', // 'scale', 'rotate3d', // 'rotateLeftScale', // 'rotateRightScale', // 'rotateTopScale', // 'rotateBottomScale' ] : ['fadeInOut', 'slideLeft', 'slideRight', 'slideTop', 'slideBottom']; this.animType = this.options.animType; if (this.animType !== 'random' && !this.supportTransforms3D && $.inArray(this.animType, this.animTypes) === -1 && this.animType !== 'showHide') { // fallback to 'fadeInOut' if user sets a type which is not supported this.animType = 'fadeInOut'; } this.animTypesTotal = this.animTypes.length; // the