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