1;( function( $, window, undefined ) { 2 3 'use strict'; 4 5 // global 6 var Modernizr = window.Modernizr; 7 8 $.CBPQTRotator = function( options, element ) { 9 this.$el = $( element ); 10 this._init( options ); 11 }; 12 13 // the options 14 $.CBPQTRotator.defaults = { 15 // default transition speed (ms) 16 speed : 700, 17 // default transition easing 18 easing : 'ease', 19 // rotator interval (ms) 20 interval : 8000 21 }; 22 23 $.CBPQTRotator.prototype = { 24 _init : function( options ) { 25 26 // options 27 this.options = $.extend( true, {}, $.CBPQTRotator.defaults, options ); 28 // cache some elements and initialize some variables 29 this._config(); 30 // show current item 31 this.$items.eq( this.current ).addClass( 'cbp-qtcurrent' ); 32 // set the transition to the items 33 if( this.support ) { 34 this._setTransition(); 35 } 36 // start rotating the items 37 this._startRotator(); 38 39 }, 40 _config : function() { 41 42 // the content items 43 this.$items = this.$el.children( 'div.cbp-qtcontent' ); 44 // total items 45 this.itemsCount = this.$items.length; 46 // current item´s index 47 this.current = 0; 48 // support for CSS Transitions 49 this.support = Modernizr.csstransitions; 50 // add the progress bar 51 if( this.support ) { 52 this.$progress = $( '<span class="cbp-qtprogress"></span>' ).appendTo( this.$el ); 53 } 54 55 }, 56 _setTransition : function() { 57 setTimeout( $.proxy( function() { 58 this.$items.css( 'transition', 'opacity ' + this.options.speed + 'ms ' + this.options.easing ); 59 }, this ), 25 ); 60 }, 61 _startRotator: function() { 62 63 if( this.support ) { 64 this._startProgress(); 65 } 66 67 setTimeout( $.proxy( function() { 68 if( this.support ) { 69 this._resetProgress(); 70 } 71 this._next(); 72 this._startRotator(); 73 }, this ), this.options.interval ); 74 75 }, 76 _next : function() { 77 78 // hide previous item 79 this.$items.eq( this.current ).removeClass( 'cbp-qtcurrent' ); 80 // update current value 81 this.current = this.current < this.itemsCount - 1 ? this.current + 1 : 0; 82 // show next item 83 this.$items.eq( this.current ).addClass('cbp-qtcurrent'); 84 85 }, 86 _startProgress : function() { 87 88 setTimeout( $.proxy( function() { 89 this.$progress.css( { transition : 'width ' + this.options.interval + 'ms linear', width : '100%' } ); 90 }, this ), 25 ); 91 92 }, 93 _resetProgress : function() { 94 this.$progress.css( { transition : 'none', width : '0%' } ); 95 }, 96 destroy : function() { 97 if( this.support ) { 98 this.$items.css( 'transition', 'none' ); 99 this.$progress.remove(); 100 } 101 this.$items.removeClass( 'cbp-qtcurrent' ).css( { 102 'position' : 'relative', 103 'z-index' : 100, 104 'pointer-events' : 'auto', 105 'opacity' : 1 106 } ); 107 } 108 }; 109 110 var logError = function( message ) { 111 if ( window.console ) { 112 window.console.error( message ); 113 } 114 }; 115 116 $.fn.cbpQTRotator = function( options ) { 117 if ( typeof options === 'string' ) { 118 var args = Array.prototype.slice.call( arguments, 1 ); 119 this.each(function() { 120 var instance = $.data( this, 'cbpQTRotator' ); 121 if ( !instance ) { 122 logError( "cannot call methods on cbpQTRotator prior to initialization; " + 123 "attempted to call method '" + options + "'" ); 124 return; 125 } 126 if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) { 127 logError( "no such method '" + options + "' for cbpQTRotator instance" ); 128 return; 129 } 130 instance[ options ].apply( instance, args ); 131 }); 132 } 133 else { 134 this.each(function() { 135 var instance = $.data( this, 'cbpQTRotator' ); 136 if ( instance ) { 137 instance._init(); 138 } 139 else { 140 instance = $.data( this, 'cbpQTRotator', new $.CBPQTRotator( options, this ) ); 141 } 142 }); 143 } 144 return this; 145 }; 146 147} )( jQuery, window );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.