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