vendor: 77,731 bytes, lines 1-1748
1/** 2 * bxSlider v4.2.12 3 * Copyright 2013-2015 Steven Wanderski 4 * Written while drinking Belgian ales and listening to jazz 5 * Licensed under MIT (http://opensource.org/licenses/MIT) 6 */ 7 8;(function ($) { 9 10 var defaults = { 11 12 // GENERAL 13 mode: 'horizontal', 14 slideSelector: '', 15 infiniteLoop: true, 16 hideControlOnEnd: false, 17 speed: 500, 18 easing: null, 19 slideMargin: 0, 20 startSlide: 0, 21 randomStart: false, 22 captions: false, 23 ticker: false, 24 tickerHover: false, 25 adaptiveHeight: false, 26 adaptiveHeightSpeed: 500, 27 video: false, 28 useCSS: true, 29 preloadImages: 'visible', 30 responsive: true, 31 slideZIndex: 50, 32 wrapperClass: 'bx-wrapper', 33 34 // TOUCH 35 touchEnabled: true, 36 swipeThreshold: 50, 37 oneToOneTouch: true, 38 preventDefaultSwipeX: true, 39 preventDefaultSwipeY: false, 40 41 // ACCESSIBILITY 42 ariaLive: true, 43 ariaHidden: true, 44 45 // KEYBOARD 46 keyboardEnabled: false, 47 48 // PAGER 49 pager: true, 50 pagerType: 'full', 51 pagerShortSeparator: ' / ', 52 pagerSelector: null, 53 buildPager: null, 54 pagerCustom: null, 55 56 // CONTROLS 57 controls: true, 58 nextText: 'Next', 59 prevText: 'Prev', 60 nextSelector: null, 61 prevSelector: null, 62 autoControls: false, 63 startText: 'Start', 64 stopText: 'Stop', 65 autoControlsCombine: false, 66 autoControlsSelector: null, 67 68 // AUTO 69 auto: false, 70 pause: 4000, 71 autoStart: true, 72 autoDirection: 'next', 73 stopAutoOnClick: false, 74 autoHover: false, 75 autoDelay: 0, 76 autoSlideForOnePage: false, 77 78 // CAROUSEL 79 minSlides: 1, 80 maxSlides: 1, 81 moveSlides: 0, 82 slideWidth: 0, 83 shrinkItems: false, 84 85 // CALLBACKS 86 onSliderLoad: function () { 87 return true; 88 }, 89 onSlideBefore: function () { 90 return true; 91 }, 92 onSlideAfter: function () { 93 return true; 94 }, 95 onSlideNext: function () { 96 return true; 97 }, 98 onSlidePrev: function () { 99 return true; 100 }, 101 onSliderResize: function () { 102 return true; 103 } 104 }; 105 106 $.fn.bxSlider = function (options) { 107 108 if (this.length === 0) { 109 return this; 110 } 111 112 // support multiple elements 113 if (this.length > 1) { 114 this.each(function () { 115 $(this).bxSlider(options); 116 }); 117 return this; 118 } 119 120 // create a namespace to be used throughout the plugin 121 var slider = {}, 122 // set a reference to our slider element 123 el = this, 124 // get the original window dimens (thanks a lot IE) 125 windowWidth = $(window).width(), 126 windowHeight = $(window).height(); 127 128 // Return if slider is already initialized 129 if ($(el).data('bxSlider')) { 130 return; 131 } 132 133 /** 134 * =================================================================================== 135 * = PRIVATE FUNCTIONS 136 * =================================================================================== 137 */ 138 139 /** 140 * Initializes namespace settings to be used throughout plugin 141 */ 142 var init = function () { 143 // Return if slider is already initialized 144 if ($(el).data('bxSlider')) { 145 return; 146 } 147 // merge user-supplied options with the defaults 148 slider.settings = $.extend({}, defaults, options); 149 // parse slideWidth setting 150 slider.settings.slideWidth = parseInt(slider.settings.slideWidth); 151 // store the original children 152 slider.children = el.children(slider.settings.slideSelector); 153 // check if actual number of slides is less than minSlides / maxSlides 154 if (slider.children.length < slider.settings.minSlides) { 155 slider.settings.minSlides = slider.children.length; 156 } 157 if (slider.children.length < slider.settings.maxSlides) { 158 slider.settings.maxSlides = slider.children.length; 159 } 160 // if random start, set the startSlide setting to random number 161 if (slider.settings.randomStart) { 162 slider.settings.startSlide = Math.floor(Math.random() * slider.children.length); 163 } 164 // store active slide information 165 slider.active = {index: slider.settings.startSlide}; 166 // store if the slider is in carousel mode (displaying / moving multiple slides) 167 slider.carousel = slider.settings.minSlides > 1 || slider.settings.maxSlides > 1 ? true : false; 168 // if carousel, force preloadImages = 'all' 169 if (slider.carousel) { 170 slider.settings.preloadImages = 'all'; 171 } 172 // calculate the min / max width thresholds based on min / max number of slides 173 // used to setup and update carousel slides dimensions 174 slider.minThreshold = (slider.settings.minSlides * slider.settings.slideWidth) + ((slider.settings.minSlides - 1) * slider.settings.slideMargin); 175 slider.maxThreshold = (slider.settings.maxSlides * slider.settings.slideWidth) + ((slider.settings.maxSlides - 1) * slider.settings.slideMargin); 176 // store the current state of the slider (if currently animating, working is true) 177 slider.working = false; 178 // initialize the controls object 179 slider.controls = {}; 180 // initialize an auto interval 181 slider.interval = null; 182 // determine which property to use for transitions 183 slider.animProp = slider.settings.mode === 'vertical' ? 'top' : 'left'; 184 // determine if hardware acceleration can be used 185 slider.usingCSS = slider.settings.useCSS && slider.settings.mode !== 'fade' && (function () { 186 // create our test div element 187 var div = document.createElement('div'), 188 // css transition properties 189 props = ['WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective']; 190 // test for each property 191 for (var i = 0; i < props.length; i++) { 192 if (div.style[props[i]] !== undefined) { 193 slider.cssPrefix = props[i].replace('Perspective', '').toLowerCase(); 194 slider.animProp = '-' + slider.cssPrefix + '-transform'; 195 return true; 196 } 197 } 198 return false; 199 }()); 200 // if vertical mode always make maxSlides and minSlides equal 201 if (slider.settings.mode === 'vertical') { 202 slider.settings.maxSlides = slider.settings.minSlides; 203 } 204 // save original style data 205 el.data('origStyle', el.attr('style')); 206 el.children(slider.settings.slideSelector).each(function () { 207 $(this).data('origStyle', $(this).attr('style')); 208 }); 209 210 // perform all DOM / CSS modifications 211 setup(); 212 }; 213 214 /** 215 * Performs all DOM and CSS modifications 216 */ 217 var setup = function () { 218 var preloadSelector = slider.children.eq(slider.settings.startSlide); // set the default preload selector (visible) 219 220 // wrap el in a wrapper 221 el.wrap('<div class="' + slider.settings.wrapperClass + '"><div class="bx-viewport"></div></div>'); 222 // store a namespace reference to .bx-viewport 223 slider.viewport = el.parent(); 224 225 // add aria-live if the setting is enabled and ticker mode is disabled 226 if (slider.settings.ariaLive && !slider.settings.ticker) { 227 slider.viewport.attr('aria-live', 'polite'); 228 } 229 // add a loading div to display while images are loading 230 slider.loader = $('<div class="bx-loading" />'); 231 slider.viewport.prepend(slider.loader); 232 // set el to a massive width, to hold any needed slides 233 // also strip any margin and padding from el 234 el.css({ 235 width: slider.settings.mode === 'horizontal' ? (slider.children.length * 1000 + 215) + '%' : 'auto', 236 position: 'relative' 237 }); 238 // if using CSS, add the easing property 239 if (slider.usingCSS && slider.settings.easing) { 240 el.css('-' + slider.cssPrefix + '-transition-timing-function', slider.settings.easing); 241 // if not using CSS and no easing value was supplied, use the default JS animation easing (swing) 242 } else if (!slider.settings.easing) { 243 slider.settings.easing = 'swing'; 244 } 245 // make modifications to the viewport (.bx-viewport) 246 slider.viewport.css({ 247 width: '100%', 248 overflow: 'hidden', 249 position: 'relative' 250 }); 251 slider.viewport.parent().css({ 252 maxWidth: getViewportMaxWidth() 253 }); 254 // apply css to all slider children 255 slider.children.css({ 256 float: slider.settings.mode === 'horizontal' ? 'left' : 'none', 257 listStyle: 'none', 258 position: 'relative' 259 }); 260 // apply the calculated width after the float is applied to prevent scrollbar interference 261 slider.children.css('width', getSlideWidth()); 262 // if slideMargin is supplied, add the css 263 if (slider.settings.mode === 'horizontal' && slider.settings.slideMargin > 0) { 264 slider.children.css('marginRight', slider.settings.slideMargin); 265 } 266 if (slider.settings.mode === 'vertical' && slider.settings.slideMargin > 0) { 267 slider.children.css('marginBottom', slider.settings.slideMargin); 268 } 269 // if "fade" mode, add positioning and z-index CSS 270 if (slider.settings.mode === 'fade') { 271 slider.children.css({ 272 position: 'absolute', 273 zIndex: 0, 274 display: 'none' 275 }); 276 // prepare the z-index on the showing element 277 slider.children.eq(slider.settings.startSlide).css({ 278 zIndex: slider.settings.slideZIndex, 279 display: 'block' 280 }); 281 } 282 // create an element to contain all slider controls (pager, start / stop, etc) 283 slider.controls.el = $('<div class="bx-controls" />'); 284 // if captions are requested, add them 285 if (slider.settings.captions) { 286 appendCaptions(); 287 } 288 // check if startSlide is last slide 289 slider.active.last = slider.settings.startSlide === getPagerQty() - 1; 290 // if video is true, set up the fitVids plugin 291 if (slider.settings.video) { 292 el.fitVids(); 293 } 294 if (slider.settings.preloadImages === 'all' || slider.settings.ticker) { 295 preloadSelector = slider.children; 296 } 297 // only check for control addition if not in "ticker" mode 298 if (!slider.settings.ticker) { 299 // if controls are requested, add them 300 if (slider.settings.controls) { 301 appendControls(); 302 } 303 // if auto is true, and auto controls are requested, add them 304 if (slider.settings.auto && slider.settings.autoControls) { 305 appendControlsAuto(); 306 } 307 // if pager is requested, add it 308 if (slider.settings.pager) { 309 appendPager(); 310 } 311 // if any control option is requested, add the controls wrapper 312 if (slider.settings.controls || slider.settings.autoControls || slider.settings.pager) { 313 slider.viewport.after(slider.controls.el); 314 } 315 // if ticker mode, do not allow a pager 316 } else { 317 slider.settings.pager = false; 318 } 319 loadElements(preloadSelector, start); 320 }; 321 322 var loadElements = function (selector, callback) { 323 var total = selector.find('img:not([src=""]), iframe').length, 324 count = 0; 325 if (total === 0) { 326 callback(); 327 return; 328 } 329 selector.find('img:not([src=""]), iframe').each(function () { 330 $(this).one('load error', function () { 331 if (++count === total) { 332 callback(); 333 } 334 }).each(function () { 335 if (this.complete) { 336 $(this).trigger('load'); 337 } 338 }); 339 }); 340 }; 341 342 /** 343 * Start the slider 344 */ 345 var start = function () { 346 // if infinite loop, prepare additional slides 347 if (slider.settings.infiniteLoop && slider.settings.mode !== 'fade' && !slider.settings.ticker) { 348 var slice = slider.settings.mode === 'vertical' ? slider.settings.minSlides : slider.settings.maxSlides, 349 sliceAppend = slider.children.slice(0, slice).clone(true).addClass('bx-clone'), 350 slicePrepend = slider.children.slice(-slice).clone(true).addClass('bx-clone'); 351 if (slider.settings.ariaHidden) { 352 sliceAppend.attr('aria-hidden', true); 353 slicePrepend.attr('aria-hidden', true); 354 } 355 el.append(sliceAppend).prepend(slicePrepend); 356 } 357 // remove the loading DOM element 358 slider.loader.remove(); 359 // set the left / top position of "el" 360 setSlidePosition(); 361 // if "vertical" mode, always use adaptiveHeight to prevent odd behavior 362 if (slider.settings.mode === 'vertical') { 363 slider.settings.adaptiveHeight = true; 364 } 365 // set the viewport height 366 slider.viewport.height(getViewportHeight()); 367 // make sure everything is positioned just right (same as a window resize) 368 el.redrawSlider(); 369 // onSliderLoad callback 370 slider.settings.onSliderLoad.call(el, slider.active.index); 371 // slider has been fully initialized 372 slider.initialized = true; 373 // bind the resize call to the window 374 if (slider.settings.responsive) { 375 $(window).bind('resize', resizeWindow); 376 } 377 // if auto is true and has more than 1 page, start the show 378 if (slider.settings.auto && slider.settings.autoStart && (getPagerQty() > 1 || slider.settings.autoSlideForOnePage)) { 379 initAuto(); 380 } 381 // if ticker is true, start the ticker 382 if (slider.settings.ticker) { 383 initTicker(); 384 } 385 // if pager is requested, make the appropriate pager link active 386 if (slider.settings.pager) { 387 updatePagerActive(slider.settings.startSlide); 388 } 389 // check for any updates to the controls (like hideControlOnEnd updates) 390 if (slider.settings.controls) { 391 updateDirectionControls(); 392 } 393 // if touchEnabled is true, setup the touch events 394 if (slider.settings.touchEnabled && !slider.settings.ticker) { 395 initTouch(); 396 } 397 // if keyboardEnabled is true, setup the keyboard events 398 if (slider.settings.keyboardEnabled && !slider.settings.ticker) { 399 $(document).keydown(keyPress); 400 } 401 }; 402 403 /** 404 * Returns the calculated height of the viewport, used to determine either adaptiveHeight or the maxHeight value 405 */ 406 var getViewportHeight = function () { 407 var height = 0; 408 // first determine which children (slides) should be used in our height calculation 409 var children = $(); 410 // if mode is not "vertical" and adaptiveHeight is false, include all children 411 if (slider.settings.mode !== 'vertical' && !slider.settings.adaptiveHeight) { 412 children = slider.children; 413 } else { 414 // if not carousel, return the single active child 415 if (!slider.carousel) { 416 children = slider.children.eq(slider.active.index); 417 // if carousel, return a slice of children 418 } else { 419 // get the individual slide index 420 var currentIndex = slider.settings.moveSlides === 1 ? slider.active.index : slider.active.index * getMoveBy(); 421 // add the current slide to the children 422 children = slider.children.eq(currentIndex); 423 // cycle through the remaining "showing" slides 424 for (i = 1; i <= slider.settings.maxSlides - 1; i++) { 425 // if looped back to the start 426 if (currentIndex + i >= slider.children.length) { 427 children = children.add(slider.children.eq(i - 1)); 428 } else { 429 children = children.add(slider.children.eq(currentIndex + i)); 430 } 431 } 432 } 433 } 434 // if "vertical" mode, calculate the sum of the heights of the children 435 if (slider.settings.mode === 'vertical') { 436 children.each(function (index) { 437 height += $(this).outerHeight(); 438 }); 439 // add user-supplied margins 440 if (slider.settings.slideMargin > 0) { 441 height += slider.settings.slideMargin * (slider.settings.minSlides - 1); 442 } 443 // if not "vertical" mode, calculate the max height of the children 444 } else { 445 height = Math.max.apply(Math, children.map(function () { 446 return $(this).outerHeight(false); 447 }).get()); 448 } 449 450 if (slider.viewport.css('box-sizing') === 'border-box') { 451 height += parseFloat(slider.viewport.css('padding-top')) + parseFloat(slider.viewport.css('padding-bottom')) + 452 parseFloat(slider.viewport.css('border-top-width')) + parseFloat(slider.viewport.css('border-bottom-width')); 453 } else if (slider.viewport.css('box-sizing') === 'padding-box') { 454 height += parseFloat(slider.viewport.css('padding-top')) + parseFloat(slider.viewport.css('padding-bottom')); 455 } 456 457 return height; 458 }; 459 460 /** 461 * Returns the calculated width to be used for the outer wrapper / viewport 462 */ 463 var getViewportMaxWidth = function () { 464 var width = '100%'; 465 if (slider.settings.slideWidth > 0) { 466 if (slider.settings.mode === 'horizontal') { 467 width = (slider.settings.maxSlides * slider.settings.slideWidth) + ((slider.settings.maxSlides - 1) * slider.settings.slideMargin); 468 } else { 469 width = slider.settings.slideWidth; 470 } 471 } 472 return width; 473 }; 474 475 /** 476 * Returns the calculated width to be applied to each slide 477 */ 478 var getSlideWidth = function () { 479 var newElWidth = slider.settings.slideWidth, // start with any user-supplied slide width 480 wrapWidth = slider.viewport.width(); // get the current viewport width 481 // if slide width was not supplied, or is larger than the viewport use the viewport width 482 if (slider.settings.slideWidth === 0 || 483 (slider.settings.slideWidth > wrapWidth && !slider.carousel) || 484 slider.settings.mode === 'vertical') { 485 newElWidth = wrapWidth; 486 // if carousel, use the thresholds to determine the width 487 } else if (slider.settings.maxSlides > 1 && slider.settings.mode === 'horizontal') { 488 if (wrapWidth > slider.maxThreshold) { 489 return newElWidth; 490 } else if (wrapWidth < slider.minThreshold) { 491 newElWidth = (wrapWidth - (slider.settings.slideMargin * (slider.settings.minSlides - 1))) / slider.settings.minSlides; 492 } else if (slider.settings.shrinkItems) { 493 newElWidth = Math.floor((wrapWidth + slider.settings.slideMargin) / (Math.ceil((wrapWidth + slider.settings.slideMargin) / (newElWidth + slider.settings.slideMargin))) - slider.settings.slideMargin); 494 } 495 } 496 return newElWidth; 497 }; 498 499 /** 500 * Returns the number of slides currently visible in the viewport (includes partially visible slides) 501 */ 502 var getNumberSlidesShowing = function () { 503 var slidesShowing = 1, 504 childWidth = null; 505 if (slider.settings.mode === 'horizontal' && slider.settings.slideWidth > 0) { 506 // if viewport is smaller than minThreshold, return minSlides 507 if (slider.viewport.width() < slider.minThreshold) { 508 slidesShowing = slider.settings.minSlides; 509 // if viewport is larger than maxThreshold, return maxSlides 510 } else if (slider.viewport.width() > slider.maxThreshold) { 511 slidesShowing = slider.settings.maxSlides; 512 // if viewport is between min / max thresholds, divide viewport width by first child width 513 } else { 514 childWidth = slider.children.first().width() + slider.settings.slideMargin; 515 slidesShowing = Math.floor((slider.viewport.width() + 516 slider.settings.slideMargin) / childWidth); 517 } 518 // if "vertical" mode, slides showing will always be minSlides 519 } else if (slider.settings.mode === 'vertical') { 520 slidesShowing = slider.settings.minSlides; 521 } 522 return slidesShowing; 523 }; 524 525 /** 526 * Returns the number of pages (one full viewport of slides is one "page") 527 */ 528 var getPagerQty = function () { 529 var pagerQty = 0, 530 breakPoint = 0, 531 counter = 0; 532 // if moveSlides is specified by the user 533 if (slider.settings.moveSlides > 0) { 534 if (slider.settings.infiniteLoop) { 535 pagerQty = Math.ceil(slider.children.length / getMoveBy()); 536 } else { 537 // when breakpoint goes above children length, counter is the number of pages 538 while (breakPoint < slider.children.length) { 539 ++pagerQty; 540 breakPoint = counter + getNumberSlidesShowing(); 541 counter += slider.settings.moveSlides <= getNumberSlidesShowing() ? slider.settings.moveSlides : getNumberSlidesShowing(); 542 } 543 } 544 // if moveSlides is 0 (auto) divide children length by sides showing, then round up 545 } else { 546 pagerQty = Math.ceil(slider.children.length / getNumberSlidesShowing()); 547 } 548 return pagerQty; 549 }; 550 551 /** 552 * Returns the number of individual slides by which to shift the slider 553 */ 554 var getMoveBy = function () { 555 // if moveSlides was set by the user and moveSlides is less than number of slides showing 556 if (slider.settings.moveSlides > 0 && slider.settings.moveSlides <= getNumberSlidesShowing()) { 557 return slider.settings.moveSlides; 558 } 559 // if moveSlides is 0 (auto) 560 return getNumberSlidesShowing(); 561 }; 562 563 /** 564 * Sets the slider's (el) left or top position 565 */ 566 var setSlidePosition = function () { 567 var position, lastChild, lastShowingIndex; 568 // if last slide, not infinite loop, and number of children is larger than specified maxSlides 569 if (slider.children.length > slider.settings.maxSlides && slider.active.last && !slider.settings.infiniteLoop) { 570 if (slider.settings.mode === 'horizontal') { 571 // get the last child's position 572 lastChild = slider.children.last(); 573 position = lastChild.position(); 574 // set the left position 575 setPositionProperty(-(position.left - (slider.viewport.width() - lastChild.outerWidth())), 'reset', 0); 576 } else if (slider.settings.mode === 'vertical') { 577 // get the last showing index's position 578 lastShowingIndex = slider.children.length - slider.settings.minSlides; 579 position = slider.children.eq(lastShowingIndex).position(); 580 // set the top position 581 setPositionProperty(-position.top, 'reset', 0); 582 } 583 // if not last slide 584 } else { 585 // get the position of the first showing slide 586 position = slider.children.eq(slider.active.index * getMoveBy()).position(); 587 // check for last slide 588 if (slider.active.index === getPagerQty() - 1) { 589 slider.active.last = true; 590 } 591 // set the respective position 592 if (position !== undefined) { 593 if (slider.settings.mode === 'horizontal') { 594 setPositionProperty(-position.left, 'reset', 0); 595 } 596 else if (slider.settings.mode === 'vertical') { 597 setPositionProperty(-position.top, 'reset', 0); 598 } 599 } 600 } 601 }; 602 603 /** 604 * Sets the el's animating property position (which in turn will sometimes animate el). 605 * If using CSS, sets the transform property. If not using CSS, sets the top / left property. 606 * 607 * @param value (int) 608 * - the animating property's value 609 * 610 * @param type (string) 'slide', 'reset', 'ticker' 611 * - the type of instance for which the function is being 612 * 613 * @param duration (int) 614 * - the amount of time (in ms) the transition should occupy 615 * 616 * @param params (array) optional 617 * - an optional parameter containing any variables that need to be passed in 618 */ 619 var setPositionProperty = function (value, type, duration, params) { 620 var animateObj, propValue; 621 // use CSS transform 622 if (slider.usingCSS) { 623 // determine the translate3d value 624 propValue = slider.settings.mode === 'vertical' ? 'translate3d(0, ' + value + 'px, 0)' : 'translate3d(' + value + 'px, 0, 0)'; 625 // add the CSS transition-duration 626 el.css('-' + slider.cssPrefix + '-transition-duration', duration / 1000 + 's'); 627 if (type === 'slide') { 628 // set the property value 629 el.css(slider.animProp, propValue); 630 if (duration !== 0) { 631 // bind a callback method - executes when CSS transition completes 632 el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function (e) { 633 //make sure it's the correct one 634 if (!$(e.target).is(el)) { 635 return; 636 } 637 // unbind the callback 638 el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); 639 updateAfterSlideTransition(); 640 }); 641 } else { //duration = 0 642 updateAfterSlideTransition(); 643 } 644 } else if (type === 'reset') { 645 el.css(slider.animProp, propValue); 646 } else if (type === 'ticker') { 647 // make the transition use 'linear' 648 el.css('-' + slider.cssPrefix + '-transition-timing-function', 'linear'); 649 el.css(slider.animProp, propValue); 650 if (duration !== 0) { 651 el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function (e) { 652 //make sure it's the correct one 653 if (!$(e.target).is(el)) { 654 return; 655 } 656 // unbind the callback 657 el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); 658 // reset the position 659 setPositionProperty(params.resetValue, 'reset', 0); 660 // start the loop again 661 tickerLoop(); 662 }); 663 } else { //duration = 0 664 setPositionProperty(params.resetValue, 'reset', 0); 665 tickerLoop(); 666 } 667 } 668 // use JS animate 669 } else { 670 animateObj = {}; 671 animateObj[slider.animProp] = value; 672 if (type === 'slide') { 673 el.animate(animateObj, duration, slider.settings.easing, function () { 674 updateAfterSlideTransition(); 675 }); 676 } else if (type === 'reset') { 677 el.css(slider.animProp, value); 678 } else if (type === 'ticker') { 679 el.animate(animateObj, duration, 'linear', function () { 680 setPositionProperty(params.resetValue, 'reset', 0); 681 // run the recursive loop after animation 682 tickerLoop(); 683 }); 684 } 685 } 686 }; 687 688 /** 689 * Populates the pager with proper amount of pages 690 */ 691 var populatePager = function () { 692 var pagerHtml = '', 693 linkContent = '', 694 pagerQty = getPagerQty(); 695 // loop through each pager item 696 for (var i = 0; i < pagerQty; i++) { 697 linkContent = ''; 698 // if a buildPager function is supplied, use it to get pager link value, else use index + 1 699 if (slider.settings.buildPager && $.isFunction(slider.settings.buildPager) || slider.settings.pagerCustom) { 700 linkContent = slider.settings.buildPager(i); 701 slider.pagerEl.addClass('bx-custom-pager'); 702 } else { 703 linkContent = i + 1; 704 slider.pagerEl.addClass('bx-default-pager'); 705 } 706 // var linkContent = slider.settings.buildPager && $.isFunction(slider.settings.buildPager) ? slider.settings.buildPager(i) : i + 1; 707 // add the markup to the string 708 pagerHtml += '<div class="bx-pager-item"><a href="" data-slide-index="' + i + '" class="bx-pager-link">' + linkContent + '</a></div>'; 709 } 710 // populate the pager element with pager links 711 slider.pagerEl.html(pagerHtml); 712 }; 713 714 /** 715 * Appends the pager to the controls element 716 */ 717 var appendPager = function () { 718 if (!slider.settings.pagerCustom) { 719 // create the pager DOM element 720 slider.pagerEl = $('<div class="bx-pager" />'); 721 // if a pager selector was supplied, populate it with the pager 722 if (slider.settings.pagerSelector) { 723 $(slider.settings.pagerSelector).html(slider.pagerEl); 724 // if no pager selector was supplied, add it after the wrapper 725 } else { 726 slider.controls.el.addClass('bx-has-pager').append(slider.pagerEl); 727 } 728 // populate the pager 729 populatePager(); 730 } else { 731 slider.pagerEl = $(slider.settings.pagerCustom); 732 } 733 // assign the pager click binding 734 slider.pagerEl.on('click touchend', 'a', clickPagerBind); 735 }; 736 737 /** 738 * Appends prev / next controls to the controls element 739 */ 740 var appendControls = function () { 741 slider.controls.next = $('<a class="bx-next" href="">' + slider.settings.nextText + '</a>'); 742 slider.controls.prev = $('<a class="bx-prev" href="">' + slider.settings.prevText + '</a>'); 743 // bind click actions to the controls 744 slider.controls.next.bind('click touchend', clickNextBind); 745 slider.controls.prev.bind('click touchend', clickPrevBind); 746 // if nextSelector was supplied, populate it 747 if (slider.settings.nextSelector) { 748 $(slider.settings.nextSelector).append(slider.controls.next); 749 } 750 // if prevSelector was supplied, populate it 751 if (slider.settings.prevSelector) { 752 $(slider.settings.prevSelector).append(slider.controls.prev); 753 } 754 // if no custom selectors were supplied 755 if (!slider.settings.nextSelector && !slider.settings.prevSelector) { 756 // add the controls to the DOM 757 slider.controls.directionEl = $('<div class="bx-controls-direction" />'); 758 // add the control elements to the directionEl 759 slider.controls.directionEl.append(slider.controls.prev).append(slider.controls.next); 760 // slider.viewport.append(slider.controls.directionEl); 761 slider.controls.el.addClass('bx-has-controls-direction').append(slider.controls.directionEl); 762 } 763 }; 764 765 /** 766 * Appends start / stop auto controls to the controls element 767 */ 768 var appendControlsAuto = function () { 769 slider.controls.start = $('<div class="bx-controls-auto-item"><a class="bx-start" href="">' + slider.settings.startText + '</a></div>'); 770 slider.controls.stop = $('<div class="bx-controls-auto-item"><a class="bx-stop" href="">' + slider.settings.stopText + '</a></div>'); 771 // add the controls to the DOM 772 slider.controls.autoEl = $('<div class="bx-controls-auto" />'); 773 // bind click actions to the controls 774 slider.controls.autoEl.on('click', '.bx-start', clickStartBind); 775 slider.controls.autoEl.on('click', '.bx-stop', clickStopBind); 776 // if autoControlsCombine, insert only the "start" control 777 if (slider.settings.autoControlsCombine) { 778 slider.controls.autoEl.append(slider.controls.start); 779 // if autoControlsCombine is false, insert both controls 780 } else { 781 slider.controls.autoEl.append(slider.controls.start).append(slider.controls.stop); 782 } 783 // if auto controls selector was supplied, populate it with the controls 784 if (slider.settings.autoControlsSelector) { 785 $(slider.settings.autoControlsSelector).html(slider.controls.autoEl); 786 // if auto controls selector was not supplied, add it after the wrapper 787 } else { 788 slider.controls.el.addClass('bx-has-controls-auto').append(slider.controls.autoEl); 789 } 790 // update the auto controls 791 updateAutoControls(slider.settings.autoStart ? 'stop' : 'start'); 792 }; 793 794 /** 795 * Appends image captions to the DOM 796 */ 797 var appendCaptions = function () { 798 // cycle through each child 799 slider.children.each(function (index) { 800 // get the image title attribute 801 var title = $(this).find('img:first').attr('title'); 802 // append the caption 803 if (title !== undefined && ('' + title).length) { 804 $(this).append('<div class="bx-caption"><span>' + title + '</span></div>'); 805 } 806 }); 807 }; 808 809 /** 810 * Click next binding 811 * 812 * @param e (event) 813 * - DOM event object 814 */ 815 var clickNextBind = function (e) { 816 e.preventDefault(); 817 if (slider.controls.el.hasClass('disabled')) { 818 return; 819 } 820 // if auto show is running, stop it 821 if (slider.settings.auto && slider.settings.stopAutoOnClick) { 822 el.stopAuto(); 823 } 824 el.goToNextSlide(); 825 }; 826 827 /** 828 * Click prev binding 829 * 830 * @param e (event) 831 * - DOM event object 832 */ 833 var clickPrevBind = function (e) { 834 e.preventDefault(); 835 if (slider.controls.el.hasClass('disabled')) { 836 return; 837 } 838 // if auto show is running, stop it 839 if (slider.settings.auto && slider.settings.stopAutoOnClick) { 840 el.stopAuto(); 841 } 842 el.goToPrevSlide(); 843 }; 844 845 /** 846 * Click start binding 847 * 848 * @param e (event) 849 * - DOM event object 850 */ 851 var clickStartBind = function (e) { 852 el.startAuto(); 853 e.preventDefault(); 854 }; 855 856 /** 857 * Click stop binding 858 * 859 * @param e (event) 860 * - DOM event object 861 */ 862 var clickStopBind = function (e) { 863 el.stopAuto(); 864 e.preventDefault(); 865 }; 866 867 /** 868 * Click pager binding 869 * 870 * @param e (event) 871 * - DOM event object 872 */ 873 var clickPagerBind = function (e) { 874 var pagerLink, pagerIndex; 875 e.preventDefault(); 876 if (slider.controls.el.hasClass('disabled')) { 877 return; 878 } 879 // if auto show is running, stop it 880 if (slider.settings.auto && slider.settings.stopAutoOnClick) { 881 el.stopAuto(); 882 } 883 pagerLink = $(e.currentTarget); 884 if (pagerLink.attr('data-slide-index') !== undefined) { 885 pagerIndex = parseInt(pagerLink.attr('data-slide-index')); 886 // if clicked pager link is not active, continue with the goToSlide call 887 if (pagerIndex !== slider.active.index) { 888 el.goToSlide(pagerIndex); 889 } 890 } 891 }; 892 893 /** 894 * Updates the pager links with an active class 895 * 896 * @param slideIndex (int) 897 * - index of slide to make active 898 */ 899 var updatePagerActive = function (slideIndex) { 900 // if "short" pager type 901 var len = slider.children.length; // nb of children 902 if (slider.settings.pagerType === 'short') { 903 if (slider.settings.maxSlides > 1) { 904 len = Math.ceil(slider.children.length / slider.settings.maxSlides); 905 } 906 slider.pagerEl.html((slideIndex + 1) + slider.settings.pagerShortSeparator + len); 907 return; 908 } 909 // remove all pager active classes 910 slider.pagerEl.find('a').removeClass('active'); 911 // apply the active class for all pagers 912 slider.pagerEl.each(function (i, el) { 913 $(el).find('a').eq(slideIndex).addClass('active'); 914 }); 915 }; 916 917 /** 918 * Performs needed actions after a slide transition 919 */ 920 var updateAfterSlideTransition = function () { 921 // if infinite loop is true 922 if (slider.settings.infiniteLoop) { 923 var position = ''; 924 // first slide 925 if (slider.active.index === 0) { 926 // set the new position 927 position = slider.children.eq(0).position(); 928 // carousel, last slide 929 } else if (slider.active.index === getPagerQty() - 1 && slider.carousel) { 930 position = slider.children.eq((getPagerQty() - 1) * getMoveBy()).position(); 931 // last slide 932 } else if (slider.active.index === slider.children.length - 1) { 933 position = slider.children.eq(slider.children.length - 1).position(); 934 } 935 if (position) { 936 if (slider.settings.mode === 'horizontal') { 937 setPositionProperty(-position.left, 'reset', 0); 938 } 939 else if (slider.settings.mode === 'vertical') { 940 setPositionProperty(-position.top, 'reset', 0); 941 } 942 } 943 } 944 // declare that the transition is complete 945 slider.working = false; 946 // onSlideAfter callback 947 slider.settings.onSlideAfter.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 948 }; 949 950 /** 951 * Updates the auto controls state (either active, or combined switch) 952 * 953 * @param state (string) "start", "stop" 954 * - the new state of the auto show 955 */ 956 var updateAutoControls = function (state) { 957 // if autoControlsCombine is true, replace the current control with the new state 958 if (slider.settings.autoControlsCombine) { 959 slider.controls.autoEl.html(slider.controls[state]); 960 // if autoControlsCombine is false, apply the "active" class to the appropriate control 961 } else { 962 slider.controls.autoEl.find('a').removeClass('active'); 963 slider.controls.autoEl.find('a:not(.bx-' + state + ')').addClass('active'); 964 } 965 }; 966 967 /** 968 * Updates the direction controls (checks if either should be hidden) 969 */ 970 var updateDirectionControls = function () { 971 if (getPagerQty() === 1) { 972 slider.controls.prev.addClass('disabled'); 973 slider.controls.next.addClass('disabled'); 974 } else if (!slider.settings.infiniteLoop && slider.settings.hideControlOnEnd) { 975 // if first slide 976 if (slider.active.index === 0) { 977 slider.controls.prev.addClass('disabled'); 978 slider.controls.next.removeClass('disabled'); 979 // if last slide 980 } else if (slider.active.index === getPagerQty() - 1) { 981 slider.controls.next.addClass('disabled'); 982 slider.controls.prev.removeClass('disabled'); 983 // if any slide in the middle 984 } else { 985 slider.controls.prev.removeClass('disabled'); 986 slider.controls.next.removeClass('disabled'); 987 } 988 } 989 }; 990 991 /** 992 * Initializes the auto process 993 */ 994 var initAuto = function () { 995 // if autoDelay was supplied, launch the auto show using a setTimeout() call 996 if (slider.settings.autoDelay > 0) { 997 var timeout = setTimeout(el.startAuto, slider.settings.autoDelay); 998 // if autoDelay was not supplied, start the auto show normally 999 } else { 1000 el.startAuto(); 1001 1002 //add focus and blur events to ensure its running if timeout gets paused 1003 $(window).focus(function () { 1004 el.startAuto(); 1005 }).blur(function () { 1006 el.stopAuto(); 1007 }); 1008 } 1009 // if autoHover is requested 1010 if (slider.settings.autoHover) { 1011 // on el hover 1012 el.hover(function () { 1013 // if the auto show is currently playing (has an active interval) 1014 if (slider.interval) { 1015 // stop the auto show and pass true argument which will prevent control update 1016 el.stopAuto(true); 1017 // create a new autoPaused value which will be used by the relative "mouseout" event 1018 slider.autoPaused = true; 1019 } 1020 }, function () { 1021 // if the autoPaused value was created be the prior "mouseover" event 1022 if (slider.autoPaused) { 1023 // start the auto show and pass true argument which will prevent control update 1024 el.startAuto(true); 1025 // reset the autoPaused value 1026 slider.autoPaused = null; 1027 } 1028 }); 1029 } 1030 }; 1031 1032 /** 1033 * Initializes the ticker process 1034 */ 1035 var initTicker = function () { 1036 var startPosition = 0, 1037 position, transform, value, idx, ratio, property, newSpeed, totalDimens; 1038 // if autoDirection is "next", append a clone of the entire slider 1039 if (slider.settings.autoDirection === 'next') { 1040 el.append(slider.children.clone().addClass('bx-clone')); 1041 // if autoDirection is "prev", prepend a clone of the entire slider, and set the left position 1042 } else { 1043 el.prepend(slider.children.clone().addClass('bx-clone')); 1044 position = slider.children.first().position(); 1045 startPosition = slider.settings.mode === 'horizontal' ? -position.left : -position.top; 1046 } 1047 setPositionProperty(startPosition, 'reset', 0); 1048 // do not allow controls in ticker mode 1049 slider.settings.pager = false; 1050 slider.settings.controls = false; 1051 slider.settings.autoControls = false; 1052 // if autoHover is requested 1053 if (slider.settings.tickerHover) { 1054 if (slider.usingCSS) { 1055 idx = slider.settings.mode === 'horizontal' ? 4 : 5; 1056 slider.viewport.hover(function () { 1057 transform = el.css('-' + slider.cssPrefix + '-transform'); 1058 value = parseFloat(transform.split(',')[idx]); 1059 setPositionProperty(value, 'reset', 0); 1060 }, function () { 1061 totalDimens = 0; 1062 slider.children.each(function (index) { 1063 totalDimens += slider.settings.mode === 'horizontal' ? $(this).outerWidth(true) : $(this).outerHeight(true); 1064 }); 1065 // calculate the speed ratio (used to determine the new speed to finish the paused animation) 1066 ratio = slider.settings.speed / totalDimens; 1067 // determine which property to use 1068 property = slider.settings.mode === 'horizontal' ? 'left' : 'top'; 1069 // calculate the new speed 1070 newSpeed = ratio * (totalDimens - (Math.abs(parseInt(value)))); 1071 tickerLoop(newSpeed); 1072 }); 1073 } else { 1074 // on el hover 1075 slider.viewport.hover(function () { 1076 el.stop(); 1077 }, function () { 1078 // calculate the total width of children (used to calculate the speed ratio) 1079 totalDimens = 0; 1080 slider.children.each(function (index) { 1081 totalDimens += slider.settings.mode === 'horizontal' ? $(this).outerWidth(true) : $(this).outerHeight(true); 1082 }); 1083 // calculate the speed ratio (used to determine the new speed to finish the paused animation) 1084 ratio = slider.settings.speed / totalDimens; 1085 // determine which property to use 1086 property = slider.settings.mode === 'horizontal' ? 'left' : 'top'; 1087 // calculate the new speed 1088 newSpeed = ratio * (totalDimens - (Math.abs(parseInt(el.css(property))))); 1089 tickerLoop(newSpeed); 1090 }); 1091 } 1092 } 1093 // start the ticker loop 1094 tickerLoop(); 1095 }; 1096 1097 /** 1098 * Runs a continuous loop, news ticker-style 1099 */ 1100 var tickerLoop = function (resumeSpeed) { 1101 var speed = resumeSpeed ? resumeSpeed : slider.settings.speed, 1102 position = {left: 0, top: 0}, 1103 reset = {left: 0, top: 0}, 1104 animateProperty, resetValue, params; 1105 1106 // if "next" animate left position to last child, then reset left to 0 1107 if (slider.settings.autoDirection === 'next') { 1108 position = el.find('.bx-clone').first().position(); 1109 // if "prev" animate left position to 0, then reset left to first non-clone child 1110 } else { 1111 reset = slider.children.first().position(); 1112 } 1113 animateProperty = slider.settings.mode === 'horizontal' ? -position.left : -position.top; 1114 resetValue = slider.settings.mode === 'horizontal' ? -reset.left : -reset.top; 1115 params = {resetValue: resetValue}; 1116 setPositionProperty(animateProperty, 'ticker', speed, params); 1117 }; 1118 1119 /** 1120 * Check if el is on screen 1121 */ 1122 var isOnScreen = function (el) { 1123 var win = $(window), 1124 viewport = { 1125 top: win.scrollTop(), 1126 left: win.scrollLeft() 1127 }, 1128 bounds = el.offset(); 1129 1130 viewport.right = viewport.left + win.width(); 1131 viewport.bottom = viewport.top + win.height(); 1132 bounds.right = bounds.left + el.outerWidth(); 1133 bounds.bottom = bounds.top + el.outerHeight(); 1134 1135 return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); 1136 }; 1137 1138 /** 1139 * Initializes keyboard events 1140 */ 1141 var keyPress = function (e) { 1142 var activeElementTag = document.activeElement.tagName.toLowerCase(), 1143 tagFilters = 'input|textarea', 1144 p = new RegExp(activeElementTag, ['i']), 1145 result = p.exec(tagFilters); 1146 1147 if (result == null && isOnScreen(el)) { 1148 if (e.keyCode === 39) { 1149 clickNextBind(e); 1150 return false; 1151 } else if (e.keyCode === 37) { 1152 clickPrevBind(e); 1153 return false; 1154 } 1155 } 1156 }; 1157 1158 /** 1159 * Initializes touch events 1160 */ 1161 var initTouch = function () { 1162 // initialize object to contain all touch values 1163 slider.touch = { 1164 start: {x: 0, y: 0}, 1165 end: {x: 0, y: 0} 1166 }; 1167 slider.viewport.bind('touchstart MSPointerDown pointerdown', onTouchStart); 1168 1169 //for browsers that have implemented pointer events and fire a click after 1170 //every pointerup regardless of whether pointerup is on same screen location as pointerdown or not 1171 slider.viewport.on('click', '.bxslider a', function (e) { 1172 if (slider.viewport.hasClass('click-disabled')) { 1173 e.preventDefault(); 1174 slider.viewport.removeClass('click-disabled'); 1175 } 1176 }); 1177 }; 1178 1179 /** 1180 * Event handler for "touchstart" 1181 * 1182 * @param e (event) 1183 * - DOM event object 1184 */ 1185 var onTouchStart = function (e) { 1186 //disable slider controls while user is interacting with slides to avoid slider freeze that happens on touch devices when a slide swipe happens immediately after interacting with slider controls 1187 slider.controls.el.addClass('disabled'); 1188 1189 if (slider.working) { 1190 e.preventDefault(); 1191 slider.controls.el.removeClass('disabled'); 1192 } else { 1193 // record the original position when touch starts 1194 slider.touch.originalPos = el.position(); 1195 var orig = e.originalEvent, 1196 touchPoints = (typeof orig.changedTouches !== 'undefined') ? orig.changedTouches : [orig]; 1197 // record the starting touch x, y coordinates 1198 slider.touch.start.x = touchPoints[0].pageX; 1199 slider.touch.start.y = touchPoints[0].pageY; 1200 1201 if (slider.viewport.get(0).setPointerCapture) { 1202 slider.pointerId = orig.pointerId; 1203 slider.viewport.get(0).setPointerCapture(slider.pointerId); 1204 } 1205 // bind a "touchmove" event to the viewport 1206 slider.viewport.bind('touchmove MSPointerMove pointermove', onTouchMove); 1207 // bind a "touchend" event to the viewport 1208 slider.viewport.bind('touchend MSPointerUp pointerup', onTouchEnd); 1209 slider.viewport.bind('MSPointerCancel pointercancel', onPointerCancel); 1210 } 1211 }; 1212 1213 /** 1214 * Cancel Pointer for Windows Phone 1215 * 1216 * @param e (event) 1217 * - DOM event object 1218 */ 1219 var onPointerCancel = function (e) { 1220 /* onPointerCancel handler is needed to deal with situations when a touchend 1221 doesn't fire after a touchstart (this happens on windows phones only) */ 1222 setPositionProperty(slider.touch.originalPos.left, 'reset', 0); 1223 1224 //remove handlers 1225 slider.controls.el.removeClass('disabled'); 1226 slider.viewport.unbind('MSPointerCancel pointercancel', onPointerCancel); 1227 slider.viewport.unbind('touchmove MSPointerMove pointermove', onTouchMove); 1228 slider.viewport.unbind('touchend MSPointerUp pointerup', onTouchEnd); 1229 if (slider.viewport.get(0).releasePointerCapture) { 1230 slider.viewport.get(0).releasePointerCapture(slider.pointerId); 1231 } 1232 }; 1233 1234 /** 1235 * Event handler for "touchmove" 1236 * 1237 * @param e (event) 1238 * - DOM event object 1239 */ 1240 var onTouchMove = function (e) { 1241 var orig = e.originalEvent, 1242 touchPoints = (typeof orig.changedTouches !== 'undefined') ? orig.changedTouches : [orig], 1243 // if scrolling on y axis, do not prevent default 1244 xMovement = Math.abs(touchPoints[0].pageX - slider.touch.start.x), 1245 yMovement = Math.abs(touchPoints[0].pageY - slider.touch.start.y), 1246 value = 0, 1247 change = 0; 1248 1249 // x axis swipe 1250 if ((xMovement * 3) > yMovement && slider.settings.preventDefaultSwipeX) { 1251 e.preventDefault(); 1252 // y axis swipe 1253 } else if ((yMovement * 3) > xMovement && slider.settings.preventDefaultSwipeY) { 1254 e.preventDefault(); 1255 } 1256 if (slider.settings.mode !== 'fade' && slider.settings.oneToOneTouch) { 1257 // if horizontal, drag along x axis 1258 if (slider.settings.mode === 'horizontal') { 1259 change = touchPoints[0].pageX - slider.touch.start.x; 1260 value = slider.touch.originalPos.left + change; 1261 // if vertical, drag along y axis 1262 } else { 1263 change = touchPoints[0].pageY - slider.touch.start.y; 1264 value = slider.touch.originalPos.top + change; 1265 } 1266 setPositionProperty(value, 'reset', 0); 1267 } 1268 }; 1269 1270 /** 1271 * Event handler for "touchend" 1272 * 1273 * @param e (event) 1274 * - DOM event object 1275 */ 1276 var onTouchEnd = function (e) { 1277 slider.viewport.unbind('touchmove MSPointerMove pointermove', onTouchMove); 1278 //enable slider controls as soon as user stops interacing with slides 1279 slider.controls.el.removeClass('disabled'); 1280 var orig = e.originalEvent, 1281 touchPoints = (typeof orig.changedTouches !== 'undefined') ? orig.changedTouches : [orig], 1282 value = 0, 1283 distance = 0; 1284 // record end x, y positions 1285 slider.touch.end.x = touchPoints[0].pageX; 1286 slider.touch.end.y = touchPoints[0].pageY; 1287 // if fade mode, check if absolute x distance clears the threshold 1288 if (slider.settings.mode === 'fade') { 1289 distance = Math.abs(slider.touch.start.x - slider.touch.end.x); 1290 if (distance >= slider.settings.swipeThreshold) { 1291 if (slider.touch.start.x > slider.touch.end.x) { 1292 el.goToNextSlide(); 1293 } else { 1294 el.goToPrevSlide(); 1295 } 1296 el.stopAuto(); 1297 } 1298 // not fade mode 1299 } else { 1300 // calculate distance and el's animate property 1301 if (slider.settings.mode === 'horizontal') { 1302 distance = slider.touch.end.x - slider.touch.start.x; 1303 value = slider.touch.originalPos.left; 1304 } else { 1305 distance = slider.touch.end.y - slider.touch.start.y; 1306 value = slider.touch.originalPos.top; 1307 } 1308 // if not infinite loop and first / last slide, do not attempt a slide transition 1309 if (!slider.settings.infiniteLoop && ((slider.active.index === 0 && distance > 0) || (slider.active.last && distance < 0))) { 1310 setPositionProperty(value, 'reset', 200); 1311 } else { 1312 // check if distance clears threshold 1313 if (Math.abs(distance) >= slider.settings.swipeThreshold) { 1314 if (distance < 0) { 1315 el.goToNextSlide(); 1316 } else { 1317 el.goToPrevSlide(); 1318 } 1319 el.stopAuto(); 1320 } else { 1321 // el.animate(property, 200); 1322 setPositionProperty(value, 'reset', 200); 1323 } 1324 } 1325 } 1326 slider.viewport.unbind('touchend MSPointerUp pointerup', onTouchEnd); 1327 if (slider.viewport.get(0).releasePointerCapture) { 1328 slider.viewport.get(0).releasePointerCapture(slider.pointerId); 1329 } 1330 }; 1331 1332 /** 1333 * Window resize event callback 1334 */ 1335 var resizeWindow = function (e) { 1336 // don't do anything if slider isn't initialized. 1337 if (!slider.initialized) { 1338 return; 1339 } 1340 // Delay if slider working. 1341 if (slider.working) { 1342 window.setTimeout(resizeWindow, 10); 1343 } else { 1344 // get the new window dimens (again, thank you IE) 1345 var windowWidthNew = $(window).width(), 1346 windowHeightNew = $(window).height(); 1347 // make sure that it is a true window resize 1348 // *we must check this because our dinosaur friend IE fires a window resize event when certain DOM elements 1349 // are resized. Can you just die already?* 1350 if (windowWidth !== windowWidthNew || windowHeight !== windowHeightNew) { 1351 // set the new window dimens 1352 windowWidth = windowWidthNew; 1353 windowHeight = windowHeightNew; 1354 // update all dynamic elements 1355 el.redrawSlider(); 1356 // Call user resize handler 1357 slider.settings.onSliderResize.call(el, slider.active.index); 1358 } 1359 } 1360 }; 1361 1362 /** 1363 * Adds an aria-hidden=true attribute to each element 1364 * 1365 * @param startVisibleIndex (int) 1366 * - the first visible element's index 1367 */ 1368 var applyAriaHiddenAttributes = function (startVisibleIndex) { 1369 var numberOfSlidesShowing = getNumberSlidesShowing(); 1370 // only apply attributes if the setting is enabled and not in ticker mode 1371 if (slider.settings.ariaHidden && !slider.settings.ticker) { 1372 // add aria-hidden=true to all elements 1373 slider.children.attr('aria-hidden', 'true'); 1374 // get the visible elements and change to aria-hidden=false 1375 slider.children.slice(startVisibleIndex, startVisibleIndex + numberOfSlidesShowing).attr('aria-hidden', 'false'); 1376 } 1377 }; 1378 1379 /** 1380 * Returns index according to present page range 1381 * 1382 * @param slideOndex (int) 1383 * - the desired slide index 1384 */ 1385 var setSlideIndex = function (slideIndex) { 1386 if (slideIndex < 0) { 1387 if (slider.settings.infiniteLoop) { 1388 return getPagerQty() - 1; 1389 } else { 1390 //we don't go to undefined slides 1391 return slider.active.index; 1392 } 1393 // if slideIndex is greater than children length, set active index to 0 (this happens during infinite loop) 1394 } else if (slideIndex >= getPagerQty()) { 1395 if (slider.settings.infiniteLoop) { 1396 return 0; 1397 } else { 1398 //we don't move to undefined pages 1399 return slider.active.index; 1400 } 1401 // set active index to requested slide 1402 } else { 1403 return slideIndex; 1404 } 1405 }; 1406 1407 /** 1408 * =================================================================================== 1409 * = PUBLIC FUNCTIONS 1410 * =================================================================================== 1411 */ 1412 1413 /** 1414 * Performs slide transition to the specified slide 1415 * 1416 * @param slideIndex (int) 1417 * - the destination slide's index (zero-based) 1418 * 1419 * @param direction (string) 1420 * - INTERNAL USE ONLY - the direction of travel ("prev" / "next") 1421 */ 1422 el.goToSlide = function (slideIndex, direction) { 1423 // onSlideBefore, onSlideNext, onSlidePrev callbacks 1424 // Allow transition canceling based on returned value 1425 var performTransition = true, 1426 moveBy = 0, 1427 position = {left: 0, top: 0}, 1428 lastChild = null, 1429 lastShowingIndex, eq, value, requestEl; 1430 // store the old index 1431 slider.oldIndex = slider.active.index; 1432 //set new index 1433 slider.active.index = setSlideIndex(slideIndex); 1434 1435 // if plugin is currently in motion, ignore request 1436 if (slider.working || slider.active.index === slider.oldIndex) { 1437 return; 1438 } 1439 // declare that plugin is in motion 1440 slider.working = true; 1441 1442 performTransition = slider.settings.onSlideBefore.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 1443 1444 // If transitions canceled, reset and return 1445 if (typeof (performTransition) !== 'undefined' && !performTransition) { 1446 slider.active.index = slider.oldIndex; // restore old index 1447 slider.working = false; // is not in motion 1448 return; 1449 } 1450 1451 if (direction === 'next') { 1452 // Prevent canceling in future functions or lack there-of from negating previous commands to cancel 1453 if (!slider.settings.onSlideNext.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index)) { 1454 performTransition = false; 1455 } 1456 } else if (direction === 'prev') { 1457 // Prevent canceling in future functions or lack there-of from negating previous commands to cancel 1458 if (!slider.settings.onSlidePrev.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index)) { 1459 performTransition = false; 1460 } 1461 } 1462 1463 // check if last slide 1464 slider.active.last = slider.active.index >= getPagerQty() - 1; 1465 // update the pager with active class 1466 if (slider.settings.pager || slider.settings.pagerCustom) { 1467 updatePagerActive(slider.active.index); 1468 } 1469 // // check for direction control update 1470 if (slider.settings.controls) { 1471 updateDirectionControls(); 1472 } 1473 // if slider is set to mode: "fade" 1474 if (slider.settings.mode === 'fade') { 1475 // if adaptiveHeight is true and next height is different from current height, animate to the new height 1476 if (slider.settings.adaptiveHeight && slider.viewport.height() !== getViewportHeight()) { 1477 slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); 1478 } 1479 // fade out the visible child and reset its z-index value 1480 slider.children.filter(':visible').fadeOut(slider.settings.speed).css({zIndex: 0}); 1481 // fade in the newly requested slide 1482 slider.children.eq(slider.active.index).css('zIndex', slider.settings.slideZIndex + 1).fadeIn(slider.settings.speed, function () { 1483 $(this).css('zIndex', slider.settings.slideZIndex); 1484 updateAfterSlideTransition(); 1485 }); 1486 // slider mode is not "fade" 1487 } else { 1488 // if adaptiveHeight is true and next height is different from current height, animate to the new height 1489 if (slider.settings.adaptiveHeight && slider.viewport.height() !== getViewportHeight()) { 1490 slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); 1491 } 1492 // if carousel and not infinite loop 1493 if (!slider.settings.infiniteLoop && slider.carousel && slider.active.last) { 1494 if (slider.settings.mode === 'horizontal') { 1495 // get the last child position 1496 lastChild = slider.children.eq(slider.children.length - 1); 1497 position = lastChild.position(); 1498 // calculate the position of the last slide 1499 moveBy = slider.viewport.width() - lastChild.outerWidth(); 1500 } else { 1501 // get last showing index position 1502 lastShowingIndex = slider.children.length - slider.settings.minSlides; 1503 position = slider.children.eq(lastShowingIndex).position(); 1504 } 1505 // horizontal carousel, going previous while on first slide (infiniteLoop mode) 1506 } else if (slider.carousel && slider.active.last && direction === 'prev') { 1507 // get the last child position 1508 eq = slider.settings.moveSlides === 1 ? slider.settings.maxSlides - getMoveBy() : ((getPagerQty() - 1) * getMoveBy()) - (slider.children.length - slider.settings.maxSlides); 1509 lastChild = el.children('.bx-clone').eq(eq); 1510 position = lastChild.position(); 1511 // if infinite loop and "Next" is clicked on the last slide 1512 } else if (direction === 'next' && slider.active.index === 0) { 1513 // get the last clone position 1514 position = el.find('> .bx-clone').eq(slider.settings.maxSlides).position(); 1515 slider.active.last = false; 1516 // normal non-zero requests 1517 } else if (slideIndex >= 0) { 1518 //parseInt is applied to allow floats for slides/page 1519 requestEl = slideIndex * parseInt(getMoveBy()); 1520 position = slider.children.eq(requestEl).position(); 1521 } 1522 1523 /* If the position doesn't exist 1524 * (e.g. if you destroy the slider on a next click), 1525 * it doesn't throw an error. 1526 */ 1527 if (typeof (position) !== 'undefined') { 1528 value = slider.settings.mode === 'horizontal' ? -(position.left - moveBy) : -position.top; 1529 // plugin values to be animated 1530 setPositionProperty(value, 'slide', slider.settings.speed); 1531 } else { 1532 slider.working = false; 1533 } 1534 } 1535 if (slider.settings.ariaHidden) { 1536 applyAriaHiddenAttributes(slider.active.index * getMoveBy()); 1537 } 1538 }; 1539 1540 /** 1541 * Transitions to the next slide in the show 1542 */ 1543 el.goToNextSlide = function () { 1544 // if infiniteLoop is false and last page is showing, disregard call 1545 if (!slider.settings.infiniteLoop && slider.active.last) { 1546 return; 1547 } 1548 var pagerIndex = parseInt(slider.active.index) + 1; 1549 el.goToSlide(pagerIndex, 'next'); 1550 }; 1551 1552 /** 1553 * Transitions to the prev slide in the show 1554 */ 1555 el.goToPrevSlide = function () { 1556 // if infiniteLoop is false and last page is showing, disregard call 1557 if (!slider.settings.infiniteLoop && slider.active.index === 0) { 1558 return; 1559 } 1560 var pagerIndex = parseInt(slider.active.index) - 1; 1561 el.goToSlide(pagerIndex, 'prev'); 1562 }; 1563 1564 /** 1565 * Starts the auto show 1566 * 1567 * @param preventControlUpdate (boolean) 1568 * - if true, auto controls state will not be updated 1569 */ 1570 el.startAuto = function (preventControlUpdate) { 1571 // if an interval already exists, disregard call 1572 if (slider.interval) { 1573 return; 1574 } 1575 // create an interval 1576 slider.interval = setInterval(function () { 1577 if (slider.settings.autoDirection === 'next') { 1578 el.goToNextSlide(); 1579 } else { 1580 el.goToPrevSlide(); 1581 } 1582 }, slider.settings.pause); 1583 // if auto controls are displayed and preventControlUpdate is not true 1584 if (slider.settings.autoControls && preventControlUpdate !== true) { 1585 updateAutoControls('stop'); 1586 } 1587 }; 1588 1589 /** 1590 * Stops the auto show 1591 * 1592 * @param preventControlUpdate (boolean) 1593 * - if true, auto controls state will not be updated 1594 */ 1595 el.stopAuto = function (preventControlUpdate) { 1596 // if no interval exists, disregard call 1597 if (!slider.interval) { 1598 return; 1599 } 1600 // clear the interval 1601 clearInterval(slider.interval); 1602 slider.interval = null; 1603 // if auto controls are displayed and preventControlUpdate is not true 1604 if (slider.settings.autoControls && preventControlUpdate !== true) { 1605 updateAutoControls('start'); 1606 } 1607 }; 1608 1609 /** 1610 * Returns current slide index (zero-based) 1611 */ 1612 el.getCurrentSlide = function () { 1613 return slider.active.index; 1614 }; 1615 1616 /** 1617 * Returns current slide element 1618 */ 1619 el.getCurrentSlideElement = function () { 1620 return slider.children.eq(slider.active.index); 1621 }; 1622 1623 /** 1624 * Returns a slide element 1625 * @param index (int) 1626 * - The index (zero-based) of the element you want returned. 1627 */ 1628 el.getSlideElement = function (index) { 1629 return slider.children.eq(index); 1630 }; 1631 1632 /** 1633 * Returns number of slides in show 1634 */ 1635 el.getSlideCount = function () { 1636 return slider.children.length; 1637 }; 1638 1639 /** 1640 * Return slider.working variable 1641 */ 1642 el.isWorking = function () { 1643 return slider.working; 1644 }; 1645 1646 /** 1647 * Update all dynamic slider elements 1648 */ 1649 el.redrawSlider = function () { 1650 // resize all children in ratio to new screen size 1651 slider.children.add(el.find('.bx-clone')).outerWidth(getSlideWidth()); 1652 // adjust the height 1653 slider.viewport.css('height', getViewportHeight()); 1654 // update the slide position 1655 if (!slider.settings.ticker) { 1656 setSlidePosition(); 1657 } 1658 // if active.last was true before the screen resize, we want 1659 // to keep it last no matter what screen size we end on 1660 if (slider.active.last) { 1661 slider.active.index = getPagerQty() - 1; 1662 } 1663 // if the active index (page) no longer exists due to the resize, simply set the index as last 1664 if (slider.active.index >= getPagerQty()) { 1665 slider.active.last = true; 1666 } 1667 // if a pager is being displayed and a custom pager is not being used, update it 1668 if (slider.settings.pager && !slider.settings.pagerCustom) { 1669 populatePager(); 1670 updatePagerActive(slider.active.index); 1671 } 1672 if (slider.settings.ariaHidden) { 1673 applyAriaHiddenAttributes(slider.active.index * getMoveBy()); 1674 } 1675 }; 1676 1677 /** 1678 * Destroy the current instance of the slider (revert everything back to original state) 1679 */ 1680 el.destroySlider = function () { 1681 // don't do anything if slider has already been destroyed 1682 if (!slider.initialized) { 1683 return; 1684 } 1685 slider.initialized = false; 1686 $('.bx-clone', this).remove(); 1687 slider.children.each(function () { 1688 if ($(this).data('origStyle') !== undefined) { 1689 $(this).attr('style', $(this).data('origStyle')); 1690 } else { 1691 $(this).removeAttr('style'); 1692 } 1693 }); 1694 if ($(this).data('origStyle') !== undefined) { 1695 this.attr('style', $(this).data('origStyle')); 1696 } else { 1697 $(this).removeAttr('style'); 1698 } 1699 $(this).unwrap().unwrap(); 1700 if (slider.controls.el) { 1701 slider.controls.el.remove(); 1702 } 1703 if (slider.controls.next) { 1704 slider.controls.next.remove(); 1705 } 1706 if (slider.controls.prev) { 1707 slider.controls.prev.remove(); 1708 } 1709 if (slider.pagerEl && slider.settings.controls && !slider.settings.pagerCustom) { 1710 slider.pagerEl.remove(); 1711 } 1712 $('.bx-caption', this).remove(); 1713 if (slider.controls.autoEl) { 1714 slider.controls.autoEl.remove(); 1715 } 1716 clearInterval(slider.interval); 1717 if (slider.settings.responsive) { 1718 $(window).unbind('resize', resizeWindow); 1719 } 1720 if (slider.settings.keyboardEnabled) { 1721 $(document).unbind('keydown', keyPress); 1722 } 1723 //remove self reference in data 1724 $(this).removeData('bxSlider'); 1725 }; 1726 1727 /** 1728 * Reload the slider (revert all DOM changes, and re-initialize) 1729 */ 1730 el.reloadSlider = function (settings) { 1731 if (settings !== undefined) { 1732 options = settings; 1733 } 1734 el.destroySlider(); 1735 init(); 1736 //store reference to self in order to access public functions later 1737 $(el).data('bxSlider', this); 1738 }; 1739 1740 init(); 1741 1742 $(el).data('bxSlider', this); 1743 1744 // returns the current jQuery object 1745 return this; 1746 }; 1747 1748})(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.