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