1/*! 2 * Hero Carousel - jQuery Plugin 3 * 4 * Copyright (c) 2011 Paul Welsh 5 * 6 * Version: 1.3 (26/05/2011) 7 * 8 * Dual licensed under the MIT and GPL licenses: 9 * http://www.opensource.org/licenses/mit-license.php 10 * http://www.gnu.org/licenses/gpl.html 11 */ 12 13jQuery.fn.heroCarousel = function(options){ 14 15 options = jQuery.extend({ 16 animationSpeed: 1000, 17 navigation: true, 18 easing: '', 19 timeout: 5000, 20 pause: true, 21 pauseOnNavHover: true, 22 prevText: '←', 23 nextText: '→', 24 css3pieFix: false, 25 currentClass: 'current', 26 onLoad: function(){}, 27 onStart: function(){}, 28 onComplete: function(){} 29 }, options); 30 31 return this.each(function() { 32 var carousel = jQuery(this), 33 elements = carousel.children(); 34 currentItem = 1; 35 childWidth = elements.width(); 36 childHeight = elements.height(); 37 38 if(elements.length > 2){ 39 40 elements.each(function(i){ 41 if(options.itemClass){ 42 jQuery(this).addClass(options.itemClass); 43 } 44 }); 45 46 elements.filter(':first').addClass(options.currentClass).before(elements.filter(':last')); 47 48 var carouselWidth = Math.round(childWidth * carousel.children().length), 49 carouselMarginLeft = '-'+ Math.round(childWidth + Math.round(childWidth / 2) ) +'px' 50 51 carousel.addClass('hero-carousel-container').css({ 52 'position': 'relative', 53 'overflow': 'hidden', 54 'left': '50%', 55 'top': 0, 56 'margin-left': carouselMarginLeft, 57 'height': childHeight, 58 'width': carouselWidth 59 }); 60 61 carousel.before('<ul class="hero-carousel-nav"><li class="prev"><a href="#">'+options.prevText+'</a></li><li class="next"><a href="#">'+options.nextText+'</a></li></ul>'); 62 63 var carouselNav = carousel.prev('.hero-carousel-nav'), 64 timeoutInterval; 65 66 if(options.timeout > 0){ 67 var paused = false; 68 if(options.pause){ 69 carousel.hover(function(){ 70 paused = true; 71 },function(){ 72 paused = false; 73 }); 74 } 75 if(options.pauseOnNavHover){ 76 carouselNav.hover(function(){ 77 paused = true; 78 },function(){ 79 paused = false; 80 }); 81 } 82 function autoSlide(){ 83 if(!paused){ 84 carouselNav.find('.next a').trigger('click'); 85 } 86 } 87 timeoutInterval = window.setInterval(autoSlide, options.timeout); 88 } 89 90 carouselNav.find('a').data('disabled', false).click(function(e){ 91 e.preventDefault(); 92 var navItem = jQuery(this), 93 isPrevious = navItem.parent().hasClass('prev'), 94 elements = carousel.children(); 95 if(navItem.data('disabled') === false){ 96 options.onStart(carousel, carouselNav, elements.eq(currentItem), options); 97 if(isPrevious){ 98 animateItem(elements.filter(':last'), 'previous'); 99 }else{ 100 animateItem(elements.filter(':first'), 'next'); 101 } 102 navItem.data('disabled', true); 103 setTimeout(function(){ 104 navItem.data('disabled', false); 105 }, options.animationSpeed+200); 106 if(options.timeout > 0){ 107 window.clearInterval(timeoutInterval); 108 timeoutInterval = window.setInterval(autoSlide, options.timeout); 109 } 110 } 111 112 }); 113 114 function animateItem(object,direction){ 115 var carouselPosLeft = parseFloat(carousel.position().left), 116 carouselPrevMarginLeft = parseFloat(carousel.css('margin-left')); 117 118 if(direction === 'previous'){ 119 object.before( object.clone().addClass('carousel-clone') ); 120 carousel.prepend( object ); 121 var marginLeft = Math.round(carouselPrevMarginLeft - childWidth); 122 var plusOrMinus = '+='; 123 }else{ 124 object.after( object.clone().addClass('carousel-clone') ); 125 carousel.append( object ); 126 var marginLeft = carouselMarginLeft; 127 var plusOrMinus = '-='; 128 } 129 if(options.css3pieFix){ 130 fixPieClones(jQuery('.carousel-clone')); 131 } 132 carousel.css({ 133 'left': carouselPosLeft, 134 'width': Math.round(carouselWidth + childWidth), 135 'margin-left': marginLeft 136 }).animate({'left':plusOrMinus+childWidth}, options.animationSpeed, options.easing, function(){ 137 carousel.css({ 138 'left': '50%', 139 'width': carouselWidth, 140 'margin-left': carouselPrevMarginLeft 141 });
142 jQuery('.carousel-clone').remove(); 143 finishCarousel(); 144 }); 145 146 } 147 148 function fixPieClones(clonedObject){ 149 var itemPieId = clonedObject.attr('_pieId'); 150 if(itemPieId){ 151 clonedObject.attr('_pieId', itemPieId+'_cloned'); 152 } 153 clonedObject.find('*[_pieId]').each(function(i, item){ 154 var descendantPieId = $(item).attr('_pieId'); 155 $(item).attr('_pieId', descendantPieId+'_cloned'); 156 }); 157 } 158 159 function finishCarousel(){ 160 var elements = carousel.children(); 161 elements.removeClass(options.currentClass).eq(currentItem).addClass(options.currentClass); 162 options.onComplete(carousel, carousel.prev('.hero-carousel-nav'), elements.eq(currentItem), options); 163 } 164 165 options.onLoad(carousel, carouselNav, carousel.children().eq(currentItem), options); 166 167 } 168 169 }); 170 171};
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.