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