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