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: 0, 25 startSlide: 0, 26 randomStart: false, 27 captions: false, 28 ticker: false, 29 tickerHover: false, 30 adaptiveHeight: false, 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: false, 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 // add a loading div to display while images are loading 190 slider.loader = $('<div class="bx-loading" />'); 191 slider.viewport.prepend(slider.loader); 192 // set el to a massive width, to hold any needed slides 193 // also strip any margin and padding from el 194 el.css({ 195 width: slider.settings.mode == 'horizontal' ? (slider.children.length * 100 + 215) + '%' : 'auto', 196 position: 'relative' 197 }); 198 // if using CSS, add the easing property 199 if(slider.usingCSS && slider.settings.easing){ 200 el.css('-' + slider.cssPrefix + '-transition-timing-function', slider.settings.easing); 201 // if not using CSS and no easing value was supplied, use the default JS animation easing (swing) 202 }else if(!slider.settings.easing){ 203 slider.settings.easing = 'swing'; 204 } 205 var slidesShowing = getNumberSlidesShowing(); 206 // make modifications to the viewport (.bx-viewport) 207 slider.viewport.css({ 208 width: '100%', 209 overflow: 'hidden', 210 position: 'relative', 211 height: '320px' 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 var propValue = slider.settings.mode == 'vertical' ? 'translate3d(0, ' + value + 'px, 0)' : 'translate3d(' + value + 'px, 0, 0)'; 541 // add the CSS transition-duration 542 el.css('-' + slider.cssPrefix + '-transition-duration', duration / 1000 + 's'); 543 if(type == 'slide'){ 544 // set the property value 545 el.css(slider.animProp, propValue); 546 // bind a callback method - executes when CSS transition completes 547 el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){ 548 // unbind the callback 549 el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); 550 updateAfterSlideTransition(); 551 }); 552 }else if(type == 'reset'){ 553 el.css(slider.animProp, propValue); 554 }else if(type == 'ticker'){ 555 // make the transition use 'linear' 556 el.css('-' + slider.cssPrefix + '-transition-timing-function', 'linear'); 557 el.css(slider.animProp, propValue); 558 // bind a callback method - executes when CSS transition completes 559 el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){ 560 // unbind the callback 561 el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); 562 // reset the position 563 setPositionProperty(params['resetValue'], 'reset', 0); 564 // start the loop again 565 tickerLoop(); 566 }); 567 } 568 // use JS animate 569 }else{ 570 var animateObj = {}; 571 animateObj[slider.animProp] = value; 572 if(type == 'slide'){ 573 el.animate(animateObj, duration, slider.settings.easing, function(){ 574 updateAfterSlideTransition(); 575 }); 576 }else if(type == 'reset'){ 577 el.css(slider.animProp, value) 578 }else if(type == 'ticker'){ 579 el.animate(animateObj, speed, 'linear', function(){ 580 setPositionProperty(params['resetValue'], 'reset', 0); 581 // run the recursive loop after animation 582 tickerLoop(); 583 }); 584 } 585 } 586 } 587 588 /** 589 * Populates the pager with proper amount of pages 590 */ 591 var populatePager = function(){ 592 var pagerHtml = ''; 593 var pagerQty = getPagerQty(); 594 // loop through each pager item 595 for(var i=0; i < pagerQty; i++){ 596 var linkContent = ''; 597 // if a buildPager function is supplied, use it to get pager link value, else use index + 1 598 if(slider.settings.buildPager && $.isFunction(slider.settings.buildPager)){ 599 linkContent = slider.settings.buildPager(i); 600 slider.pagerEl.addClass('bx-custom-pager'); 601 }else{ 602 linkContent = i + 1; 603 slider.pagerEl.addClass('bx-default-pager'); 604 } 605 // var linkContent = slider.settings.buildPager && $.isFunction(slider.settings.buildPager) ? slider.settings.buildPager(i) : i + 1; 606 // add the markup to the string 607 pagerHtml += '<div class="bx-pager-item">
vendor: 3,844 bytes, lines 607-691
607<a href="" data-slide-index="' + i + '" class="bx-pager-link">' + linkContent + '</a></div>'; 608 }; 609 // populate the pager element with pager links 610 slider.pagerEl.html(pagerHtml); 611 } 612 613 /** 614 * Appends the pager to the controls element 615 */ 616 var appendPager = function(){ 617 if(!slider.settings.pagerCustom){ 618 // create the pager DOM element 619 slider.pagerEl = $('<div class="bx-pager" />'); 620 // if a pager selector was supplied, populate it with the pager 621 if(slider.settings.pagerSelector){ 622 $(slider.settings.pagerSelector).html(slider.pagerEl); 623 // if no pager selector was supplied, add it after the wrapper 624 }else{ 625 slider.controls.el.addClass('bx-has-pager').append(slider.pagerEl); 626 } 627 // populate the pager 628 populatePager(); 629 }else{ 630 slider.pagerEl = $(slider.settings.pagerCustom); 631 } 632 // assign the pager click binding 633 slider.pagerEl.on('click', 'a', clickPagerBind); 634 } 635 636 /** 637 * Appends prev / next controls to the controls element 638 */ 639 var appendControls = function(){ 640//// slider.controls.next = $('<a class="bx-next" href="">' + slider.settings.nextText + '</a>'); 641//// slider.controls.prev = $('<a class="bx-prev" href="">' + slider.settings.prevText + '</a>'); 642 slider.controls.next = $('<a class="bx-next" href=""><i class="fa fa-chevron-right"></i></a>'); 643 slider.controls.prev = $('<a class="bx-prev" href=""><i class="fa fa-chevron-left"></i></a>'); 644 // bind click actions to the controls 645 slider.controls.next.bind('click', clickNextBind); 646 slider.controls.prev.bind('click', clickPrevBind); 647 // if nextSlector was supplied, populate it 648 if(slider.settings.nextSelector){ 649 $(slider.settings.nextSelector).append(slider.controls.next); 650 } 651 // if prevSlector was supplied, populate it 652 if(slider.settings.prevSelector){ 653 $(slider.settings.prevSelector).append(slider.controls.prev); 654 } 655 // if no custom selectors were supplied 656 if(!slider.settings.nextSelector && !slider.settings.prevSelector){ 657 // add the controls to the DOM 658 slider.controls.directionEl = $('<div class="bx-controls-direction" />'); 659 // add the control elements to the directionEl 660 slider.controls.directionEl.append(slider.controls.prev).append(slider.controls.next); 661 // slider.viewport.append(slider.controls.directionEl); 662 slider.controls.el.addClass('bx-has-controls-direction').append(slider.controls.directionEl); 663 } 664 } 665 666 /** 667 * Appends start / stop auto controls to the controls element 668 */ 669 var appendControlsAuto = function(){ 670 slider.controls.start = $('<div class="bx-controls-auto-item"><a class="bx-start" href="">' + slider.settings.startText + '</a></div>'); 671 slider.controls.stop = $('<div class="bx-controls-auto-item"><a class="bx-stop" href="">' + slider.settings.stopText + '</a></div>'); 672 // add the controls to the DOM 673 slider.controls.autoEl = $('<div class="bx-controls-auto" />'); 674 // bind click actions to the controls 675 slider.controls.autoEl.on('click', '.bx-start', clickStartBind); 676 slider.controls.autoEl.on('click', '.bx-stop', clickStopBind); 677 // if autoControlsCombine, insert only the "start" control 678 if(slider.settings.autoControlsCombine){ 679 slider.controls.autoEl.append(slider.controls.start); 680 // if autoControlsCombine is false, insert both controls 681 }else{ 682 slider.controls.autoEl.append(slider.controls.start).append(slider.controls.stop); 683 } 684 // if auto controls selector was supplied, populate it with the controls 685 if(slider.settings.autoControlsSelector){ 686 $(slider.settings.autoControlsSelector).html(slider.controls.autoEl); 687 // if auto controls selector was not supplied, add it after the wrapper 688 }else{ 689 slider.controls.el.addClass('bx-has-controls-auto').append(slider.controls.autoEl); 690 } 691 // update the auto controls
692 updateAutoControls(slider.settings.autoStart ? 'stop' : 'start'); 693 } 694 695 /** 696 * Appends image captions to the DOM 697 */ 698 var appendCaptions = function(){ 699 // cycle through each child 700 slider.children.each(function(index){ 701 // get the image title attribute 702 var title = $(this).find('img:first').attr('title'); 703 // append the caption 704 if (title != undefined && ('' + title).length) { 705 $(this).append('<div class="bx-caption"><span>' + title + '</span></div>'); 706 } 707 }); 708 } 709 710 /** 711 * Click next binding 712 * 713 * @param e (event) 714 * - DOM event object 715 */ 716 var clickNextBind = function(e){ 717 // if auto show is running, stop it 718 if (slider.settings.auto) el.stopAuto(); 719 el.goToNextSlide(); 720 e.preventDefault(); 721 } 722 723 /** 724 * Click prev binding 725 * 726 * @param e (event) 727 * - DOM event object 728 */ 729 var clickPrevBind = function(e){ 730 // if auto show is running, stop it 731 if (slider.settings.auto) el.stopAuto(); 732 el.goToPrevSlide(); 733 e.preventDefault(); 734 } 735 736 /** 737 * Click start binding 738 * 739 * @param e (event) 740 * - DOM event object 741 */ 742 var clickStartBind = function(e){ 743 el.startAuto(); 744 e.preventDefault(); 745 } 746 747 /** 748 * Click stop binding 749 * 750 * @param e (event) 751 * - DOM event object 752 */ 753 var clickStopBind = function(e){ 754 el.stopAuto(); 755 e.preventDefault(); 756 } 757 758 /** 759 * Click pager binding 760 * 761 * @param e (event) 762 * - DOM event object 763 */ 764 var clickPagerBind = function(e){ 765 // if auto show is running, stop it 766 if (slider.settings.auto) el.stopAuto(); 767 var pagerLink = $(e.currentTarget); 768 if(pagerLink.attr('data-slide-index') !== undefined){ 769 var pagerIndex = parseInt(pagerLink.attr('data-slide-index')); 770 // if clicked pager link is not active, continue with the goToSlide call 771 if(pagerIndex != slider.active.index) el.goToSlide(pagerIndex); 772 e.preventDefault(); 773 } 774 } 775 776 /** 777 * Updates the pager links with an active class 778 * 779 * @param slideIndex (int) 780 * - index of slide to make active 781 */ 782 var updatePagerActive = function(slideIndex){ 783 // if "short" pager type 784 var len = slider.children.length; // nb of children 785 if(slider.settings.pagerType == 'short'){ 786 if(slider.settings.maxSlides > 1) { 787 len = Math.ceil(slider.children.length/slider.settings.maxSlides); 788 } 789 slider.pagerEl.html( (slideIndex + 1) + slider.settings.pagerShortSeparator + len); 790 return; 791 } 792 // remove all pager active classes 793 slider.pagerEl.find('a').removeClass('active'); 794 // apply the active class for all pagers 795 slider.pagerEl.each(function(i, el) { $(el).find('a').eq(slideIndex).addClass('active'); }); 796 } 797 798 /** 799 * Performs needed actions after a slide transition 800 */ 801 var updateAfterSlideTransition = function(){ 802 // if infinte loop is true 803 if(slider.settings.infiniteLoop){ 804 var position = ''; 805 // first slide 806 if(slider.active.index == 0){ 807 // set the new position 808 position = slider.children.eq(0).position(); 809 // carousel, last slide 810 }else if(slider.active.index == getPagerQty() - 1 && slider.carousel){ 811 position = slider.children.eq((getPagerQty() - 1) * getMoveBy()).position(); 812 // last slide 813 }else if(slider.active.index == slider.children.length - 1){ 814 position = slider.children.eq(slider.children.length - 1).position(); 815 } 816 if(position){ 817 if (slider.settings.mode == 'horizontal') { setPositionProperty(-position.left, 'reset', 0); } 818 else if (slider.settings.mode == 'vertical') { setPositionProperty(-position.top, 'reset', 0); } 819 } 820 } 821 // declare that the transition is complete 822 slider.working = false; 823 // onSlideAfter callback 824 slider.settings.onSlideAfter(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 825 } 826 827 /** 828 * Updates the auto controls state (either active, or combined switch) 829 * 830 * @param state (string) "start", "stop" 831 * - the new state of the auto show 832 */ 833 var updateAutoControls = function(state){ 834 // if autoControlsCombine is true, replace the current control with the new state 835 if(slider.settings.autoControlsCombine){ 836 slider.controls.autoEl.html(slider.controls[state]); 837 // if autoControlsCombine is false, apply the "active" class to the appropriate control 838 }else{ 839 slider.controls.autoEl.find('a').removeClass('active');
840 slider.controls.autoEl.find('a:not(.bx-' + state + ')').addClass('active'); 841 } 842 } 843 844 /** 845 * Updates the direction controls (checks if either should be hidden) 846 */ 847 var updateDirectionControls = function(){ 848 if(getPagerQty() == 1){ 849 slider.controls.prev.addClass('disabled'); 850 slider.controls.next.addClass('disabled'); 851 }else if(!slider.settings.infiniteLoop && slider.settings.hideControlOnEnd){ 852 // if first slide 853 if (slider.active.index == 0){ 854 slider.controls.prev.addClass('disabled'); 855 slider.controls.next.removeClass('disabled'); 856 // if last slide 857 }else if(slider.active.index == getPagerQty() - 1){ 858 slider.controls.next.addClass('disabled'); 859 slider.controls.prev.removeClass('disabled'); 860 // if any slide in the middle 861 }else{ 862 slider.controls.prev.removeClass('disabled'); 863 slider.controls.next.removeClass('disabled'); 864 } 865 } 866 } 867 868 /** 869 * Initialzes the auto process 870 */ 871 var initAuto = function(){ 872 // if autoDelay was supplied, launch the auto show using a setTimeout() call 873 if(slider.settings.autoDelay > 0){ 874 var timeout = setTimeout(el.startAuto, slider.settings.autoDelay); 875 // if autoDelay was not supplied, start the auto show normally 876 }else{ 877 el.startAuto(); 878 } 879 // if autoHover is requested 880 if(slider.settings.autoHover){ 881 // on el hover 882 el.hover(function(){ 883 // if the auto show is currently playing (has an active interval) 884 if(slider.interval){ 885 // stop the auto show and pass true agument which will prevent control update 886 el.stopAuto(true); 887 // create a new autoPaused value which will be used by the relative "mouseout" event 888 slider.autoPaused = true; 889 } 890 }, function(){ 891 // if the autoPaused value was created be the prior "mouseover" event 892 if(slider.autoPaused){ 893 // start the auto show and pass true agument which will prevent control update 894 el.startAuto(true); 895 // reset the autoPaused value 896 slider.autoPaused = null; 897 } 898 }); 899 } 900 } 901 902 /** 903 * Initialzes the ticker process 904 */ 905 var initTicker = function(){ 906 var startPosition = 0; 907 // if autoDirection is "next", append a clone of the entire slider 908 if(slider.settings.autoDirection == 'next'){ 909 el.append(slider.children.clone().addClass('bx-clone')); 910 // if autoDirection is "prev", prepend a clone of the entire slider, and set the left position 911 }else{ 912 el.prepend(slider.children.clone().addClass('bx-clone')); 913 var position = slider.children.first().position(); 914 startPosition = slider.settings.mode == 'horizontal' ? -position.left : -position.top; 915 } 916 setPositionProperty(startPosition, 'reset', 0); 917 // do not allow controls in ticker mode 918 slider.settings.pager = false; 919 slider.settings.controls = false; 920 slider.settings.autoControls = false; 921 // if autoHover is requested 922 if(slider.settings.tickerHover && !slider.usingCSS){ 923 // on el hover 924 slider.viewport.hover(function(){ 925 el.stop(); 926 }, function(){ 927 // calculate the total width of children (used to calculate the speed ratio) 928 var totalDimens = 0; 929 slider.children.each(function(index){ 930 totalDimens += slider.settings.mode == 'horizontal' ? $(this).outerWidth(true) : $(this).outerHeight(true); 931 }); 932 // calculate the speed ratio (used to determine the new speed to finish the paused animation) 933 var ratio = slider.settings.speed / totalDimens; 934 // determine which property to use 935 var property = slider.settings.mode == 'horizontal' ? 'left' : 'top'; 936 // calculate the new speed 937 var newSpeed = ratio * (totalDimens - (Math.abs(parseInt(el.css(property))))); 938 tickerLoop(newSpeed); 939 }); 940 } 941 // start the ticker loop 942 tickerLoop(); 943 } 944 945 /** 946 * Runs a continuous loop, news ticker-style 947 */ 948 var tickerLoop = function(resumeSpeed){ 949 speed = resumeSpeed ? resumeSpeed : slider.settings.speed; 950 var position = {left: 0, top: 0}; 951 var reset = {left: 0, top: 0}; 952 // if "next" animate left position to last child, then reset left to 0 953 if(slider.settings.autoDirection == 'next'){ 954 position = el.find('.bx-clone').first().position(); 955 // if "prev" animate left position to 0, then reset left to first non-clone child 956 }else{ 957 reset = slider.children.first().position(); 958 } 959 var animateProperty = slider.settings.mode == 'horizontal' ? -position.left : -position.top; 960 var resetValue = slider.settings.mode == 'horizontal' ? -reset.left : -reset.top; 961 var params = {resetValue: resetValue}; 962 setPositionProperty(animateProperty, 'ticker', speed, params); 963 } 964 965 /** 966 * Initializes touch events 967 */ 968 var initTouch = function(){ 969 // initialize object to contain all touch values 970 slider.touch = { 971 start: {x: 0, y: 0}, 972 end: {x: 0, y: 0} 973 } 974 slider.viewport.bind('touchstart', onTouchStart); 975 } 976 977 /** 978 * Event handler for "touchstart" 979 * 980 * @param e (event) 981 * - DOM event object 982 */ 983 var onTouchStart = function(e){ 984 if(slider.working){ 985 e.preventDefault(); 986 }else{ 987 // record the original position when touch starts 988 slider.touch.originalPos = el.position(); 989 var orig = e.originalEvent; 990 // record the starting touch x, y coordinates
991 slider.touch.start.x = orig.changedTouches[0].pageX; 992 slider.touch.start.y = orig.changedTouches[0].pageY; 993 // bind a "touchmove" event to the viewport 994 slider.viewport.bind('touchmove', onTouchMove); 995 // bind a "touchend" event to the viewport 996 slider.viewport.bind('touchend', onTouchEnd); 997 } 998 } 999 1000 /** 1001 * Event handler for "touchmove" 1002 * 1003 * @param e (event) 1004 * - DOM event object 1005 */ 1006 var onTouchMove = function(e){ 1007 var orig = e.originalEvent; 1008 // if scrolling on y axis, do not prevent default 1009 var xMovement = Math.abs(orig.changedTouches[0].pageX - slider.touch.start.x); 1010 var yMovement = Math.abs(orig.changedTouches[0].pageY - slider.touch.start.y); 1011 // x axis swipe 1012 if((xMovement * 3) > yMovement && slider.settings.preventDefaultSwipeX){ 1013 e.preventDefault(); 1014 // y axis swipe 1015 }else if((yMovement * 3) > xMovement && slider.settings.preventDefaultSwipeY){ 1016 e.preventDefault(); 1017 } 1018 if(slider.settings.mode != 'fade' && slider.settings.oneToOneTouch){ 1019 var value = 0; 1020 // if horizontal, drag along x axis 1021 if(slider.settings.mode == 'horizontal'){ 1022 var change = orig.changedTouches[0].pageX - slider.touch.start.x; 1023 value = slider.touch.originalPos.left + change; 1024 // if vertical, drag along y axis 1025 }else{ 1026 var change = orig.changedTouches[0].pageY - slider.touch.start.y; 1027 value = slider.touch.originalPos.top + change; 1028 } 1029 setPositionProperty(value, 'reset', 0); 1030 } 1031 } 1032 1033 /** 1034 * Event handler for "touchend" 1035 * 1036 * @param e (event) 1037 * - DOM event object 1038 */ 1039 var onTouchEnd = function(e){ 1040 slider.viewport.unbind('touchmove', onTouchMove); 1041 var orig = e.originalEvent; 1042 var value = 0; 1043 // record end x, y positions 1044 slider.touch.end.x = orig.changedTouches[0].pageX; 1045 slider.touch.end.y = orig.changedTouches[0].pageY; 1046 // if fade mode, check if absolute x distance clears the threshold 1047 if(slider.settings.mode == 'fade'){ 1048 var distance = Math.abs(slider.touch.start.x - slider.touch.end.x); 1049 if(distance >= slider.settings.swipeThreshold){ 1050 slider.touch.start.x > slider.touch.end.x ? el.goToNextSlide() : el.goToPrevSlide(); 1051 el.stopAuto(); 1052 } 1053 // not fade mode 1054 }else{ 1055 var distance = 0; 1056 // calculate distance and el's animate property 1057 if(slider.settings.mode == 'horizontal'){ 1058 distance = slider.touch.end.x - slider.touch.start.x; 1059 value = slider.touch.originalPos.left; 1060 }else{ 1061 distance = slider.touch.end.y - slider.touch.start.y; 1062 value = slider.touch.originalPos.top; 1063 } 1064 // if not infinite loop and first / last slide, do not attempt a slide transition 1065 if(!slider.settings.infiniteLoop && ((slider.active.index == 0 && distance > 0) || (slider.active.last && distance < 0))){ 1066 setPositionProperty(value, 'reset', 200); 1067 }else{ 1068 // check if distance clears threshold 1069 if(Math.abs(distance) >= slider.settings.swipeThreshold){ 1070 distance < 0 ? el.goToNextSlide() : el.goToPrevSlide(); 1071 el.stopAuto(); 1072 }else{ 1073 // el.animate(property, 200); 1074 setPositionProperty(value, 'reset', 200); 1075 } 1076 } 1077 } 1078 slider.viewport.unbind('touchend', onTouchEnd); 1079 } 1080 1081 /** 1082 * Window resize event callback 1083 */ 1084 var resizeWindow = function(e){ 1085 // don't do anything if slider isn't initialized. 1086 if(!slider.initialized) return; 1087 // get the new window dimens (again, thank you IE) 1088 var windowWidthNew = $(window).width(); 1089 var windowHeightNew = $(window).height(); 1090 // make sure that it is a true window resize 1091 // *we must check this because our dinosaur friend IE fires a window resize event when certain DOM elements 1092 // are resized. Can you just die already?* 1093 if(windowWidth != windowWidthNew || windowHeight != windowHeightNew){ 1094 // set the new window dimens 1095 windowWidth = windowWidthNew; 1096 windowHeight = windowHeightNew; 1097 // update all dynamic elements 1098 el.redrawSlider(); 1099 // Call user resize handler 1100 slider.settings.onSliderResize.call(el, slider.active.index); 1101 } 1102 } 1103 1104 /** 1105 * =================================================================================== 1106 * = PUBLIC FUNCTIONS 1107 * =================================================================================== 1108 */ 1109 1110 /** 1111 * Performs slide transition to the specified slide 1112 * 1113 * @param slideIndex (int) 1114 * - the destination slide's index (zero-based) 1115 * 1116 * @param direction (string) 1117 * - INTERNAL USE ONLY - the direction of travel ("prev" / "next") 1118 */ 1119 el.goToSlide = function(slideIndex, direction){ 1120 // if plugin is currently in motion, ignore request 1121 if(slider.working || slider.active.index == slideIndex) return; 1122 // declare that plugin is in motion 1123 slider.working = true; 1124 // store the old index 1125 slider.oldIndex = slider.active.index; 1126 // if slideIndex is less than zero, set active index to last child (this happens during infinite loop) 1127 if(slideIndex < 0){ 1128 slider.active.index = getPagerQty() - 1; 1129 // if slideIndex is greater than children length, set active index to 0 (this happens during infinite loop) 1130 }else if(slideIndex >= getPagerQty()){ 1131 slider.active.index = 0; 1132 // set active index to requested slide 1133 }else{ 1134 slider.active.index = slideIndex; 1135 } 1136 // onSlideBefore, onSlideNext, onSlidePrev callbacks 1137 slider.settings.onSlideBefore(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 1138 if(direction == 'next'){ 1139 slider.settings.onSlideNext(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 1140 }else if(direction == 'prev'){ 1141 slider.settings.onSlidePrev(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 1142 } 1143 // check if last slide 1144 slider.active.last = slider.active.index >= getPagerQty() - 1; 1145 // update the pager with active class 1146 if(slider.settings.pager) updatePagerActive(slider.active.index); 1147 // // check for direction control update 1148 if(slider.settings.controls) updateDirectionControls(); 1149 // if slider is set to mode: "fade" 1150 if(slider.settings.mode == 'fade'){ 1151 // if adaptiveHeight is true and next height is different from current height, animate to the new height 1152 if(slider.settings.adaptiveHeight && slider.viewport.height() != getViewportHe
1152ight()){ 1153 slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); 1154 } 1155 // fade out the visible child and reset its z-index value 1156 slider.children.filter(':visible').fadeOut(slider.settings.speed).css({zIndex: 0}); 1157 // fade in the newly requested slide 1158 slider.children.eq(slider.active.index).css('zIndex', slider.settings.slideZIndex+1).fadeIn(slider.settings.speed, function(){ 1159 $(this).css('zIndex', slider.settings.slideZIndex); 1160 updateAfterSlideTransition(); 1161 }); 1162 // slider mode is not "fade" 1163 }else{ 1164 // if adaptiveHeight is true and next height is different from current height, animate to the new height 1165 if(slider.settings.adaptiveHeight && slider.viewport.height() != getViewportHeight()){ 1166 slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); 1167 } 1168 var moveBy = 0; 1169 var position = {left: 0, top: 0}; 1170 // if carousel and not infinite loop 1171 if(!slider.settings.infiniteLoop && slider.carousel && slider.active.last){ 1172 if(slider.settings.mode == 'horizontal'){ 1173 // get the last child position 1174 var lastChild = slider.children.eq(slider.children.length - 1); 1175 position = lastChild.position(); 1176 // calculate the position of the last slide 1177 moveBy = slider.viewport.width() - lastChild.outerWidth(); 1178 }else{ 1179 // get last showing index position 1180 var lastShowingIndex = slider.children.length - slider.settings.minSlides; 1181 position = slider.children.eq(lastShowingIndex).position(); 1182 } 1183 // horizontal carousel, going previous while on first slide (infiniteLoop mode) 1184 }else if(slider.carousel && slider.active.last && direction == 'prev'){ 1185 // get the last child position 1186 var eq = slider.settings.moveSlides == 1 ? slider.settings.maxSlides - getMoveBy() : ((getPagerQty() - 1) * getMoveBy()) - (slider.children.length - slider.settings.maxSlides); 1187 var lastChild = el.children('.bx-clone').eq(eq); 1188 position = lastChild.position(); 1189 // if infinite loop and "Next" is clicked on the last slide 1190 }else if(direction == 'next' && slider.active.index == 0){ 1191 // get the last clone position 1192 position = el.find('> .bx-clone').eq(slider.settings.maxSlides).position(); 1193 slider.active.last = false; 1194 // normal non-zero requests 1195 }else if(slideIndex >= 0){ 1196 var requestEl = slideIndex * getMoveBy(); 1197 position = slider.children.eq(requestEl).position(); 1198 } 1199 1200 /* If the position doesn't exist 1201 * (e.g. if you destroy the slider on a next click), 1202 * it doesn't throw an error. 1203 */ 1204 if ("undefined" !== typeof(position)) { 1205 var value = slider.settings.mode == 'horizontal' ? -(position.left - moveBy) : -position.top; 1206 // plugin values to be animated 1207 setPositionProperty(value, 'slide', slider.settings.speed); 1208 } 1209 } 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);
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.