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