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