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