1/** 2 * BxSlider v4.0 - Fully loaded, responsive content slider 3 * http://bxslider.com 4 * 5 * Copyright 2012, Steven Wanderski - http://stevenwanderski.com - http://bxcreative.com 6 * Written while drinking Belgian ales and listening to jazz 7 * 8 * Released under the WTFPL license - http://sam.zoy.org/wtfpl/ 9 */ 10 11;(function($){ 12 13 var plugin = {}; 14 15 var defaults = { 16 17 // GENERAL 18 mode: 'horizontal', 19 slideSelector: '', 20 infiniteLoop: true, 21 hideControlOnEnd: false, 22 speed: 1500, 23 easing: null, 24 slideMargin: 0, 25 startSlide: 0, 26 randomStart: false, 27 captions: false, 28 ticker: false, 29 tickerHover: false, 30 adaptiveHeight: false, 31 adaptiveHeightSpeed: 500, 32 touchEnabled: true, 33 swipeThreshold: 50, 34 video: false, 35 useCSS: true, 36 37 // PAGER 38 pager: true, 39 pagerType: 'full', 40 pagerShortSeparator: ' / ', 41 pagerSelector: null, 42 buildPager: null, 43 pagerCustom: null, 44 45 // CONTROLS 46 controls: true, 47 nextText: 'Next', 48 prevText: 'Prev', 49 nextSelector: null, 50 prevSelector: null, 51 autoControls: false, 52 startText: 'Start', 53 stopText: 'Stop', 54 autoControlsCombine: false, 55 autoControlsSelector: null, 56 57 // AUTO 58 auto: false, 59 pause: 4000, 60 autoStart: true, 61 autoDirection: 'next', 62 autoHover: false, 63 autoDelay: 0, 64 65 // CAROUSEL 66 minSlides: 1, 67 maxSlides: 1, 68 moveSlides: 0, 69 slideWidth: 0, 70 71 // CALLBACKS 72 onSliderLoad: function() {}, 73 onSlideBefore: function() {}, 74 onSlideAfter: function() {}, 75 onSlideNext: function() {}, 76 onSlidePrev: function() {} 77 } 78 79 $.fn.bxSlider = function(options){ 80 81 if(this.length == 0) return; 82 83 // support mutltiple elements 84 if(this.length > 1){ 85 this.each(function(){$(this).bxSlider(options)}); 86 return this; 87 } 88 89 // create a namespace to be used throughout the plugin 90 var slider = {}; 91 // set a reference to our slider element 92 var el = this; 93 plugin.el = this; 94 95 /** 96 * Makes slideshow responsive 97 */ 98 // first get the original window dimens (thanks alot IE) 99 var windowWidth = $(window).width(); 100 var windowHeight = $(window).height(); 101 102 103 104 /** 105 * =================================================================================== 106 * = PRIVATE FUNCTIONS 107 * =================================================================================== 108 */ 109 110 /** 111 * Initializes namespace settings to be used throughout plugin 112 */ 113 var init = function(){ 114 // merge user-supplied options with the defaults 115 slider.settings = $.extend({}, defaults, options); 116 // store the original children 117 slider.children = el.children(slider.settings.slideSelector); 118 // check if actual number of slides is less than minSlides / maxSlides 119 if(slider.children.length < slider.settings.minSlides) slider.settings.minSlides = slider.children.length; 120 if(slider.children.length < slider.settings.maxSlides) slider.settings.maxSlides = slider.children.length; 121 // if random start, set the startSlide setting to random number 122 if(slider.settings.randomStart) slider.settings.startSlide = Math.floor(Math.random() * slider.children.length); 123 // store active slide information 124 slider.active = { index: slider.settings.startSlide } 125 // store if the slider is in carousel mode (displaying / moving multiple slides) 126 slider.carousel = slider.settings.minSlides > 1 || slider.settings.maxSlides > 1; 127 // calculate the min / max width thresholds based on min / max number of slides 128 // used to setup and update carousel slides dimensions 129 slider.minThreshold = (slider.settings.minSlides * slider.settings.slideWidth) + ((slider.settings.minSlides - 1) * slider.settings.slideMargin); 130 slider.maxThreshold = (slider.settings.maxSlides * slider.settings.slideWidth) + ((slider.settings.maxSlides - 1) * slider.settings.slideMargin); 131 // store the current state of the slider (if currently animating, working is true) 132 slider.working = false; 133 // initialize the controls object 134 slider.controls = {}; 135 // initialize an auto interval 136 slider.interval = null; 137 // determine which property to use for transitions 138 slider.animProp = slider.settings.mode == 'vertical' ? 'top' : 'left'; 139 // determine if hardware acceleration can be used 140 slider.usingCSS = slider.settings.useCSS && slider.settings.mode != 'fade' && (function(){ 141 // create our test div element 142 var div = document.createElement('div'); 143 // css transition properties 144 var props = ['WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective']; 145 // test for each property
146 for(var i in props){ 147 if(div.style[props[i]] !== undefined){ 148 slider.cssPrefix = props[i].replace('Perspective', '').toLowerCase(); 149 slider.animProp = '-' + slider.cssPrefix + '-transform'; 150 return true; 151 } 152 } 153 return false; 154 }()); 155 // if vertical mode always make maxSlides and minSlides equal 156 if(slider.settings.mode == 'vertical') slider.settings.maxSlides = slider.settings.minSlides; 157 // perform all DOM / CSS modifications 158 setup(); 159 } 160 161 /** 162 * Performs all DOM and CSS modifications 163 */ 164 var setup = function(){ 165 // wrap el in a wrapper 166 el.wrap('<div class="bx-wrapper"><div class="bx-viewport"></div></div>'); 167 // store a namspace reference to .bx-viewport 168 slider.viewport = el.parent(); 169 // add a loading div to display while images are loading 170 slider.loader = $('<div class="bx-loading" />'); 171 slider.viewport.prepend(slider.loader); 172 // set el to a massive width, to hold any needed slides 173 // also strip any margin and padding from el 174 el.css({ 175 width: slider.settings.mode == 'horizontal' ? slider.children.length * 215 + '%' : 'auto', 176 position: 'relative' 177 }); 178 // if using CSS, add the easing property 179 if(slider.usingCSS && slider.settings.easing){ 180 el.css('-' + slider.cssPrefix + '-transition-timing-function', slider.settings.easing); 181 // if not using CSS and no easing value was supplied, use the default JS animation easing (swing) 182 }else if(!slider.settings.easing){ 183 slider.settings.easing = 'swing'; 184 } 185 // make modifications to the viewport (.bx-viewport) 186 slider.viewport.css({ 187 width: '100%', 188 overflow: 'hidden', 189 position: 'relative' 190 }); 191 // apply css to all slider children 192 slider.children.css({ 193 'float': slider.settings.mode == 'horizontal' ? 'left' : 'none', 194 listStyle: 'none', 195 position: 'relative' 196 }); 197 // apply the calculated width after the float is applied to prevent scrollbar interference 198 slider.children.width(getSlideWidth()); 199 // if slideMargin is supplied, add the css 200 if(slider.settings.mode == 'horizontal' && slider.settings.slideMargin > 0) slider.children.css('marginRight', slider.settings.slideMargin); 201 if(slider.settings.mode == 'vertical' && slider.settings.slideMargin > 0) slider.children.css('marginBottom', slider.settings.slideMargin); 202 // if "fade" mode, add positioning and z-index CSS 203 if(slider.settings.mode == 'fade'){ 204 slider.children.css({ 205 position: 'absolute', 206 zIndex: 0, 207 display: 'none' 208 }); 209 // prepare the z-index on the showing element 210 slider.children.eq(slider.settings.startSlide).css({zIndex: 50, display: 'block'}); 211 } 212 // create an element to contain all slider controls (pager, start / stop, etc) 213 slider.controls.el = $('<div class="bx-controls" />'); 214 // if captions are requested, add them 215 if(slider.settings.captions) appendCaptions(); 216 // if infinite loop, prepare additional slides 217 if(slider.settings.infiniteLoop && slider.settings.mode != 'fade' && !slider.settings.ticker){ 218 var slice = slider.settings.mode == 'vertical' ? slider.settings.minSlides : slider.settings.maxSlides; 219 var sliceAppend = slider.children.slice(0, slice).clone().addClass('bx-clone'); 220 var slicePrepend = slider.children.slice(-slice).clone().addClass('bx-clone'); 221 el.append(sliceAppend).prepend(slicePrepend); 222 } 223 // check if startSlide is last slide 224 slider.active.last = slider.settings.startSlide == getPagerQty() - 1; 225 // if video is true, set up the fitVids plugin 226 if(slider.settings.video) el.fitVids();
227 // only check for control addition if not in "ticker" mode 228 if(!slider.settings.ticker){ 229 // if pager is requested, add it 230 if(slider.settings.pager) appendPager(); 231 // if controls are requested, add them 232 if(slider.settings.controls) appendControls(); 233 // if auto is true, and auto controls are requested, add them 234 if(slider.settings.auto && slider.settings.autoControls) appendControlsAuto(); 235 // if any control option is requested, add the controls wrapper 236 if(slider.settings.controls || slider.settings.autoControls || slider.settings.pager) slider.viewport.after(slider.controls.el); 237 } 238 // preload all images, then perform final DOM / CSS modifications that depend on images being loaded 239 el.children().imagesLoaded(function(){ 240 // remove the loading DOM element 241 slider.loader.remove(); 242 // set the left / top position of "el" 243 setSlidePosition(); 244 // if "vertical" mode, always use adaptiveHeight to prevent odd behavior 245 if (slider.settings.mode == 'vertical') slider.settings.adaptiveHeight = true; 246 // set the viewport height 247 slider.viewport.height(getViewportHeight()); 248 // onSliderLoad callback 249 slider.settings.onSliderLoad(slider.active.index); 250 // slider has been fully initialized 251 slider.initialized = true; 252 // bind the resize call to the window 253 $(window).bind('resize', resizeWindow); 254 // if auto is true, start the show 255 if (slider.settings.auto && slider.settings.autoStart) initAuto(); 256 // if ticker is true, start the ticker 257 if (slider.settings.ticker) initTicker(); 258 // if pager is requested, make the appropriate pager link active 259 if (slider.settings.pager) updatePagerActive(slider.settings.startSlide); 260 // check for any updates to the controls (like hideControlOnEnd updates) 261 if (slider.settings.controls) updateDirectionControls(); 262 // if touchEnabled is true, setup the touch events 263 if (slider.settings.touchEnabled && !slider.settings.ticker) initTouch(); 264 }); 265 } 266 267 /** 268 * Returns the calculated height of the viewport, used to determine either adaptiveHeight or the maxHeight value 269 */ 270 var getViewportHeight = function(){ 271 var height = 0; 272 // first determine which children (slides) should be used in our height calculation 273 var children = $(); 274 // if mode is not "vertical", adaptiveHeight is always false, so return all children 275 if(slider.settings.mode != 'vertical' && !slider.settings.adaptiveHeight){ 276 children = slider.children; 277 }else{ 278 // if not carousel, return the single active child 279 if(!slider.carousel){ 280 children = slider.children.eq(slider.active.index); 281 // if carousel, return a slice of children 282 }else{ 283 // get the individual slide index 284 var currentIndex = slider.settings.moveSlides == 1 ? slider.active.index : slider.active.index * getMoveBy(); 285 // add the current slide to the children 286 children = slider.children.eq(currentIndex); 287 // cycle through the remaining "showing" slides 288 for (i = 1; i <= slider.settings.maxSlides - 1; i++){ 289 // if looped back to the start 290 if(currentIndex + i >= slider.children.length){ 291 children = children.add(slider.children.eq(i - 1)); 292 }else{ 293 children = children.add(slider.children.eq(currentIndex + i)); 294 } 295 } 296 } 297 } 298 // if "vertical" mode, calculate the sum of the heights of the children 299 if(slider.settings.mode == 'vertical'){ 300 children.each(function(index) { 301 height += $(this).outerHeight(); 302 }); 303 // add user-supplied margins 304 if(slider.settings.slideMargin > 0){ 305 height += slider.settings.slideMargin * (slider.settings.minSlides - 1); 306 } 307 // if not "vertical" mode, calculate the max height of the children 308 }else{ 309 height = Math.max.apply(Math, children.map(function(){ 310 return $(this).outerHeight(false); 311 }).get()); 312 } 313 return height; 314 } 315 316 /** 317 * Returns the calculated width to be applied to each slide 318 */ 319 var getSlideWidth = function(){ 320 // start with any user-supplied slide width 321 var newElWidth = slider.settings.slideWidth; 322 // get the current viewport width 323 var wrapWidth = slider.viewport.width(); 324 // if slide width was not supplied, use the viewport width (means not carousel) 325 if(slider.settings.slideWidth == 0){ 326 newElWidth = wrapWidth; 327 // if carousel, use the thresholds to determine the width 328 }else{ 329 if(wrapWidth > slider.maxThreshold){ 330 newElWidth = (wrapWidth - (slider.settings.slideMargin * (slider.settings.maxSlides - 1))) / slider.settings.maxSlides; 331 }else if(wrapWidth < slider.minThreshold){ 332 newElWidth = (wrapWidth - (slider.settings.slideMargin * (slider.settings.minSlides - 1))) / slider.settings.minSlides; 333 } 334 } 335 return newElWidth; 336 } 337 338 /** 339 * Returns the number of slides currently visible in the viewport (includes partially visible slides) 340 */ 341 var getNumberSlidesShowing = function(){ 342 var slidesShowing = 1; 343 if(slider.settings.mode == 'horizontal'){ 344 // if viewport is smaller than minThreshold, return minSlides 345 if(slider.viewport.width() < slider.minThreshold){ 346 slidesShowing = slider.settings.minSlides; 347 // if viewport is larger than minThreshold, return maxSlides 348 }else if(slider.viewport.width() > slider.maxThreshold){ 349 slidesShowing = slider.settings.maxSlides; 350 // if viewport is between min / max thresholds, divide viewport width by first child width 351 }else{ 352 var childWidth = slider.children.first().width(); 353 slidesShowing = Math.floor(slider.viewport.width() / childWidth); 354 } 355 // if "vertical" mode, slides showing will always be minSlides 356 }else if(slider.settings.mode == 'vertical'){ 357 slidesShowing = slider.settings.minSlides; 358 } 359 return slidesShowing; 360 } 361 362 /** 363 * Returns the number of pages (one full viewport of slides is one "page") 364 */ 365 var getPagerQty = function(){ 366 var pagerQty = 0; 367 // if moveSlides is specified by the user 368 if(slider.settings.moveSlides > 0){ 369 if(slider.settings.infiniteLoop){ 370 pagerQty = slider.children.length / getMoveBy(); 371 }else{ 372 // use a while loop to determine pages 373 var breakPoint = 0; 374 var counter = 0 375 // when breakpoint goes above children length, counter is the number of pages 376 while (breakPoint < slider.children.length){ 377 ++pagerQty; 378 breakPoint = counter + getNumberSlidesShowing(); 379 counter += slider.settings.moveSlides <= getNumberSlidesShowing() ? slider.settings.moveSlides : getNumberSlidesShowing(); 380 } 381 }
382 // if moveSlides is 0 (auto) divide children length by sides showing, then round up 383 }else{ 384 pagerQty = Math.ceil(slider.children.length / getNumberSlidesShowing()); 385 } 386 return pagerQty; 387 } 388 389 /** 390 * Returns the number of indivual slides by which to shift the slider 391 */ 392 var getMoveBy = function(){ 393 // if moveSlides was set by the user and moveSlides is less than number of slides showing 394 if(slider.settings.moveSlides > 0 && slider.settings.moveSlides <= getNumberSlidesShowing()){ 395 return slider.settings.moveSlides; 396 } 397 // if moveSlides is 0 (auto) 398 return getNumberSlidesShowing(); 399 } 400 401 /** 402 * Sets the slider's (el) left or top position 403 */ 404 var setSlidePosition = function(){ 405 // if last slide 406 if(slider.active.last && !slider.settings.infiniteLoop){ 407 if (slider.settings.mode == 'horizontal'){ 408 // get the last child's position 409 var lastChild = slider.children.last(); 410 var position = lastChild.position(); 411 // set the left position 412 setPositionProperty(-(position.left - (slider.viewport.width() - lastChild.width())), 'reset', 0); 413 }else if(slider.settings.mode == 'vertical'){ 414 // get the last showing index's position 415 var lastShowingIndex = slider.children.length - slider.settings.minSlides; 416 var position = slider.children.eq(lastShowingIndex).position(); 417 // set the top position 418 setPositionProperty(-position.top, 'reset', 0); 419 } 420 // if not last slide 421 }else{ 422 // get the position of the first showing slide 423 var position = slider.children.eq(slider.active.index * getMoveBy()).position(); 424 // check for last slide 425 if (slider.active.index == getPagerQty() - 1) slider.active.last = true; 426 // set the repective position 427 if (position != undefined){ 428 if (slider.settings.mode == 'horizontal') setPositionProperty(-position.left, 'reset', 0); 429 else if (slider.settings.mode == 'vertical') setPositionProperty(-position.top, 'reset', 0); 430 } 431 } 432 } 433 434 /** 435 * Sets the el's animating property position (which in turn will sometimes animate el). 436 * If using CSS, sets the transform property. If not using CSS, sets the top / left property. 437 * 438 * @param value (int) 439 * - the animating property's value 440 * 441 * @param type (string) 'slider', 'reset', 'ticker' 442 * - the type of instance for which the function is being 443 * 444 * @param duration (int) 445 * - the amount of time (in ms) the transition should occupy 446 * 447 * @param params (array) optional 448 * - an optional parameter containing any variables that need to be passed in 449 */ 450 var setPositionProperty = function(value, type, duration, params){ 451 // use CSS transform 452 if(slider.usingCSS){ 453 // determine the translate3d value 454 var propValue = slider.settings.mode == 'vertical' ? 'translate3d(0, ' + value + 'px, 0)' : 'translate3d(' + value + 'px, 0, 0)'; 455 // add the CSS transition-duration 456 el.css('-' + slider.cssPrefix + '-transition-duration', duration / 1000 + 's'); 457 if(type == 'slide'){ 458 // set the property value 459 el.css(slider.animProp, propValue); 460 // bind a callback method - executes when CSS transition completes 461 el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){ 462 // unbind the callback 463 el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); 464 updateAfterSlideTransition(); 465 }); 466 }else if(type == 'reset'){ 467 el.css(slider.animProp, propValue); 468 }else if(type == 'ticker'){ 469 // make the transition use 'linear' 470 el.css('-' + slider.cssPrefix + '-transition-timing-function', 'linear'); 471 el.css(slider.animProp, propValue); 472 // bind a callback method - executes when CSS transition completes 473 el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){ 474 // unbind the callback 475 el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); 476 // reset the position 477 setPositionProperty(params['resetValue'], 'reset', 0); 478 // start the loop again 479 tickerLoop(); 480 }); 481 } 482 // use JS animate 483 }else{ 484 var animateObj = {}; 485 animateObj[slider.animProp] = value; 486 if(type == 'slide'){ 487 el.animate(animateObj, duration, slider.settings.easing, function(){ 488 updateAfterSlideTransition(); 489 }); 490 }else if(type == 'reset'){ 491 el.css(slider.animProp, value) 492 }else if(type == 'ticker'){ 493 el.animate(animateObj, speed, 'linear', function(){ 494 setPositionProperty(params['resetValue'], 'reset', 0); 495 // run the recursive loop after animation 496 tickerLoop(); 497 }); 498 } 499 } 500 } 501 502 /** 503 * Populates the pager with proper amount of pages 504 */ 505 var populatePager = function(){ 506 var pagerHtml = ''; 507 pagerQty = getPagerQty(); 508 // loop through each pager item 509 for(var i=0; i < pagerQty; i++){ 510 var linkContent = ''; 511 // if a buildPager function is supplied, use it to get pager link value, else use index + 1 512 if(slider.settings.buildPager && $.isFunction(slider.settings.buildPager)){ 513 linkContent = slider.settings.buildPager(i); 514 slider.pagerEl.addClass('bx-custom-pager'); 515 }else{ 516 linkContent = i + 1; 517 slider.pagerEl.addClass('bx-default-pager'); 518 } 519 // var linkContent = slider.settings.buildPager && $.isFunction(slider.settings.buildPager) ? slider.settings.buildPager(i) : i + 1; 520 // add the markup to the string 521 pagerHtml += '<div class="bx-pager-item">
vendor: 3,654 bytes, lines 521-603
521<a href="" data-slide-index="' + i + '" class="bx-pager-link">' + linkContent + '</a></div>'; 522 }; 523 // populate the pager element with pager links 524 slider.pagerEl.html(pagerHtml); 525 } 526 527 /** 528 * Appends the pager to the controls element 529 */ 530 var appendPager = function(){ 531 if(!slider.settings.pagerCustom){ 532 // create the pager DOM element 533 slider.pagerEl = $('<div class="bx-pager" />'); 534 // if a pager selector was supplied, populate it with the pager 535 if(slider.settings.pagerSelector){ 536 $(slider.settings.pagerSelector).html(slider.pagerEl); 537 // if no pager selector was supplied, add it after the wrapper 538 }else{ 539 slider.controls.el.addClass('bx-has-pager').append(slider.pagerEl); 540 } 541 // populate the pager 542 populatePager(); 543 }else{ 544 slider.pagerEl = $(slider.settings.pagerCustom); 545 } 546 // assign the pager click binding 547 slider.pagerEl.delegate('a', 'click', clickPagerBind); 548 } 549 550 /** 551 * Appends prev / next controls to the controls element 552 */ 553 var appendControls = function(){ 554 slider.controls.next = $('<a class="bx-next" href="">' + slider.settings.nextText + '</a>'); 555 slider.controls.prev = $('<a class="bx-prev" href="">' + slider.settings.prevText + '</a>'); 556 // bind click actions to the controls 557 slider.controls.next.bind('click', clickNextBind); 558 slider.controls.prev.bind('click', clickPrevBind); 559 // if nextSlector was supplied, populate it 560 if(slider.settings.nextSelector){ 561 $(slider.settings.nextSelector).append(slider.controls.next); 562 } 563 // if prevSlector was supplied, populate it 564 if(slider.settings.prevSelector){ 565 $(slider.settings.prevSelector).append(slider.controls.prev); 566 } 567 // if no custom selectors were supplied 568 if(!slider.settings.nextSelector && !slider.settings.prevSelector){ 569 // add the controls to the DOM 570 slider.controls.directionEl = $('<div class="bx-controls-direction" />'); 571 // add the control elements to the directionEl 572 slider.controls.directionEl.append(slider.controls.prev).append(slider.controls.next); 573 // slider.viewport.append(slider.controls.directionEl); 574 slider.controls.el.addClass('bx-has-controls-direction').append(slider.controls.directionEl); 575 } 576 } 577 578 /** 579 * Appends start / stop auto controls to the controls element 580 */ 581 var appendControlsAuto = function(){ 582 slider.controls.start = $('<div class="bx-controls-auto-item"><a class="bx-start" href="">' + slider.settings.startText + '</a></div>'); 583 slider.controls.stop = $('<div class="bx-controls-auto-item"><a class="bx-stop" href="">' + slider.settings.stopText + '</a></div>'); 584 // add the controls to the DOM 585 slider.controls.autoEl = $('<div class="bx-controls-auto" />'); 586 // bind click actions to the controls 587 slider.controls.autoEl.delegate('.bx-start', 'click', clickStartBind); 588 slider.controls.autoEl.delegate('.bx-stop', 'click', clickStopBind); 589 // if autoControlsCombine, insert only the "start" control 590 if(slider.settings.autoControlsCombine){ 591 slider.controls.autoEl.append(slider.controls.start); 592 // if autoControlsCombine is false, insert both controls 593 }else{ 594 slider.controls.autoEl.append(slider.controls.start).append(slider.controls.stop); 595 } 596 // if auto controls selector was supplied, populate it with the controls 597 if(slider.settings.autoControlsSelector){ 598 $(slider.settings.autoControlsSelector).html(slider.controls.autoEl); 599 // if auto controls selector was not supplied, add it after the wrapper 600 }else{ 601 slider.controls.el.addClass('bx-has-controls-auto').append(slider.controls.autoEl); 602 } 603 // update the auto controls
604 updateAutoControls(slider.settings.autoStart ? 'stop' : 'start'); 605 } 606 607 /** 608 * Appends image captions to the DOM 609 */ 610 var appendCaptions = function(){ 611 // cycle through each child 612 slider.children.each(function(index){ 613 // get the image title attribute 614 var title = $(this).find('img:first').attr('title'); 615 // append the caption 616 if (title != undefined) $(this).append('<div class="bx-caption"><span>' + title + '</span></div>'); 617 }); 618 } 619 620 /** 621 * Click next binding 622 * 623 * @param e (event) 624 * - DOM event object 625 */ 626 var clickNextBind = function(e){ 627 // if auto show is running, stop it 628 if (slider.settings.auto) el.stopAuto(); 629 el.goToNextSlide(); 630 e.preventDefault(); 631 } 632 633 /** 634 * Click prev binding 635 * 636 * @param e (event) 637 * - DOM event object 638 */ 639 var clickPrevBind = function(e){ 640 // if auto show is running, stop it 641 if (slider.settings.auto) el.stopAuto(); 642 el.goToPrevSlide(); 643 e.preventDefault(); 644 } 645 646 /** 647 * Click start binding 648 * 649 * @param e (event) 650 * - DOM event object 651 */ 652 var clickStartBind = function(e){ 653 el.startAuto(); 654 e.preventDefault(); 655 } 656 657 /** 658 * Click stop binding 659 * 660 * @param e (event) 661 * - DOM event object 662 */ 663 var clickStopBind = function(e){ 664 el.stopAuto(); 665 e.preventDefault(); 666 } 667 668 /** 669 * Click pager binding 670 * 671 * @param e (event) 672 * - DOM event object 673 */ 674 var clickPagerBind = function(e){ 675 // if auto show is running, stop it 676 if (slider.settings.auto) el.stopAuto(); 677 var pagerLink = $(e.currentTarget); 678 var pagerIndex = parseInt(pagerLink.attr('data-slide-index')); 679 // if clicked pager link is not active, continue with the goToSlide call 680 if(pagerIndex != slider.active.index) el.goToSlide(pagerIndex); 681 e.preventDefault(); 682 } 683 684 /** 685 * Updates the pager links with an active class 686 * 687 * @param slideIndex (int) 688 * - index of slide to make active 689 */ 690 var updatePagerActive = function(slideIndex){ 691 // if "short" pager type 692 if(slider.settings.pagerType == 'short'){ 693 slider.pagerEl.html((slideIndex + 1) + slider.settings.pagerShortSeparator + slider.children.length); 694 return; 695 } 696 // remove all pager active classes 697 slider.pagerEl.find('a').removeClass('active'); 698 // apply the active class for all pagers 699 slider.pagerEl.each(function(i, el) { $(el).find('a').eq(slideIndex).addClass('active'); }); 700 } 701 702 /** 703 * Performs needed actions after a slide transition 704 */ 705 var updateAfterSlideTransition = function(){ 706 // if infinte loop is true 707 if(slider.settings.infiniteLoop){ 708 var position = ''; 709 // first slide 710 if(slider.active.index == 0){ 711 // set the new position 712 position = slider.children.eq(0).position(); 713 // carousel, last slide 714 }else if(slider.active.index == getPagerQty() - 1 && slider.carousel){ 715 position = slider.children.eq((getPagerQty() - 1) * getMoveBy()).position(); 716 // last slide 717 }else if(slider.active.index == slider.children.length - 1){ 718 position = slider.children.eq(slider.children.length - 1).position(); 719 } 720 if (slider.settings.mode == 'horizontal') { setPositionProperty(-position.left, 'reset', 0);; } 721 else if (slider.settings.mode == 'vertical') { setPositionProperty(-position.top, 'reset', 0);; } 722 } 723 // declare that the transition is complete 724 slider.working = false; 725 // onSlideAfter callback 726 slider.settings.onSlideAfter(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 727 } 728 729 /** 730 * Updates the auto controls state (either active, or combined switch) 731 * 732 * @param state (string) "start", "stop" 733 * - the new state of the auto show 734 */ 735 var updateAutoControls = function(state){ 736 // if autoControlsCombine is true, replace the current control with the new state 737 if(slider.settings.autoControlsCombine){ 738 slider.controls.autoEl.html(slider.controls[state]); 739 // if autoControlsCombine is false, apply the "active" class to the appropriate control 740 }else{ 741 slider.controls.autoEl.find('a').removeClass('active');
742 slider.controls.autoEl.find('a:not(.bx-' + state + ')').addClass('active'); 743 } 744 } 745 746 /** 747 * Updates the direction controls (checks if either should be hidden) 748 */ 749 var updateDirectionControls = function(){ 750 // if infiniteLoop is false and hideControlOnEnd is true 751 if(!slider.settings.infiniteLoop && slider.settings.hideControlOnEnd){ 752 // if first slide 753 if (slider.active.index == 0){ 754 slider.controls.prev.addClass('disabled'); 755 slider.controls.next.removeClass('disabled'); 756 // if last slide 757 }else if(slider.active.index == getPagerQty() - 1){ 758 slider.controls.next.addClass('disabled'); 759 slider.controls.prev.removeClass('disabled'); 760 // if any slide in the middle 761 }else{ 762 slider.controls.prev.removeClass('disabled'); 763 slider.controls.next.removeClass('disabled'); 764 } 765 } 766 } 767 768 /** 769 * Initialzes the auto process 770 */ 771 var initAuto = function(){ 772 // if autoDelay was supplied, launch the auto show using a setTimeout() call 773 if(slider.settings.autoDelay > 0){ 774 var timeout = setTimeout(el.startAuto, slider.settings.autoDelay); 775 // if autoDelay was not supplied, start the auto show normally 776 }else{ 777 el.startAuto(); 778 } 779 // if autoHover is requested 780 if(slider.settings.autoHover){ 781 // on el hover 782 el.hover(function(){ 783 // if the auto show is currently playing (has an active interval) 784 if(slider.interval){ 785 // stop the auto show and pass true agument which will prevent control update 786 el.stopAuto(true); 787 // create a new autoPaused value which will be used by the relative "mouseout" event 788 slider.autoPaused = true; 789 } 790 }, function(){ 791 // if the autoPaused value was created be the prior "mouseover" event 792 if(slider.autoPaused){ 793 // start the auto show and pass true agument which will prevent control update 794 el.startAuto(true); 795 // reset the autoPaused value 796 slider.autoPaused = null; 797 } 798 }); 799 } 800 } 801 802 /** 803 * Initialzes the ticker process 804 */ 805 var initTicker = function(){ 806 var startPosition = 0; 807 // if autoDirection is "next", append a clone of the entire slider 808 if(slider.settings.autoDirection == 'next'){ 809 el.append(slider.children.clone().addClass('bx-clone')); 810 // if autoDirection is "prev", prepend a clone of the entire slider, and set the left position 811 }else{ 812 el.prepend(slider.children.clone().addClass('bx-clone')); 813 var position = slider.children.first().position(); 814 startPosition = slider.settings.mode == 'horizontal' ? -position.left : -position.top; 815 } 816 setPositionProperty(startPosition, 'reset', 0); 817 // do not allow controls in ticker mode 818 slider.settings.pager = false; 819 slider.settings.controls = false; 820 slider.settings.autoControls = false; 821 // if autoHover is requested 822 if(slider.settings.tickerHover && !slider.usingCSS){ 823 // on el hover 824 slider.viewport.hover(function(){ 825 el.stop(); 826 }, function(){ 827 // calculate the total width of children (used to calculate the speed ratio) 828 var totalDimens = 0; 829 slider.children.each(function(index){ 830 totalDimens += slider.settings.mode == 'horizontal' ? $(this).outerWidth(true) : $(this).outerHeight(true); 831 }); 832 // calculate the speed ratio (used to determine the new speed to finish the paused animation) 833 var ratio = slider.settings.speed / totalDimens; 834 // determine which property to use 835 var property = slider.settings.mode == 'horizontal' ? 'left' : 'top'; 836 // calculate the new speed 837 var newSpeed = ratio * (totalDimens - (Math.abs(parseInt(el.css(property))))); 838 tickerLoop(newSpeed); 839 }); 840 } 841 // start the ticker loop 842 tickerLoop(); 843 } 844 845 /** 846 * Runs a continuous loop, news ticker-style 847 */ 848 var tickerLoop = function(resumeSpeed){ 849 speed = resumeSpeed ? resumeSpeed : slider.settings.speed; 850 var position = {left: 0, top: 0}; 851 var reset = {left: 0, top: 0}; 852 // if "next" animate left position to last child, then reset left to 0 853 if(slider.settings.autoDirection == 'next'){ 854 position = el.find('.bx-clone').first().position(); 855 // if "prev" animate left position to 0, then reset left to first non-clone child 856 }else{ 857 reset = slider.children.first().position(); 858 } 859 var animateProperty = slider.settings.mode == 'horizontal' ? -position.left : -position.top; 860 var resetValue = slider.settings.mode == 'horizontal' ? -reset.left : -reset.top; 861 var params = {resetValue: resetValue}; 862 setPositionProperty(animateProperty, 'ticker', speed, params); 863 } 864 865 /** 866 * Initializes touch events 867 */ 868 var initTouch = function(){ 869 // initialize object to contain all touch values 870 slider.touch = { 871 start: {x: 0, y: 0}, 872 end: {x: 0, y: 0} 873 } 874 slider.viewport.bind('touchstart', onTouchStart); 875 } 876 877 /** 878 * Event handler for "touchstart" 879 * 880 * @param e (event) 881 * - DOM event object 882 */ 883 var onTouchStart = function(e){ 884 if(slider.working){ 885 e.preventDefault(); 886 }else{ 887 // record the original position when touch starts 888 slider.touch.originalPos = el.position(); 889 var orig = e.originalEvent; 890 // record the starting touch x, y coordinates
891 slider.touch.start.x = orig.changedTouches[0].pageX; 892 slider.touch.start.y = orig.changedTouches[0].pageY; 893 // bind a "touchmove" event to the viewport 894 slider.viewport.bind('touchmove', onTouchMove); 895 // bind a "touchend" event to the viewport 896 slider.viewport.bind('touchend', onTouchEnd); 897 } 898 } 899 900 /** 901 * Event handler for "touchmove" 902 * 903 * @param e (event) 904 * - DOM event object 905 */ 906 var onTouchMove = function(e){ 907 e.preventDefault(); 908 if(slider.settings.mode != 'fade'){ 909 var orig = e.originalEvent; 910 var value = 0; 911 // if horizontal, drag along x axis 912 if(slider.settings.mode == 'horizontal'){ 913 var change = orig.changedTouches[0].pageX - slider.touch.start.x; 914 value = slider.touch.originalPos.left + change; 915 // if vertical, drag along y axis 916 }else{ 917 var change = orig.changedTouches[0].pageY - slider.touch.start.y; 918 value = slider.touch.originalPos.top + change; 919 } 920 setPositionProperty(value, 'reset', 0); 921 } 922 } 923 924 /** 925 * Event handler for "touchend" 926 * 927 * @param e (event) 928 * - DOM event object 929 */ 930 var onTouchEnd = function(e){ 931 slider.viewport.unbind('touchmove', onTouchMove); 932 var orig = e.originalEvent; 933 var value = 0; 934 // record end x, y positions 935 slider.touch.end.x = orig.changedTouches[0].pageX; 936 slider.touch.end.y = orig.changedTouches[0].pageY; 937 // if fade mode, check if absolute x distance clears the threshold 938 if(slider.settings.mode == 'fade'){ 939 var distance = Math.abs(slider.touch.start.x - slider.touch.end.x); 940 if(distance >= slider.settings.swipeThreshold){ 941 slider.touch.start.x > slider.touch.end.x ? el.goToNextSlide() : el.goToPrevSlide(); 942 el.stopAuto(); 943 } 944 // not fade mode 945 }else{ 946 var distance = 0; 947 // calculate distance and el's animate property 948 if(slider.settings.mode == 'horizontal'){ 949 distance = slider.touch.end.x - slider.touch.start.x; 950 value = slider.touch.originalPos.left; 951 }else{ 952 distance = slider.touch.end.y - slider.touch.start.y; 953 value = slider.touch.originalPos.top; 954 } 955 // if not infinite loop and first / last slide, do not attempt a slide transition 956 if(!slider.settings.infiniteLoop && ((slider.active.index == 0 && distance > 0) || (slider.active.last && distance < 0))){ 957 setPositionProperty(value, 'reset', 200); 958 }else{ 959 // check if distance clears threshold 960 if(Math.abs(distance) >= slider.settings.swipeThreshold){ 961 distance < 0 ? el.goToNextSlide() : el.goToPrevSlide(); 962 el.stopAuto(); 963 }else{ 964 // el.animate(property, 200); 965 setPositionProperty(value, 'reset', 200); 966 } 967 } 968 } 969 slider.viewport.unbind('touchend', onTouchEnd); 970 } 971 972 var resizeWindow = function(e){ 973 // get the new window dimens (again, thank you IE) 974 var windowWidthNew = $(window).width(); 975 var windowHeightNew = $(window).height(); 976 // make sure that it is a true window resize 977 // *we must check this because our dinosaur friend IE fires a window resize event when certain DOM elements 978 // are resized. Can you just die already?* 979 if(windowWidth != windowWidthNew || windowHeight != windowHeightNew){ 980 // set the new window dimens 981 windowWidth = windowWidthNew; 982 windowHeight = windowHeightNew; 983 // resize all children in ratio to new screen size 984 slider.children.add(el.find('.bx-clone')).width(getSlideWidth()); 985 // adjust the height 986 slider.viewport.css('height', getViewportHeight()); 987 // if active.last was true before the screen resize, we want 988 // to keep it last no matter what screen size we end on 989 if (slider.active.last) slider.active.index = getPagerQty() - 1; 990 // if the active index (page) no longer exists due to the resize, simply set the index as last 991 if (slider.active.index >= getPagerQty()) slider.active.last = true; 992 // if a pager is being displayed and a custom pager is not being used, update it 993 if(slider.settings.pager && !slider.settings.pagerCustom){ 994 populatePager(); 995 updatePagerActive(slider.active.index); 996 } 997 // update the slide position
998 if(!slider.settings.ticker) setSlidePosition(); 999 } 1000 } 1001 1002 /** 1003 * =================================================================================== 1004 * = PUBLIC FUNCTIONS 1005 * =================================================================================== 1006 */ 1007 1008 /** 1009 * Performs slide transition to the specified slide 1010 * 1011 * @param slideIndex (int) 1012 * - the destination slide's index (zero-based) 1013 * 1014 * @param direction (string) 1015 * - INTERNAL USE ONLY - the direction of travel ("prev" / "next") 1016 */ 1017 el.goToSlide = function(slideIndex, direction){ 1018 // if plugin is currently in motion, ignore request 1019 if(slider.working || slider.active.index == slideIndex) return; 1020 // declare that plugin is in motion 1021 slider.working = true; 1022 // store the old index 1023 slider.oldIndex = slider.active.index; 1024 // if slideIndex is less than zero, set active index to last child (this happens during infinite loop) 1025 if(slideIndex < 0){ 1026 slider.active.index = getPagerQty() - 1; 1027 // if slideIndex is greater than children length, set active index to 0 (this happens during infinite loop) 1028 }else if(slideIndex >= getPagerQty()){ 1029 slider.active.index = 0; 1030 // set active index to requested slide 1031 }else{ 1032 slider.active.index = slideIndex; 1033 } 1034 // onSlideBefore, onSlideNext, onSlidePrev callbacks 1035 slider.settings.onSlideBefore(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 1036 if(direction == 'next'){ 1037 slider.settings.onSlideNext(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 1038 }else if(direction == 'prev'){ 1039 slider.settings.onSlidePrev(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 1040 } 1041 // check if last slide 1042 slider.active.last = slider.active.index >= getPagerQty() - 1; 1043 // update the pager with active class 1044 if(slider.settings.pager) updatePagerActive(slider.active.index); 1045 // // check for direction control update 1046 if(slider.settings.controls) updateDirectionControls(); 1047 // if slider is set to mode: "fade" 1048 if(slider.settings.mode == 'fade'){ 1049 // if adaptiveHeight is true and next height is different from current height, animate to the new height 1050 if(slider.settings.adaptiveHeight && slider.viewport.height() != getViewportHeight()){ 1051 slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); 1052 } 1053 // fade out the visible child and reset its z-index value 1054 slider.children.filter(':visible').fadeOut(slider.settings.speed).css({zIndex: 0}); 1055 // fade in the newly requested slide 1056 slider.children.eq(slider.active.index).css('zIndex', 51).fadeIn(slider.settings.speed, function(){ 1057 $(this).css('zIndex', 50); 1058 updateAfterSlideTransition(); 1059 }); 1060 // slider mode is not "fade" 1061 }else{ 1062 // if adaptiveHeight is true and next height is different from current height, animate to the new height 1063 if(slider.settings.adaptiveHeight && slider.viewport.height() != getViewportHeight()){ 1064 slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); 1065 } 1066 var moveBy = 0; 1067 var position = {left: 0, top: 0}; 1068 // if carousel and not infinite loop 1069 if(!slider.settings.infiniteLoop && slider.carousel && slider.active.last){ 1070 if(slider.settings.mode == 'horizontal'){ 1071 // get the last child position 1072 var lastChild = slider.children.eq(slider.children.length - 1); 1073 position = lastChild.position(); 1074 // calculate the position of the last slide 1075 moveBy = slider.viewport.width() - lastChild.width(); 1076 }else{ 1077 // get last showing index position 1078 var lastShowingIndex = slider.children.length - slider.settings.minSlides; 1079 position = slider.children.eq(lastShowingIndex).position(); 1080 } 1081 // horizontal carousel, going previous while on first slide (infiniteLoop mode) 1082 }else if(slider.carousel && slider.active.last && direction == 'prev'){ 1083 // get the last child position 1084 var eq = slider.settings.moveSlides == 1 ? slider.settings.maxSlides - getMoveBy() : ((getPagerQty() - 1) * getMoveBy()) - (slider.children.length - slider.settings.maxSlides); 1085 var lastChild = el.children('.bx-clone').eq(eq); 1086 position = lastChild.position(); 1087 // if infinite loop and "Next" is clicked on the last slide 1088 }else if(direction == 'next' && slider.active.index == 0){ 1089 // get the last clone position 1090 position = el.find('.bx-clone').eq(slider.settings.maxSlides).position(); 1091 slider.active.last = false;
1092 // normal non-zero requests 1093 }else if(slideIndex >= 0){ 1094 var requestEl = slideIndex * getMoveBy(); 1095 position = slider.children.eq(requestEl).position(); 1096 } 1097 // plugin values to be animated 1098 var value = slider.settings.mode == 'horizontal' ? -(position.left - moveBy) : -position.top; 1099 setPositionProperty(value, 'slide', slider.settings.speed); 1100 } 1101 } 1102 1103 /** 1104 * Transitions to the next slide in the show 1105 */ 1106 el.goToNextSlide = function(){ 1107 // if infiniteLoop is false and last page is showing, disregard call 1108 if (!slider.settings.infiniteLoop && slider.active.last) return; 1109 var pagerIndex = slider.active.index + 1; 1110 el.goToSlide(pagerIndex, 'next'); 1111 } 1112 1113 /** 1114 * Transitions to the prev slide in the show 1115 */ 1116 el.goToPrevSlide = function(){ 1117 // if infiniteLoop is false and last page is showing, disregard call 1118 if (!slider.settings.infiniteLoop && slider.active.index == 0) return; 1119 var pagerIndex = slider.active.index - 1; 1120 el.goToSlide(pagerIndex, 'prev'); 1121 } 1122 1123 /** 1124 * Starts the auto show 1125 * 1126 * @param preventControlUpdate (boolean) 1127 * - if true, auto controls state will not be updated 1128 */ 1129 el.startAuto = function(preventControlUpdate){ 1130 // if an interval already exists, disregard call 1131 if(slider.interval) return; 1132 // create an interval 1133 slider.interval = setInterval(function(){ 1134 slider.settings.autoDirection == 'next' ? el.goToNextSlide() : el.goToPrevSlide(); 1135 }, slider.settings.pause); 1136 // if auto controls are displayed and preventControlUpdate is not true 1137 if (slider.settings.autoControls && preventControlUpdate != true) updateAutoControls('stop'); 1138 } 1139 1140 /** 1141 * Stops the auto show 1142 * 1143 * @param preventControlUpdate (boolean) 1144 * - if true, auto controls state will not be updated 1145 */ 1146 el.stopAuto = function(preventControlUpdate){ 1147 // if no interval exists, disregard call 1148 if(!slider.interval) return; 1149 // clear the interval 1150 clearInterval(slider.interval); 1151 slider.interval = null; 1152 // if auto controls are displayed and preventControlUpdate is not true 1153 if (slider.settings.autoControls && preventControlUpdate != true) updateAutoControls('start'); 1154 } 1155 1156 /** 1157 * Returns current slide index (zero-based) 1158 */ 1159 el.getCurrentSlide = function(){ 1160 return slider.active.index; 1161 } 1162 1163 /** 1164 * Returns number of slides in show 1165 */ 1166 el.getSlideCount = function(){ 1167 return slider.children.length; 1168 } 1169 1170 /** 1171 * Destroy the current instance of the slider (revert everything back to original state) 1172 */ 1173 el.destroySlider = function(){ 1174 // don't do anything if slider has already been destroyed 1175 if(!slider.initialized) return; 1176 slider.initialized = false; 1177 $('.bx-clone', this).remove(); 1178 slider.children.removeAttr('style'); 1179 this.removeAttr('style').unwrap().unwrap(); 1180 if(slider.controls.el) slider.controls.el.remove(); 1181 if(slider.controls.next) slider.controls.next.remove(); 1182 if(slider.controls.prev) slider.controls.prev.remove(); 1183 if(slider.pagerEl) slider.pagerEl.remove(); 1184 $('.bx-caption', this).remove(); 1185 if(slider.controls.autoEl) slider.controls.autoEl.remove(); 1186 clearInterval(slider.interval); 1187 $(window).unbind('resize', resizeWindow); 1188 } 1189 1190 /** 1191 * Reload the slider (revert all DOM changes, and re-initialize) 1192 */ 1193 el.reloadSlider = function(settings){ 1194 if (settings != undefined) options = settings; 1195 el.destroySlider(); 1196 init(); 1197 } 1198 1199 init(); 1200 1201 // returns the current jQuery object 1202 return this; 1203 } 1204 1205})(jQuery); 1206 1207/*! 1208 * jQuery imagesLoaded plugin v2.1.0 1209 * http://github.com/desandro/imagesloaded 1210 * 1211 * MIT License. by Paul Irish et al. 1212 */ 1213 1214/*jshint curly: true, eqeqeq: true, noempty: true, strict: true, undef: true, browser: true */ 1215/*global jQuery: false */ 1216 1217(function(c,n){var l="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";c.fn.imagesLoaded=function(f){function m(){var b=c(i),a=c(h);d&&(h.length?d.reject(e,b,a):d.resolve(e));c.isFunction(f)&&f.call(g,e,b,a)}function j(b,a){b.src===l||-1!==c.inArray(b,k)||(k.push(b),a?h.push(b):i.push(b),c.data(b,"imagesLoaded",{isBroken:a,src:b.src}),o&&d.notifyWith(c(b),[a,e,c(i),c(h)]),e.length===k.length&&(setTimeout(m),e.unbind(".imagesLoaded")))}var g=this,d=c.isFunction(c.Deferred)?c.Deferred(): 12180,o=c.isFunction(d.notify),e=g.find("img").add(g.filter("img")),k=[],i=[],h=[];c.isPlainObject(f)&&c.each(f,function(b,a){if("callback"===b)f=a;else if(d)d[b](a)});e.length?e.bind("load.imagesLoaded error.imagesLoaded",function(b){j(b.target,"error"===b.type)}).each(function(b,a){var d=a.src,e=c.data(a,"imagesLoaded");
1218if(e&&e.src===d)j(a,e.isBroken);else if(a.complete&&a.naturalWidth!==n)j(a,0===a.naturalWidth||0===a.naturalHeight);else if(a.readyState||a.complete)a.src=l,a.src=d}):m();return d?d.promise(g): 1219g}})(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.