vendor: 37,895 bytes, lines 1-925
1/** 2 * bxSlider v4.2.12 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: true, 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.bxSlider = 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).bxSlider(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('bxSlider')) { 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('bxSlider')) { 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 }); 183 184 // perform all DOM / CSS modifications 185 setup(); 186 }; 187 188 /** 189 * Performs all DOM and CSS modifications 190 */ 191 var setup = function() { 192 var preloadSelector = slider.children.eq(slider.settings.startSlide); // set the default preload selector (visible) 193 194 // wrap el in a wrapper 195 el.wrap('<div class="' + slider.settings.wrapperClass + '"><div class="bx-viewport"></div></div>'); 196 // store a namespace reference to .bx-viewport 197 slider.viewport = el.parent(); 198 199 // add aria-live if the setting is enabled and ticker mode is disabled 200 if (slider.settings.ariaLive && !slider.settings.ticker) { 201 slider.viewport.attr('aria-live', 'polite'); 202 } 203 // add a loading div to display while images are loading 204 slider.loader = $('<div class="bx-loading" />'); 205 slider.viewport.prepend(slider.loader); 206 // set el to a massive width, to hold any needed slides 207 // also strip any margin and padding from el 208 el.css({ 209 width: slider.settings.mode === 'horizontal' ? (slider.children.length * 1000 + 215) + '%' : 'auto', 210 position: 'relative' 211 }); 212 // if using CSS, add the easing property 213 if (slider.usingCSS && slider.settings.easing) { 214 el.css('-' + slider.cssPrefix + '-transition-timing-function', slider.settings.easing); 215 // if not using CSS and no easing value was supplied, use the default JS animation easing (swing) 216 } else if (!slider.settings.easing) { 217 slider.settings.easing = 'swing'; 218 } 219 // make modifications to the viewport (.bx-viewport) 220 slider.viewport.css({ 221 width: '100%', 222 overflow: 'hidden', 223 position: 'relative' 224 }); 225 slider.viewport.parent().css({ 226 maxWidth: getViewportMaxWidth() 227 }); 228 // apply css to all slider children 229 slider.children.css({ 230 float: slider.settings.mode === 'horizontal' ? 'left' : 'none', 231 listStyle: 'none', 232 position: 'relative' 233 }); 234 // apply the calculated width after the float is applied to prevent scrollbar interference 235 slider.children.css('width', getSlideWidth()); 236 slider.children.css("height", getSlideHeight()); 237 238 // if slideMargin is supplied, add the css 239 if (slider.settings.mode === 'horizontal' && slider.settings.slideMargin > 0) { slider.children.css('marginRight', slider.settings.slideMargin); } 240 if (slider.settings.mode === 'vertical' && slider.settings.slideMargin > 0) { slider.children.css('marginBottom', slider.settings.slideMargin); } 241 // if "fade" mode, add positioning and z-index CSS 242 if (slider.settings.mode === 'fade') { 243 slider.children.css({ 244 position: 'absolute', 245 zIndex: 0, 246 display: 'none' 247 }); 248 // prepare the z-index on the showing element 249 slider.children.eq(slider.settings.startSlide).css({zIndex: slider.settings.slideZIndex, display: 'block'}); 250 } 251 // create an element to contain all slider controls (pager, start / stop, etc) 252 slider.controls.el = $('<div class="bx-controls" />'); 253 // if captions are requested, add them 254 if (slider.settings.captions) { appendCaptions(); } 255 // check if startSlide is last slide 256 slider.active.last = slider.settings.startSlide === getPagerQty() - 1; 257 // if video is true, set up the fitVids plugin 258 if (slider.settings.video) { el.fitVids(); } 259 if (slider.settings.preloadImages === 'all' || slider.settings.ticker) { preloadSelector = slider.children; } 260 // only check for control addition if not in "ticker" mode 261 if (!slider.settings.ticker) { 262 // if controls are requested, add them 263 if (slider.settings.controls) { appendControls(); } 264 // if auto is true, and auto controls are requested, add them 265 if (slider.settings.auto && slider.settings.autoControls) { appendControlsAuto(); } 266 // if pager is requested, add it 267 if (slider.settings.pager) { appendPager(); } 268 // if any control option is requested, add the controls wrapper 269 if (slider.settings.controls || slider.settings.autoControls || slider.settings.pager) { slider.viewport.after(slider.controls.el); } 270 // if ticker mode, do not allow a pager 271 } else { 272 slider.settings.pager = false; 273 } 274 loadElements(preloadSelector, start); 275 }; 276 277 var loadElements = function(selector, callback) { 278 var total = selector.find('img:not([src=""]), iframe').length, 279 count = 0; 280 if (total === 0) { 281 callback(); 282 return; 283 } 284 selector.find('img:not([src=""]), iframe').each(function() { 285 $(this).one('load error', function() { 286 if (++count === total) { callback(); } 287 }).each(function() { 288 if (this.complete) { $(this).trigger('load'); } 289 }); 290 }); 291 }; 292 293 /** 294 * Start the slider 295 */ 296 var start = function() { 297 // if infinite loop, prepare additional slides 298 if (slider.settings.infiniteLoop && slider.settings.mode !== 'fade' && !slider.settings.ticker) { 299 var slice = slider.settings.mode === 'vertical' ? slider.settings.minSlides : slider.settings.maxSlides, 300 sliceAppend = slider.children.slice(0, slice).clone(true).addClass('bx-clone'), 301 slicePrepend = slider.children.slice(-slice).clone(true).addClass('bx-clone'); 302 if (slider.settings.ariaHidden) { 303 sliceAppend.attr('aria-hidden', true); 304 slicePrepend.attr('aria-hidden', true); 305 } 306 el.append(sliceAppend).prepend(slicePrepend); 307 } 308 // remove the loading DOM element 309 slider.loader.remove(); 310 // set the left / top position of "el" 311 setSlidePosition(); 312 // if "vertical" mode, always use adaptiveHeight to prevent odd behavior 313 if (slider.settings.mode === 'vertical') { slider.settings.adaptiveHeight = true; } 314 // set the viewport height 315 slider.viewport.height(getViewportHeight()); 316 // make sure everything is positioned just right (same as a window resize) 317 el.redrawSlider(); 318 // onSliderLoad callback 319 slider.settings.onSliderLoad.call(el, slider.active.index); 320 // slider has been fully initialized 321 slider.initialized = true; 322 // bind the resize call to the window 323 if (slider.settings.responsive) { $(window).bind('resize', resizeWindow); } 324 // if auto is true and has more than 1 page, start the show 325 if (slider.settings.auto && slider.settings.autoStart && (getPagerQty() > 1 || slider.settings.autoSlideForOnePage)) { initAuto(); } 326 // if ticker is true, start the ticker 327 if (slider.settings.ticker) { initTicker(); } 328 // if pager is requested, make the appropriate pager link active 329 if (slider.settings.pager) { updatePagerActive(slider.settings.startSlide); } 330 // check for any updates to the controls (like hideControlOnEnd updates) 331 if (slider.settings.controls) { updateDirectionControls(); } 332 // if touchEnabled is true, setup the touch events 333 if (slider.settings.touchEnabled && !slider.settings.ticker) { initTouch(); } 334 // if keyboardEnabled is true, setup the keyboard events 335 if (slider.settings.keyboardEnabled && !slider.settings.ticker) { 336 $(document).keydown(keyPress); 337 } 338 }; 339 340 /** 341 * Returns the calculated height of the viewport, used to determine either adaptiveHeight or the maxHeight value 342 */ 343 var getViewportHeight = function() { 344 var height = 0; 345 // first determine which children (slides) should be used in our height calculation 346 var children = $(); 347 // if mode is not "vertical" and adaptiveHeight is false, include all children 348 if (slider.settings.mode !== 'vertical' && !slider.settings.adaptiveHeight) { 349 children = slider.children; 350 } else { 351 // if not carousel, return the single active child 352 if (!slider.carousel) { 353 children = slider.children.eq(slider.active.index); 354 // if carousel, return a slice of children 355 } else { 356 // get the individual slide index 357 var currentIndex = slider.settings.moveSlides === 1 ? slider.active.index : slider.active.index * getMoveBy(); 358 // add the current slide to the children 359 children = slider.children.eq(currentIndex); 360 // cycle through the remaining "showing" slides 361 for (i = 1; i <= slider.settings.maxSlides - 1; i++) { 362 // if looped back to the start 363 if (currentIndex + i >= slider.children.length) { 364 children = children.add(slider.children.eq(i - 1)); 365 } else { 366 children = children.add(slider.children.eq(currentIndex + i)); 367 } 368 } 369 } 370 } 371 // if "vertical" mode, calculate the sum of the heights of the children 372 if (slider.settings.mode === 'vertical') { 373 children.each(function(index) { 374 height += $(this).outerHeight(); 375 }); 376 // add user-supplied margins 377 if (slider.settings.slideMargin > 0) { 378 height += slider.settings.slideMargin * (slider.settings.minSlides - 1); 379 } 380 // if not "vertical" mode, calculate the max height of the children 381 } else { 382 height = Math.max.apply(Math, children.map(function() { 383 return $(this).outerHeight(false); 384 }).get()); 385 } 386 387 if (slider.viewport.css('box-sizing') === 'border-box') { 388 height += parseFloat(slider.viewport.css('padding-top')) + parseFloat(slider.viewport.css('padding-bottom')) + 389 parseFloat(slider.viewport.css('border-top-width')) + parseFloat(slider.viewport.css('border-bottom-width')); 390 } else if (slider.viewport.css('box-sizing') === 'padding-box') { 391 height += parseFloat(slider.viewport.css('padding-top')) + parseFloat(slider.viewport.css('padding-bottom')); 392 } 393 394 return height; 395 }; 396 397 /** 398 * Returns the calculated width to be used for the outer wrapper / viewport 399 */ 400 var getViewportMaxWidth = function() { 401 var width = '100%'; 402 if (slider.settings.slideWidth > 0) { 403 if (slider.settings.mode === 'horizontal') { 404 width = (slider.settings.maxSlides * slider.settings.slideWidth) + ((slider.settings.maxSlides - 1) * slider.settings.slideMargin); 405 } else { 406 width = slider.settings.slideWidth; 407 } 408 } 409 return width; 410 }; 411 412 /** 413 * Returns the calculated width to be applied to each slide 414 */ 415 var getSlideWidth = function() { 416 var newElWidth = slider.settings.slideWidth, // start with any user-supplied slide width 417 wrapWidth = slider.viewport.width(); // get the current viewport width 418 // if slide width was not supplied, or is larger than the viewport use the viewport width 419 if (slider.settings.slideWidth === 0 || 420 (slider.settings.slideWidth > wrapWidth && !slider.carousel) || 421 slider.settings.mode === 'vertical') { 422 newElWidth = wrapWidth; 423 // if carousel, use the thresholds to determine the width 424 } else if (slider.settings.maxSlides > 1 && slider.settings.mode === 'horizontal') { 425 if (wrapWidth > slider.maxThreshold) { 426 return newElWidth; 427 } else if (wrapWidth < slider.minThreshold) { 428 newElWidth = (wrapWidth - (slider.settings.slideMargin * (slider.settings.minSlides - 1))) / slider.settings.minSlides; 429 } else if (slider.settings.shrinkItems) { 430 newElWidth = Math.floor((wrapWidth + slider.settings.slideMargin) / (Math.ceil((wrapWidth + slider.settings.slideMargin) / (newElWidth + slider.settings.slideMargin))) - slider.settings.slideMargin); 431 } 432 } 433 return newElWidth; 434 }; 435 436 /** 437 * Returns the calculated width to be applied to each slide 438 */ 439 var getSlideHeight = function() { 440 var newElHeight = slider.settings.slideHeight; 441 var wrapWidth = slider.settings.slideWidth; 442 return newElHeight * getSlideWidth() / wrapWidth; 443 }; 444 445 /** 446 * Returns the number of slides currently visible in the viewport (includes partially visible slides) 447 */ 448 var getNumberSlidesShowing = function() { 449 var slidesShowing = 1, 450 childWidth = null; 451 if (slider.settings.mode === 'horizontal' && slider.settings.slideWidth > 0) { 452 // if viewport is smaller than minThreshold, return minSlides 453 if (slider.viewport.width() < slider.minThreshold) { 454 slidesShowing = slider.settings.minSlides; 455 // if viewport is larger than maxThreshold, return maxSlides 456 } else if (slider.viewport.width() > slider.maxThreshold) { 457 slidesShowing = slider.settings.maxSlides; 458 // if viewport is between min / max thresholds, divide viewport width by first child width 459 } else { 460 childWidth = slider.children.first().width() + slider.settings.slideMargin; 461 slidesShowing = Math.floor((slider.viewport.width() + 462 slider.settings.slideMargin) / childWidth); 463 } 464 // if "vertical" mode, slides showing will always be minSlides 465 } else if (slider.settings.mode === 'vertical') { 466 slidesShowing = slider.settings.minSlides; 467 } 468 return slidesShowing; 469 }; 470 471 /** 472 * Returns the number of pages (one full viewport of slides is one "page") 473 */ 474 var getPagerQty = function() { 475 var pagerQty = 0, 476 breakPoint = 0, 477 counter = 0; 478 // if moveSlides is specified by the user 479 if (slider.settings.moveSlides > 0) { 480 if (slider.settings.infiniteLoop) { 481 pagerQty = Math.ceil(slider.children.length / getMoveBy()); 482 } else { 483 // when breakpoint goes above children length, counter is the number of pages 484 while (breakPoint < slider.children.length) { 485 ++pagerQty; 486 breakPoint = counter + getNumberSlidesShowing(); 487 counter += slider.settings.moveSlides <= getNumberSlidesShowing() ? slider.settings.moveSlides : getNumberSlidesShowing(); 488 } 489 } 490 // if moveSlides is 0 (auto) divide children length by sides showing, then round up 491 } else { 492 pagerQty = Math.ceil(slider.children.length / getNumberSlidesShowing()); 493 } 494 return pagerQty; 495 }; 496 497 /** 498 * Returns the number of individual slides by which to shift the slider 499 */ 500 var getMoveBy = function() { 501 // if moveSlides was set by the user and moveSlides is less than number of slides showing 502 if (slider.settings.moveSlides > 0 && slider.settings.moveSlides <= getNumberSlidesShowing()) { 503 return slider.settings.moveSlides; 504 } 505 // if moveSlides is 0 (auto) 506 return getNumberSlidesShowing(); 507 }; 508 509 /** 510 * Sets the slider's (el) left or top position 511 */ 512 var setSlidePosition = function() { 513 var position, lastChild, lastShowingIndex; 514 // if last slide, not infinite loop, and number of children is larger than specified maxSlides 515 if (slider.children.length > slider.settings.maxSlides && slider.active.last && !slider.settings.infiniteLoop) { 516 if (slider.settings.mode === 'horizontal') { 517 // get the last child's position 518 lastChild = slider.children.last(); 519 position = lastChild.position(); 520 // set the left position 521 setPositionProperty(-(position.left - (slider.viewport.width() - lastChild.outerWidth())), 'reset', 0); 522 } else if (slider.settings.mode === 'vertical') { 523 // get the last showing index's position 524 lastShowingIndex = slider.children.length - slider.settings.minSlides; 525 position = slider.children.eq(lastShowingIndex).position(); 526 // set the top position 527 setPositionProperty(-position.top, 'reset', 0); 528 } 529 // if not last slide 530 } else { 531 // get the position of the first showing slide 532 position = slider.children.eq(slider.active.index * getMoveBy()).position(); 533 // check for last slide 534 if (slider.active.index === getPagerQty() - 1) { slider.active.last = true; } 535 // set the respective position 536 if (position !== undefined) { 537 if (slider.settings.mode === 'horizontal') { setPositionProperty(-position.left, 'reset', 0); } 538 else if (slider.settings.mode === 'vertical') { setPositionProperty(-position.top, 'reset', 0); } 539 } 540 } 541 }; 542 543 /** 544 * Sets the el's animating property position (which in turn will sometimes animate el). 545 * If using CSS, sets the transform property. If not using CSS, sets the top / left property. 546 * 547 * @param value (int) 548 * - the animating property's value 549 * 550 * @param type (string) 'slide', 'reset', 'ticker' 551 * - the type of instance for which the function is being 552 * 553 * @param duration (int) 554 * - the amount of time (in ms) the transition should occupy 555 * 556 * @param params (array) optional 557 * - an optional parameter containing any variables that need to be passed in 558 */ 559 var setPositionProperty = function(value, type, duration, params) { 560 var animateObj, propValue; 561 // use CSS transform 562 if (slider.usingCSS) { 563 // determine the translate3d value 564 propValue = slider.settings.mode === 'vertical' ? 'translate3d(0, ' + value + 'px, 0)' : 'translate3d(' + value + 'px, 0, 0)'; 565 // add the CSS transition-duration 566 el.css('-' + slider.cssPrefix + '-transition-duration', duration / 1000 + 's'); 567 if (type === 'slide') { 568 // set the property value 569 el.css(slider.animProp, propValue); 570 if (duration !== 0) { 571 // bind a callback method - executes when CSS transition completes 572 el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(e) { 573 //make sure it's the correct one 574 if (!$(e.target).is(el)) { return; } 575 // unbind the callback 576 el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); 577 updateAfterSlideTransition(); 578 }); 579 } else { //duration = 0 580 updateAfterSlideTransition(); 581 } 582 } else if (type === 'reset') { 583 el.css(slider.animProp, propValue); 584 } else if (type === 'ticker') { 585 // make the transition use 'linear' 586 el.css('-' + slider.cssPrefix + '-transition-timing-function', 'linear'); 587 el.css(slider.animProp, propValue); 588 if (duration !== 0) { 589 el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(e) { 590 //make sure it's the correct one 591 if (!$(e.target).is(el)) { return; } 592 // unbind the callback 593 el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); 594 // reset the position 595 setPositionProperty(params.resetValue, 'reset', 0); 596 // start the loop again 597 tickerLoop(); 598 }); 599 } else { //duration = 0 600 setPositionProperty(params.resetValue, 'reset', 0); 601 tickerLoop(); 602 } 603 } 604 // use JS animate 605 } else { 606 animateObj = {}; 607 animateObj[slider.animProp] = value; 608 if (type === 'slide') { 609 el.animate(animateObj, duration, slider.settings.easing, function() { 610 updateAfterSlideTransition(); 611 }); 612 } else if (type === 'reset') { 613 el.css(slider.animProp, value); 614 } else if (type === 'ticker') { 615 el.animate(animateObj, duration, 'linear', function() { 616 setPositionProperty(params.resetValue, 'reset', 0); 617 // run the recursive loop after animation 618 tickerLoop(); 619 }); 620 } 621 } 622 }; 623 624 /** 625 * Populates the pager with proper amount of pages 626 */ 627 var populatePager = function() { 628 var pagerHtml = '', 629 linkContent = '', 630 pagerQty = getPagerQty(); 631 // loop through each pager item 632 for (var i = 0; i < pagerQty; i++) { 633 linkContent = ''; 634 // if a buildPager function is supplied, use it to get pager link value, else use index + 1 635 if (slider.settings.buildPager && $.isFunction(slider.settings.buildPager) || slider.settings.pagerCustom) { 636 linkContent = slider.settings.buildPager(i); 637 slider.pagerEl.addClass('bx-custom-pager'); 638 } else { 639 linkContent = i + 1; 640 slider.pagerEl.addClass('bx-default-pager'); 641 } 642 // var linkContent = slider.settings.buildPager && $.isFunction(slider.settings.buildPager) ? slider.settings.buildPager(i) : i + 1; 643 // add the markup to the string 644 pagerHtml += '<div class="bx-pager-item"><a href="" data-slide-index="' + i + '" class="bx-pager-link">' + linkContent + '</a></div>'; 645 } 646 // populate the pager element with pager links 647 slider.pagerEl.html(pagerHtml); 648 }; 649 650 /** 651 * Appends the pager to the controls element 652 */ 653 var appendPager = function() { 654 if (!slider.settings.pagerCustom) { 655 // create the pager DOM element 656 slider.pagerEl = $('<div class="bx-pager" />'); 657 // if a pager selector was supplied, populate it with the pager 658 if (slider.settings.pagerSelector) { 659 $(slider.settings.pagerSelector).html(slider.pagerEl); 660 // if no pager selector was supplied, add it after the wrapper 661 } else { 662 slider.controls.el.addClass('bx-has-pager').append(slider.pagerEl); 663 } 664 // populate the pager 665 populatePager(); 666 } else { 667 slider.pagerEl = $(slider.settings.pagerCustom); 668 } 669 // assign the pager click binding 670 slider.pagerEl.on('click touchend', 'a', clickPagerBind); 671 }; 672 673 /** 674 * Appends prev / next controls to the controls element 675 */ 676 var appendControls = function() { 677 slider.controls.next = $('<a class="bx-next" href="">' + slider.settings.nextText + '</a>'); 678 slider.controls.prev = $('<a class="bx-prev" href="">' + slider.settings.prevText + '</a>'); 679 // bind click actions to the controls 680 slider.controls.next.bind('click touchend', clickNextBind); 681 slider.controls.prev.bind('click touchend', clickPrevBind); 682 // if nextSelector was supplied, populate it 683 if (slider.settings.nextSelector) { 684 $(slider.settings.nextSelector).append(slider.controls.next); 685 } 686 // if prevSelector was supplied, populate it 687 if (slider.settings.prevSelector) { 688 $(slider.settings.prevSelector).append(slider.controls.prev); 689 } 690 // if no custom selectors were supplied 691 if (!slider.settings.nextSelector && !slider.settings.prevSelector) { 692 // add the controls to the DOM 693 slider.controls.directionEl = $('<div class="bx-controls-direction" />'); 694 // add the control elements to the directionEl 695 slider.controls.directionEl.append(slider.controls.prev).append(slider.controls.next); 696 // slider.viewport.append(slider.controls.directionEl); 697 slider.controls.el.addClass('bx-has-controls-direction').append(slider.controls.directionEl); 698 } 699 }; 700 701 /** 702 * Appends start / stop auto controls to the controls element 703 */ 704 var appendControlsAuto = function() { 705 slider.controls.start = $('<div class="bx-controls-auto-item"><a class="bx-start" href="">' + slider.settings.startText + '</a></div>'); 706 slider.controls.stop = $('<div class="bx-controls-auto-item"><a class="bx-stop" href="">' + slider.settings.stopText + '</a></div>'); 707 // add the controls to the DOM 708 slider.controls.autoEl = $('<div class="bx-controls-auto" />'); 709 // bind click actions to the controls 710 slider.controls.autoEl.on('click', '.bx-start', clickStartBind); 711 slider.controls.autoEl.on('click', '.bx-stop', clickStopBind); 712 // if autoControlsCombine, insert only the "start" control 713 if (slider.settings.autoControlsCombine) { 714 slider.controls.autoEl.append(slider.controls.start); 715 // if autoControlsCombine is false, insert both controls 716 } else { 717 slider.controls.autoEl.append(slider.controls.start).append(slider.controls.stop); 718 } 719 // if auto controls selector was supplied, populate it with the controls 720 if (slider.settings.autoControlsSelector) { 721 $(slider.settings.autoControlsSelector).html(slider.controls.autoEl); 722 // if auto controls selector was not supplied, add it after the wrapper 723 } else { 724 slider.controls.el.addClass('bx-has-controls-auto').append(slider.controls.autoEl); 725 } 726 // update the auto controls 727 updateAutoControls(slider.settings.autoStart ? 'stop' : 'start'); 728 }; 729 730 /** 731 * Appends image captions to the DOM 732 */ 733 var appendCaptions = function() { 734 // cycle through each child 735 slider.children.each(function(index) { 736 // get the image title attribute 737 var title = $(this).find('img:first').attr('alt'); 738 // append the caption 739 if (title !== undefined && ('' + title).length) { 740 $(this).append('<div class="bx-caption"><span>' + title + '</span></div>'); 741 } 742 }); 743 }; 744 745 /** 746 * Click next binding 747 * 748 * @param e (event) 749 * - DOM event object 750 */ 751 var clickNextBind = function(e) { 752 e.preventDefault(); 753 if (slider.controls.el.hasClass('disabled')) { return; } 754 // if auto show is running, stop it 755 if (slider.settings.auto && slider.settings.stopAutoOnClick) { el.stopAuto(); } 756 el.goToNextSlide(); 757 }; 758 759 /** 760 * Click prev binding 761 * 762 * @param e (event) 763 * - DOM event object 764 */ 765 var clickPrevBind = function(e) { 766 e.preventDefault(); 767 if (slider.controls.el.hasClass('disabled')) { return; } 768 // if auto show is running, stop it 769 if (slider.settings.auto && slider.settings.stopAutoOnClick) { el.stopAuto(); } 770 el.goToPrevSlide(); 771 }; 772 773 /** 774 * Click start binding 775 * 776 * @param e (event) 777 * - DOM event object 778 */ 779 var clickStartBind = function(e) { 780 el.startAuto(); 781 e.preventDefault(); 782 }; 783 784 /** 785 * Click stop binding 786 * 787 * @param e (event) 788 * - DOM event object 789 */ 790 var clickStopBind = function(e) { 791 el.stopAuto(); 792 e.preventDefault(); 793 }; 794 795 /** 796 * Click pager binding 797 * 798 * @param e (event) 799 * - DOM event object 800 */ 801 var clickPagerBind = function(e) { 802 var pagerLink, pagerIndex; 803 e.preventDefault(); 804 if (slider.controls.el.hasClass('disabled')) { 805 return; 806 } 807 // if auto show is running, stop it 808 if (slider.settings.auto && slider.settings.stopAutoOnClick) { el.stopAuto(); } 809 pagerLink = $(e.currentTarget); 810 if (pagerLink.attr('data-slide-index') !== undefined) { 811 pagerIndex = parseInt(pagerLink.attr('data-slide-index')); 812 // if clicked pager link is not active, continue with the goToSlide call 813 if (pagerIndex !== slider.active.index) { el.goToSlide(pagerIndex); } 814 } 815 }; 816 817 /** 818 * Updates the pager links with an active class 819 * 820 * @param slideIndex (int) 821 * - index of slide to make active 822 */ 823 var updatePagerActive = function(slideIndex) { 824 // if "short" pager type 825 var len = slider.children.length; // nb of children 826 if (slider.settings.pagerType === 'short') { 827 if (slider.settings.maxSlides > 1) { 828 len = Math.ceil(slider.children.length / slider.settings.maxSlides); 829 } 830 slider.pagerEl.html((slideIndex + 1) + slider.settings.pagerShortSeparator + len); 831 return; 832 } 833 // remove all pager active classes 834 slider.pagerEl.find('a').removeClass('active'); 835 // apply the active class for all pagers 836 slider.pagerEl.each(function(i, el) { $(el).find('a').eq(slideIndex).addClass('active'); }); 837 }; 838 839 /** 840 * Performs needed actions after a slide transition 841 */ 842 var updateAfterSlideTransition = function() { 843 // if infinite loop is true 844 if (slider.settings.infiniteLoop) { 845 var position = ''; 846 // first slide 847 if (slider.active.index === 0) { 848 // set the new position 849 position = slider.children.eq(0).position(); 850 // carousel, last slide 851 } else if (slider.active.index === getPagerQty() - 1 && slider.carousel) { 852 position = slider.children.eq((getPagerQty() - 1) * getMoveBy()).position(); 853 // last slide 854 } else if (slider.active.index === slider.children.length - 1) { 855 position = slider.children.eq(slider.children.length - 1).position(); 856 } 857 if (position) { 858 if (slider.settings.mode === 'horizontal') { setPositionProperty(-position.left, 'reset', 0); } 859 else if (slider.settings.mode === 'vertical') { setPositionProperty(-position.top, 'reset', 0); } 860 } 861 } 862 // declare that the transition is complete 863 slider.working = false; 864 // onSlideAfter callback 865 slider.settings.onSlideAfter.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 866 }; 867 868 /** 869 * Updates the auto controls state (either active, or combined switch) 870 * 871 * @param state (string) "start", "stop" 872 * - the new state of the auto show 873 */ 874 var updateAutoControls = function(state) { 875 // if autoControlsCombine is true, replace the current control with the new state 876 if (slider.settings.autoControlsCombine) { 877 slider.controls.autoEl.html(slider.controls[state]); 878 // if autoControlsCombine is false, apply the "active" class to the appropriate control 879 } else { 880 slider.controls.autoEl.find('a').removeClass('active'); 881 slider.controls.autoEl.find('a:not(.bx-' + state + ')').addClass('active'); 882 } 883 }; 884 885 /** 886 * Updates the direction controls (checks if either should be hidden) 887 */ 888 var updateDirectionControls = function() { 889 if (getPagerQty() === 1) { 890 slider.controls.prev.addClass('disabled'); 891 slider.controls.next.addClass('disabled'); 892 } else if (!slider.settings.infiniteLoop && slider.settings.hideControlOnEnd) { 893 // if first slide 894 if (slider.active.index === 0) { 895 slider.controls.prev.addClass('disabled'); 896 slider.controls.next.removeClass('disabled'); 897 // if last slide 898 } else if (slider.active.index === getPagerQty() - 1) { 899 slider.controls.next.addClass('disabled'); 900 slider.controls.prev.removeClass('disabled'); 901 // if any slide in the middle 902 } else { 903 slider.controls.prev.removeClass('disabled'); 904 slider.controls.next.removeClass('disabled'); 905 } 906 } 907 }; 908 909 /** 910 * Initializes the auto process 911 */ 912 var initAuto = function() { 913 // if autoDelay was supplied, launch the auto show using a setTimeout() call 914 if (slider.settings.autoDelay > 0) { 915 var timeout = setTimeout(el.startAuto, slider.settings.autoDelay); 916 // if autoDelay was not supplied, start the auto show normally 917 } else { 918 el.startAuto(); 919 920 //add focus and blur events to ensure its running if timeout gets paused 921 $(window).focus(function() { 922 el.startAuto(); 923 }).blur(function() { 924 el.stopAuto(); 925 }
vendor: 6,202 bytes, lines 925-1083
925); 926 } 927 // if autoHover is requested 928 if (slider.settings.autoHover) { 929 // on el hover 930 el.hover(function() { 931 // if the auto show is currently playing (has an active interval) 932 if (slider.interval) { 933 // stop the auto show and pass true argument which will prevent control update 934 el.stopAuto(true); 935 // create a new autoPaused value which will be used by the relative "mouseout" event 936 slider.autoPaused = true; 937 } 938 }, function() { 939 // if the autoPaused value was created be the prior "mouseover" event 940 if (slider.autoPaused) { 941 // start the auto show and pass true argument which will prevent control update 942 el.startAuto(true); 943 // reset the autoPaused value 944 slider.autoPaused = null; 945 } 946 }); 947 } 948 }; 949 950 /** 951 * Initializes the ticker process 952 */ 953 var initTicker = function() { 954 var startPosition = 0, 955 position, transform, value, idx, ratio, property, newSpeed, totalDimens; 956 // if autoDirection is "next", append a clone of the entire slider 957 if (slider.settings.autoDirection === 'next') { 958 el.append(slider.children.clone().addClass('bx-clone')); 959 // if autoDirection is "prev", prepend a clone of the entire slider, and set the left position 960 } else { 961 el.prepend(slider.children.clone().addClass('bx-clone')); 962 position = slider.children.first().position(); 963 startPosition = slider.settings.mode === 'horizontal' ? -position.left : -position.top; 964 } 965 setPositionProperty(startPosition, 'reset', 0); 966 // do not allow controls in ticker mode 967 slider.settings.pager = false; 968 slider.settings.controls = false; 969 slider.settings.autoControls = false; 970 // if autoHover is requested 971 if (slider.settings.tickerHover) { 972 if (slider.usingCSS) { 973 idx = slider.settings.mode === 'horizontal' ? 4 : 5; 974 slider.viewport.hover(function() { 975 transform = el.css('-' + slider.cssPrefix + '-transform'); 976 value = parseFloat(transform.split(',')[idx]); 977 setPositionProperty(value, 'reset', 0); 978 }, function() { 979 totalDimens = 0; 980 slider.children.each(function(index) { 981 totalDimens += slider.settings.mode === 'horizontal' ? $(this).outerWidth(true) : $(this).outerHeight(true); 982 }); 983 // calculate the speed ratio (used to determine the new speed to finish the paused animation) 984 ratio = slider.settings.speed / totalDimens; 985 // determine which property to use 986 property = slider.settings.mode === 'horizontal' ? 'left' : 'top'; 987 // calculate the new speed 988 newSpeed = ratio * (totalDimens - (Math.abs(parseInt(value)))); 989 tickerLoop(newSpeed); 990 }); 991 } else { 992 // on el hover 993 slider.viewport.hover(function() { 994 el.stop(); 995 }, function() { 996 // calculate the total width of children (used to calculate the speed ratio) 997 totalDimens = 0; 998 slider.children.each(function(index) { 999 totalDimens += slider.settings.mode === 'horizontal' ? $(this).outerWidth(true) : $(this).outerHeight(true); 1000 }); 1001 // calculate the speed ratio (used to determine the new speed to finish the paused animation) 1002 ratio = slider.settings.speed / totalDimens; 1003 // determine which property to use 1004 property = slider.settings.mode === 'horizontal' ? 'left' : 'top'; 1005 // calculate the new speed 1006 newSpeed = ratio * (totalDimens - (Math.abs(parseInt(el.css(property))))); 1007 tickerLoop(newSpeed); 1008 }); 1009 } 1010 } 1011 // start the ticker loop 1012 tickerLoop(); 1013 }; 1014 1015 /** 1016 * Runs a continuous loop, news ticker-style 1017 */ 1018 var tickerLoop = function(resumeSpeed) { 1019 var speed = resumeSpeed ? resumeSpeed : slider.settings.speed, 1020 position = {left: 0, top: 0}, 1021 reset = {left: 0, top: 0}, 1022 animateProperty, resetValue, params; 1023 1024 // if "next" animate left position to last child, then reset left to 0 1025 if (slider.settings.autoDirection === 'next') { 1026 position = el.find('.bx-clone').first().position(); 1027 // if "prev" animate left position to 0, then reset left to first non-clone child 1028 } else { 1029 reset = slider.children.first().position(); 1030 } 1031 animateProperty = slider.settings.mode === 'horizontal' ? -position.left : -position.top; 1032 resetValue = slider.settings.mode === 'horizontal' ? -reset.left : -reset.top; 1033 params = {resetValue: resetValue}; 1034 setPositionProperty(animateProperty, 'ticker', speed, params); 1035 }; 1036 1037 /** 1038 * Check if el is on screen 1039 */ 1040 var isOnScreen = function(el) { 1041 var win = $(window), 1042 viewport = { 1043 top: win.scrollTop(), 1044 left: win.scrollLeft() 1045 }, 1046 bounds = el.offset(); 1047 1048 viewport.right = viewport.left + win.width(); 1049 viewport.bottom = viewport.top + win.height(); 1050 bounds.right = bounds.left + el.outerWidth(); 1051 bounds.bottom = bounds.top + el.outerHeight(); 1052 1053 return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); 1054 }; 1055 1056 /** 1057 * Initializes keyboard events 1058 */ 1059 var keyPress = function(e) { 1060 var activeElementTag = document.activeElement.tagName.toLowerCase(), 1061 tagFilters = 'input|textarea', 1062 p = new RegExp(activeElementTag,['i']), 1063 result = p.exec(tagFilters); 1064 1065 if (result == null && isOnScreen(el)) { 1066 if (e.keyCode === 39) { 1067 clickNextBind(e); 1068 return false; 1069 } else if (e.keyCode === 37) { 1070 clickPrevBind(e); 1071 return false; 1072 } 1073 } 1074 }; 1075 1076 /** 1077 * Initializes touch events 1078 */ 1079 var initTouch = function() { 1080 // initialize object to contain all touch values 1081 slider.touch = { 1082 start: {x: 0, y: 0}, 1083 end: {x: 0, y: 0}
1083, 1084 time: 0 1085 }; 1086 slider.viewport.on('touchstart MSPointerDown pointerdown', onTouchStart); 1087 1088 slider.viewport.on('click', 'a', function(e) { 1089 e.preventDefault(); 1090 }); 1091 }; 1092 1093 /** 1094 * Event handler for "touchstart" 1095 * 1096 * @param e (event) 1097 * - DOM event object 1098 */ 1099 var onTouchStart = function(e) { 1100 //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 1101 slider.controls.el.addClass('disabled'); 1102 1103 if (slider.working) { 1104 e.preventDefault(); 1105 slider.controls.el.removeClass('disabled'); 1106 } else { 1107 // record the original position when touch starts 1108 slider.touch.originalPos = el.position(); 1109 var orig = e.originalEvent, 1110 touchPoints = (typeof orig.changedTouches !== 'undefined') ? orig.changedTouches : [orig]; 1111 // record the starting touch x, y coordinates 1112 slider.touch.start.x = touchPoints[0].pageX; 1113 slider.touch.start.y = touchPoints[0].pageY; 1114 slider.touch.time = new Date; 1115 /*if (slider.viewport.get(0).setPointerCapture) { 1116 slider.pointerId = orig.pointerId; 1117 if(slider.pointerId === 1){ 1118 slider.viewport.get(0).setPointerCapture(slider.pointerId); 1119 } 1120 }*/ 1121 // bind a "touchmove" event to the viewport 1122 slider.viewport.bind('touchmove MSPointerMove pointermove', onTouchMove); 1123 // bind a "touchend" event to the viewport 1124 slider.viewport.bind('touchend MSPointerUp pointerup', onTouchEnd); 1125 slider.viewport.bind('MSPointerCancel pointercancel', onPointerCancel); 1126 } 1127 1128 }; 1129 1130 /** 1131 * Cancel Pointer for Windows Phone 1132 * 1133 * @param e (event) 1134 * - DOM event object 1135 */ 1136 var onPointerCancel = function(e) { 1137 /* onPointerCancel handler is needed to deal with situations when a touchend 1138 doesn't fire after a touchstart (this happens on windows phones only) */ 1139 setPositionProperty(slider.touch.originalPos.left, 'reset', 0); 1140 1141 //remove handlers 1142 slider.controls.el.removeClass('disabled'); 1143 slider.viewport.unbind('MSPointerCancel pointercancel', onPointerCancel); 1144 slider.viewport.unbind('touchmove MSPointerMove pointermove', onTouchMove); 1145 slider.viewport.unbind('touchend MSPointerUp pointerup', onTouchEnd); 1146 /*if (slider.viewport.get(0).releasePointerCapture) { 1147 slider.viewport.get(0).releasePointerCapture(slider.pointerId); 1148 }*/ 1149 }; 1150 1151 /** 1152 * Event handler for "touchmove" 1153 * 1154 * @param e (event) 1155 * - DOM event object 1156 */ 1157 var onTouchMove = function(e) { 1158 var orig = e.originalEvent, 1159 touchPoints = (typeof orig.changedTouches !== 'undefined') ? orig.changedTouches : [orig], 1160 // if scrolling on y axis, do not prevent default 1161 xMovement = Math.abs(touchPoints[0].pageX - slider.touch.start.x), 1162 yMovement = Math.abs(touchPoints[0].pageY - slider.touch.start.y), 1163 value = 0, 1164 change = 0; 1165 1166 // x axis swipe 1167 if ((xMovement * 3) > yMovement && slider.settings.preventDefaultSwipeX) { 1168 e.preventDefault(); 1169 // y axis swipe 1170 } else if ((yMovement * 3) > xMovement && slider.settings.preventDefaultSwipeY) { 1171 e.preventDefault(); 1172 } 1173 if (slider.settings.mode !== 'fade' && slider.settings.oneToOneTouch) { 1174 // if horizontal, drag along x axis 1175 if (slider.settings.mode === 'horizontal') { 1176 change = touchPoints[0].pageX - slider.touch.start.x; 1177 value = slider.touch.originalPos.left + change; 1178 // if vertical, drag along y axis 1179 } else { 1180 change = touchPoints[0].pageY - slider.touch.start.y; 1181 value = slider.touch.originalPos.top + change; 1182 } 1183 setPositionProperty(value, 'reset', 0); 1184 } 1185 }; 1186 1187 /** 1188 * Event handler for "touchend" 1189 * 1190 * @param e (event) 1191 * - DOM event object 1192 */ 1193 var onTouchEnd = function(e) { 1194 slider.viewport.unbind('touchmove MSPointerMove pointermove', onTouchMove); 1195 //enable slider controls as soon as user stops interacing with slides 1196 1197 slider.controls.el.removeClass('disabled'); 1198 var orig = e.originalEvent, 1199 touchPoints = (typeof orig.changedTouches !== 'undefined') ? orig.changedTouches : [orig], 1200 value = 0, 1201 distance = 0; 1202 // record end x, y positions 1203 slider.touch.end.x = touchPoints[0].pageX; 1204 slider.touch.end.y = touchPoints[0].pageY; 1205 // if fade mode, check if absolute x distance clears the threshold 1206 if (slider.settings.mode === 'fade') { 1207 distance = Math.abs(slider.touch.start.x - slider.touch.end.x); 1208 if (distance >= slider.settings.swipeThreshold) { 1209 if (slider.touch.start.x > slider.touch.end.x) { 1210 el.goToNextSlide(); 1211 } else { 1212 el.goToPrevSlide(); 1213 } 1214 el.stopAuto(); 1215 } 1216 // not fade mode 1217 } else { 1218 // calculate distance and el's animate property 1219 if (slider.settings.mode === 'horizontal') { 1220 distance = slider.touch.end.x - slider.touch.start.x; 1221 value = slider.touch.originalPos.left; 1222 } else { 1223 distance = slider.touch.end.y - slider.touch.start.y; 1224 value = slider.touch.originalPos.top; 1225 } 1226 // if not infinite loop and first / last slide, do not attempt a slide transition 1227 if (!slider.settings.infiniteLoop && ((slider.active.index === 0 && distance > 0) || (slider.active.last && distance < 0))) { 1228 setPositionProperty(value, 'reset', 200); 1229 } else { 1230 // check if distance clears threshold 1231 1232 if (Math.abs(distance) >= slider.settings.swipeThreshold) { 1233 if (distance < 0) { 1234 el.goToNextSlide(); 1235 } else { 1236 el.goToPrevSlide(); 1237 } 1238 el.stopAuto(); 1239 } else { 1240 // el.animate(property, 200); 1241 setPositionProperty(value, 'reset', 200); 1242 1243 if ( new Date - slider.touch.time<300 ) { 1244 window.location.href = orig.target.parentElement.href; 1245 } 1246 1247 } 1248 } 1249 } 1250 slider.viewport.unbind('touchend MSPointerUp pointerup', onTouchEnd); 1251 /*if (slider.viewport.get(0).releasePointerCapture) { 1252 slider.viewport.get(0).releasePointerCapture(slider.pointerId); 1253 }*/
vendor: 8,765 bytes, lines 1254-1448
1254 1255 }; 1256 1257 /** 1258 * Window resize event callback 1259 */ 1260 var resizeWindow = function(e) { 1261 // don't do anything if slider isn't initialized. 1262 if (!slider.initialized) { return; } 1263 // Delay if slider working. 1264 if (slider.working) { 1265 window.setTimeout(resizeWindow, 10); 1266 } else { 1267 // get the new window dimens (again, thank you IE) 1268 var windowWidthNew = $(window).width(), 1269 windowHeightNew = $(window).height(); 1270 // make sure that it is a true window resize 1271 // *we must check this because our dinosaur friend IE fires a window resize event when certain DOM elements 1272 // are resized. Can you just die already?* 1273 if (windowWidth !== windowWidthNew || windowHeight !== windowHeightNew) { 1274 // set the new window dimens 1275 windowWidth = windowWidthNew; 1276 windowHeight = windowHeightNew; 1277 // update all dynamic elements 1278 el.redrawSlider(); 1279 // Call user resize handler 1280 slider.settings.onSliderResize.call(el, slider.active.index); 1281 } 1282 } 1283 }; 1284 1285 /** 1286 * Adds an aria-hidden=true attribute to each element 1287 * 1288 * @param startVisibleIndex (int) 1289 * - the first visible element's index 1290 */ 1291 var applyAriaHiddenAttributes = function(startVisibleIndex) { 1292 var numberOfSlidesShowing = getNumberSlidesShowing(); 1293 // only apply attributes if the setting is enabled and not in ticker mode 1294 if (slider.settings.ariaHidden && !slider.settings.ticker) { 1295 // add aria-hidden=true to all elements 1296 slider.children.attr('aria-hidden', 'true'); 1297 // get the visible elements and change to aria-hidden=false 1298 slider.children.slice(startVisibleIndex, startVisibleIndex + numberOfSlidesShowing).attr('aria-hidden', 'false'); 1299 } 1300 }; 1301 1302 /** 1303 * Returns index according to present page range 1304 * 1305 * @param slideOndex (int) 1306 * - the desired slide index 1307 */ 1308 var setSlideIndex = function(slideIndex) { 1309 if (slideIndex < 0) { 1310 if (slider.settings.infiniteLoop) { 1311 return getPagerQty() - 1; 1312 }else { 1313 //we don't go to undefined slides 1314 return slider.active.index; 1315 } 1316 // if slideIndex is greater than children length, set active index to 0 (this happens during infinite loop) 1317 } else if (slideIndex >= getPagerQty()) { 1318 if (slider.settings.infiniteLoop) { 1319 return 0; 1320 } else { 1321 //we don't move to undefined pages 1322 return slider.active.index; 1323 } 1324 // set active index to requested slide 1325 } else { 1326 return slideIndex; 1327 } 1328 }; 1329 1330 /** 1331 * =================================================================================== 1332 * = PUBLIC FUNCTIONS 1333 * =================================================================================== 1334 */ 1335 1336 /** 1337 * Performs slide transition to the specified slide 1338 * 1339 * @param slideIndex (int) 1340 * - the destination slide's index (zero-based) 1341 * 1342 * @param direction (string) 1343 * - INTERNAL USE ONLY - the direction of travel ("prev" / "next") 1344 */ 1345 el.goToSlide = function(slideIndex, direction) { 1346 // onSlideBefore, onSlideNext, onSlidePrev callbacks 1347 // Allow transition canceling based on returned value 1348 var performTransition = true, 1349 moveBy = 0, 1350 position = {left: 0, top: 0}, 1351 lastChild = null, 1352 lastShowingIndex, eq, value, requestEl; 1353 // store the old index 1354 slider.oldIndex = slider.active.index; 1355 //set new index 1356 slider.active.index = setSlideIndex(slideIndex); 1357 1358 // if plugin is currently in motion, ignore request 1359 if (slider.working || slider.active.index === slider.oldIndex) { return; } 1360 // declare that plugin is in motion 1361 slider.working = true; 1362 1363 performTransition = slider.settings.onSlideBefore.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); 1364 1365 // If transitions canceled, reset and return 1366 if (typeof (performTransition) !== 'undefined' && !performTransition) { 1367 slider.active.index = slider.oldIndex; // restore old index 1368 slider.working = false; // is not in motion 1369 return; 1370 } 1371 1372 if (direction === 'next') { 1373 // Prevent canceling in future functions or lack there-of from negating previous commands to cancel 1374 if (!slider.settings.onSlideNext.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index)) { 1375 performTransition = false; 1376 } 1377 } else if (direction === 'prev') { 1378 // Prevent canceling in future functions or lack there-of from negating previous commands to cancel 1379 if (!slider.settings.onSlidePrev.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index)) { 1380 performTransition = false; 1381 } 1382 } 1383 1384 // check if last slide 1385 slider.active.last = slider.active.index >= getPagerQty() - 1; 1386 // update the pager with active class 1387 if (slider.settings.pager || slider.settings.pagerCustom) { updatePagerActive(slider.active.index); } 1388 // // check for direction control update 1389 if (slider.settings.controls) { updateDirectionControls(); } 1390 // if slider is set to mode: "fade" 1391 if (slider.settings.mode === 'fade') { 1392 // if adaptiveHeight is true and next height is different from current height, animate to the new height 1393 if (slider.settings.adaptiveHeight && slider.viewport.height() !== getViewportHeight()) { 1394 slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); 1395 } 1396 // fade out the visible child and reset its z-index value 1397 slider.children.filter(':visible').fadeOut(slider.settings.speed).css({zIndex: 0}); 1398 // fade in the newly requested slide 1399 slider.children.eq(slider.active.index).css('zIndex', slider.settings.slideZIndex + 1).fadeIn(slider.settings.speed, function() { 1400 $(this).css('zIndex', slider.settings.slideZIndex); 1401 updateAfterSlideTransition(); 1402 }); 1403 // slider mode is not "fade" 1404 } else { 1405 // if adaptiveHeight is true and next height is different from current height, animate to the new height 1406 if (slider.settings.adaptiveHeight && slider.viewport.height() !== getViewportHeight()) { 1407 slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); 1408 } 1409 // if carousel and not infinite loop 1410 if (!slider.settings.infiniteLoop && slider.carousel && slider.active.last) { 1411 if (slider.settings.mode === 'horizontal') { 1412 // get the last child position 1413 lastChild = slider.children.eq(slider.children.length - 1); 1414 position = lastChild.position(); 1415 // calculate the position of the last slide 1416 moveBy = slider.viewport.width() - lastChild.outerWidth(); 1417 } else { 1418 // get last showing index position 1419 lastShowingIndex = slider.children.length - slider.settings.minSlides; 1420 position = slider.children.eq(lastShowingIndex).position(); 1421 } 1422 // horizontal carousel, going previous while on first slide (infiniteLoop mode) 1423 } else if (slider.carousel && slider.active.last && direction === 'prev') { 1424 // get the last child position 1425 eq = slider.settings.moveSlides === 1 ? slider.settings.maxSlides - getMoveBy() : ((getPagerQty() - 1) * getMoveBy()) - (slider.children.length - slider.settings.maxSlides); 1426 lastChild = el.children('.bx-clone').eq(eq); 1427 position = lastChild.position(); 1428 // if infinite loop and "Next" is clicked on the last slide 1429 } else if (direction === 'next' && slider.active.index === 0) { 1430 // get the last clone position 1431 position = el.find('> .bx-clone').eq(slider.settings.maxSlides).position(); 1432 slider.active.last = false; 1433 // normal non-zero requests 1434 } else if (slideIndex >= 0) { 1435 //parseInt is applied to allow floats for slides/page 1436 requestEl = slideIndex * parseInt(getMoveBy()); 1437 position = slider.children.eq(requestEl).position(); 1438 } 1439 1440 /* If the position doesn't exist 1441 * (e.g. if you destroy the slider on a next click), 1442 * it doesn't throw an error. 1443 */ 1444 if (typeof (position) !== 'undefined') { 1445 value = slider.settings.mode === 'horizontal' ? -(position.left - moveBy) : -position.top; 1446 // plugin values to be animated 1447 setPositionProperty(value, 'slide', slider.settings.speed); 1448 }
1448 else { 1449 slider.working = false; 1450 } 1451 } 1452 if (slider.settings.ariaHidden) { applyAriaHiddenAttributes(slider.active.index * getMoveBy()); } 1453 }; 1454 1455 /** 1456 * Transitions to the next slide in the show 1457 */ 1458 el.goToNextSlide = function() { 1459 // if infiniteLoop is false and last page is showing, disregard call 1460 if (!slider.settings.infiniteLoop && slider.active.last) { return; } 1461 var pagerIndex = parseInt(slider.active.index) + 1; 1462 el.goToSlide(pagerIndex, 'next'); 1463 }; 1464 1465 /** 1466 * Transitions to the prev slide in the show 1467 */ 1468 el.goToPrevSlide = function() { 1469 // if infiniteLoop is false and last page is showing, disregard call 1470 if (!slider.settings.infiniteLoop && slider.active.index === 0) { return; } 1471 var pagerIndex = parseInt(slider.active.index) - 1; 1472 el.goToSlide(pagerIndex, 'prev'); 1473 }; 1474 1475 /** 1476 * Starts the auto show 1477 * 1478 * @param preventControlUpdate (boolean) 1479 * - if true, auto controls state will not be updated 1480 */ 1481 el.startAuto = function(preventControlUpdate) { 1482 // if an interval already exists, disregard call 1483 if (slider.interval) { return; } 1484 // create an interval 1485 slider.interval = setInterval(function() { 1486 if (slider.settings.autoDirection === 'next') { 1487 el.goToNextSlide(); 1488 } else { 1489 el.goToPrevSlide(); 1490 } 1491 }, slider.settings.pause); 1492 // if auto controls are displayed and preventControlUpdate is not true 1493 if (slider.settings.autoControls && preventControlUpdate !== true) { updateAutoControls('stop'); } 1494 }; 1495 1496 /** 1497 * Stops the auto show 1498 * 1499 * @param preventControlUpdate (boolean) 1500 * - if true, auto controls state will not be updated 1501 */ 1502 el.stopAuto = function(preventControlUpdate) { 1503 // if no interval exists, disregard call 1504 if (!slider.interval) { return; } 1505 // clear the interval 1506 clearInterval(slider.interval); 1507 slider.interval = null; 1508 // if auto controls are displayed and preventControlUpdate is not true 1509 if (slider.settings.autoControls && preventControlUpdate !== true) { updateAutoControls('start'); } 1510 }; 1511 1512 /** 1513 * Returns current slide index (zero-based) 1514 */ 1515 el.getCurrentSlide = function() { 1516 return slider.active.index; 1517 }; 1518 1519 /** 1520 * Returns current slide element 1521 */ 1522 el.getCurrentSlideElement = function() { 1523 return slider.children.eq(slider.active.index); 1524 }; 1525 1526 /** 1527 * Returns a slide element 1528 * @param index (int) 1529 * - The index (zero-based) of the element you want returned. 1530 */ 1531 el.getSlideElement = function(index) { 1532 return slider.children.eq(index); 1533 }; 1534 1535 /** 1536 * Returns number of slides in show 1537 */ 1538 el.getSlideCount = function() { 1539 return slider.children.length; 1540 }; 1541 1542 /** 1543 * Return slider.working variable 1544 */ 1545 el.isWorking = function() { 1546 return slider.working; 1547 }; 1548 1549 /** 1550 * Update all dynamic slider elements 1551 */ 1552 el.redrawSlider = function() { 1553 // resize all children in ratio to new screen size 1554 slider.children.add(el.find('.bx-clone')).outerWidth(getSlideWidth()); 1555 // adjust the height 1556 slider.viewport.css('height', getViewportHeight()); 1557 // update the slide position 1558 if (!slider.settings.ticker) { setSlidePosition(); } 1559 // if active.last was true before the screen resize, we want 1560 // to keep it last no matter what screen size we end on 1561 if (slider.active.last) { slider.active.index = getPagerQty() - 1; } 1562 // if the active index (page) no longer exists due to the resize, simply set the index as last 1563 if (slider.active.index >= getPagerQty()) { slider.active.last = true; } 1564 // if a pager is being displayed and a custom pager is not being used, update it 1565 if (slider.settings.pager && !slider.settings.pagerCustom) { 1566 populatePager(); 1567 updatePagerActive(slider.active.index); 1568 } 1569 if (slider.settings.ariaHidden) { applyAriaHiddenAttributes(slider.active.index * getMoveBy()); } 1570 }; 1571 1572 /** 1573 * Destroy the current instance of the slider (revert everything back to original state) 1574 */ 1575 el.destroySlider = function() { 1576 // don't do anything if slider has already been destroyed 1577 if (!slider.initialized) { return; } 1578 slider.initialized = false;
1579 $('.bx-clone', this).remove(); 1580 slider.children.each(function() { 1581 if ($(this).data('origStyle') !== undefined) { 1582 $(this).attr('style', $(this).data('origStyle')); 1583 } else { 1584 $(this).removeAttr('style'); 1585 } 1586 }); 1587 if ($(this).data('origStyle') !== undefined) { 1588 this.attr('style', $(this).data('origStyle')); 1589 } else { 1590 $(this).removeAttr('style'); 1591 } 1592 $(this).unwrap().unwrap(); 1593 if (slider.controls.el) { slider.controls.el.remove(); } 1594 if (slider.controls.next) { slider.controls.next.remove(); } 1595 if (slider.controls.prev) { slider.controls.prev.remove(); } 1596 if (slider.pagerEl && slider.settings.controls && !slider.settings.pagerCustom) { slider.pagerEl.remove(); } 1597 $('.bx-caption', this).remove(); 1598 if (slider.controls.autoEl) { slider.controls.autoEl.remove(); } 1599 clearInterval(slider.interval); 1600 if (slider.settings.responsive) { $(window).unbind('resize', resizeWindow); } 1601 if (slider.settings.keyboardEnabled) { $(document).unbind('keydown', keyPress); } 1602 //remove self reference in data 1603 $(this).removeData('bxSlider'); 1604 }; 1605 1606 /** 1607 * Reload the slider (revert all DOM changes, and re-initialize) 1608 */ 1609 el.reloadSlider = function(settings) { 1610 if (settings !== undefined) { options = settings; } 1611 el.destroySlider(); 1612 init(); 1613 //store reference to self in order to access public functions later 1614 $(el).data('bxSlider', this); 1615 }; 1616 1617 init(); 1618 1619 $(el).data('bxSlider', this); 1620 1621 // returns the current jQuery object 1622 return this; 1623 }; 1624 1625})(jQuery); 1626 1627/** 1628 * carouselTicker v1.0.0 1629 * More information visit http://likeclever1.github.io/carouselTicker/ 1630 * Copyright 2015, Yuriy Berezovskiy 1631 * 1632 * Released under the MIT license - http://opensource.org/licenses/MIT 1633 * 1634 * Usages: $(...).carouselTicker(); 1635 * 1636 * Options: 1637 * - speed: integer 1638 * - delay: integer 1639 * - direction: string - "prev", "next" 1640 */ 1641 1642"use strict"; 1643 1644;(function($) { 1645 1646 var plugin = {}; 1647 1648 var defaults = { 1649 1650 // GENERAL 1651 direction: "prev", 1652 mode: "horizontal", 1653 speed: 1, 1654 delay: 30, 1655 1656 // CALLBACKS 1657 onCarouselTickerLoad: function() {} 1658 }; 1659 1660 $.fn.carouselTicker = function(options) { 1661 if(this.length == 0) return this; 1662 1663 // support multiple elements 1664 if(this.length > 1) { 1665 this.each(function() { 1666 $(this).carouselTicker(options); 1667 }); 1668 return this; 1669 } 1670 1671 // create a namespace to be throughout the plugin 1672 var ticker = {}; 1673 // set a reference to our slider element 1674 var el = this, 1675 $el = $(this); 1676 1677 plugin.el = this, 1678 plugin.$el = $(this); 1679 1680 /** 1681 * =================================================================================== 1682 * = PRIVATE FUNCTIONS 1683 * =================================================================================== 1684 */ 1685 1686 /** 1687 * Initializes namespace settings to be used throughout plugin 1688 */ 1689 1690 var _init = function() { 1691 // merge user-supplied options with defaults 1692 ticker.settings = $.extend({}, defaults, options); 1693 // initialize pointer timeout 1694 ticker.intervalPointer = null; 1695 // determine direction ticker 1696 ticker.directionSwitcher = (ticker.settings.direction === "prev") ? -1 : 1; 1697 // set default value items inside ticker 1698 ticker.itemsWidth = 0; 1699 // set default value childs (items + clone) 1700 ticker.childsWidth = 0; 1701 // set default value items inside ticker 1702 ticker.itemsHeight = 0; 1703 // set default value childs (items + clone) 1704 ticker.childsHeight = 0; 1705 // determine list 1706 ticker.$list = $el.children("ul"); 1707 // determine items 1708 ticker.$items = ticker.$list.children("li"); 1709 // initialize initialize flag 1710 ticker.isInitialize = false;
1711 // initialize mousemove flag 1712 ticker.isMousemove = false; 1713 // determine ticker parent 1714 ticker.$parent = $el.parent(); 1715 // set wrapper class 1716 ticker.wrapCls = "carouselTicker__wrap"; 1717 // set loader class 1718 ticker.loaderCls = "carouselTicker__loader"; 1719 // set clone class 1720 ticker.cloneCls = "carouselTicker__clone"; 1721 // determine touch events 1722 ticker.touch = ("ontouchstart" in document.documentElement) ? true : false; 1723 // determine event types 1724 ticker.eventTypes = { 1725 mousedown: (ticker.touch) ? "touchstart" : "mousedown", 1726 mousemove: (ticker.touch) ? "touchmove" : "mousemove", 1727 mouseup: (ticker.touch) ? "touchend" : "mouseup" 1728 }; 1729 1730 _setup(); 1731 }; 1732 1733 /** 1734 * Performs all DOM and CSS modifications 1735 */ 1736 1737 var _setup = function() { 1738 // if horizontal mode 1739 if(ticker.settings.mode === "horizontal") { 1740 // determine summ items width 1741 _calcItemsWidth(); 1742 // if summ items width > width parent el 1743 if(ticker.itemsWidth > ticker.$parent.width()) { 1744 // set new width 1745 $el.find("." + ticker.wrapCls).css({"width": ticker.$parent.width() + "px"}); 1746 ticker.$list.css({"width": ticker.itemsWidth*2, "left": 0}); 1747 // set common parameters 1748 setupFunc(); 1749 } 1750 // if vertical mode 1751 } else if(ticker.settings.mode === "vertical") { 1752 // determine summ items height 1753 _calcItemsHeight(); 1754 // if summ items height > height parent el 1755 if(ticker.itemsHeight > ticker.$parent.height()) { 1756 // set new height 1757 $el.find("." + ticker.wrapCls).css({"height": ticker.$parent.height() + "px"}); 1758 ticker.$list.css({"height": ticker.itemsHeight*2, "top": 0}); 1759 // set common parameters 1760 setupFunc(); 1761 } 1762 } 1763 1764 if(ticker.isInitialize) { 1765 // delete event dragstart from link and image 1766 $el.on("dragstart", function(e) { 1767 if (e.target.nodeName.toUpperCase() == "IMG" || e.target.nodeName.toUpperCase() == "A") { 1768 return false; 1769 } 1770 }); 1771 } 1772 1773 function setupFunc() { 1774 // check wrap el 1775 if($el.children().hasClass(ticker.wrapCls)) return; 1776 // add loader 1777 $("<div class='" + ticker.loaderCls + "'></div>").appendTo($el); 1778 // set css to element 1779 $el.find("." + ticker.wrapCls).css({"position": "relative"}); 1780 // wrap list in a wrapper 1781 ticker.$list.wrap("<div class='carouselTicker__wrap' style='position: relative; overflow: hidden; user-select: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none;'></div>"); 1782 // clone items and push to list 1783 ticker.$items.clone().addClass(ticker.cloneCls).appendTo(ticker.$list); 1784 // add css for list 1785 ticker.$list.css({ 1786 "position": "relative" 1787 }); 1788 1789 // set true to initialize value 1790 ticker.isInitialize = true; 1791 // onSliderLoad callback 1792 ticker.settings.onCarouselTickerLoad(); 1793 // start add functionality 1794 _start(); 1795 }; 1796 }; 1797 1798 /** 1799 * Start the ticker 1800 */ 1801 1802 var _start = function() { 1803 // remove the loading DOM element 1804 if($el.find("." + ticker.loaderCls).length) $el.find("." + ticker.loaderCls).remove(); 1805 // start ticker-carousel 1806 ticker.intervalPointer = setInterval(function() {_moveTicker()}, ticker.settings.delay); 1807 // initialize eventOver event 1808 _eventOver(); 1809 // initialize eventOut event 1810 _eventOut(); 1811 // initialize drag and drop event 1812 _eventDragAndDrop(); 1813 }; 1814 1815 /** 1816 * Move carouselTicker 1817 */ 1818 1819 var _moveTicker = function() { 1820 var mode = (ticker.settings.mode === "horizontal") ? "left" : "top", 1821 itemsSize = (ticker.settings.mode === "horizontal") ? ticker.itemsWidth : ticker.itemsHeight; 1822 // step ticker moving 1823 ticker.$list.css(mode, '+=' + ticker.directionSwitcher * ticker.settings.speed + "px"); 1824 // depending of direction change offset list for effect Infinity rotate 1825 if(ticker.settings.direction === "prev") { 1826 if(Math.abs(parseInt(ticker.$list.css(mode))) >= itemsSize) { 1827 ticker.$list.css(mode, 0); 1828 } 1829 } 1830 1831 if(ticker.settings.direction === "next") { 1832 if(parseInt(ticker.$list.css(mode)) >= 0) { 1833 ticker.$list.css(mode, -itemsSize + "px"); 1834 } 1835 } 1836 }; 1837 1838 /** 1839 * Method calc summ items width 1840 */ 1841 function _calcItemsWidth() { 1842 // set value 0 to default 1843 ticker.itemsWidth = 0; 1844 // calc sum 1845 ticker.$items.each(function() { 1846 var $this = $(this), 1847 style = this.currentStyle || window.getComputedStyle(this), 1848 margin = parseFloat(style.marginLeft) + parseFloat(style.marginRight); 1849 // if item clone - calc summ without it 1850 if($this.hasClass(ticker.cloneCls)) return; 1851 ticker.itemsWidth += this.getBoundingClientRect().width + margin; 1852 }); 1853 }; 1854 1855 /** 1856 * Method calc summ items height 1857 */ 1858 function _calcItemsHeight() { 1859 // set value 0 to default 1860 ticker.itemsHeight = 0; 1861 // calc sum 1862 ticker.$items.each(function() { 1863 var $this = $(this); 1864 // if item clone - calc summ without it 1865 if($this.hasClass(ticker.cloneCls)) return; 1866 ticker.itemsHeight += $this.outerHeight(true); 1867 }); 1868 }; 1869 1870 /** 1871 * Event Methods _eventOver, _eventOut, _eventDragAndDrop 1872 */ 1873 function _eventOver() { 1874 // if mouse over ticker 1875 $el.on("mouseover", function() { 1876 // depending from mode choose condition 1877 var condition = (ticker.settings.mode === "horizontal") ? (ticker.itemsWidth > ticker.$parent.width()) : (ticker.itemsHeight > ticker.$parent.height()); 1878 // if ticker width/height > outer width/height block 1879 if(condition) { 1880 // make clearInterval 1881 clearInterval(ticker.intervalPointer); 1882 // make clearInterval 1883 ticker.intervalPointer = false;
1884 } 1885 }); 1886 }; 1887 1888 function _eventOut() { 1889 // if mouse leave from el 1890 $el.on("mouseleave", function() { 1891 // depending from mode choose condition 1892 var condition = (ticker.settings.mode === "horizontal") ? (ticker.itemsWidth > ticker.$parent.width()) : (ticker.itemsHeight > ticker.$parent.height()); 1893 // if mouse move 1894 if(ticker.isMousemove) { 1895 // off event behaviour mousemove 1896 ticker.$list.off(ticker.eventTypes.mousemove); 1897 // call event mouseup 1898 ticker.$list.trigger(ticker.eventTypes.mouseup); 1899 } 1900 // if ticker width > outer width block 1901 if(condition) { 1902 // protection from double setInterval 1903 if(ticker.intervalPointer) return; 1904 // call _moveTicker 1905 ticker.intervalPointer = setInterval(function() {_moveTicker()}, ticker.settings.delay); 1906 } 1907 }); 1908 }; 1909 1910 function _eventDragAndDrop() { 1911 var flag = false; 1912 1913 ticker.$list.on(ticker.eventTypes.mousedown, function(e) { 1914 var start = e.clientX || event.touches[0].pageX, 1915 startY = e.clientY || event.touches[0].pageY, 1916 $this = $(this), 1917 posList = parseFloat($(this).css("left")), 1918 posListY = parseFloat($(this).css("top")); 1919 1920 $(e.target).off("click"); 1921 clearInterval(ticker.intervalPointer); 1922 ticker.intervalPointer = false; 1923 flag = true; 1924 1925 $this.on(ticker.eventTypes.mousemove, function(e) { 1926 1927 var x = e.clientX || event.touches[0].pageX, 1928 y = e.clientY || event.touches[0].pageY, 1929 // fix for touch device 1930 diff = start - x, 1931 diffY = startY - y; 1932 1933 if(ticker.touch) { 1934 $(document).on("touchmove", function(e) { 1935 e.preventDefault(); 1936 }); 1937 } 1938 1939 if(ticker.settings.mode === "horizontal") { 1940 ticker.directionSwitcher = (diff >= 0) ? -1 : 1; 1941 } else if(ticker.settings.mode === "vertical") { 1942 ticker.directionSwitcher = (diffY >= 0) ? -1 : 1; 1943 } 1944 1945 ticker.isMousemove = true; 1946 1947 if(flag) { 1948 if(ticker.settings.mode === "horizontal") { 1949 // if drag more left side 1950 if(posList - diff >= 0 && ticker.directionSwitcher === 1) { 1951 $this.css("left", "-=" + ticker.itemsWidth); 1952 posList = -ticker.itemsWidth; 1953 start = e.clientX || event.touches[0].pageX; 1954 diff = 0; 1955 } 1956 // if drag more right side 1957 if(posList - diff <= -ticker.itemsWidth && ticker.directionSwitcher === -1) { 1958 $this.css("left", 0); 1959 posList = 0; 1960 diff = 0; 1961 start = e.clientX || event.touches[0].pageX; 1962 } 1963 1964 $this.css("left", posList - diff + "px"); 1965 1966 } else if(ticker.settings.mode === "vertical") { 1967 // if drag more top side 1968 if(posListY - diffY >= 0 && ticker.directionSwitcher === 1) { 1969 $this.css("top", "-=" + ticker.itemsHeight); 1970 posListY = -ticker.itemsHeight; 1971 startY = e.clientY || event.touches[0].pageY; 1972 diffY = 0; 1973 } 1974 // if drag more right side 1975 if(posListY - diffY <= -ticker.itemsHeight && ticker.directionSwitcher === -1) { 1976 $this.css("top", 0); 1977 posListY = 0; 1978 diffY = 0; 1979 startY = e.clientY || event.touches[0].pageY; 1980 } 1981 1982 $this.css("top", posListY - diffY + "px"); 1983 } 1984 } 1985 }); 1986 }); 1987 1988 ticker.$list.on(ticker.eventTypes.mouseup, function(e) { 1989 var $target = $(e.target); 1990 e.preventDefault(); 1991 1992 if($target.attr("href") || $target.parents().attr("href") && ticker.isMousemove){ 1993 $target.on("click", function(e) { 1994 e.preventDefault(); 1995 }); 1996 } 1997 1998 flag = false;
1999 ticker.isMousemove = false; 2000 ticker.settings.direction = (ticker.directionSwitcher === 1) ? "next" : "prev"; 2001 $(this).off(ticker.eventTypes.mousemove); 2002 2003 if(ticker.touch) { 2004 $(document).off("touchmove"); 2005 } 2006 2007 if(ticker.intervalPointer) clearInterval(ticker.intervalPointer); 2008 2009 if(ticker.touch) ticker.intervalPointer = setInterval(function() {_moveTicker()}, ticker.settings.delay); 2010 }); 2011 }; 2012 2013 /** 2014 * Public Methods 2015 */ 2016 2017 /** 2018 * resize carouselTicker 2019 * 2020 **/ 2021 2022 el.resizeTicker = function() { 2023 2024 _calcItemsWidth(); 2025 2026 if(ticker.itemsWidth > ticker.$parent.width()) { 2027 if(!ticker.isInitialize) _init(); 2028 } else { 2029 if(ticker.isInitialize) el.destructor(); 2030 } 2031 }; 2032 2033 /** 2034 * Stop rotate carouselTicker 2035 */ 2036 2037 el.stop = function() { 2038 clearInterval(ticker.intervalPointer); 2039 ticker.intervalPointer = false; 2040 }; 2041 2042 /** 2043 * Run carouselTicker 2044 */ 2045 2046 el.run = function() { 2047 _start(); 2048 }; 2049 2050 /** 2051 * Destroy the current instance of the ticker (revert everything back to original state) 2052 */ 2053 2054 el.destructor = function() { 2055 $el.find("." + ticker.cloneCls).remove(); 2056 2057 if($el.find("." + ticker.wrapCls).length) { 2058 ticker.$list.unwrap(); 2059 ticker.$list.css({'left': 'auto', 'position': 'static', 'width': 'auto'}); 2060 $el.css({"width": "auto", "position": "static"}) 2061 } 2062 2063 clearInterval(ticker.intervalPointer); 2064 ticker.isInitialize = false; 2065 ticker.intervalPointer = false; 2066 }; 2067 2068 /** 2069 * Reload the ticker (revert all DOM changes, and re-initialize) 2070 */ 2071 el.reloadCarouselTicker = function(settings){ 2072 if (settings != undefined) options = settings; 2073 el.destructor(); 2074 _init(); 2075 } 2076 2077 if(document.readyState === "loading") { 2078 $(window).on("load", function() { 2079 _init(); 2080 }); 2081 } else { 2082 _init(); 2083 } 2084 2085 2086 // returns the current jQuery object 2087 return this; 2088 } 2089 2090})(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.