1/* 2* Slides, A Slideshow Plugin for jQuery 3* Intructions: http://slidesjs.com 4* By: Nathan Searles, http://nathansearles.com 5* Version: 1.1.9 6* Updated: September 5th, 2011 7* 8* Licensed under the Apache License, Version 2.0 (the "License"); 9* you may not use this file except in compliance with the License. 10* You may obtain a copy of the License at 11* 12* http://www.apache.org/licenses/LICENSE-2.0 13* 14* Unless required by applicable law or agreed to in writing, software 15* distributed under the License is distributed on an "AS IS" BASIS, 16* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17* See the License for the specific language governing permissions and 18* limitations under the License. 19*/ 20(function($){ 21 $.fn.slides = function( option ) { 22 // override defaults with specified option 23 option = $.extend( {}, $.fn.slides.option, option ); 24 25 return this.each(function(){ 26 // wrap slides in control container, make sure slides are block level 27 $('.' + option.container, $(this)).children().wrapAll('<div class="slides_control"/>'); 28 var elem = $(this), 29 control = $('.slides_control',elem), 30 total = control.children().size(), 31 width = getWidth(), 32 height = getHeight(), 33 start = option.start - 1, 34 effect = option.effect.indexOf(',') < 0 ? option.effect : option.effect.replace(' ', '').split(',')[0], 35 paginationEffect = option.effect.indexOf(',') < 0 ? effect : option.effect.replace(' ', '').split(',')[1], 36 next = 0, prev = 0, number = 0, current = 0, loaded, active, clicked, position, direction, imageParent, pauseTimeout, playInterval; 37 equalHeight(); 38 if(option.width=="auto"){ 39 $(window).resize(function(){ 40 var width = getWidth(); 41 elem.find('.slide').css({ 42 left: width, 43 width: width 44 }); 45 equalHeight(); 46 control.css({ 47 left: -width, 48 width: (width * 3), 49 height:getHeight() 50 }); 51 52 }); 53 } 54 55 // is there only one slide? 56 if (total < 2) { 57 // Fade in .slides_container 58 $('.' + option.container, $(this)).fadeIn(option.fadeSpeed, option.fadeEasing, function(){ 59 // let the script know everything is loaded 60 loaded = true; 61 // call the loaded funciton 62 option.slidesLoaded(); 63 }); 64 // Hide the next/previous buttons 65 $('.' + option.next + ', .' + option.prev,elem).fadeOut(0); 66 return false; 67 } 68 69 // animate slides 70 function animate(direction, effect, clicked) { 71 if (!active && loaded) { 72 active = true; 73 // start of animation 74 option.animationStart(current + 1); 75 switch(direction) { 76 case 'next': 77 // change current slide to previous 78 prev = current; 79 // get next from current + 1 80 next = current + 1; 81 // if last slide, set next to first slide 82 next = total === next ? 0 : next; 83 // set position of next slide to right of previous 84 position = getWidth()*2; 85 // distance to slide based on width of slides 86 direction = -getWidth()*2; 87 // store new current slide 88 current = next; 89 break; 90 case 'prev': 91 // change current slide to previous 92 prev = current; 93 // get next from current - 1 94 next = current - 1; 95 // if first slide, set next to last slide 96 next = next === -1 ? total-1 : next; 97 // set position of next slide to left of previous 98 position = 0; 99 // distance to slide based on width of slides 100 direction = 0; 101 // store new current slide 102 current = next; 103 break; 104 case 'pagination': 105 // get next from pagination item clicked, convert to number 106 next = parseInt(clicked,10); 107 // get previous from pagination item with class of current 108 prev = $('.' + option.paginationClass + ' li.'+ option.currentClass +' a', elem).attr('href').match('[^#/]+$'); 109 // if next is greater then previous set position of next slide to right of previous 110 if (next > prev) { 111 position = getWidth()*2; 112 direction = -getWidth()*2; 113 } else { 114 // if next is less then previous set position of next slide to left of previous 115 position = 0; 116 direction = 0; 117 } 118 // store new current slide 119 current = next; 120 break; 121 } 122 123 // fade animation 124 if (effect === 'fade') { 125 // fade animation with crossfade 126 if (option.crossfade) { 127 // put hidden next above current 128 control.children(':eq('+ next +')', elem).css({ 129 zIndex: 10 130 // fade in next 131 }).fadeIn(option.fadeSpeed, option.fadeEasing, function(){ 132 if (option.autoHeight) { 133 // animate container to height of next 134 equalHeight(next); 135 control.animate({ 136 height: control.children(':eq('+ next +')', elem).outerHeight() 137 }, option.autoHeightSpeed, function(){ 138 // hide previous 139 control.children(':eq('+ prev +')', elem).css({ 140 display: 'none', 141 zIndex: 0 142 }); 143 // reset z index 144 control.children(':eq('+ next +')', elem).css({ 145 zIndex: 0 146 }); 147 // end of animation 148 option.animationComplete(next + 1); 149 active = false;
150 }); 151 } else { 152 // hide previous 153 control.children(':eq('+ prev +')', elem).css({ 154 display: 'none', 155 zIndex: 0 156 }); 157 // reset zindex 158 control.children(':eq('+ next +')', elem).css({ 159 zIndex: 0 160 }); 161 // end of animation 162 option.animationComplete(next + 1); 163 active = false; 164 } 165 }); 166 } else { 167 // fade animation with no crossfade 168 control.children(':eq('+ prev +')', elem).fadeOut(option.fadeSpeed, option.fadeEasing, function(){ 169 // animate to new height 170 equalHeight(next); 171 if (option.autoHeight) { 172 control.animate({ 173 // animate container to height of next 174 height: control.children(':eq('+ next +')', elem).outerHeight() 175 }, option.autoHeightSpeed, 176 // fade in next slide 177 function(){ 178 control.children(':eq('+ next +')', elem).fadeIn(option.fadeSpeed, option.fadeEasing); 179 }); 180 } else { 181 // if fixed height 182 control.children(':eq('+ next +')', elem).fadeIn(option.fadeSpeed, option.fadeEasing, function(){ 183 // fix font rendering in ie, lame 184 if($.browser.msie) { 185 $(this).get(0).style.removeAttribute('filter'); 186 } 187 }); 188 } 189 // end of animation 190 option.animationComplete(next + 1); 191 active = false; 192 }); 193 } 194 // slide animation 195 } else { 196 // move next slide to right of previous 197 control.children(':eq('+ next +')').css({ 198 left: position, 199 display: 'block' 200 }); 201 // animate to new height 202 if (option.autoHeight) { 203 equalHeight(next); 204 control.animate({ 205 left: direction, 206 height: control.children(':eq('+ next +')').outerHeight() 207 },option.slideSpeed, option.slideEasing, function(){ 208 control.css({ 209 left: -getWidth() 210 }); 211 control.children(':eq('+ next +')').css({ 212 left: getWidth(), 213 zIndex: 5 214 }); 215 // reset previous slide 216 control.children(':eq('+ prev +')').css({ 217 left: getWidth(), 218 display: 'none', 219 zIndex: 0 220 }); 221 // end of animation 222 option.animationComplete(next + 1); 223 active = false; 224 }); 225 // if fixed height 226 } else { 227 // animate control 228 equalHeight(next); 229 control.animate({ 230 left: direction 231 },option.slideSpeed, option.slideEasing, function(){ 232 // after animation reset control position 233 control.css({ 234 left: -getWidth() 235 }); 236 // reset and show next 237 control.children(':eq('+ next +')').css({ 238 left: getWidth(), 239 zIndex: 5 240 }); 241 // reset previous slide 242 control.children(':eq('+ prev +')').css({ 243 left: getWidth(), 244 display: 'none', 245 zIndex: 0 246 }); 247 // end of animation 248 option.animationComplete(next + 1); 249 active = false; 250 }); 251 } 252 } 253 // set current state for pagination 254 if (option.pagination) { 255 // remove current class from all 256 $('.'+ option.paginationClass +' li.' + option.currentClass, elem).removeClass(option.currentClass); 257 // add current class to next 258 $('.' + option.paginationClass + ' li:eq('+ next +')', elem).addClass(option.currentClass); 259 } 260 261 } 262 263 } // end animate function 264 265 function stop() { 266 // clear interval from stored id 267 clearInterval(elem.data('interval')); 268 } 269 function equalHeight(pointer){ 270 // equal height for title/description 271 if(!pointer) pointer = current; 272 if(option.equalHeight){ 273 //setEqualHeight(control.children(':eq('+ pointer +')')); 274 var el = control.children(':eq('+ pointer +')'); 275 jQuery('.bt-title,.bt-introtext',el).height('auto'); 276 var maxHeight = Math.max.apply(null, jQuery('.bt-title',el).map(function (){return jQuery(this).height();}).get()); 277 if(maxHeight) jQuery('.bt-title',el).height(maxHeight); 278 maxHeight = Math.max.apply(null, jQuery('.bt-introtext',el).map(function (){return jQuery(this).height();}).get()); 279 if(maxHeight) jQuery('.bt-introtext',el).height(maxHeight); 280 } 281 } 282 function getWidth(){ 283 return option.width!="auto"?option.width:elem.width(); 284 } 285 function getHeight(){ 286 var mheight = 0; 287 288 if(option.autoHeight){ 289 mheight = control.children(':eq('+ current +')').outerHeight(); 290 }else{ 291 if(option.height=='auto'){ 292 mheight= Math.max.apply(null, control.children().map(function (){return $(this).outerHeight();}).get()); 293 }else{ 294 mheight = option.height; 295 } 296 } 297 return mheight? mheight:'auto'; 298 } 299 function pause() { 300 if (option.pause) { 301 // clear timeout and interval 302 clearTimeout(elem.data('pause')); 303 clearInterval(elem.data('interval')); 304 // pause slide show for option.pause amount 305 pauseTimeout = setTimeout(function() { 306 // clear pause timeout 307 clearTimeout(elem.data('pause')); 308 // start play interval after pause 309 playInterval = setInterval( function(){ 310 animate("next", effect); 311 },option.play); 312 // store play interval 313 elem.data('interval',playInterval); 314 },option.pause); 315 // store pause interval 316 elem.data('pause',pauseTimeout); 317 } else { 318 // if no pause, just stop 319 stop(); 320 } 321 } 322 323 // 2 or more slides required 324 if (total < 2) { 325 return; 326 } 327 328 // error corection for start slide 329 if (start < 0) { 330 start = 0; 331 } 332 333 if (start > total) { 334 start = total - 1; 335 } 336 337 // change current based on start option number 338 if (option.start) { 339 current = start; 340 } 341 342 // randomizes slide order 343 if (option.randomize) { 344 control.randomize(); 345 } 346 347 // make sure overflow is hidden, width is set 348 $('.' + option.container, elem).css({ 349 overflow: 'hidden', 350 // fix for ie 351 position: 'relative' 352 }); 353 354 // set css for slides 355 control.children().css({ 356 position: 'absolute', 357 top: 0, 358 left: control.children().outerWidth(), 359 zIndex: 0, 360 display: 'none' 361 }); 362
363 // set css for control div 364 control.css({ 365 position: 'relative', 366 // size of control 3 x slide width 367 width: (getWidth() * 3), 368 // set height to slide height 369 height: height, 370 // center control to slide 371 left: -getWidth() 372 }); 373 374 // show slides 375 $('.' + option.container, elem).css({ 376 display: 'block' 377 }); 378 379 // if autoHeight true, get and set height of first slide 380 if (option.autoHeight) { 381 control.children().css({ 382 height: 'auto' 383 }); 384 control.animate({ 385 height: control.children(':eq('+ start +')').outerHeight() 386 },option.autoHeightSpeed); 387 } 388 389 // checks if image is loaded 390 if (option.preload && control.find('img:eq(' + start + ')').length) { 391 // adds preload image 392 $('.' + option.container, elem).css({ 393 background: 'url(' + option.preloadImage + ') no-repeat 50% 50%' 394 }); 395 396 /* 397 // gets image src, with cache buster 398 var img = control.find('img:eq(' + start + ')').attr('src') + '?' + (new Date()).getTime(); 399 400 // check if the image has a parent 401 if ($('img', elem).parent().attr('class') != 'slides_control') { 402 // If image has parent, get tag name 403 imageParent = control.children(':eq(0)')[0].tagName.toLowerCase(); 404 } else { 405 // Image doesn't have parent, use image tag name 406 imageParent = control.find('img:eq(' + start + ')'); 407 } 408 */ 409 // checks if image is loaded 410 var $imgs = control.find('img'); 411 var imgsl = $imgs.length; 412 var u=0; 413 $imgs.each(function(){ 414 var img = new Image(); 415 $(img).load(function(){ 416 ++u; 417 if (u == imgsl) { 418 startSlider(); 419 } 420 }).error(function () { 421 ++u; 422 if (u == imgsl) { 423 startSlider(); 424 } 425 }).attr('src',this.src); 426 }); 427 } else { 428 // if no preloader fade in start slide 429 control.children(':eq(' + start + ')').fadeIn(option.fadeSpeed, option.fadeEasing, function(){ 430 // let the script know everything is loaded 431 loaded = true; 432 // call the loaded funciton 433 option.slidesLoaded(); 434 }); 435 } 436 function startSlider(){ 437 // once image is fully loaded, fade in 438 control.children(':eq(' + start + ')').fadeIn(option.fadeSpeed, option.fadeEasing, function(){ 439 $(this).css({ 440 zIndex: 5 441 }); 442 // removes preload image 443 $('.' + option.container, elem).css({ 444 background: '' 445 }); 446 control.css({ 447 height:getHeight() 448 }); 449 // let the script know everything is loaded 450 loaded = true; 451 // call the loaded funciton 452 option.slidesLoaded(); 453 }); 454 } 455 456 // click slide for next 457 if (option.bigTarget) { 458 // set cursor to pointer 459 control.children().css({ 460 cursor: 'pointer' 461 }); 462 // click handler 463 control.children().click(function(){ 464 // animate to next on slide click 465 animate('next', effect); 466 return false; 467 }); 468 } 469 470 // pause on mouseover 471 if (option.hoverPause && option.play) { 472 control.bind('mouseover',function(){ 473 // on mouse over stop 474 stop(); 475 }); 476 control.bind('mouseleave',function(){ 477 // on mouse leave start pause timeout 478 pause(); 479 }); 480 } 481 482 // generate next/prev buttons 483 if (option.generateNextPrev) { 484 $('.' + option.container, elem).after('<a href="#" class="'+ option.prev +'">Prev</a>'); 485 $('.' + option.prev, elem).after('<a href="#" class="'+ option.next +'">Next</a>'); 486 } 487 488 // next button 489 $('.' + option.next ,elem).click(function(e){ 490 e.preventDefault(); 491 if (option.play) { 492 pause(); 493 } 494 animate('next', effect); 495 }); 496 497 // previous button 498 $('.' + option.prev, elem).click(function(e){ 499 e.preventDefault(); 500 if (option.play) { 501 pause(); 502 } 503 animate('prev', effect); 504 }); 505 506 // generate pagination 507 if (option.generatePagination) { 508 // create unordered list 509 if($('.' + option.next ,elem).length){ 510 $('.' + option.next ,elem).before('<ul class='+ option.paginationClass +'></ul>'); 511 }else 512 if (option.prependPagination){ 513 elem.prepend('<ul class='+ option.paginationClass +'></ul>'); 514 }else{ 515 elem.append('<ul class='+ option.paginationClass +'></ul>'); 516 } 517 // for each slide create a list item and link 518 control.children().each(function(){ 519 $('.' + option.paginationClass, elem).append('<li><a href="#'+ number +'">'+ (number+1) +'</a></li>'); 520 number++; 521 }); 522 } else { 523 // if pagination exists, add href w/ value of item number to links 524 $('.' + option.paginationClass + ' li a', elem).each(function(){ 525 $(this).attr('href', '#' + number); 526 number++; 527 }); 528 } 529 530 // add current class to start slide pagination 531 $('.' + option.paginationClass + ' li:eq('+ start +')', elem).addClass(option.currentClass); 532 533 // click handling 534 $('.' + option.paginationClass + ' li a', elem ).click(function(){ 535 // pause slideshow 536 if (option.play) { 537 pause(); 538 } 539 // get clicked, pass to animate function 540 clicked = $(this).attr('href').match('[^#/]+$'); 541 // if current slide equals clicked, don't do anything 542 if (current != clicked) { 543 animate('pagination', paginationEffect, clicked); 544 } 545 return false;
546 }); 547 548 // click handling 549 $('a.link', elem).click(function(){ 550 // pause slideshow 551 if (option.play) { 552 pause(); 553 } 554 // get clicked, pass to animate function 555 clicked = $(this).attr('href').match('[^#/]+$') - 1; 556 // if current slide equals clicked, don't do anything 557 if (current != clicked) { 558 animate('pagination', paginationEffect, clicked); 559 } 560 return false; 561 }); 562 563 if (option.play) { 564 // set interval 565 playInterval = setInterval(function() { 566 animate('next', effect); 567 }, option.play); 568 // store interval id 569 elem.data('interval',playInterval); 570 } 571 572 573 if(option.touchScreen){ 574 var timeStart, xStart, yStart; 575 $(control).on('touchstart', function(e){ 576 var touch = e.originalEvent.touches[0]; 577 xStart = touch.pageX; 578 yStart = touch.pageY; 579 timeStart = Number(new Date()); 580 581 }); 582 $(control).on('touchend', function(e){ 583 var touch = e.originalEvent.changedTouches[0]; 584 var duration = Number(new Date()) - timeStart; 585 var xDistance = touch.pageX - xStart; 586 var yDistance = touch.pageY - yStart; 587 588 if(duration <= 300 && Math.abs(yDistance) <= 20 && xDistance != 0){ 589 if (option.play) { 590 pause(); 591 } 592 if(xDistance < 0){ 593 animate('next', effect); 594 }else{ 595 animate('prev', effect); 596 } 597 }else{ 598 return; 599 } 600 601 }); 602 } 603 604 }); 605 }; 606 607 // default options 608 $.fn.slides.option = { 609 preload: false, // boolean, Set true to preload images in an image based slideshow 610 preloadImage: '/img/loading.gif', // string, Name and location of loading image for preloader. Default is "/img/loading.gif" 611 container: 'slides_container', // string, Class name for slides container. Default is "slides_container" 612 generateNextPrev: false, // boolean, Auto generate next/prev buttons 613 next: 'next', // string, Class name for next button 614 prev: 'prev', // string, Class name for previous button 615 pagination: true, // boolean, If you're not using pagination you can set to false, but don't have to 616 generatePagination: true, // boolean, Auto generate pagination 617 prependPagination: false, // boolean, prepend pagination 618 paginationClass: 'pagination', // string, Class name for pagination 619 currentClass: 'current', // string, Class name for current class 620 fadeSpeed: 350, // number, Set the speed of the fading animation in milliseconds 621 fadeEasing: '', // string, must load jQuery's easing plugin before http://gsgd.co.uk/sandbox/jquery/easing/ 622 slideSpeed: 350, // number, Set the speed of the sliding animation in milliseconds 623 slideEasing: '', // string, must load jQuery's easing plugin before http://gsgd.co.uk/sandbox/jquery/easing/ 624 start: 1, // number, Set the speed of the sliding animation in milliseconds 625 effect: 'slide', // string, '[next/prev], [pagination]', e.g. 'slide, fade' or simply 'fade' for both 626 crossfade: false, // boolean, Crossfade images in a image based slideshow 627 randomize: false, // boolean, Set to true to randomize slides 628 play: 0, // number, Autoplay slideshow, a positive number will set to true and be the time between slide animation in milliseconds 629 pause: 0, // number, Pause slideshow on click of next/prev or pagination. A positive number will set to true and be the time of pause in milliseconds 630 hoverPause: false, // boolean, Set to true and hovering over slideshow will pause it 631 autoHeight: false, // boolean, Set to true to auto adjust height 632 autoHeightSpeed: 350, // number, Set auto height animation time in milliseconds 633 bigTarget: false, // boolean, Set to true and the whole slide will link to next slide on click 634 animationStart: function(){}, // Function called at the start of animation 635 animationComplete: function(){}, // Function called at the completion of animation 636 slidesLoaded: function() {}, // Function is called when slides is fully loaded 637 width:'auto', 638 equalHeight:true 639 }; 640 641 // Randomize slide order on load 642 $.fn.randomize = function(callback) { 643 function randomizeOrder() { return(Math.round(Math.random())-0.5); } 644 return($(this).each(function() { 645 var $this = $(this); 646 var $children = $this.children(); 647 var childCount = $children.length; 648 if (childCount > 1) { 649 $children.hide(); 650 var indices = []; 651 for (i=0;i<childCount;i++) { indices[indices.length] = i; } 652 indices = indices.sort(randomizeOrder); 653 $.each(indices,function(j,k) { 654 var $child = $children.eq(k); 655 var $clone = $child.clone(true); 656 $clone.show().appendTo($this); 657 if (callback !== undefined) { 658 callback($child, $clone); 659 } 660 $child.remove(); 661 }); 662 } 663 })); 664 }; 665})(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.