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