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