vendor: 4,173 bytes, lines 1-145
1/** 2 * bxSlider v4.2.4 3 * Copyright 2013-2015 Steven Wanderski 4 * Written while drinking Belgian ales and listening to jazz 5 * Licensed under MIT (http://opensource.org/licenses/MIT) 6 */ 7 8;(function($) { 9 10 var defaults = { 11 12 // GENERAL 13 mode: 'horizontal', 14 slideSelector: '', 15 infiniteLoop: true, 16 hideControlOnEnd: false, 17 speed: 500, 18 easing: null, 19 slideMargin: 0, 20 startSlide: 0, 21 randomStart: false, 22 captions: false, 23 ticker: false, 24 tickerHover: false, 25 adaptiveHeight: false, 26 adaptiveHeightSpeed: 500, 27 video: false, 28 useCSS: true, 29 preloadImages: 'visible', 30 responsive: true, 31 slideZIndex: 50, 32 wrapperClass: 'bx-wrapper', 33 34 // TOUCH 35 touchEnabled: true, 36 swipeThreshold: 50, 37 oneToOneTouch: true, 38 preventDefaultSwipeX: true, 39 preventDefaultSwipeY: false, 40 41 // ACCESSIBILITY 42 ariaLive: true, 43 ariaHidden: true, 44 45 // KEYBOARD 46 keyboardEnabled: false, 47 48 // PAGER 49 pager: true, 50 pagerType: 'full', 51 pagerShortSeparator: ' / ', 52 pagerSelector: null, 53 buildPager: null, 54 pagerCustom: null, 55 56 // CONTROLS 57 controls: true, 58 nextText: 'Next', 59 prevText: 'Prev', 60 nextSelector: null, 61 prevSelector: null, 62 autoControls: false, 63 startText: 'Start', 64 stopText: 'Stop', 65 autoControlsCombine: false, 66 autoControlsSelector: null, 67 68 // AUTO 69 auto: false, 70 pause: 4000, 71 autoStart: true, 72 autoDirection: 'next', 73 stopAutoOnClick: false, 74 autoHover: false, 75 autoDelay: 0, 76 autoSlideForOnePage: false, 77 78 // CAROUSEL 79 minSlides: 1, 80 maxSlides: 1, 81 moveSlides: 0, 82 slideWidth: 0, 83 shrinkItems: false, 84 85 // CALLBACKS 86 onSliderLoad: function() { return true; }, 87 onSlideBefore: function() { return true; }, 88 onSlideAfter: function() { return true; }, 89 onSlideNext: function() { return true; }, 90 onSlidePrev: function() { return true; }, 91 onSliderResize: function() { return true; } 92 }; 93 94 $.fn.bxSliderx = function(options) { 95 96 if (this.length === 0) { 97 return this; 98 } 99 100 // support multiple elements 101 if (this.length > 1) { 102 this.each(function() { 103 $(this).bxSliderx(options); 104 }); 105 return this; 106 } 107 108 // create a namespace to be used throughout the plugin 109 var slider = {}, 110 // set a reference to our slider element 111 el = this, 112 // get the original window dimens (thanks a lot IE) 113 windowWidth = $(window).width(), 114 windowHeight = $(window).height(); 115 116 // Return if slider is already initialized 117 if ($(el).data('bxSliderx')) { return; } 118 119 /** 120 * =================================================================================== 121 * = PRIVATE FUNCTIONS 122 * =================================================================================== 123 */ 124 125 /** 126 * Initializes namespace settings to be used throughout plugin 127 */ 128 var init = function() { 129 // Return if slider is already initialized 130 if ($(el).data('bxSliderx')) { return; } 131 // merge user-supplied options with the defaults 132 slider.settings = $.extend({}, defaults, options); 133 // parse slideWidth setting 134 slider.settings.slideWidth = parseInt(slider.settings.slideWidth); 135 // store the original children 136 slider.children = el.children(slider.settings.slideSelector); 137 // check if actual number of slides is less than minSlides / maxSlides 138 if (slider.children.length < slider.settings.minSlides) { slider.settings.minSlides = slider.children.length; } 139 if (slider.children.length < slider.settings.maxSlides) { slider.settings.maxSlides = slider.children.length; } 140 // if random start, set the startSlide setting to random number 141 if (slider.settings.randomStart) { slider.settings.startSlide = Math.floor(Math.random() * slider.children.length); } 142 // store active slide information 143 slider.active = { index: slider.settings.startSlide }; 144 // store if the slider is in carousel mode (displaying / moving multiple slides) 145 slider.carousel = slider.settings.minSlides > 1 || slider.settings.maxSlides > 1 ? true : false;
146 // if carousel, force preloadImages = 'all' 147 if (slider.carousel) { slider.settings.preloadImages = 'all'; } 148 // calculate the min / max width thresholds based on min / max number of slides 149 // used to setup and update carousel slides dimensions 150 slider.minThreshold = (slider.settings.minSlides * slider.settings.slideWidth) + ((slider.settings.minSlides - 1) * slider.settings.slideMargin); 151 slider.maxThreshold = (slider.settings.maxSlides * slider.settings.slideWidth) + ((slider.settings.maxSlides - 1) * slider.settings.slideMargin); 152 // store the current state of the slider (if currently animating, working is true) 153 slider.working = false; 154 // initialize the controls object 155 slider.controls = {}; 156 // initialize an auto interval 157 slider.interval = null; 158 // determine which property to use for transitions 159 slider.animProp = slider.settings.mode === 'vertical' ? 'top' : 'left'; 160 // determine if hardware acceleration can be used 161 slider.usingCSS = slider.settings.useCSS && slider.settings.mode !== 'fade' && (function() { 162 // create our test div element 163 var div = document.createElement('div'), 164 // css transition properties 165 props = ['WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective']; 166 // test for each property 167 for (var i = 0; i < props.length; i++) { 168 if (div.style[props[i]] !== undefined) { 169 slider.cssPrefix = props[i].replace('Perspective', '').toLowerCase(); 170 slider.animProp = '-' + slider.cssPrefix + '-transform'; 171 return true; 172 } 173 } 174 return false; 175 }()); 176 // if vertical mode always make maxSlides and minSlides equal 177 if (slider.settings.mode === 'vertical') { slider.settings.maxSlides = slider.settings.minSlides; } 178 // save original style data 179 el.data('origStyle', el.attr('style')); 180 el.children(slider.settings.slideSelector).each(function() { 181 $(this).data('origStyle', $(this).attr('style')); 182 if($(this).find('img').length >0){ 183 184 $(this).find('img').each(function(index, elm) { 185 186 var toload=''; 187 var toloadval=''; 188 $.each(this.attributes, function(i, attrib){ 189 190 var value = attrib.value; 191 var aname=attrib.name; 192 193 var pattern = /^((http|https):\/\/)/; 194 195 if(pattern.test(value) && aname!='src') { 196 197 toload=aname; 198 toloadval=value; 199 } 200 // do your magic :-) 201 }); 202 203 vsrc=$(elm).attr("src"); 204 $(elm).removeAttr("src"); 205 dsrc=$(elm).attr("data-src"); 206 lsrc=$(elm).attr("data-lazy-src"); 207 208 if(dsrc!== undefined && dsrc!='' && dsrc!=vsrc){ 209 $(elm).attr("src",dsrc); 210 } 211 else if(lsrc!== undefined && lsrc!=vsrc){ 212 213 $(elm).attr("src",lsrc); 214 } 215 else if(toload!='' && toload!='srcset' && toloadval!='' && toloadval!=vsrc){ 216 217 $(elm).attr("src",toloadval); 218 219 220 } 221 else{ 222 223 $(elm).attr("src",vsrc); 224 225 } 226 227 elm=$(elm)[0]; 228 if(!elm.complete && elm.naturalHeight == 0){ 229 230 $(elm).removeAttr('loading'); 231 $(elm).removeAttr('data-lazy-type'); 232 233 234 $(elm).removeClass('lazy'); 235 236 $(elm).removeClass('lazyLoad'); 237 $(elm).removeClass('lazy-loaded'); 238 $(elm).removeClass('jetpack-lazy-image'); 239 $(elm).removeClass('jetpack-lazy-image--handled'); 240 $(elm).removeClass('lazy-hidden'); 241 242 } 243 244 }); 245 246 } 247 }); 248 249 // perform all DOM / CSS modifications 250 setup(); 251 }; 252 253 /** 254 * Performs all DOM and CSS modifications 255 */ 256 var setup = function() { 257 var preloadSelector = slider.children.eq(slider.settings.startSlide); // set the default preload selector (visible) 258 259 // wrap el in a wrapper 260 el.wrap('<div class="' + slider.settings.wrapperClass + '"><div class="bx-viewport"></div></div>'); 261 // store a namespace reference to .bx-viewport 262 slider.viewport = el.parent(); 263 264 // add aria-live if the setting is enabled and ticker mode is disabled 265 if (slider.settings.ariaLive && !slider.settings.ticker) { 266 slider.viewport.attr('aria-live', 'polite'); 267 } 268 // add a loading div to display while images are loading
vendor: 22,816 bytes, lines 269-763
269 slider.loader = $('<div class="bx-loading" />'); 270 slider.viewport.prepend(slider.loader); 271 // set el to a massive width, to hold any needed slides 272 // also strip any margin and padding from el 273 el.css({ 274 width: slider.settings.mode === 'horizontal' ? (slider.children.length * 1000 + 215) + '%' : 'auto', 275 position: 'relative' 276 }); 277 // if using CSS, add the easing property 278 if (slider.usingCSS && slider.settings.easing) { 279 el.css('-' + slider.cssPrefix + '-transition-timing-function', slider.settings.easing); 280 // if not using CSS and no easing value was supplied, use the default JS animation easing (swing) 281 } else if (!slider.settings.easing) { 282 slider.settings.easing = 'swing'; 283 } 284 // make modifications to the viewport (.bx-viewport) 285 slider.viewport.css({ 286 width: '100%', 287 overflow: 'hidden', 288 position: 'relative' 289 }); 290 slider.viewport.parent().css({ 291 maxWidth: getViewportMaxWidth() 292 }); 293 // make modification to the wrapper (.bx-wrapper) 294 if (!slider.settings.pager && !slider.settings.controls) { 295 slider.viewport.parent().css({ 296 margin: '0 auto 0px' 297 }); 298 } 299 // apply css to all slider children 300 slider.children.css({ 301 float: slider.settings.mode === 'horizontal' ? 'left' : 'none', 302 listStyle: 'none', 303 position: 'relative' 304 }); 305 // apply the calculated width after the float is applied to prevent scrollbar interference 306 slider.children.css('width', getSlideWidth()); 307 // if slideMargin is supplied, add the css 308 if (slider.settings.mode === 'horizontal' && slider.settings.slideMargin > 0) { slider.children.css('marginRight', slider.settings.slideMargin); } 309 if (slider.settings.mode === 'vertical' && slider.settings.slideMargin > 0) { slider.children.css('marginBottom', slider.settings.slideMargin); } 310 // if "fade" mode, add positioning and z-index CSS 311 if (slider.settings.mode === 'fade') { 312 slider.children.css({ 313 position: 'absolute', 314 zIndex: 0, 315 display: 'none' 316 }); 317 // prepare the z-index on the showing element 318 slider.children.eq(slider.settings.startSlide).css({zIndex: slider.settings.slideZIndex, display: 'block'}); 319 } 320 // create an element to contain all slider controls (pager, start / stop, etc) 321 slider.controls.el = $('<div class="bx-controls" />'); 322 // if captions are requested, add them 323 if (slider.settings.captions) { appendCaptions(); } 324 // check if startSlide is last slide 325 slider.active.last = slider.settings.startSlide === getPagerQty() - 1; 326 // if video is true, set up the fitVids plugin 327 if (slider.settings.video) { el.fitVids(); } 328 if (slider.settings.preloadImages === 'all' || slider.settings.ticker) { preloadSelector = slider.children; } 329 // only check for control addition if not in "ticker" mode 330 if (!slider.settings.ticker) { 331 // if controls are requested, add them 332 if (slider.settings.controls) { appendControls(); } 333 // if auto is true, and auto controls are requested, add them 334 if (slider.settings.auto && slider.settings.autoControls) { appendControlsAuto(); } 335 // if pager is requested, add it 336 if (slider.settings.pager) { appendPager(); } 337 // if any control option is requested, add the controls wrapper 338 if (slider.settings.controls || slider.settings.autoControls || slider.settings.pager) { slider.viewport.after(slider.controls.el); } 339 // if ticker mode, do not allow a pager 340 } else { 341 slider.settings.pager = false; 342 } 343 loadElements(preloadSelector, start); 344 }; 345 346 var loadElements = function(selector, callback) { 347 var total = selector.find('img:not([src=""]), iframe').length, 348 count = 0; 349 if (total === 0) { 350 callback(); 351 return; 352 } 353 selector.find('img:not([src=""]), iframe').each(function() { 354 $(this).one('load error', function() { 355 if (++count === total) { callback(); } 356 }).each(function() { 357 if (this.complete) { $(this).trigger("load"); } 358 }); 359 }); 360 }; 361 362 /** 363 * Start the slider 364 */ 365 var start = function() { 366 // if infinite loop, prepare additional slides 367 if (slider.settings.infiniteLoop && slider.settings.mode !== 'fade' && !slider.settings.ticker) { 368 var slice = slider.settings.mode === 'vertical' ? slider.settings.minSlides : slider.settings.maxSlides, 369 sliceAppend = slider.children.slice(0, slice).clone(true).addClass('bx-clone'), 370 slicePrepend = slider.children.slice(-slice).clone(true).addClass('bx-clone'); 371 if (slider.settings.ariaHidden) { 372 sliceAppend.attr('aria-hidden', true); 373 slicePrepend.attr('aria-hidden', true); 374 } 375 el.append(sliceAppend).prepend(slicePrepend); 376 } 377 // remove the loading DOM element 378 slider.loader.remove(); 379 // set the left / top position of "el" 380 setSlidePosition(); 381 // if "vertical" mode, always use adaptiveHeight to prevent odd behavior 382 if (slider.settings.mode === 'vertical') { slider.settings.adaptiveHeight = true; } 383 // set the viewport height 384 slider.viewport.height(getViewportHeight()); 385 // make sure everything is positioned just right (same as a window resize) 386 el.redrawSlider(); 387 // onSliderLoad callback 388 slider.settings.onSliderLoad.call(el, slider.active.index); 389 // slider has been fully initialized 390 slider.initialized = true; 391 // add the resize call to the window 392 if (slider.settings.responsive) { $(window).on('resize', resizeWindow); } 393 // if auto is true and has more than 1 page, start the show 394 if (slider.settings.auto && slider.settings.autoStart && (getPagerQty() > 1 || slider.settings.autoSlideForOnePage)) { initAuto(); } 395 // if ticker is true, start the ticker 396 if (slider.settings.ticker) { initTicker(); } 397 // if pager is requested, make the appropriate pager link active 398 if (slider.settings.pager) { updatePagerActive(slider.settings.startSlide); } 399 // check for any updates to the controls (like hideControlOnEnd updates) 400 if (slider.settings.controls) { updateDirectionControls(); } 401 // if touchEnabled is true, setup the touch events 402 if (slider.settings.touchEnabled && !slider.settings.ticker) { initTouch(); } 403 // if keyboardEnabled is true, setup the keyboard events 404 if (slider.settings.keyboardEnabled && !slider.settings.ticker) { 405 $(document).keydown(keyPress); 406 } 407 }; 408 409 /** 410 * Returns the calculated height of the viewport, used to determine either adaptiveHeight or the maxHeight value 411 */ 412 var getViewportHeight = function() { 413 414 var height = el.outerHeight(), 415 currentIndex = null, 416 // first determine which children (slides) should be used in our height calculation 417 children = $(); 418 // if mode is not "vertical" and adaptiveHeight is false, include all children 419 if (slider.settings.mode !== 'vertical' && !slider.settings.adaptiveHeight) { 420 children = slider.children; 421 } else { 422 // if not carousel, return the single active child 423 if (!slider.carousel) { 424 children = slider.children.eq(slider.active.index); 425 // if carousel, return a slice of children 426 } else { 427 // get the individual slide index 428 currentIndex = slider.settings.moveSlides === 1 ? slider.active.index : slider.active.index * getMoveBy(); 429 // add the current slide to the children 430 children = slider.children.eq(currentIndex); 431 // cycle through the remaining "showing" slides 432 for (var i = 1; i <= slider.settings.maxSlides - 1; i++) { 433 // if looped back to the start 434 if (currentIndex + i >= slider.children.length) { 435 children = children.add(slider.children.eq(currentIndex + i - slider.children.length)); 436 } else { 437 children = children.add(slider.children.eq(currentIndex + i)); 438 } 439 } 440 } 441 } 442 // if "vertical" mode, calculate the sum of the heights of the children 443 if (slider.settings.mode === 'vertical') { 444 children.each(function(index) { 445 height += $(this).outerHeight(); 446 }); 447 // add user-supplied margins 448 if (slider.settings.slideMargin > 0) { 449 height += slider.settings.slideMargin * (slider.settings.minSlides - 1); 450 } 451 // if not "vertical" mode, calculate the max height of the children 452 } else { 453 height = Math.max.apply(Math, children.map(function() { 454 return $(this).outerHeight(false); 455 }).get()); 456 } 457 458 if (slider.viewport.css('box-sizing') === 'border-box') { 459 height += parseFloat(slider.viewport.css('padding-top')) + parseFloat(slider.viewport.css('padding-bottom')) + 460 parseFloat(slider.viewport.css('border-top-width')) + parseFloat(slider.viewport.css('border-bottom-width')); 461 } else if (slider.viewport.css('box-sizing') === 'padding-box') { 462 height += parseFloat(slider.viewport.css('padding-top')) + parseFloat(slider.viewport.css('padding-bottom')); 463 } 464 465 return height; 466 }; 467 468 /** 469 * Returns the calculated width to be used for the outer wrapper / viewport 470 */ 471 var getViewportMaxWidth = function() { 472 var width = '100%'; 473 if (slider.settings.slideWidth > 0) { 474 if (slider.settings.mode === 'horizontal') { 475 width = (slider.settings.maxSlides * slider.settings.slideWidth) + ((slider.settings.maxSlides - 1) * slider.settings.slideMargin); 476 } else { 477 width = slider.settings.slideWidth; 478 } 479 } 480 return width; 481 }; 482 483 /** 484 * Returns the calculated width to be applied to each slide 485 */ 486 var getSlideWidth = function() { 487 var newElWidth = slider.settings.slideWidth, // start with any user-supplied slide width 488 wrapWidth = slider.viewport.width(); // get the current viewport width 489 // if slide width was not supplied, or is larger than the viewport use the viewport width 490 if (slider.settings.slideWidth === 0 || 491 (slider.settings.slideWidth > wrapWidth && !slider.carousel) || 492 slider.settings.mode === 'vertical') { 493 newElWidth = wrapWidth; 494 // if carousel, use the thresholds to determine the width 495 } else if (slider.settings.maxSlides > 1 && slider.settings.mode === 'horizontal') { 496 if (wrapWidth > slider.maxThreshold) { 497 return newElWidth; 498 } else if (wrapWidth < slider.minThreshold) { 499 newElWidth = (wrapWidth - (slider.settings.slideMargin * (slider.settings.minSlides - 1))) / slider.settings.minSlides; 500 } else if (slider.settings.shrinkItems) { 501 newElWidth = Math.floor((wrapWidth + slider.settings.slideMargin) / (Math.ceil((wrapWidth + slider.settings.slideMargin) / (newElWidth + slider.settings.slideMargin))) - slider.settings.slideMargin); 502 } 503 } 504 return newElWidth; 505 }; 506 507 /** 508 * Returns the number of slides currently visible in the viewport (includes partially visible slides) 509 */ 510 var getNumberSlidesShowing = function() { 511 var slidesShowing = 1, 512 childWidth = null; 513 if (slider.settings.mode === 'horizontal' && slider.settings.slideWidth > 0) { 514 // if viewport is smaller than minThreshold, return minSlides 515 if (slider.viewport.width() < slider.minThreshold) { 516 slidesShowing = slider.settings.minSlides; 517 // if viewport is larger than maxThreshold, return maxSlides 518 } else if (slider.viewport.width() > slider.maxThreshold) { 519 slidesShowing = slider.settings.maxSlides; 520 // if viewport is between min / max thresholds, divide viewport width by first child width 521 } else { 522 childWidth = slider.children.first().width() + slider.settings.slideMargin; 523 slidesShowing = Math.floor((slider.viewport.width() + 524 slider.settings.slideMargin) / childWidth); 525 } 526 // if "vertical" mode, slides showing will always be minSlides 527 } else if (slider.settings.mode === 'vertical') { 528 slidesShowing = slider.settings.minSlides; 529 } 530 return slidesShowing; 531 }; 532 533 /** 534 * Returns the number of pages (one full viewport of slides is one "page") 535 */ 536 var getPagerQty = function() { 537 var pagerQty = 0, 538 breakPoint = 0, 539 counter = 0; 540 // if moveSlides is specified by the user 541 if (slider.settings.moveSlides > 0) { 542 if (slider.settings.infiniteLoop) { 543 pagerQty = Math.ceil(slider.children.length / getMoveBy()); 544 } else { 545 // when breakpoint goes above children length, counter is the number of pages 546 while (breakPoint < slider.children.length) { 547 ++pagerQty; 548 breakPoint = counter + getNumberSlidesShowing(); 549 counter += slider.settings.moveSlides <= getNumberSlidesShowing() ? slider.settings.moveSlides : getNumberSlidesShowing(); 550 } 551 } 552 // if moveSlides is 0 (auto) divide children length by sides showing, then round up 553 } else { 554 pagerQty = Math.ceil(slider.children.length / getNumberSlidesShowing()); 555 } 556 return pagerQty; 557 }; 558 559 /** 560 * Returns the number of individual slides by which to shift the slider 561 */ 562 var getMoveBy = function() { 563 // if moveSlides was set by the user and moveSlides is less than number of slides showing 564 if (slider.settings.moveSlides > 0 && slider.settings.moveSlides <= getNumberSlidesShowing()) { 565 return slider.settings.moveSlides; 566 } 567 // if moveSlides is 0 (auto) 568 return getNumberSlidesShowing(); 569 }; 570 571 /** 572 * Sets the slider's (el) left or top position 573 */ 574 var setSlidePosition = function() { 575 var position, lastChild, lastShowingIndex; 576 // if last slide, not infinite loop, and number of children is larger than specified maxSlides 577 if (slider.children.length > slider.settings.maxSlides && slider.active.last && !slider.settings.infiniteLoop) { 578 if (slider.settings.mode === 'horizontal') { 579 // get the last child's position 580 lastChild = slider.children.last(); 581 position = lastChild.position(); 582 // set the left position 583 setPositionProperty(-(position.left - (slider.viewport.width() - lastChild.outerWidth())), 'reset', 0); 584 } else if (slider.settings.mode === 'vertical') { 585 // get the last showing index's position 586 lastShowingIndex = slider.children.length - slider.settings.minSlides; 587 position = slider.children.eq(lastShowingIndex).position(); 588 // set the top position 589 setPositionProperty(-position.top, 'reset', 0); 590 } 591 // if not last slide 592 } else { 593 // get the position of the first showing slide 594 position = slider.children.eq(slider.active.index * getMoveBy()).position(); 595 // check for last slide 596 if (slider.active.index === getPagerQty() - 1) { slider.active.last = true; } 597 // set the respective position 598 if (position !== undefined) { 599 if (slider.settings.mode === 'horizontal') { setPositionProperty(-position.left, 'reset', 0); } 600 else if (slider.settings.mode === 'vertical') { setPositionProperty(-position.top, 'reset', 0); } 601 } 602 } 603 }; 604 605 /** 606 * Sets the el's animating property position (which in turn will sometimes animate el). 607 * If using CSS, sets the transform property. If not using CSS, sets the top / left property. 608 * 609 * @param value (int) 610 * - the animating property's value 611 * 612 * @param type (string) 'slide', 'reset', 'ticker' 613 * - the type of instance for which the function is being 614 * 615 * @param duration (int) 616 * - the amount of time (in ms) the transition should occupy 617 * 618 * @param params (array) optional 619 * - an optional parameter containing any variables that need to be passed in 620 */ 621 var setPositionProperty = function(value, type, duration, params) { 622 var animateObj, propValue; 623 // use CSS transform 624 if (slider.usingCSS) { 625 // determine the translate3d value 626 propValue = slider.settings.mode === 'vertical' ? 'translate3d(0, ' + value + 'px, 0)' : 'translate3d(' + value + 'px, 0, 0)'; 627 // add the CSS transition-duration 628 el.css('-' + slider.cssPrefix + '-transition-duration', duration / 1000 + 's'); 629 if (type === 'slide') { 630 // set the property value 631 el.css(slider.animProp, propValue); 632 // bind a callback method - executes when CSS transition completes 633 el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(e) { 634 //make sure it's the correct one 635 if (!$(e.target).is(el)) { return; } 636 // unbind the callback 637 el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); 638 updateAfterSlideTransition(); 639 }); 640 } else if (type === 'reset') { 641 el.css(slider.animProp, propValue); 642 } else if (type === 'ticker') { 643 // make the transition use 'linear' 644 el.css('-' + slider.cssPrefix + '-transition-timing-function', 'linear'); 645 el.css(slider.animProp, propValue); 646 // bind a callback method - executes when CSS transition completes 647 el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(e) { 648 //make sure it's the correct one 649 if (!$(e.target).is(el)) { return; } 650 // unbind the callback 651 el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); 652 // reset the position 653 setPositionProperty(params.resetValue, 'reset', 0); 654 // start the loop again 655 tickerLoop(); 656 }); 657 } 658 // use JS animate 659 } else { 660 animateObj = {}; 661 animateObj[slider.animProp] = value; 662 if (type === 'slide') { 663 el.animate(animateObj, duration, slider.settings.easing, function() { 664 updateAfterSlideTransition(); 665 }); 666 } else if (type === 'reset') { 667 el.css(slider.animProp, value); 668 } else if (type === 'ticker') { 669 el.animate(animateObj, duration, 'linear', function() { 670 setPositionProperty(params.resetValue, 'reset', 0); 671 // run the recursive loop after animation 672 tickerLoop(); 673 }); 674 } 675 } 676 }; 677 678 /** 679 * Populates the pager with proper amount of pages 680 */ 681 var populatePager = function() { 682 var pagerHtml = '', 683 linkContent = '', 684 pagerQty = getPagerQty(); 685 // loop through each pager item 686 for (var i = 0; i < pagerQty; i++) { 687 linkContent = ''; 688 // if a buildPager function is supplied, use it to get pager link value, else use index + 1 689 if (slider.settings.buildPager && $.isFunction(slider.settings.buildPager) || slider.settings.pagerCustom) { 690 linkContent = slider.settings.buildPager(i); 691 slider.pagerEl.addClass('bx-custom-pager'); 692 } else { 693 linkContent = i + 1; 694 slider.pagerEl.addClass('bx-default-pager'); 695 } 696 // var linkContent = slider.settings.buildPager && $.isFunction(slider.settings.buildPager) ? slider.settings.buildPager(i) : i + 1; 697 // add the markup to the string 698 pagerHtml += '<div class="bx-pager-item"><a href="" data-slide-index="' + i + '" class="bx-pager-link">' + linkContent + '</a></div>'; 699 } 700 // populate the pager element with pager links 701 slider.pagerEl.html(pagerHtml); 702 }; 703 704 /** 705 * Appends the pager to the controls element 706 */ 707 var appendPager = function() { 708 if (!slider.settings.pagerCustom) { 709 // create the pager DOM element 710 slider.pagerEl = $('<div class="bx-pager" />'); 711 // if a pager selector was supplied, populate it with the pager 712 if (slider.settings.pagerSelector) { 713 $(slider.settings.pagerSelector).html(slider.pagerEl); 714 // if no pager selector was supplied, add it after the wrapper 715 } else { 716 slider.controls.el.addClass('bx-has-pager').append(slider.pagerEl); 717 } 718 // populate the pager 719 populatePager(); 720 } else { 721 slider.pagerEl = $(slider.settings.pagerCustom); 722 } 723 // assign the pager click binding 724 slider.pagerEl.on('click touchend', 'a', clickPagerBind); 725 }; 726 727 /** 728 * Appends prev / next controls to the controls element 729 */ 730 var appendControls = function() { 731 slider.controls.next = $('<a class="bx-next" href="">' + slider.settings.nextText + '</a>'); 732 slider.controls.prev = $('<a class="bx-prev" href="">' + slider.settings.prevText + '</a>'); 733 // bind click actions to the controls 734 slider.controls.next.bind('click touchend', clickNextBind); 735 slider.controls.prev.bind('click touchend', clickPrevBind); 736 // if nextSelector was supplied, populate it 737 if (slider.settings.nextSelector) { 738 $(slider.settings.nextSelector).append(slider.controls.next); 739 } 740 // if prevSelector was supplied, populate it 741 if (slider.settings.prevSelector) { 742 $(slider.settings.prevSelector).append(slider.controls.prev); 743 } 744 // if no custom selectors were supplied 745 if (!slider.settings.nextSelector && !slider.settings.prevSelector) { 746 // add the controls to the DOM 747 slider.controls.directionEl = $('<div class="bx-controls-direction" />'); 748 // add the control elements to the directionEl 749 slider.controls.directionEl.append(slider.controls.prev).append(slider.controls.next); 750 // slider.viewport.append(slider.controls.directionEl); 751 slider.controls.el.addClass('bx-has-controls-direction').append(slider.controls.directionEl); 752 } 753 }; 754 755 /** 756 * Appends start / stop auto controls to the controls element 757 */ 758 var appendControlsAuto = function() { 759 slider.controls.start = $('<div class="bx-controls-auto-item"><a class="bx-start" href="">' + slider.settings.startText + '</a></div>'); 760 slider.controls.stop = $('<div class="bx-controls-auto-item"><a class="bx-stop" href="">' + slider.settings.stopText + '</a></div>'); 761 // add the controls to the DOM 762 slider.controls.autoEl = $('<div class="bx-controls-auto" />'); 763 // bind
vendor: 7,154 bytes, lines 763-961
763 click actions to the controls 764 slider.controls.autoEl.on('click', '.bx-start', clickStartBind); 765 slider.controls.autoEl.on('click', '.bx-stop', clickStopBind); 766 // if autoControlsCombine, insert only the "start" control 767 if (slider.settings.autoControlsCombine) { 768 slider.controls.autoEl.append(slider.controls.start); 769 // if autoControlsCombine is false, insert both controls 770 } else { 771 slider.controls.autoEl.append(slider.controls.start).append(slider.controls.stop); 772 } 773 // if auto controls selector was supplied, populate it with the controls 774 if (slider.settings.autoControlsSelector) { 775 $(slider.settings.autoControlsSelector).html(slider.controls.autoEl); 776 // if auto controls selector was not supplied, add it after the wrapper 777 } else { 778 slider.controls.el.addClass('bx-has-controls-auto').append(slider.controls.autoEl); 779 } 780 // update the auto controls 781 updateAutoControls(slider.settings.autoStart ? 'stop' : 'start'); 782 }; 783 784 /** 785 * Appends image captions to the DOM 786 */ 787 var appendCaptions = function() { 788 // cycle through each child 789 slider.children.each(function(index) { 790 // get the image title attribute 791 var title = $(this).find('img:first').attr('title'); 792 // append the caption 793 if (title !== undefined && ('' + title).length) { 794 $(this).append('<div class="bx-caption"><span>' + title + '</span></div>'); 795 } 796 }); 797 }; 798 799 /** 800 * Click next binding 801 * 802 * @param e (event) 803 * - DOM event object 804 */ 805 var clickNextBind = function(e) { 806 e.preventDefault(); 807 if (slider.controls.el.hasClass('disabled')) { return; } 808 // if auto show is running, stop it 809 if (slider.settings.auto && slider.settings.stopAutoOnClick) { el.stopAuto(); } 810 el.goToNextSlide(); 811 }; 812 813 /** 814 * Click prev binding 815 * 816 * @param e (event) 817 * - DOM event object 818 */ 819 var clickPrevBind = function(e) { 820 e.preventDefault(); 821 if (slider.controls.el.hasClass('disabled')) { return; } 822 // if auto show is running, stop it 823 if (slider.settings.auto && slider.settings.stopAutoOnClick) { el.stopAuto(); } 824 el.goToPrevSlide(); 825 }; 826 827 /** 828 * Click start binding 829 * 830 * @param e (event) 831 * - DOM event object 832 */ 833 var clickStartBind = function(e) { 834 el.startAuto(); 835 e.preventDefault(); 836 }; 837 838 /** 839 * Click stop binding 840 * 841 * @param e (event) 842 * - DOM event object 843 */ 844 var clickStopBind = function(e) { 845 el.stopAuto(); 846 e.preventDefault(); 847 }; 848 849 /** 850 * Click pager binding 851 * 852 * @param e (event) 853 * - DOM event object 854 */ 855 var clickPagerBind = function(e) { 856 var pagerLink, pagerIndex; 857 e.preventDefault(); 858 if (slider.controls.el.hasClass('disabled')) { 859 return; 860 } 861 // if auto show is running, stop it 862 if (slider.settings.auto && slider.settings.stopAutoOnClick) { el.stopAuto(); } 863 pagerLink = $(e.currentTarget); 864 if (pagerLink.attr('data-slide-index') !== undefined) { 865 pagerIndex = parseInt(pagerLink.attr('data-slide-index')); 866 // if clicked pager link is not active, continue with the goToSlide call 867 if (pagerIndex !== slider.active.index) { el.goToSlide(pagerIndex); } 868 } 869 }; 870 871 /** 872 * Updates the pager links with an active class 873 * 874 * @param slideIndex (int) 875 * - index of slide to make active 876 */ 877 var updatePagerActive = function(slideIndex) { 878 // if "short" pager type 879 var len = slider.children.length; // nb of children 880 if (slider.settings.pagerType === 'short') { 881 if (slider.settings.maxSlides > 1) { 882 len = Math.ceil(slider.children.length / slider.settings.maxSlides); 883 } 884 slider.pagerEl.html((slideIndex + 1) + slider.settings.pagerShortSeparator + len); 885 return; 886 } 887 // remove all pager active classes 888 slider.pagerEl.find('a').removeClass('active'); 889 // apply the active class for all pagers 890 slider.pagerEl.each(function(i, el) { $(el).find('a').eq(slideIndex).addClass('active'); }); 891 }; 892 893 /** 894 * Performs needed actions after a slide transition 895 */ 896 var updateAfterSlideTransition = function() { 897 // if infinite loop is true 898 if (slider.settings.infiniteLoop) { 899 var position = ''; 900 // first slide 901 if (slider.active.index === 0) { 902 // set the new position 903 position = slider.children.eq(0).position(); 904 // carousel, last slide 905 } else if (slider.active.index === getPagerQty() - 1 && slider.carousel) { 906 position = slider.children.eq((getPagerQty() - 1) * getMoveBy()).position(); 907 // last slide 908 } else if (slider.active.index === slider.children.length - 1) { 909 position = slider.children.eq(slider.children.length - 1).position(); 910 } 911 if (position) { 912 if (slider.settings.mode === 'horizontal') { setPositionProperty(-position.left, 'reset', 0); } 913 else if (slider.settings.mode === 'vertical') { setPositionProperty(-position.top, 'reset', 0); } 914 } 915 } 916 // declare that the transition is complete 917 slider.working = false; 918 // onSlideAfter callback 919 slider.settings.onSlideAfter.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 920 }; 921 922 /** 923 * Updates the auto controls state (either active, or combined switch) 924 * 925 * @param state (string) "start", "stop" 926 * - the new state of the auto show 927 */ 928 var updateAutoControls = function(state) { 929 // if autoControlsCombine is true, replace the current control with the new state 930 if (slider.settings.autoControlsCombine) { 931 slider.controls.autoEl.html(slider.controls[state]); 932 // if autoControlsCombine is false, apply the "active" class to the appropriate control 933 } else { 934 slider.controls.autoEl.find('a').removeClass('active'); 935 slider.controls.autoEl.find('a:not(.bx-' + state + ')').addClass('active'); 936 } 937 }; 938 939 /** 940 * Updates the direction controls (checks if either should be hidden) 941 */ 942 var updateDirectionControls = function() { 943 if (getPagerQty() === 1) { 944 slider.controls.prev.addClass('disabled'); 945 slider.controls.next.addClass('disabled'); 946 } else if (!slider.settings.infiniteLoop && slider.settings.hideControlOnEnd) { 947 // if first slide 948 if (slider.active.index === 0) { 949 slider.controls.prev.addClass('disabled'); 950 slider.controls.next.removeClass('disabled'); 951 // if last slide 952 } else if (slider.active.index === getPagerQty() - 1) { 953 slider.controls.next.addClass('disabled'); 954 slider.controls.prev.removeClass('disabled'); 955 // if any slide in the middle 956 } else { 957 slider.controls.prev.removeClass('disabled'); 958 slider.controls.next.removeClass('disabled'); 959 } 960 } 961 };
vendor: 15,806 bytes, lines 962-1372
962 963 /** 964 * Initializes the auto process 965 */ 966 var initAuto = function() { 967 // if autoDelay was supplied, launch the auto show using a setTimeout() call 968 if (slider.settings.autoDelay > 0) { 969 var timeout = setTimeout(el.startAuto, slider.settings.autoDelay); 970 // if autoDelay was not supplied, start the auto show normally 971 } else { 972 el.startAuto(); 973 974 //add focus and blur events to ensure its running if timeout gets paused 975 $(window).focus(function() { 976 el.startAuto(); 977 }).blur(function() { 978 el.stopAuto(); 979 }); 980 } 981 // if autoHover is requested 982 if (slider.settings.autoHover) { 983 // on el hover 984 el.hover(function() { 985 // if the auto show is currently playing (has an active interval) 986 if (slider.interval) { 987 // stop the auto show and pass true argument which will prevent control update 988 el.stopAuto(true); 989 // create a new autoPaused value which will be used by the relative "mouseout" event 990 slider.autoPaused = true; 991 } 992 }, function() { 993 // if the autoPaused value was created be the prior "mouseover" event 994 if (slider.autoPaused) { 995 // start the auto show and pass true argument which will prevent control update 996 el.startAuto(true); 997 // reset the autoPaused value 998 slider.autoPaused = null; 999 } 1000 }); 1001 } 1002 }; 1003 1004 /** 1005 * Initializes the ticker process 1006 */ 1007 var initTicker = function() { 1008 var startPosition = 0, 1009 position, transform, value, idx, ratio, property, newSpeed, totalDimens; 1010 // if autoDirection is "next", append a clone of the entire slider 1011 if (slider.settings.autoDirection === 'next') { 1012 el.append(slider.children.clone().addClass('bx-clone')); 1013 // if autoDirection is "prev", prepend a clone of the entire slider, and set the left position 1014 } else { 1015 el.prepend(slider.children.clone().addClass('bx-clone')); 1016 position = slider.children.first().position(); 1017 startPosition = slider.settings.mode === 'horizontal' ? -position.left : -position.top; 1018 } 1019 setPositionProperty(startPosition, 'reset', 0); 1020 // do not allow controls in ticker mode 1021 slider.settings.pager = false; 1022 slider.settings.controls = false; 1023 slider.settings.autoControls = false; 1024 // if autoHover is requested 1025 if (slider.settings.tickerHover) { 1026 if (slider.usingCSS) { 1027 idx = slider.settings.mode === 'horizontal' ? 4 : 5; 1028 slider.viewport.hover(function() { 1029 transform = el.css('-' + slider.cssPrefix + '-transform'); 1030 value = parseFloat(transform.split(',')[idx]); 1031 setPositionProperty(value, 'reset', 0); 1032 }, function() { 1033 totalDimens = 0; 1034 slider.children.each(function(index) { 1035 totalDimens += slider.settings.mode === 'horizontal' ? $(this).outerWidth(true) : $(this).outerHeight(true); 1036 }); 1037 // calculate the speed ratio (used to determine the new speed to finish the paused animation) 1038 ratio = slider.settings.speed / totalDimens; 1039 // determine which property to use 1040 property = slider.settings.mode === 'horizontal' ? 'left' : 'top'; 1041 // calculate the new speed 1042 newSpeed = ratio * (totalDimens - (Math.abs(parseInt(value)))); 1043 tickerLoop(newSpeed); 1044 }); 1045 } else { 1046 // on el hover 1047 slider.viewport.hover(function() { 1048 el.stop(true); 1049 }, function() { 1050 // calculate the total width of children (used to calculate the speed ratio) 1051 totalDimens = 0; 1052 slider.children.each(function(index) { 1053 totalDimens += slider.settings.mode === 'horizontal' ? $(this).outerWidth(true) : $(this).outerHeight(true); 1054 }); 1055 // calculate the speed ratio (used to determine the new speed to finish the paused animation) 1056 ratio = slider.settings.speed / totalDimens; 1057 // determine which property to use 1058 property = slider.settings.mode === 'horizontal' ? 'left' : 'top'; 1059 // calculate the new speed 1060 newSpeed = ratio * (totalDimens - (Math.abs(parseInt(el.css(property))))); 1061 tickerLoop(newSpeed); 1062 }); 1063 } 1064 } 1065 // start the ticker loop 1066 tickerLoop(); 1067 }; 1068 1069 /** 1070 * Runs a continuous loop, news ticker-style 1071 */ 1072 var tickerLoop = function(resumeSpeed) { 1073 var speed = resumeSpeed ? resumeSpeed : slider.settings.speed, 1074 position = {left: 0, top: 0}, 1075 reset = {left: 0, top: 0}, 1076 animateProperty, resetValue, params; 1077 1078 // if "next" animate left position to last child, then reset left to 0 1079 if (slider.settings.autoDirection === 'next') { 1080 position = el.find('.bx-clone').first().position(); 1081 // if "prev" animate left position to 0, then reset left to first non-clone child 1082 } else { 1083 reset = slider.children.first().position(); 1084 } 1085 animateProperty = slider.settings.mode === 'horizontal' ? -position.left : -position.top; 1086 resetValue = slider.settings.mode === 'horizontal' ? -reset.left : -reset.top; 1087 params = {resetValue: resetValue}; 1088 setPositionProperty(animateProperty, 'ticker', speed, params); 1089 }; 1090 1091 /** 1092 * Check if el is on screen 1093 */ 1094 var isOnScreen = function(el) { 1095 var win = $(window), 1096 viewport = { 1097 top: win.scrollTop(), 1098 left: win.scrollLeft() 1099 }, 1100 bounds = el.offset(); 1101 1102 viewport.right = viewport.left + win.width(); 1103 viewport.bottom = viewport.top + win.height(); 1104 bounds.right = bounds.left + el.outerWidth(); 1105 bounds.bottom = bounds.top + el.outerHeight(); 1106 1107 return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); 1108 }; 1109 1110 /** 1111 * Initializes keyboard events 1112 */ 1113 var keyPress = function(e) { 1114 var activeElementTag = document.activeElement.tagName.toLowerCase(), 1115 tagFilters = 'input|textarea', 1116 p = new RegExp(activeElementTag,['i']), 1117 result = p.exec(tagFilters); 1118 1119 if (result == null && isOnScreen(el)) { 1120 if (e.keyCode === 39) { 1121 clickNextBind(e); 1122 return false; 1123 } else if (e.keyCode === 37) { 1124 clickPrevBind(e); 1125 return false; 1126 } 1127 } 1128 }; 1129 1130 /** 1131 * Initializes touch events 1132 */ 1133 var initTouch = function() { 1134 // initialize object to contain all touch values 1135 slider.touch = { 1136 start: {x: 0, y: 0}, 1137 end: {x: 0, y: 0} 1138 }; 1139 slider.viewport.bind('touchstart MSPointerDown pointerdown', onTouchStart); 1140 1141 //for browsers that have implemented pointer events and fire a click after 1142 //every pointerup regardless of whether pointerup is on same screen location as pointerdown or not 1143 slider.viewport.on('click', '.bxslider a', function(e) { 1144 if (slider.viewport.hasClass('click-disabled')) { 1145 e.preventDefault(); 1146 slider.viewport.removeClass('click-disabled'); 1147 } 1148 }); 1149 }; 1150 1151 /** 1152 * Event handler for "touchstart" 1153 * 1154 * @param e (event) 1155 * - DOM event object 1156 */ 1157 /** 1158 * Event handler for "touchstart" 1159 * 1160 * @param e (event) 1161 * - DOM event object 1162 */ 1163 var onTouchStart = function(e) { 1164 // watch only for left mouse, touch contact and pen contact 1165 // touchstart event object doesn`t have button property 1166 if ( (e.type !== 'touchstart' && e.button !== 0) || ( $(event.target).hasClass('alink'))) { 1167 1168 return; 1169 } 1170 //e.preventDefault(); 1171 //disable slider controls while user is interacting with slides to avoid slider freeze that happens on touch devices when a slide swipe happens immediately after interacting with slider controls 1172 slider.controls.el.addClass('disabled'); 1173 1174 if (slider.working) { 1175 slider.controls.el.removeClass('disabled'); 1176 } else { 1177 // record the original position when touch starts 1178 slider.touch.originalPos = el.position(); 1179 parentHorizontalPadding = slider.viewport.innerWidth() - slider.viewport.width(); 1180 1181 // In case slider parent have horizontal padding recalculate position 1182 if(parentHorizontalPadding > 0) 1183 slider.touch.originalPos.left -= (parentHorizontalPadding/2) 1184 1185 1186 var orig = e.originalEvent, 1187 touchPoints = (typeof orig.changedTouches !== 'undefined') ? orig.changedTouches : [orig]; 1188 var chromePointerEvents = typeof PointerEvent === 'function'; 1189 if (chromePointerEvents) { 1190 if (orig.pointerId === undefined) { 1191 return; 1192 } 1193 } 1194 // record the starting touch x, y coordinates 1195 slider.touch.start.x = touchPoints[0].pageX; 1196 slider.touch.start.y = touchPoints[0].pageY; 1197 1198 if (e.target.setPointerCapture) { 1199 slider.pointerId = orig.pointerId; 1200 e.target.setPointerCapture(slider.pointerId); 1201 } 1202 // store original event data for click fixation 1203 slider.originalClickTarget = orig.originalTarget || orig.target; 1204 slider.originalClickButton = orig.button; 1205 slider.originalClickButtons = orig.buttons; 1206 slider.originalEventType = orig.type; 1207 // at this moment we don`t know what it is click or swipe 1208 slider.hasMove = false; 1209 // on a "touchmove" event to the viewport 1210 slider.viewport.on('touchmove MSPointerMove pointermove', onTouchMove); 1211 // on a "touchend" event to the viewport 1212 slider.viewport.on('touchend MSPointerUp pointerup', onTouchEnd); 1213 slider.viewport.on('MSPointerCancel pointercancel', onPointerCancel); 1214 } 1215 }; 1216 1217 /** 1218 * Cancel Pointer for Windows Phone 1219 * 1220 * @param e (event) 1221 * - DOM event object 1222 */ 1223 var onPointerCancel = function(e) { 1224 e.preventDefault(); 1225 /* onPointerCancel handler is needed to deal with situations when a touchend 1226 doesn't fire after a touchstart (this happens on windows phones only) */ 1227 setPositionProperty(slider.touch.originalPos.left, 'reset', 0); 1228 1229 //remove handlers 1230 slider.controls.el.removeClass('disabled'); 1231 slider.viewport.off('MSPointerCancel pointercancel', onPointerCancel); 1232 slider.viewport.off('touchmove MSPointerMove pointermove', onTouchMove); 1233 slider.viewport.off('touchend MSPointerUp pointerup', onTouchEnd); 1234 if (slider.viewport.get(0).releasePointerCapture) { 1235 try { 1236 slider.viewport.get(0).releasePointerCapture(slider.pointerId); 1237 } 1238 catch (e) { 1239 //Handle the error if you wish. 1240 } 1241 } 1242 1243 }; 1244 1245 /** 1246 * Event handler for "touchmove" 1247 * 1248 * @param e (event) 1249 * - DOM event object 1250 */ 1251 var onTouchMove = function(e) { 1252 1253 if($(e.target).parent()[0].hasAttribute('href') && e.type=='pointermove' && ! ('ontouchstart' in window)){ 1254 var href=$(e.target).parent().attr('href'); 1255 $(e.target).parent().attr('data-href',href); 1256 $(e.target).parent().removeAttr('href'); 1257 } 1258 1259 var orig = e.originalEvent, 1260 touchPoints = (typeof orig.changedTouches !== 'undefined') ? orig.changedTouches : [orig], 1261 // if scrolling on y axis, do not prevent default 1262 xMovement = Math.abs(touchPoints[0].pageX - slider.touch.start.x), 1263 yMovement = Math.abs(touchPoints[0].pageY - slider.touch.start.y), 1264 value = 0, 1265 change = 0; 1266 // this is swipe 1267 slider.hasMove = true; 1268 1269 // x axis swipe 1270 if ((xMovement * 3) > yMovement && slider.settings.preventDefaultSwipeX) { 1271 if (e.hasOwnProperty('cancelable') && e.cancelable) { 1272 e.preventDefault(); 1273 } 1274 // y axis swipe 1275 } else if ((yMovement * 3) > xMovement && slider.settings.preventDefaultSwipeY) { 1276 if (e.hasOwnProperty('cancelable') && e.cancelable) { 1277 e.preventDefault(); 1278 } 1279 } 1280 if (e.type !== 'touchmove') { 1281 if (e.hasOwnProperty('cancelable') && e.cancelable) { 1282 e.preventDefault(); 1283 } 1284 } 1285 1286 if (slider.settings.mode !== 'fade' && slider.settings.oneToOneTouch) { 1287 // if horizontal, drag along x axis 1288 if (slider.settings.mode === 'horizontal') { 1289 change = touchPoints[0].pageX - slider.touch.start.x; 1290 value = slider.touch.originalPos.left + change; 1291 // if vertical, drag along y axis 1292 } else { 1293 change = touchPoints[0].pageY - slider.touch.start.y; 1294 value = slider.touch.originalPos.top + change; 1295 } 1296 setPositionProperty(value, 'reset', 0); 1297 } 1298 }; 1299 1300 /** 1301 * Event handler for "touchend" 1302 * 1303 * @param e (event) 1304 * - DOM event object 1305 */ 1306 var onTouchEnd = function(e) { 1307 e.preventDefault(); 1308 slider.viewport.off('touchmove MSPointerMove pointermove', onTouchMove); 1309 //enable slider controls as soon as user stops interacing with slides 1310 slider.controls.el.removeClass('disabled'); 1311 var orig = e.originalEvent, 1312 touchPoints = (typeof orig.changedTouches !== 'undefined') ? orig.changedTouches : [orig], 1313 value = 0, 1314 distance = 0; 1315 // record end x, y positions 1316 slider.touch.end.x = touchPoints[0].pageX; 1317 slider.touch.end.y = touchPoints[0].pageY; 1318 // if fade mode, check if absolute x distance clears the threshold 1319 if (slider.settings.mode === 'fade') { 1320 distance = Math.abs(slider.touch.start.x - slider.touch.end.x); 1321 if (distance >= slider.settings.swipeThreshold) { 1322 if (slider.touch.start.x > slider.touch.end.x) { 1323 el.goToNextSlide(); 1324 } else { 1325 el.goToPrevSlide(); 1326 } 1327 el.stopAuto(); 1328 } 1329 // not fade mode 1330 } else { 1331 // calculate distance and el's animate property 1332 if (slider.settings.mode === 'horizontal') { 1333 distance = slider.touch.end.x - slider.touch.start.x; 1334 value = slider.touch.originalPos.left; 1335 } else { 1336 distance = slider.touch.end.y - slider.touch.start.y; 1337 value = slider.touch.originalPos.top; 1338 } 1339 // if not infinite loop and first / last slide, do not attempt a slide transition 1340 if (!slider.settings.infiniteLoop && ((slider.active.index === 0 && distance > 0) || (slider.active.last && distance < 0))) { 1341 setPositionProperty(value, 'reset', 200); 1342 } else { 1343 // check if distance clears threshold 1344 if (Math.abs(distance) >= slider.settings.swipeThreshold) { 1345 if (distance < 0) { 1346 el.goToNextSlide(); 1347 } else { 1348 el.goToPrevSlide(); 1349 } 1350 el.stopAuto(); 1351 } else { 1352 // el.animate(property, 200); 1353 setPositionProperty(value, 'reset', 200); 1354 } 1355 } 1356 } 1357 slider.viewport.off('touchend MSPointerUp pointerup', onTouchEnd); 1358 1359 if (slider.viewport.get(0).releasePointerCapture) { 1360 slider.viewport.get(0).releasePointerCapture(slider.pointerId); 1361 } 1362 // if slider had swipe with left mouse, touch contact and pen contact 1363 if (slider.hasMove === false && (slider.originalClickButton === 0 || slider.originalEventType === 'touchstart')) { 1364 // trigger click event (fix for Firefox59 and PointerEvent standard compatibility) 1365 if ('ontouchstart' in window) { 1366 $(slider.originalClickTarget).trigger({ 1367 type: 'click', 1368 button: slider.originalClickButton, 1369 buttons: slider.originalClickButtons 1370 }); 1371 } 1372 }
1373 else if( slider.touch.start.x==slider.touch.end.x){ 1374 1375 if ( ('ontouchstart' in window) || (/Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor) && navigator.appVersion.indexOf("Win")!=-1)) { 1376 1377 if((/Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor) && navigator.appVersion.indexOf("Win")!=-1)){ 1378 if( (! $(e.target).parent()[0].hasAttribute('href') || $(e.target).parent().attr('href')=='') && $(e.target).parent().attr('data-href')!=''){ 1379 1380 var href=$(e.target).parent().attr('data-href'); 1381 $(e.target).parent().attr('href',href); 1382 1383 } 1384 } 1385 1386 if( (/Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor) && navigator.appVersion.indexOf("Win")!=-1) && ( $(e.target).parent()[0].hasAttribute('target') && $(e.target).parent().attr('target')=='_blank')){ 1387 1388 1389 } 1390 else{ 1391 1392 1393 $(slider.originalClickTarget).trigger({ 1394 type: 'click', 1395 button: slider.originalClickButton, 1396 buttons: slider.originalClickButtons 1397 }); 1398 } 1399 1400 } 1401 } 1402 else{ 1403 1404 setTimeout(function(){ 1405 if (slider.settings.mode === 'fade') { 1406 distance = Math.abs(slider.touch.start.x - slider.touch.end.x); 1407 1408 // not fade mode 1409 } else { 1410 // calculate distance and el's animate property 1411 if (slider.settings.mode === 'horizontal') { 1412 distance = slider.touch.end.x - slider.touch.start.x; 1413 value = slider.touch.originalPos.left; 1414 } else { 1415 distance = slider.touch.end.y - slider.touch.start.y; 1416 value = slider.touch.originalPos.top; 1417 } 1418 // if not infinite loop and first / last slide, do not attempt a slide transition 1419 if (!slider.settings.infiniteLoop && ((slider.active.index === 0 && distance > 0) || (slider.active.last && distance < 0))) { 1420 setPositionProperty(value, 'reset', 200); 1421 } else { 1422 // check if distance clears threshold 1423 if (Math.abs(distance) >= slider.settings.swipeThreshold) { 1424 if (distance < 0) { 1425 el.goToNextSlide(); 1426 } else { 1427 el.goToPrevSlide(); 1428 } 1429 el.stopAuto(); 1430 } else { 1431 if((distance>=-10 && distance<=0) || ( distance>=0 && distance<=5)){ 1432 1433 if ('ontouchstart' in window) { 1434 $(slider.originalClickTarget).trigger({ 1435 type: 'click', 1436 button: slider.originalClickButton, 1437 buttons: slider.originalClickButtons 1438 }); 1439 } 1440 } 1441 1442 } 1443 } 1444 } 1445 }, 5); 1446 1447 } 1448 1449 if (slider.hasMove && e.type=='pointerup' && !('ontouchstart' in window)){ 1450 1451 if($(e.target).parent()[0].hasAttribute('data-href')){ 1452 setTimeout(function(){ 1453 var href=$(e.target).parent().attr('data-href'); 1454 $(e.target).parent().attr('href',href); 1455 }, 5); 1456 } 1457 } 1458 }; 1459 1460 /** 1461 * Window resize event callback 1462 */ 1463 var resizeWindow = function(e) { 1464 // don't do anything if slider isn't initialized. 1465 if (!slider.initialized) { return; } 1466 // Delay if slider working. 1467 if (slider.working) { 1468 window.setTimeout(resizeWindow, 10); 1469 } else { 1470 // get the new window dimens (again, thank you IE) 1471 var windowWidthNew = $(window).width(), 1472 windowHeightNew = $(window).height(); 1473 // make sure that it is a true window resize 1474 // *we must check this because our dinosaur friend IE fires a window resize event when certain DOM elements 1475 // are resized. Can you just die already?* 1476 if (windowWidth !== windowWidthNew || windowHeight !== windowHeightNew
1476) { 1477 // set the new window dimens 1478 windowWidth = windowWidthNew; 1479 windowHeight = windowHeightNew; 1480 // update all dynamic elements 1481 el.redrawSlider(); 1482 // Call user resize handler 1483 slider.settings.onSliderResize.call(el, slider.active.index); 1484 } 1485 } 1486 }; 1487 1488 /** 1489 * Adds an aria-hidden=true attribute to each element 1490 * 1491 * @param startVisibleIndex (int) 1492 * - the first visible element's index 1493 */ 1494 var applyAriaHiddenAttributes = function(startVisibleIndex) { 1495 var numberOfSlidesShowing = getNumberSlidesShowing(); 1496 // only apply attributes if the setting is enabled and not in ticker mode 1497 if (slider.settings.ariaHidden && !slider.settings.ticker) { 1498 // add aria-hidden=true to all elements 1499 slider.children.attr('aria-hidden', 'true'); 1500 // get the visible elements and change to aria-hidden=false 1501 slider.children.slice(startVisibleIndex, startVisibleIndex + numberOfSlidesShowing).attr('aria-hidden', 'false'); 1502 } 1503 }; 1504 1505 /** 1506 * =================================================================================== 1507 * = PUBLIC FUNCTIONS 1508 * =================================================================================== 1509 */ 1510 1511 /** 1512 * Performs slide transition to the specified slide 1513 * 1514 * @param slideIndex (int) 1515 * - the destination slide's index (zero-based) 1516 * 1517 * @param direction (string) 1518 * - INTERNAL USE ONLY - the direction of travel ("prev" / "next") 1519 */ 1520 el.goToSlide = function(slideIndex, direction) { 1521 // onSlideBefore, onSlideNext, onSlidePrev callbacks 1522 // Allow transition canceling based on returned value 1523 var performTransition = true, 1524 moveBy = 0, 1525 position = {left: 0, top: 0}, 1526 lastChild = null, 1527 lastShowingIndex, eq, value, requestEl; 1528 1529 // if plugin is currently in motion, ignore request 1530 if (slider.working || slider.active.index === slideIndex) { return; } 1531 // declare that plugin is in motion 1532 slider.working = true; 1533 // store the old index 1534 slider.oldIndex = slider.active.index; 1535 // if slideIndex is less than zero, set active index to last child (this happens during infinite loop) 1536 if (slideIndex < 0) { 1537 slider.active.index = getPagerQty() - 1; 1538 // if slideIndex is greater than children length, set active index to 0 (this happens during infinite loop) 1539 } else if (slideIndex >= getPagerQty()) { 1540 slider.active.index = 0; 1541 // set active index to requested slide 1542 } else { 1543 slider.active.index = slideIndex; 1544 } 1545 1546 performTransition = slider.settings.onSlideBefore.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 1547 1548 if (typeof (performTransition) !== 'undefined' && !performTransition) { 1549 slider.active.index = slider.oldIndex; // restore old index 1550 slider.working = false; // is not in motion 1551 return; 1552 } 1553 if (direction === 'next') { 1554 // Prevent canceling in future functions or lack there-of from negating previous commands to cancel 1555 if (!slider.settings.onSlideNext.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index)) { 1556 performTransition = false; 1557 } 1558 } else if (direction === 'prev') { 1559 // Prevent canceling in future functions or lack there-of from negating previous commands to cancel 1560 if (!slider.settings.onSlidePrev.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index)) { 1561 performTransition = false; 1562 } 1563 } 1564 1565 // If transitions canceled, reset and return 1566 if (typeof (performTransition) !== 'undefined' && !performTransition) { 1567 slider.active.index = slider.oldIndex; // restore old index 1568 slider.working = false; // is not in motion 1569 return; 1570 } 1571 1572 // check if last slide 1573 slider.active.last = slider.active.index >= getPagerQty() - 1; 1574 // update the pager with active class 1575 if (slider.settings.pager || slider.settings.pagerCustom) { updatePagerActive(slider.active.index); } 1576 // // check for direction control update 1577 if (slider.settings.controls) { updateDirectionControls(); } 1578 // if slider is set to mode: "fade" 1579 if (slider.settings.mode === 'fade') { 1580 // if adaptiveHeight is true and next height is different from current height, animate to the new height 1581 if (slider.settings.adaptiveHeight && slider.viewport.height() !== getViewportHe
vendor: 9,116 bytes, lines 1581-1810
1581ight()) { 1582 slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); 1583 } 1584 // fade out the visible child and reset its z-index value 1585 slider.children.filter(':visible').fadeOut(slider.settings.speed).css({zIndex: 0}); 1586 // fade in the newly requested slide 1587 slider.children.eq(slider.active.index).css('zIndex', slider.settings.slideZIndex + 1).fadeIn(slider.settings.speed, function() { 1588 $(this).css('zIndex', slider.settings.slideZIndex); 1589 updateAfterSlideTransition(); 1590 }); 1591 // slider mode is not "fade" 1592 } else { 1593 // if adaptiveHeight is true and next height is different from current height, animate to the new height 1594 if (slider.settings.adaptiveHeight && slider.viewport.height() !== getViewportHeight()) { 1595 slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); 1596 } 1597 // if carousel and not infinite loop 1598 if (!slider.settings.infiniteLoop && slider.carousel && slider.active.last) { 1599 if (slider.settings.mode === 'horizontal') { 1600 // get the last child position 1601 lastChild = slider.children.eq(slider.children.length - 1); 1602 position = lastChild.position(); 1603 // calculate the position of the last slide 1604 moveBy = slider.viewport.width() - lastChild.outerWidth(); 1605 } else { 1606 // get last showing index position 1607 lastShowingIndex = slider.children.length - slider.settings.minSlides; 1608 position = slider.children.eq(lastShowingIndex).position(); 1609 } 1610 // horizontal carousel, going previous while on first slide (infiniteLoop mode) 1611 } else if (slider.carousel && slider.active.last && direction === 'prev') { 1612 // get the last child position 1613 eq = slider.settings.moveSlides === 1 ? slider.settings.maxSlides - getMoveBy() : ((getPagerQty() - 1) * getMoveBy()) - (slider.children.length - slider.settings.maxSlides); 1614 lastChild = el.children('.bx-clone').eq(eq); 1615 position = lastChild.position(); 1616 // if infinite loop and "Next" is clicked on the last slide 1617 } else if (direction === 'next' && slider.active.index === 0) { 1618 // get the last clone position 1619 position = el.find('> .bx-clone').eq(slider.settings.maxSlides).position(); 1620 slider.active.last = false; 1621 // normal non-zero requests 1622 } else if (slideIndex >= 0) { 1623 requestEl = slideIndex * getMoveBy(); 1624 position = slider.children.eq(requestEl).position(); 1625 } 1626 1627 /* If the position doesn't exist 1628 * (e.g. if you destroy the slider on a next click), 1629 * it doesn't throw an error. 1630 */ 1631 if (typeof (position) !== undefined) { 1632 value = slider.settings.mode === 'horizontal' ? -(position.left - moveBy) : -position.top; 1633 // plugin values to be animated 1634 setPositionProperty(value, 'slide', slider.settings.speed); 1635 } 1636 } 1637 if (slider.settings.ariaHidden) { applyAriaHiddenAttributes(slider.active.index * getMoveBy()); } 1638 }; 1639 1640 /** 1641 * Transitions to the next slide in the show 1642 */ 1643 el.goToNextSlide = function() { 1644 // if infiniteLoop is false and last page is showing, disregard call 1645 if (!slider.settings.infiniteLoop && slider.active.last) { return; } 1646 var pagerIndex = parseInt(slider.active.index) + 1; 1647 el.goToSlide(pagerIndex, 'next'); 1648 }; 1649 1650 /** 1651 * Transitions to the prev slide in the show 1652 */ 1653 el.goToPrevSlide = function() { 1654 // if infiniteLoop is false and last page is showing, disregard call 1655 if (!slider.settings.infiniteLoop && slider.active.index === 0) { return; } 1656 var pagerIndex = parseInt(slider.active.index) - 1; 1657 el.goToSlide(pagerIndex, 'prev'); 1658 }; 1659 1660 /** 1661 * Starts the auto show 1662 * 1663 * @param preventControlUpdate (boolean) 1664 * - if true, auto controls state will not be updated 1665 */ 1666 el.startAuto = function(preventControlUpdate) { 1667 // if an interval already exists, disregard call 1668 if (slider.interval) { return; } 1669 // create an interval 1670 slider.interval = setInterval(function() { 1671 if (slider.settings.autoDirection === 'next') { 1672 el.goToNextSlide(); 1673 } else { 1674 el.goToPrevSlide(); 1675 } 1676 }, slider.settings.pause); 1677 // if auto controls are displayed and preventControlUpdate is not true 1678 if (slider.settings.autoControls && preventControlUpdate !== true) { updateAutoControls('stop'); } 1679 }; 1680 1681 /** 1682 * Stops the auto show 1683 * 1684 * @param preventControlUpdate (boolean) 1685 * - if true, auto controls state will not be updated 1686 */ 1687 el.stopAuto = function(preventControlUpdate) { 1688 // if no interval exists, disregard call 1689 if (!slider.interval) { return; } 1690 // clear the interval 1691 clearInterval(slider.interval); 1692 slider.interval = null; 1693 // if auto controls are displayed and preventControlUpdate is not true 1694 if (slider.settings.autoControls && preventControlUpdate !== true) { updateAutoControls('start'); } 1695 }; 1696 1697 /** 1698 * Returns current slide index (zero-based) 1699 */ 1700 el.getCurrentSlide = function() { 1701 return slider.active.index; 1702 }; 1703 1704 /** 1705 * Returns current slide element 1706 */ 1707 el.getCurrentSlideElement = function() { 1708 return slider.children.eq(slider.active.index); 1709 }; 1710 1711 /** 1712 * Returns a slide element 1713 * @param index (int) 1714 * - The index (zero-based) of the element you want returned. 1715 */ 1716 el.getSlideElement = function(index) { 1717 return slider.children.eq(index); 1718 }; 1719 1720 /** 1721 * Returns number of slides in show 1722 */ 1723 el.getSlideCount = function() { 1724 return slider.children.length; 1725 }; 1726 1727 /** 1728 * Return slider.working variable 1729 */ 1730 el.isWorking = function() { 1731 return slider.working; 1732 }; 1733 1734 /** 1735 * Update all dynamic slider elements 1736 */ 1737 el.redrawSlider = function() { 1738 // resize all children in ratio to new screen size 1739 slider.children.add(el.find('.bx-clone')).outerWidth(getSlideWidth()); 1740 // adjust the height 1741 slider.viewport.css('height', getViewportHeight()); 1742 // update the slide position 1743 if (!slider.settings.ticker) { setSlidePosition(); } 1744 // if active.last was true before the screen resize, we want 1745 // to keep it last no matter what screen size we end on 1746 if (slider.active.last) { slider.active.index = getPagerQty() - 1; } 1747 // if the active index (page) no longer exists due to the resize, simply set the index as last 1748 if (slider.active.index >= getPagerQty()) { slider.active.last = true; } 1749 // if a pager is being displayed and a custom pager is not being used, update it 1750 if (slider.settings.pager && !slider.settings.pagerCustom) { 1751 populatePager(); 1752 updatePagerActive(slider.active.index); 1753 } 1754 if (slider.settings.ariaHidden) { applyAriaHiddenAttributes(slider.active.index * getMoveBy()); } 1755 }; 1756 1757 /** 1758 * Destroy the current instance of the slider (revert everything back to original state) 1759 */ 1760 el.destroySlider = function() { 1761 // don't do anything if slider has already been destroyed 1762 if (!slider.initialized) { return; } 1763 slider.initialized = false; 1764 $('.bx-clone', this).remove(); 1765 slider.children.each(function() { 1766 if ($(this).data('origStyle') !== undefined) { 1767 $(this).attr('style', $(this).data('origStyle')); 1768 } else { 1769 $(this).removeAttr('style'); 1770 } 1771 }); 1772 if ($(this).data('origStyle') !== undefined) { 1773 this.attr('style', $(this).data('origStyle')); 1774 } else { 1775 $(this).removeAttr('style'); 1776 } 1777 $(this).unwrap().unwrap(); 1778 if (slider.controls.el) { slider.controls.el.remove(); } 1779 if (slider.controls.next) { slider.controls.next.remove(); } 1780 if (slider.controls.prev) { slider.controls.prev.remove(); } 1781 if (slider.pagerEl && slider.settings.controls && !slider.settings.pagerCustom) { slider.pagerEl.remove(); } 1782 $('.bx-caption', this).remove(); 1783 if (slider.controls.autoEl) { slider.controls.autoEl.remove(); } 1784 clearInterval(slider.interval); 1785 if (slider.settings.responsive) { $(window).unbind('resize', resizeWindow); } 1786 if (slider.settings.keyboardEnabled) { $(document).unbind('keydown', keyPress); } 1787 //remove self reference in data 1788 $(this).removeData('bxSliderx'); 1789 }; 1790 1791 /** 1792 * Reload the slider (revert all DOM changes, and re-initialize) 1793 */ 1794 el.reloadSlider = function(settings) { 1795 if (settings !== undefined) { options = settings; } 1796 el.destroySlider(); 1797 init(); 1798 //store reference to self in order to access public functions later 1799 $(el).data('bxSliderx', this); 1800 }; 1801 1802 init(); 1803 1804 $(el).data('bxSliderx', this); 1805 1806 // returns the current jQuery object 1807 return this; 1808 }; 1809 1810})(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.