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