/** * jquery.flipshow.js v1.0.0 * http://www.codrops.com * * Licensed under the MIT license. * http://www.opensource.org/licenses/mit-license.php * * Copyright 2013, Codrops * http://www.codrops.com */ ;( function( $, window, undefined ) { 'use strict'; // ======================= imagesLoaded Plugin =============================== // https://github.com/desandro/imagesloaded // $('#my-container').imagesLoaded(myFunction) // execute a callback when all images have loaded. // needed because .load() doesn't work on cached images // callback function gets image collection as argument // this is the container // original: mit license. paul irish. 2010. // contributors: Oren Solomianik, David DeSandro, Yiannis Chatzikonstantinou // blank image data-uri bypasses webkit log warning (thx doug jones) // blank image data-uri bypasses webkit log warning (thx doug jones) var BLANK = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=='; $.fn.imagesLoaded = function( callback ) { var $this = this, deferred = $.isFunction($.Deferred) ? $.Deferred() : 0, hasNotify = $.isFunction(deferred.notify), $images = $this.find('img').add( $this.filter('img') ), loaded = [], proper = [], broken = []; // Register deferred callbacks if ($.isPlainObject(callback)) { $.each(callback, function (key, value) { if (key === 'callback') { callback = value; } else if (deferred) { deferred[key](value); } }); } function doneLoading() { var $proper = $(proper), $broken = $(broken); if ( deferred ) { if ( broken.length ) { deferred.reject( $images, $proper, $broken ); } else { deferred.resolve( $images ); } } if ( $.isFunction( callback ) ) { callback.call( $this, $images, $proper, $broken ); } } function imgLoadedHandler( event ) { imgLoaded( event.target, event.type === 'error' ); } function imgLoaded( img, isBroken ) { // don't proceed if BLANK image, or image is already loaded if ( img.src === BLANK || $.inArray( img, loaded ) !== -1 ) { return; } // store element in loaded images array loaded.push( img ); // keep track of broken and properly loaded images if ( isBroken ) { broken.push( img ); } else { proper.push( img ); } // cache image and its state for future calls $.data( img, 'imagesLoaded', { isBroken: isBroken, src: img.src } ); // trigger deferred progress method if present if ( hasNotify ) { deferred.notifyWith( $(img), [ isBroken, $images, $(proper), $(broken) ] ); } // call doneLoading and clean listeners if all images are loaded if ( $images.length === loaded.length ) { setTimeout( doneLoading ); $images.unbind( '.imagesLoaded', imgLoadedHandler ); } } // if no images, trigger immediately if ( !$images.length ) { doneLoading(); } else { $images.bind( 'load.imagesLoaded error.imagesLoaded', imgLoadedHandler ) .each( function( i, el ) { var src = el.src; // find out if this image has been already checked for status // if it was, and src has not changed, call imgLoaded on it var cached = $.data( el, 'imagesLoaded' ); if ( cached && cached.src === src ) { imgLoaded( el, cached.isBroken ); return; } // if complete is true and browser supports natural sizes, try // to check for image status manually if ( el.complete && el.naturalWidth !== undefined ) { imgLoaded( el, el.naturalWidth === 0 || el.naturalHeight === 0 ); return; } // cached images don't fire load sometimes, so we reset src, but only when // dealing with IE, or image is complete (loaded) and failed manual check // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f if ( el.readyState || el.complete ) { el.src = BLANK; el.src = src; } }); } return deferred ? deferred.promise( $this ) : $this; }; // global var Modernizr = window.Modernizr; $.Flipshow = function( options, element ) { this.$el = $( element ); this._init( options ); }; // the options $.Flipshow.defaults = { // default transition speed (ms) speed : 700, // default transition easing easing : 'ease-out' }; $.Flipshow.prototype = { _init : function( options ) { // options this.options = $.extend( true, {}, $.Flipshow.defaults, options ); // support for CSS Transitions & 3D transforms this.support = Modernizr.csstransitions && Modernizr.csstransforms3d && !(/MSIE (\d+\.\d+);/.test(navigator.userAgent)); // transition end event name and transform name var transEndEventNames = { 'WebkitTransition' : 'webkitTransitionEnd', 'MozTransition' : 'transitionend', 'OTransition' : 'oTransitionEnd', 'msTransition' : 'MSTransitionEnd', 'transition' : 'transitionend' }, transformNames = { 'WebkitTransform' : '-webkit-transform', 'MozTransform' : '-moz-transform', 'OTransform' : '-o-transform', 'msTransform' : '-ms-transform', 'transform' : 'transform' }; if( this.support ) { this.transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ] + '.cbpFWSlider'; this.transformName = transformNames[ Modernizr.prefixed( 'transform' ) ]; } this.transitionProperties = this.transformName + ' ' + this.options.speed + 'ms ' + this.options.easing; // the list of items this.$listItems = this.$el.children( 'ul.fc-slides' ); // the items this.$items = this.$listItems.children( 'li' ).hide(); // total number of items this.itemsCount = this.$items.length; // current itemĀ“s index this.current = 0; this.$listItems.imagesLoaded( $.proxy( function() { // show first item this.$items.eq( this.current ).show(); // add navigation and flipping structure if( this.itemsCount > 0 ) { this._addNav(); if( this.support ) { this._layout(); } } }, this ) ); }, _addNav : function() { var self = this, $navLeft = $( '