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