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