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