1/* 2 * loopedCarousel 0.5 - jQuery plugin 3 * written by Nathan Searles, based on loopedSlider (http://github.com/nathansearles/loopedSlider) 4 * http://github.com/nathansearles/loopedCarousel 5 * 6 * Copyright (c) 2009 Nathan Searles (http://nathansearles.com/) 7 * Dual licensed under the MIT (MIT-LICENSE.txt) 8 * and GPL (GPL-LICENSE.txt) licenses. 9 * 10 * Built for jQuery library 11 * http://jquery.com 12 * 13 */ 14 15/* 16 * markup example for $("#loopedCarousel").loopedCarousel(); 17 * 18 * <div id="loopedCarousel"> 19 * <div class="container"> 20 * <div class="slides"> 21 * <div>1</div> 22 * <div>2</div> 23 * <div>3</div> 24 * <div>4</div> 25 * <div>5</div> 26 * <div>6</div> 27 * <div>7</div> 28 * <div>8</div> 29 * <div>9</div> 30 * <div>10</div> 31 * <div>11</div> 32 * <div>12</div> 33 * <div>13</div> 34 * <div>14</div> 35 * <div>15</div> 36 * </div> 37 * </div> 38 * <a href="#" class="previous">previous</a> 39 * <a href="#" class="next">next</a> 40 * </div> 41 * 42 */ 43 44(function($) { 45 $.fn.loopedCarousel = function(options) { 46 47 var defaults = { 48 container: '.container', 49 slides: '.slides', 50 pagination: '.pagination', 51 autoStart: 0, // Set to positive number for auto interval and interval time 52 slidespeed: 300, // Speed of slide animation 53 fadespeed: 300, // Speed of fade animation 54 items: 4, // Items show 55 padding: 0, // Padding between items 56 showPagination: false, // Shows pagination links 57 vertical: false 58 }; 59 60 this.each(function() { 61 var obj = $(this); 62 var o = $.extend(defaults, options); 63 var i = o.items; 64 var m = 0; 65 var t = 1; 66 var s = $(o.slides,obj).children().size(); 67 var w = $(o.slides,obj).children().outerWidth()+o.padding; 68 var h = $(o.slides,obj).children().outerHeight()+o.padding; 69 var c = Math.ceil($(o.slides,obj).children().size()/i); 70 var pd = o.padding/2; 71 var p = 0; 72 var u = false; 73 var n = 0; 74 var pt = 0; 75 var os = i*c-s; 76 var params = {}; 77 78 if (o.vertical===true) { w = h; } 79 80 if(o.showPagination){ 81 var buttons = s/i; 82 $(obj).append('<ul class="pagination">'); 83 $(o.slides,obj).children().each(function(){ 84 if (n<buttons) { 85 $(o.pagination,obj).append('<li><a rel="'+(n+1)+'" href="#" >'+(n+1)+'</a></li>'); 86 n = n+1; 87 } else { 88 n = 0; 89 return false; 90 } 91 $(o.pagination+' li a:eq(0)',obj).parent().addClass('active'); 92 }); 93 } 94 95 if (o.vertical===true) { 96 $(o.container,obj).css({height:(w*i)}); 97 $(o.slides,obj).css({height:(s*w)}); 98 } else { 99 $(o.container,obj).css({width:(w*i)}); 100 $(o.slides,obj).css({width:(s*w)}); 101 } 102 103 $(o.slides,obj).children().each(function(){ 104 if (o.vertical===true) { 105 $(this).css({position:'absolute',top:p+pd,display:'block'}); 106 } else { 107 $(this).css({position:'absolute',left:p+pd,display:'block'}); 108 } 109 p=p+w; 110 }); 111 112 $(o.slides,obj).children().each(function(){ 113 pt = pt+1; 114 if (pt<i+1) { 115 params[o.vertical ? 'top' : 'left'] = (-w*pt)+pd-(w*os); 116 $(o.slides,obj).children(':eq('+(s-pt)+')').css(params); 117 } 118 if (pt===i+2) { 119 pt = 0; 120 return false; 121 } 122 }); 123 124 $('.next',obj).click(function(){ 125 if(u===false) { 126 animate('next',true); 127 if(o.autoStart){clearInterval(sliderIntervalID);} 128 } 129 return false; 130 }); 131 132 $('.previous',obj).click(function(){ 133 if(u===false) { 134 animate('prev',true); 135 if(o.autoStart){clearInterval(sliderIntervalID);} 136 } return false; 137 }); 138 139 $(o.pagination+' li a',obj).click(function(){ 140 if ($(this).parent().hasClass('active')) {return false;} 141 else { 142 t = $(this).attr('rel'); 143 $(o.pagination+' li a',obj).parent().siblings().removeClass('active'); 144 $(this).parent().addClass('active'); 145 animate('fade',t); 146 if(o.autoStart){clearInterval(sliderIntervalID);} 147 } return false; 148 }); 149 150 if (o.autoStart) { 151 sliderIntervalID = setInterval(function(){ 152 if(u===false) {animate('next',true);} 153 }, o.autoStart); 154 } 155 156 function current(t) { 157 if(t===c+1){t=1;} 158 if(t===0){t=c;} 159 $(o.pagination+' li a',obj).parent().siblings().removeClass('active'); 160 $(o.pagination+' li a[rel="' + (t) + '"]',obj).parent().addClass('active'); 161 } 162 163 function animate(dir,clicked){ 164 u = true; 165 switch(dir){ 166 case 'next': 167 t = t+1; 168 m = (-(t*w-w)*i); 169 current(t); 170 params[o.vertical ? 'top' : 'left'] = m; 171 $(o.slides,obj).animate(params, o.slidespeed,function(){ 172 if (t===c+1) { 173 t = 1; 174 params[o.vertical ? 'top' : 'left'] = 0; 175 $(o.slides,obj).css(params,function(){ 176 $(o.slides,obj).animate(params); 177 }); 178 $(o.slides,obj).children().each(function(){ 179 if (pt<i) { 180 params[o.vertical ? 'top' : 'left'] = (w*pt)+pd; 181 $(o.slides,obj).children(':eq('+pt+')').css(params); 182 params[o.vertical ? 'top' : 'left'] = -(w*(pt+os+1)-pd); 183 $(o.slides,obj).children(':eq('+(s-(pt+1))+')').css(params); 184 } else { 185 pt = 0; 186 return false; 187 } 188 pt = pt+1; 189 }); 190 } 191 if (t===c) { 192 $(o.slides,obj).children().each(function(){ 193 if (pt<i) { 194 params[o.vertical ? 'top' : 'left'] = w*(s+pt+os)+pd; 195 $(o.slides,obj).children(':eq('+(pt)+')').css(params); 196 } else { 197 pt = 0; 198 return false; 199 } 200 pt = pt+1; 201 });
202 } 203 if (t===2) { 204 $(o.slides,obj).children().each(function(){ 205 pt = pt+1; 206 if (pt<i+1) { 207 params[o.vertical ? 'top' : 'left'] = ((w*s)+pd)-(w*pt); 208 $(o.slides,obj).children(':eq('+(s-pt)+')').css(params); 209 } else { 210 pt = 0; 211 return false; 212 } 213 }); 214 } 215 u = false; 216 }); 217 break; 218 case 'prev': 219 t = t-1; 220 m = (-(t*w-w)*i); 221 current(t); 222 params[o.vertical ? 'top' : 'left'] = m; 223 $(o.slides,obj).animate(params, o.slidespeed,function(){ 224 if (t===0) { 225 t = c; 226 params[o.vertical ? 'top' : 'left'] = -w*(s-i)-(w*os); 227 $(o.slides,obj).css(params); 228 $(o.slides,obj).children().each(function(){ 229 if (pt<i) { 230 params[o.vertical ? 'top' : 'left'] = w*(s+pt+os)+pd; 231 $(o.slides,obj).children(':eq('+pt+')').css(params); 232 params[o.vertical ? 'top' : 'left'] = (s*w)+pd-(pt*w)-w; 233 $(o.slides,obj).children(':eq('+((s-1)-pt)+')').css(params); 234 } else { 235 pt = 0; 236 return false; 237 } 238 pt = pt+1; 239 }); 240 } 241 if (t===2) { 242 $(o.slides,obj).children().each(function(){ 243 if (pt<i) { 244 params[o.vertical ? 'top' : 'left'] = (w*pt)+pd; 245 $(o.slides,obj).children(':eq('+pt+')').css(params); 246 } else { 247 pt = 0; 248 return false; 249 } 250 pt = pt+1; 251 }); 252 } 253 if (t===1) { 254 $(o.slides,obj).children().each(function(){ 255 if (pt<i) { 256 params[o.vertical ? 'top' : 'left'] = -(w*pt)-w+pd-(w*os); 257 $(o.slides,obj).children(':eq('+((s-1)-pt)+')').css(params); 258 } else { 259 pt = 0; 260 return false; 261 } 262 pt = pt+1; 263 }); 264 } 265 266 u = false; 267 }); 268 break; 269 case 'fade': 270 t = [t]*1; 271 m = (-(t*w-w)*i); 272 current(t); 273 $(o.slides,obj).children().fadeOut(o.fadespeed, function(){ 274 params[o.vertical ? 'top' : 'left'] = m; 275 $(o.slides,obj).css(params); 276 $(o.slides,obj).children().each(function(){ 277 if (pt<i) { 278 params[o.vertical ? 'top' : 'left'] = (pt*w)+pd; 279 $(o.slides,obj).children(':eq('+pt+')').css(params); 280 params[o.vertical ? 'top' : 'left'] = w*(s-pt)-w+pd; 281 $(o.slides,obj).children(':eq('+((s-1)-pt)+')').css(params); 282 } else { 283 pt = 0; 284 return false; 285 } 286 pt = pt+1; 287 }); 288 289 if(t===c){ 290 $(o.slides,obj).children().each(function(){ 291 if (pt<i) { 292 params[o.vertical ? 'top' : 'left'] = w*(s+pt+os)+pd; 293 $(o.slides,obj).children(':eq('+(pt)+')').css(params); 294 } else { 295 pt = 0; 296 return false; 297 } 298 pt = pt+1; 299 }); 300 } 301 if(t===1){ 302 $(o.slides,obj).children().each(function(){ 303 pt = pt+1; 304 if (pt<i+1) { 305 params[o.vertical ? 'top' : 'left'] = -(w*pt)+pd-(w*os); 306 $(o.slides,obj).children(':eq('+(s-pt)+')').css(params); 307 } else { 308 pt = 0; 309 return false; 310 } 311 }); 312 } 313 $(o.slides,obj).children().fadeIn(o.fadespeed); 314 u = false; 315 }); 316 break; 317 default: 318 break; 319 } 320 } 321 }); 322 }; 323})(jQuery);
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.