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