1/* 2 * Swiper 2.2 - Mobile Touch Slider 3 * http://www.idangero.us/sliders/swiper/ 4 * 5 * Copyright 2012-2013, Vladimir Kharlampidi 6 * The iDangero.us 7 * http://www.idangero.us/ 8 * 9 * Licensed under GPL & MIT 10 * 11 * Updated on: September 15, 2013 12*/ 13var Swiper = function (selector, params) { 14 /*========================= 15 A little bit dirty but required part for IE8 and old FF support 16 ===========================*/ 17 if (document.body.__defineGetter__) { 18 if (HTMLElement) { 19 var element = HTMLElement.prototype; 20 if (element.__defineGetter__) { 21 element.__defineGetter__("outerHTML", function () { return new XMLSerializer().serializeToString(this); } ); 22 } 23 } 24 } 25 26 if (!window.getComputedStyle) { 27 window.getComputedStyle = function (el, pseudo) { 28 this.el = el; 29 this.getPropertyValue = function (prop) { 30 var re = /(\-([a-z]){1})/g; 31 if (prop === 'float') prop = 'styleFloat'; 32 if (re.test(prop)) { 33 prop = prop.replace(re, function () { 34 return arguments[2].toUpperCase(); 35 }); 36 } 37 return el.currentStyle[prop] ? el.currentStyle[prop] : null; 38 } 39 return this; 40 } 41 } 42 if (!Array.prototype.indexOf) { 43 Array.prototype.indexOf = function(obj, start) { 44 for (var i = (start || 0), j = this.length; i < j; i++) { 45 if (this[i] === obj) { return i; } 46 } 47 return -1; 48 } 49 } 50 if (!document.querySelectorAll) { 51 if (!window.jQuery) return; 52 } 53 function $$(selector, context) { 54 if (document.querySelectorAll) 55 return (context || document).querySelectorAll(selector); 56 else 57 return jQuery(selector, context); 58 } 59 60 /*========================= 61 Check for correct selector 62 ===========================*/ 63 if(typeof selector === 'undefined') return; 64 65 if(!(selector.nodeType)){ 66 if ($$(selector).length === 0) return; 67 } 68 69 /*========================= 70 _this 71 ===========================*/ 72 var _this = this; 73 74 /*========================= 75 Default Flags and vars 76 ===========================*/ 77 _this.touches = { 78 start:0, 79 startX:0, 80 startY:0, 81 current:0, 82 currentX:0, 83 currentY:0, 84 diff:0, 85 abs:0 86 }; 87 _this.positions = { 88 start:0, 89 abs:0, 90 diff:0, 91 current:0 92 }; 93 _this.times = { 94 start:0, 95 end:0 96 }; 97 98 _this.id = (new Date()).getTime(); 99 _this.container = (selector.nodeType) ? selector : $$(selector)[0]; 100 _this.isTouched = false; 101 _this.isMoved = false; 102 _this.activeIndex = 0; 103 _this.activeLoaderIndex = 0; 104 _this.activeLoopIndex = 0; 105 _this.previousIndex = null; 106 _this.velocity = 0; 107 _this.snapGrid = []; 108 _this.slidesGrid = []; 109 _this.imagesToLoad = []; 110 _this.imagesLoaded = 0; 111 _this.wrapperLeft=0; 112 _this.wrapperRight=0; 113 _this.wrapperTop=0; 114 _this.wrapperBottom=0; 115 var wrapper, slideSize, wrapperSize, direction, isScrolling, containerSize; 116 117 /*========================= 118 Default Parameters 119 ===========================*/ 120 var defaults = { 121 mode : 'horizontal', // or 'vertical' 122 touchRatio : 1, 123 speed : 300, 124 freeMode : false, 125 freeModeFluid : false, 126 momentumRatio: 1, 127 momentumBounce: true, 128 momentumBounceRatio: 1, 129 slidesPerView : 1, 130 slidesPerGroup : 1, 131 simulateTouch : true, 132 followFinger : true, 133 shortSwipes : true, 134 moveStartThreshold:false, 135 autoplay: false, 136 onlyExternal : false, 137 createPagination : true, 138 pagination : false, 139 paginationElement: 'span', 140 paginationClickable: false, 141 paginationAsRange: true, 142 resistance : true, // or false or 100% 143 scrollContainer : false, 144 preventLinks : true, 145 noSwiping : false, // or class 146 noSwipingClass : 'swiper-no-swiping', //:) 147 initialSlide: 0, 148 keyboardControl: false, 149 mousewheelControl : false, 150 mousewheelDebounce: 600, 151 useCSS3Transforms : true, 152 //Loop mode 153 loop:false, 154 loopAdditionalSlides:0, 155 //Auto Height 156 calculateHeight: false, 157 //Images Preloader 158 updateOnImagesReady : true, 159 //Form elements 160 releaseFormElements : true, 161 //Watch for active slide, useful when use effects on different slide states
162 watchActiveIndex: false, 163 //Slides Visibility Fit 164 visibilityFullFit : false, 165 //Slides Offset 166 offsetPxBefore : 0, 167 offsetPxAfter : 0, 168 offsetSlidesBefore : 0, 169 offsetSlidesAfter : 0, 170 centeredSlides: false, 171 //Queue callbacks 172 queueStartCallbacks : false, 173 queueEndCallbacks : false, 174 //Auto Resize 175 autoResize : true, 176 resizeReInit : false, 177 //DOMAnimation 178 DOMAnimation : true, 179 //Slides Loader 180 loader: { 181 slides:[], //array with slides 182 slidesHTMLType:'inner', // or 'outer' 183 surroundGroups: 1, //keep preloaded slides groups around view 184 logic: 'reload', //or 'change' 185 loadAllSlides: false 186 }, 187 //Namespace 188 slideElement : 'div', 189 slideClass : 'swiper-slide', 190 slideActiveClass : 'swiper-slide-active', 191 slideVisibleClass : 'swiper-slide-visible', 192 wrapperClass : 'swiper-wrapper', 193 paginationElementClass: 'swiper-pagination-switch', 194 paginationActiveClass : 'swiper-active-switch', 195 paginationVisibleClass : 'swiper-visible-switch' 196 } 197 params = params || {}; 198 for (var prop in defaults) { 199 if (prop in params && typeof params[prop]==='object') { 200 for (var subProp in defaults[prop]) { 201 if (! (subProp in params[prop])) { 202 params[prop][subProp] = defaults[prop][subProp]; 203 } 204 } 205 } 206 else if (! (prop in params)) { 207 params[prop] = defaults[prop] 208 } 209 } 210 _this.params = params; 211 if (params.scrollContainer) { 212 params.freeMode = true; 213 params.freeModeFluid = true; 214 } 215 if (params.loop) { 216 params.resistance = '100%'; 217 } 218 var isH = params.mode==='horizontal'; 219 220 /*========================= 221 Define Touch Events 222 ===========================*/ 223 224 _this.touchEvents = { 225 touchStart : _this.support.touch || !params.simulateTouch ? 'touchstart' : (_this.browser.ie10 ? 'MSPointerDown' : 'mousedown'), 226 touchMove : _this.support.touch || !params.simulateTouch ? 'touchmove' : (_this.browser.ie10 ? 'MSPointerMove' : 'mousemove'), 227 touchEnd : _this.support.touch || !params.simulateTouch ? 'touchend' : (_this.browser.ie10 ? 'MSPointerUp' : 'mouseup') 228 }; 229 230 /*========================= 231 Wrapper 232 ===========================*/ 233 for (var i = _this.container.childNodes.length - 1; i >= 0; i--) { 234 if (_this.container.childNodes[i].className) { 235 var _wrapperClasses = _this.container.childNodes[i].className.split(' ') 236 for (var j = 0; j < _wrapperClasses.length; j++) { 237 if (_wrapperClasses[j]===params.wrapperClass) { 238 wrapper = _this.container.childNodes[i]; 239 } 240 }; 241 } 242 }; 243 244 _this.wrapper = wrapper; 245 /*========================= 246 Slide API 247 ===========================*/ 248 _this._extendSwiperSlide = function (el) { 249 el.append = function () { 250 if (params.loop) { 251 el.insertAfter(_this.slides.length-_this.loopedSlides); 252 _this.removeLoopedSlides(); 253 _this.calcSlides(); 254 _this.createLoop(); 255 } 256 else { 257 _this.wrapper.appendChild(el); 258 } 259 260 _this.reInit(); 261 return el; 262 } 263 el.prepend = function () { 264 if (params.loop) { 265 _this.wrapper.insertBefore(el, _this.slides[_this.loopedSlides]); 266 _this.removeLoopedSlides(); 267 _this.calcSlides(); 268 _this.createLoop(); 269 } 270 else { 271 _this.wrapper.insertBefore(el, _this.wrapper.firstChild); 272 } 273 _this.reInit(); 274 return el; 275 } 276 el.insertAfter = function (index) { 277 if(typeof index === 'undefined') return false; 278 var beforeSlide; 279 280 if (params.loop) { 281 beforeSlide = _this.slides[index + 1 + _this.loopedSlides]; 282 _this.wrapper.insertBefore(el, beforeSlide); 283 _this.removeLoopedSlides(); 284 _this.calcSlides(); 285 _this.createLoop(); 286 } 287 else { 288 beforeSlide = _this.slides[index + 1]; 289 _this.wrapper.insertBefore(el, beforeSlide) 290 } 291 _this.reInit(); 292 return el; 293 } 294 el.clone = function () { 295 return _this._extendSwiperSlide(el.cloneNode(true)) 296 } 297 el.remove = function () { 298 _this.wrapper.removeChild(el); 299 _this.reInit(); 300 } 301 el.html = function (html) { 302 if (typeof html === 'undefined') { 303 return el.innerHTML; 304 } 305 else { 306 el.innerHTML = html; 307 return el; 308 } 309 } 310 el.index = function () { 311 var index; 312 for (var i = _this.slides.length - 1; i >= 0; i--) { 313 if(el === _this.slides[i]) index = i; 314 } 315 return index; 316 } 317 el.isActive = function () { 318 if (el.index() === _this.activeIndex) return true; 319 else return false; 320 } 321 if (!el.swiperSlideDataStorage) el.swiperSlideDataStorage={}; 322 el.getData = function (name) { 323 return el.swiperSlideDataStorage[name]; 324 } 325 el.setData = function (name, value) { 326 el.swiperSlideDataStorage[name] = value; 327 return el; 328 } 329 el.data = function (name, value) { 330 if (!value) { 331 return el.getAttribute('data-'+name); 332 } 333 else { 334 el.setAttribute('data-'+name,value); 335 return el; 336 } 337 } 338 el.getWidth = function (outer) { 339 return _this.h.getWidth(el, outer); 340 } 341 el.getHeight = function (outer) { 342 return _this.h.getHeight(el, outer); 343 } 344 el.getOffset = function() { 345 return _this.h.getOffset(el); 346 } 347 return el; 348 } 349 350 //Calculate information about number of slides 351 _this.calcSlides = function (forceCalcSlides) { 352 var oldNumber = _this.slides ? _this.slides.length : false; 353 _this.slides = []; 354 _this.displaySlides = []; 355 for (var i = 0; i < _this.wrapper.childNodes.length; i++) { 356 if (_this.wrapper.childNodes[i].className) { 357 var _className = _this.wrapper.childNodes[i].className; 358 var _slideClasses = _className.split(' '); 359 for (var j = 0; j < _slideClasses.length; j++) { 360 if(_slideClasses[j]===params.slideClass) { 361 _this.slides.push(_this.wrapper.childNodes[i]); 362 } 363 } 364 } 365 } 366 for (i = _this.slides.length - 1; i >= 0; i--) { 367 _this._extendSwiperSlide(_this.slides[i]); 368 } 369 if (!oldNumber) return; 370 if(oldNumber!==_this.slides.length || forceCalcSlides) { 371 // Number of slides has been changed 372 removeSlideEvents(); 373 addSlideEvents(); 374 _this.updateActiveSlide(); 375 if (params.createPagination && _this.params.pagination) _this.createPagination(); 376 _this.callPlugins('numberOfSlidesChanged'); 377 } 378 } 379 380 //Create Slide 381 _this.createSlide = function (html, slideClassList, el) { 382 var slideClassList = slideClassList || _this.params.slideClass; 383 var el = el||params.slideElement; 384 var newSlide = document.createElement(el); 385 newSlide.innerHTML = html||''; 386 newSlide.className = slideClassList; 387 return _this._extendSwiperSlide(newSlide); 388 } 389 390 //Append Slide 391 _this.appendSlide = function (html, slideClassList, el) { 392 if (!html) return; 393 if (html.nodeType) { 394 return _this._extendSwiperSlide(html).append() 395 } 396 else { 397 return _this.createSlide(html, slideClassList, el).append() 398 } 399 } 400 _this.prependSlide = function (html, slideClassList, el) { 401 if (!html) return; 402 if (html.nodeType) { 403 return _this._extendSwiperSlide(html).prepend() 404 } 405 else { 406 return _this.createSlide(html, slideClassList, el).prepend() 407 } 408 } 409 _this.insertSlideAfter = function (index, html, slideClassList, el) { 410 if (typeof index === 'undefined') return false; 411 if (html.nodeType) { 412 return _this._extendSwiperSlide(html).insertAfter(index); 413 } 414 else { 415 return _this.createSlide(html, slideClassList, el).insertAfter(index); 416 } 417 } 418 _this.removeSlide = function (index) { 419 if (_this.slides[index]) { 420 if (params.loop) { 421 if (!_this.slides[index+_this.loopedSlides]) return false; 422 _this.slides[index+_this.loopedSlides].remove(); 423 _this.removeLoopedSlides(); 424 _this.calcSlides(); 425 _this.createLoop(); 426 } 427 else _this.slides[index].remove(); 428 return true; 429 } 430 else return false; 431 } 432 _this.removeLastSlide = function () { 433 if (_this.slides.length>0) { 434 if (params.loop) { 435 _this.slides[_this.slides.length - 1 - _this.loopedSlides].remove(); 436 _this.removeLoopedSlides(); 437 _this.calcSlides(); 438 _this.createLoop(); 439 } 440 else _this.slides[ (_this.slides.length-1) ].remove(); 441 return true; 442 } 443 else { 444 return false; 445 } 446 } 447 _this.removeAllSlides = function () { 448 for (var i = _this.slides.length - 1; i >= 0; i--) { 449 _this.slides[i].remove() 450 } 451 }
452 _this.getSlide = function (index) { 453 return _this.slides[index] 454 } 455 _this.getLastSlide = function () { 456 return _this.slides[ _this.slides.length-1 ] 457 } 458 _this.getFirstSlide = function () { 459 return _this.slides[0] 460 } 461 462 //Currently Active Slide 463 _this.activeSlide = function () { 464 return _this.slides[_this.activeIndex] 465 } 466 467 /*========================= 468 Plugins API 469 ===========================*/ 470 var _plugins = []; 471 for (var plugin in _this.plugins) { 472 if (params[plugin]) { 473 var p = _this.plugins[plugin](_this, params[plugin]); 474 if (p) _plugins.push( p ); 475 } 476 } 477 _this.callPlugins = function(method, args) { 478 if (!args) args = {} 479 for (var i=0; i<_plugins.length; i++) { 480 if (method in _plugins[i]) { 481 _plugins[i][method](args); 482 } 483 } 484 } 485 486 /*========================= 487 WP8 Fix 488 ===========================*/ 489 if (_this.browser.ie10 && !params.onlyExternal) { 490 _this.wrapper.classList.add('swiper-wp8-' + (isH ? 'horizontal' : 'vertical')); 491 } 492 493 /*========================= 494 Free Mode Class 495 ===========================*/ 496 if (params.freeMode) { 497 _this.container.className+=' swiper-free-mode'; 498 } 499 500 /*================================================== 501 Init/Re-init/Resize Fix 502 ====================================================*/ 503 _this.initialized = false; 504 _this.init = function(force, forceCalcSlides) { 505 var _width = _this.h.getWidth(_this.container); 506 var _height = _this.h.getHeight(_this.container); 507 if (_width===_this.width && _height===_this.height && !force) return; 508 _this.width = _width; 509 _this.height = _height; 510 511 containerSize = isH ? _width : _height; 512 var wrapper = _this.wrapper; 513 514 if (force) { 515 _this.calcSlides(forceCalcSlides); 516 } 517 518 if (params.slidesPerView==='auto') { 519 //Auto mode 520 var slidesWidth = 0; 521 var slidesHeight = 0; 522 523 //Unset Styles 524 if (params.slidesOffset>0) { 525 wrapper.style.paddingLeft = ''; 526 wrapper.style.paddingRight = ''; 527 wrapper.style.paddingTop = ''; 528 wrapper.style.paddingBottom = ''; 529 } 530 wrapper.style.width = ''; 531 wrapper.style.height = ''; 532 if (params.offsetPxBefore>0) { 533 if (isH) _this.wrapperLeft = params.offsetPxBefore; 534 else _this.wrapperTop = params.offsetPxBefore; 535 } 536 if (params.offsetPxAfter>0) { 537 if (isH) _this.wrapperRight = params.offsetPxAfter; 538 else _this.wrapperBottom = params.offsetPxAfter; 539 } 540 541 if (params.centeredSlides) { 542 if (isH) { 543 _this.wrapperLeft = (containerSize - this.slides[0].getWidth(true) )/2; 544 _this.wrapperRight = (containerSize - _this.slides[ _this.slides.length-1 ].getWidth(true))/2; 545 } 546 else { 547 _this.wrapperTop = (containerSize - _this.slides[0].getHeight(true))/2; 548 _this.wrapperBottom = (containerSize - _this.slides[ _this.slides.length-1 ].getHeight(true))/2; 549 } 550 } 551 552 if (isH) { 553 if (_this.wrapperLeft>=0) wrapper.style.paddingLeft = _this.wrapperLeft+'px'; 554 if (_this.wrapperRight>=0) wrapper.style.paddingRight = _this.wrapperRight+'px'; 555 } 556 else { 557 if (_this.wrapperTop>=0) wrapper.style.paddingTop = _this.wrapperTop+'px'; 558 if (_this.wrapperBottom>=0) wrapper.style.paddingBottom = _this.wrapperBottom+'px'; 559 } 560 var slideLeft = 0; 561 var centeredSlideLeft=0; 562 _this.snapGrid = []; 563 _this.slidesGrid = []; 564 565 var slideMaxHeight = 0; 566 for(var i = 0; i<_this.slides.length; i++) { 567 var slideWidth = _this.slides[i].getWidth(true); 568 var slideHeight = _this.slides[i].getHeight(true); 569 if (params.calculateHeight) { 570 slideMaxHeight = Math.max(slideMaxHeight, slideHeight) 571 } 572 var _slideSize = isH ? slideWidth : slideHeight; 573 if (params.centeredSlides) { 574 var nextSlideWidth = i === _this.slides.length-1 ? 0 : _this.slides[i+1].getWidth(true); 575 var nextSlideHeight = i === _this.slides.length-1 ? 0 : _this.slides[i+1].getHeight(true); 576 var nextSlideSize = isH ? nextSlideWidth : nextSlideHeight; 577 if (_slideSize>containerSize) { 578 for (var j=0; j<=Math.floor(_slideSize/(containerSize+_this.wrapperLeft)); j++) { 579 if (j === 0) _this.snapGrid.push(slideLeft+_this.wrapperLeft); 580 else _this.snapGrid.push(slideLeft+_this.wrapperLeft+containerSize*j); 581 } 582 _this.slidesGrid.push(slideLeft+_this.wrapperLeft); 583 } 584 else { 585 _this.snapGrid.push(centeredSlideLeft); 586 _this.slidesGrid.push(centeredSlideLeft); 587 } 588 589 centeredSlideLeft += _slideSize/2 + nextSlideSize/2; 590 591 } 592 else { 593 if (_slideSize>containerSize) { 594 for (var j=0; j<=Math.floor(_slideSize/containerSize); j++) { 595 _this.snapGrid.push(slideLeft+containerSize*j); 596 } 597 } 598 else { 599 _this.snapGrid.push(slideLeft); 600 } 601 _this.slidesGrid.push(slideLeft); 602 } 603 604 slideLeft += _slideSize; 605 606 slidesWidth += slideWidth; 607 slidesHeight += slideHeight; 608 } 609 if (params.calculateHeight) _this.height = slideMaxHeight; 610 if(isH) { 611 wrapperSize = slidesWidth + _this.wrapperRight + _this.wrapperLeft; 612 wrapper.style.width = (slidesWidth)+'px'; 613 wrapper.style.height = (_this.height)+'px'; 614 } 615 else { 616 wrapperSize = slidesHeight + _this.wrapperTop + _this.wrapperBottom; 617 wrapper.style.width = (_this.width)+'px'; 618 wrapper.style.height = (slidesHeight)+'px'; 619 } 620 621 } 622 else if (params.scrollContainer) { 623 //Scroll Container 624 wrapper.style.width = ''; 625 wrapper.style.height = '';
626 var wrapperWidth = _this.slides[0].getWidth(true); 627 var wrapperHeight = _this.slides[0].getHeight(true); 628 wrapperSize = isH ? wrapperWidth : wrapperHeight; 629 wrapper.style.width = wrapperWidth+'px'; 630 wrapper.style.height = wrapperHeight+'px'; 631 slideSize = isH ? wrapperWidth : wrapperHeight; 632 633 } 634 else { 635 //For usual slides 636 if (params.calculateHeight) { 637 var slideMaxHeight = 0; 638 var wrapperHeight = 0; 639 //ResetWrapperSize 640 if (!isH) _this.container.style.height= ''; 641 wrapper.style.height=''; 642 643 for (var i=0; i<_this.slides.length; i++) { 644 //ResetSlideSize 645 _this.slides[i].style.height=''; 646 slideMaxHeight = Math.max( _this.slides[i].getHeight(true), slideMaxHeight ); 647 if (!isH) wrapperHeight+=_this.slides[i].getHeight(true); 648 } 649 var slideHeight = slideMaxHeight; 650 _this.height = slideHeight; 651 652 if (isH) wrapperHeight = slideHeight; 653 else containerSize = slideHeight, _this.container.style.height= containerSize+'px'; 654 } 655 else { 656 var slideHeight = isH ? _this.height : _this.height/params.slidesPerView; 657 var wrapperHeight = isH ? _this.height : _this.slides.length*slideHeight; 658 } 659 var slideWidth = isH ? _this.width/params.slidesPerView : _this.width; 660 var wrapperWidth = isH ? _this.slides.length*slideWidth : _this.width; 661 slideSize = isH ? slideWidth : slideHeight; 662 663 if (params.offsetSlidesBefore>0) { 664 if (isH) _this.wrapperLeft = slideSize*params.offsetSlidesBefore; 665 else _this.wrapperTop = slideSize*params.offsetSlidesBefore; 666 } 667 if (params.offsetSlidesAfter>0) { 668 if (isH) _this.wrapperRight = slideSize*params.offsetSlidesAfter; 669 else _this.wrapperBottom = slideSize*params.offsetSlidesAfter; 670 } 671 if (params.offsetPxBefore>0) { 672 if (isH) _this.wrapperLeft = params.offsetPxBefore; 673 else _this.wrapperTop = params.offsetPxBefore; 674 } 675 if (params.offsetPxAfter>0) { 676 if (isH) _this.wrapperRight = params.offsetPxAfter; 677 else _this.wrapperBottom = params.offsetPxAfter; 678 } 679 if (params.centeredSlides) { 680 if (isH) { 681 _this.wrapperLeft = (containerSize - slideSize)/2; 682 _this.wrapperRight = (containerSize - slideSize)/2; 683 } 684 else { 685 _this.wrapperTop = (containerSize - slideSize)/2; 686 _this.wrapperBottom = (containerSize - slideSize)/2; 687 } 688 } 689 if (isH) { 690 if (_this.wrapperLeft>0) wrapper.style.paddingLeft = _this.wrapperLeft+'px'; 691 if (_this.wrapperRight>0) wrapper.style.paddingRight = _this.wrapperRight+'px'; 692 } 693 else { 694 if (_this.wrapperTop>0) wrapper.style.paddingTop = _this.wrapperTop+'px'; 695 if (_this.wrapperBottom>0) wrapper.style.paddingBottom = _this.wrapperBottom+'px'; 696 } 697 698 wrapperSize = isH ? wrapperWidth + _this.wrapperRight + _this.wrapperLeft : wrapperHeight + _this.wrapperTop + _this.wrapperBottom; 699 wrapper.style.width = wrapperWidth+'px'; 700 wrapper.style.height = wrapperHeight+'px'; 701 var slideLeft = 0; 702 _this.snapGrid = []; 703 _this.slidesGrid = []; 704 for (var i=0; i<_this.slides.length; i++) { 705 _this.snapGrid.push(slideLeft); 706 _this.slidesGrid.push(slideLeft); 707 slideLeft+=slideSize; 708 _this.slides[i].style.width = slideWidth+'px'; 709 _this.slides[i].style.height = slideHeight+'px'; 710 } 711 712 } 713 714 if (!_this.initialized) { 715 _this.callPlugins('onFirstInit'); 716 if (params.onFirstInit) params.onFirstInit(_this); 717 } 718 else { 719 _this.callPlugins('onInit'); 720 if (params.onInit) params.onInit(_this); 721 } 722 _this.initialized = true; 723 } 724 725 _this.reInit = function (forceCalcSlides) { 726 _this.init(true, forceCalcSlides); 727 } 728 729 _this.resizeFix = function (reInit) { 730 _this.callPlugins('beforeResizeFix'); 731 732 _this.init(params.resizeReInit || reInit); 733 734 // swipe to active slide in fixed mode 735 if (!params.freeMode) { 736 _this.swipeTo((params.loop ? _this.activeLoopIndex : _this.activeIndex), 0, false); 737 } 738 739 // move wrapper to the beginning in free mode 740 else if (_this.getWrapperTranslate() < -maxWrapperPosition()) { 741 _this.setWrapperTransition(0);
742 _this.setWrapperTranslate(-maxWrapperPosition()); 743 } 744 745 _this.callPlugins('afterResizeFix'); 746 } 747 748 /*========================================== 749 Max and Min Positions 750 ============================================*/ 751 function maxWrapperPosition() { 752 var a = (wrapperSize - containerSize); 753 if (params.freeMode) { 754 a = wrapperSize - containerSize; 755 } 756 // if (params.loop) a -= containerSize; 757 if (params.slidesPerView > _this.slides.length) a = 0; 758 if (a<0) a = 0; 759 return a; 760 } 761 function minWrapperPosition() { 762 var a = 0; 763 // if (params.loop) a = containerSize; 764 return a; 765 } 766 767 /*========================================== 768 Event Listeners 769 ============================================*/ 770 function initEvents() { 771 var bind = _this.h.addEventListener; 772 773 //Touch Events 774 if (!_this.browser.ie10) { 775 if (_this.support.touch) { 776 bind(_this.wrapper, 'touchstart', onTouchStart); 777 bind(_this.wrapper, 'touchmove', onTouchMove); 778 bind(_this.wrapper, 'touchend', onTouchEnd); 779 } 780 if (params.simulateTouch) { 781 bind(_this.wrapper, 'mousedown', onTouchStart); 782 bind(document, 'mousemove', onTouchMove); 783 bind(document, 'mouseup', onTouchEnd); 784 } 785 } 786 else { 787 bind(_this.wrapper, _this.touchEvents.touchStart, onTouchStart); 788 bind(document, _this.touchEvents.touchMove, onTouchMove); 789 bind(document, _this.touchEvents.touchEnd, onTouchEnd); 790 } 791 792 //Resize Event 793 if (params.autoResize) { 794 bind(window, 'resize', _this.resizeFix); 795 } 796 //Slide Events 797 addSlideEvents(); 798 //Mousewheel 799 _this._wheelEvent = false; 800 if (params.mousewheelControl) { 801 if ( document.onmousewheel !== undefined ) { 802 _this._wheelEvent = "mousewheel"; 803 } 804 try { 805 WheelEvent("wheel"); 806 _this._wheelEvent = "wheel"; 807 } catch (e) {} 808 if ( !_this._wheelEvent ) { 809 _this._wheelEvent = "DOMMouseScroll"; 810 } 811 812 if (_this._wheelEvent) { 813 bind(_this.container, _this._wheelEvent, handleMousewheel); 814 } 815 } 816 817 //Keyboard 818 if (params.keyboardControl) { 819 bind(document, 'keydown', handleKeyboardKeys); 820 } 821 if (params.updateOnImagesReady) { 822 _this.imagesToLoad = $$('img', _this.container); 823 824 for (var i=0; i<_this.imagesToLoad.length; i++) { 825 _loadImage(_this.imagesToLoad[i].getAttribute('src')) 826 } 827 } 828 function _loadImage(src) { 829 var image = new Image(); 830 image.onload = function(){ 831 _this.imagesLoaded++; 832 if (_this.imagesLoaded==_this.imagesToLoad.length) { 833 _this.reInit(); 834 if (params.onImagesReady) params.onImagesReady(_this); 835 } 836 } 837 image.src = src; 838 } 839 } 840 841 //Remove Event Listeners 842 _this.destroy = function(removeResizeFix){ 843 var unbind = _this.h.removeEventListener; 844 845 //Touch Events 846 if (!_this.browser.ie10) { 847 if (_this.support.touch) { 848 unbind(_this.wrapper, 'touchstart', onTouchStart); 849 unbind(_this.wrapper, 'touchmove', onTouchMove); 850 unbind(_this.wrapper, 'touchend', onTouchEnd); 851 } 852 if (params.simulateTouch) { 853 unbind(_this.wrapper, 'mousedown', onTouchStart); 854 unbind(document, 'mousemove', onTouchMove); 855 unbind(document, 'mouseup', onTouchEnd); 856 } 857 } 858 else { 859 unbind(_this.wrapper, _this.touchEvents.touchStart, onTouchStart); 860 unbind(document, _this.touchEvents.touchMove, onTouchMove); 861 unbind(document, _this.touchEvents.touchEnd, onTouchEnd); 862 } 863 864 //Resize Event 865 if (params.autoResize) { 866 unbind(window, 'resize', _this.resizeFix); 867 } 868 869 //Init Slide Events 870 removeSlideEvents(); 871 872 //Pagination 873 if (params.paginationClickable) { 874 removePaginationEvents(); 875 } 876 877 //Mousewheel 878 if (params.mousewheelControl && _this._wheelEvent) { 879 unbind(_this.container, _this._wheelEvent, handleMousewheel); 880 } 881 882 //Keyboard 883 if (params.keyboardControl) { 884 unbind(document, 'keydown', handleKeyboardKeys); 885 } 886 887 //Stop autoplay 888 if (params.autoplay) { 889 _this.stopAutoplay(); 890 } 891 _this.callPlugins('onDestroy'); 892 893 //Destroy variable 894 _this = null; 895 } 896 function addSlideEvents() { 897 var bind = _this.h.addEventListener, 898 i; 899 900 //Prevent Links Events 901 if (params.preventLinks) { 902 var links = $$('a', _this.container); 903 for (i=0; i<links.length; i++) { 904 bind(links[i], 'click', preventClick); 905 } 906 } 907 //Release Form Elements 908 if (params.releaseFormElements) { 909 var formElements = $$('input, textarea, select', _this.container); 910 for (i=0; i<formElements.length; i++) { 911 bind(formElements[i], _this.touchEvents.touchStart, releaseForms, true); 912 } 913 } 914 915 //Slide Clicks & Touches 916 if (params.onSlideClick) { 917 for (i=0; i<_this.slides.length; i++) { 918 bind(_this.slides[i], 'click', slideClick); 919 } 920 } 921 if (params.onSlideTouch) { 922 for (i=0; i<_this.slides.length; i++) { 923 bind(_this.slides[i], _this.touchEvents.touchStart, slideTouch); 924 } 925 } 926 } 927 function removeSlideEvents() { 928 var unbind = _this.h.removeEventListener, 929 i; 930 931 //Slide Clicks & Touches 932 if (params.onSlideClick) { 933 for (i=0; i<_this.slides.length; i++) { 934 unbind(_this.slides[i], 'click', slideClick); 935 } 936 } 937 if (params.onSlideTouch) { 938 for (i=0; i<_this.slides.length; i++) { 939 unbind(_this.slides[i], _this.touchEvents.touchStart, slideTouch); 940 } 941 } 942 //Release Form Elements 943 if (params.releaseFormElements) { 944 var formElements = $$('input, textarea, select', _this.container); 945 for (i=0; i<formElements.length; i++) { 946 unbind(formElements[i], _this.touchEvents.touchStart, releaseForms, true); 947 } 948 } 949 //Prevent Links Events 950 if (params.preventLinks) { 951 var links = $$('a', _this.container); 952 for (i=0; i<links.length; i++) { 953 unbind(links[i], 'click', preventClick); 954 } 955 } 956 } 957 /*========================================== 958 Keyboard Control 959 ============================================*/ 960 function handleKeyboardKeys (e) { 961 var kc = e.keyCode || e.charCode; 962 if (kc==37 || kc==39 || kc==38 || kc==40) { 963 var inView = false; 964 //Check that swiper should be inside of visible area of window 965 var swiperOffset = _this.h.getOffset( _this.container ); 966 var scrollLeft = _this.h.windowScroll().left; 967 var scrollTop = _this.h.windowScroll().top; 968 var windowWidth = _this.h.windowWidth(); 969 var windowHeight = _this.h.windowHeight(); 970 var swiperCoord = [ 971 [swiperOffset.left, swiperOffset.top], 972 [swiperOffset.left + _this.width, swiperOffset.top], 973 [swiperOffset.left, swiperOffset.top + _this.height], 974 [swiperOffset.left + _this.width, swiperOffset.top + _this.height] 975 ] 976 for (var i=0; i<swiperCoord.length; i++) { 977 var point = swiperCoord[i]; 978 if ( 979 point[0]>=scrollLeft && point[0]<=scrollLeft+windowWidth && 980 point[1]>=scrollTop && point[1]<=scrollTop+windowHeight 981 ) { 982 inView = true; 983 } 984 985 } 986 if (!inView) return; 987 } 988 if (isH) { 989 if (kc==37 || kc==39) { 990 if (e.preventDefault) e.preventDefault(); 991 else e.returnValue = false; 992 } 993 if (kc == 39) _this.swipeNext(); 994 if (kc == 37) _this.swipePrev(); 995 } 996 else { 997 if (kc==38 || kc==40) { 998 if (e.preventDefault) e.preventDefault(); 999 else e.returnValue = false; 1000 } 1001 if (kc == 40) _this.swipeNext(); 1002 if (kc == 38) _this.swipePrev(); 1003 } 1004 } 1005 1006 /*========================================== 1007 Mousewheel Control 1008 ============================================*/ 1009 var allowScrollChange = true; 1010 function handleMousewheel (e) { 1011 var we = _this._wheelEvent; 1012 var delta; 1013 //Opera & IE 1014 if (e.detail) delta = -e.detail; 1015 //WebKits 1016 else if (we == 'mousewheel') delta = e.wheelDelta; 1017 //Old FireFox 1018 else if (we == 'DOMMouseScroll') delta = -e.detail; 1019 //New FireFox 1020 else if (we == 'wheel') { 1021 delta = Math.abs(e.deltaX)>Math.abs(e.deltaY) ? - e.deltaX : - e.deltaY; 1022 } 1023 if (!params.freeMode) { 1024 if(delta<0) _this.swipeNext(); 1025 else _this.swipePrev(); 1026 } 1027 else { 1028 //Freemode or scrollContainer: 1029 var position = _this.getWrapperTranslate() + delta; 1030 1031 if (position > 0) position = 0; 1032 if (position < -maxWrapperPosition()) position = -maxWrapperPosition(); 1033 1034 _this.setWrapperTransition(0); 1035 _this.setWrapperTranslate(position); 1036 _this.updateActiveSlide(position); 1037 } 1038 if (params.autoplay) _this.stopAutoplay(); 1039 1040 if(e.preventDefault) e.preventDefault(); 1041 else e.returnValue = false; 1042 return false; 1043 } 1044 1045 /*========================= 1046 Grab Cursor 1047 ===========================*/ 1048 if (params.grabCursor) { 1049 var containerStyle = _this.container.style; 1050 containerStyle.cursor = 'move'; 1051 containerStyle.cursor = 'grab'; 1052 containerStyle.cursor = '-moz-grab'; 1053 containerStyle.cursor = '-webkit-grab'; 1054 } 1055 1056 /*========================= 1057 Slides Events Handlers 1058 ===========================*/ 1059 1060 _this.allowSlideClick = true; 1061 function slideClick(event) { 1062 if (_this.allowSlideClick) { 1063 1064 setClickedSlide(event); 1065 params.onSlideClick(_this); 1066 } 1067 } 1068 1069 function slideTouch(event) { 1070 1071 setClickedSlide(event); 1072 params.onSlideTouch(_this); 1073 } 1074 1075 function setClickedSlide(event) { 1076 1077 // IE 6-8 support 1078 if (!event.currentTarget) { 1079 var element = event.srcElement; 1080 do { 1081 if (element.className.indexOf(params.slideClass) > -1) { 1082 break; 1083 } 1084 } 1085 while (element = element.parentNode); 1086 _this.clickedSlide = element; 1087 } 1088 else { 1089 _this.clickedSlide = event.currentTarget; 1090 } 1091 1092 _this.clickedSlideIndex = _this.slides.indexOf(_this.clickedSlide); 1093 _this.clickedSlideLoopIndex = _this.clickedSlideIndex - (_this.loopedSlides || 0); 1094 } 1095 1096 _this.allowLinks = true; 1097 function preventClick(e) { 1098 if (!_this.allowLinks) { 1099 if(e.preventDefault) e.preventDefault(); 1100 else e.returnValue = false; 1101 return false; 1102 } 1103 } 1104 function releaseForms(e) { 1105 if (e.stopPropagation) e.stopPropagation(); 1106 else e.returnValue = false; 1107 return false; 1108 } 1109 1110 /*================================================== 1111 Event Handlers 1112 ====================================================*/ 1113 var isTouchEvent = false; 1114 var allowThresholdMove; 1115 var allowMomentumBounce = true; 1116 function onTouchStart(event) { 1117 1118 //deactivate touch if only one slide 1119 if(jQuery(event.target).parents('.swiper-container').find('.swiper-slide').length == 1) return false; 1120 1121 //deactivate touch for duplicate transitions 1122 if(jQuery(event.target).parents('.swiper-container').find('.swiper-slide.duplicate-transition').length > 0) return false; 1123 1124 if (params.preventLinks) _this.allowLinks = true; 1125 //Exit if slider is already was touched 1126 if (_this.isTouched || params.onlyExternal) { 1127 return false; 1128 } 1129 1130 if (params.noSwiping && (event.target || event.srcElement) && noSwipingSlide(event.target || event.srcElement)) return false; 1131 allowMomentumBounce = false; 1132 1133 //Check For Nested Swipers 1134 _this.isTouched = true; 1135 isTouchEvent = event.type=='touchstart'; 1136 1137 if (!isTouchEvent || event.targetTouches.length == 1 ) { 1138 _this.callPlugins('onTouchStartBegin'); 1139 1140 if(!isTouchEvent) { 1141 if(event.preventDefault) event.preventDefault(); 1142 else event.returnValue = false; 1143 } 1144 1145 var pageX = isTouchEvent ? event.targetTouches[0].pageX : (event.pageX || event.clientX); 1146 var pageY = isTouchEvent ? event.targetTouches[0].pageY : (event.pageY || event.clientY); 1147 1148 //Start Touches to check the scrolling 1149 _this.touches.startX = _this.touches.currentX = pageX; 1150 _this.touches.startY = _this.touches.currentY = pageY; 1151 1152 _this.touches.start = _this.touches.current = isH ? pageX : pageY; 1153 1154 //Set Transition Time to 0 1155 _this.setWrapperTransition(0); 1156 1157 //Get Start Translate Position 1158 _this.positions.start = _this.positions.current = _this.getWrapperTranslate(); 1159 1160 //Set Transform 1161 _this.setWrapperTranslate(_this.positions.start); 1162 1163 //TouchStartTime 1164 _this.times.start = (new Date()).getTime(); 1165 1166 //Unset Scrolling 1167 isScrolling = undefined; 1168 1169 //Set Treshold 1170 if (params.moveStartThreshold>0) allowThresholdMove = false; 1171 1172 //CallBack 1173 if (params.onTouchStart) params.onTouchStart(_this); 1174 _this.callPlugins('onTouchStartEnd'); 1175 1176 } 1177 } 1178 var velocityPrevPosition, velocityPrevTime; 1179 function onTouchMove(event) { 1180 // If slider is not touched - exit 1181 if (!_this.isTouched || params.onlyExternal) return; 1182 if (isTouchEvent && event.type=='mousemove') return; 1183 1184 var pageX = isTouchEvent ? event.targetTouches[0].pageX : (event.pageX || event.clientX); 1185 var pageY = isTouchEvent ? event.targetTouches[0].pageY : (event.pageY || event.clientY); 1186 1187 //check for scrolling
1188 if ( typeof isScrolling === 'undefined' && isH) { 1189 isScrolling = !!( isScrolling || Math.abs(pageY - _this.touches.startY) > Math.abs( pageX - _this.touches.startX ) ); 1190 } 1191 if ( typeof isScrolling === 'undefined' && !isH) { 1192 isScrolling = !!( isScrolling || Math.abs(pageY - _this.touches.startY) < Math.abs( pageX - _this.touches.startX ) ); 1193 } 1194 if (isScrolling ) { 1195 _this.isTouched = false; 1196 return; 1197 } 1198 1199 //Check For Nested Swipers 1200 if (event.assignedToSwiper) { 1201 _this.isTouched = false; 1202 return; 1203 } 1204 event.assignedToSwiper = true; 1205 1206 //Block inner links 1207 if (params.preventLinks) { 1208 _this.allowLinks = false; 1209 } 1210 if (params.onSlideClick) { 1211 _this.allowSlideClick = false; 1212 } 1213 1214 //Stop AutoPlay if exist 1215 if (params.autoplay) { 1216 _this.stopAutoplay(); 1217 } 1218 if (!isTouchEvent || event.touches.length == 1) { 1219 1220 //Moved Flag 1221 if (!_this.isMoved) { 1222 _this.callPlugins('onTouchMoveStart'); 1223 1224 if (params.loop) { 1225 _this.fixLoop(); 1226 _this.positions.start = _this.getWrapperTranslate(); 1227 } 1228 if (params.onTouchMoveStart) params.onTouchMoveStart(_this); 1229 } 1230 _this.isMoved = true; 1231 1232 // cancel event 1233 if(event.preventDefault) event.preventDefault(); 1234 else event.returnValue = false; 1235 1236 _this.touches.current = isH ? pageX : pageY ; 1237 1238 _this.positions.current = (_this.touches.current - _this.touches.start) * params.touchRatio + _this.positions.start; 1239 1240 //Resistance Callbacks 1241 if(_this.positions.current > 0 && params.onResistanceBefore) { 1242 params.onResistanceBefore(_this, _this.positions.current); 1243 } 1244 if(_this.positions.current < -maxWrapperPosition() && params.onResistanceAfter) { 1245 params.onResistanceAfter(_this, Math.abs(_this.positions.current + maxWrapperPosition())); 1246 } 1247 //Resistance 1248 if (params.resistance && params.resistance!='100%') { 1249 //Resistance for Negative-Back sliding 1250 if(_this.positions.current > 0) { 1251 var resistance = 1 - _this.positions.current/containerSize/2; 1252 if (resistance < 0.5) 1253 _this.positions.current = (containerSize/2); 1254 else 1255 _this.positions.current = _this.positions.current * resistance; 1256 } 1257 //Resistance for After-End Sliding 1258 if ( _this.positions.current < -maxWrapperPosition() ) { 1259 1260 var diff = (_this.touches.current - _this.touches.start)*params.touchRatio + (maxWrapperPosition()+_this.positions.start); 1261 var resistance = (containerSize+diff)/(containerSize); 1262 var newPos = _this.positions.current-diff*(1-resistance)/2; 1263 var stopPos = -maxWrapperPosition() - containerSize/2; 1264 1265 if (newPos < stopPos || resistance<=0) 1266 _this.positions.current = stopPos; 1267 else 1268 _this.positions.current = newPos; 1269 } 1270 } 1271 if (params.resistance && params.resistance=='100%') { 1272 //Resistance for Negative-Back sliding 1273 if(_this.positions.current > 0 && !(params.freeMode&&!params.freeModeFluid)) { 1274 _this.positions.current = 0; 1275 } 1276 //Resistance for After-End Sliding 1277 if ( (_this.positions.current) < -maxWrapperPosition() && !(params.freeMode&&!params.freeModeFluid)) { 1278 _this.positions.current = -maxWrapperPosition(); 1279 } 1280 } 1281 //Move Slides 1282 if (!params.followFinger) return; 1283 1284 if (!params.moveStartThreshold) { 1285 _this.setWrapperTranslate(_this.positions.current); 1286 } 1287 else { 1288 if ( Math.abs(_this.touches.current - _this.touches.start)>params.moveStartThreshold || allowThresholdMove) { 1289 allowThresholdMove = true; 1290 _this.setWrapperTranslate(_this.positions.current); 1291 } 1292 else { 1293 _this.positions.current = _this.positions.start; 1294 } 1295 } 1296 1297 if (params.freeMode || params.watchActiveIndex) { 1298 _this.updateActiveSlide(_this.positions.current); 1299 } 1300 1301 //Grab Cursor 1302 //Grab Cursor 1303 if (params.grabCursor) { 1304 _this.container.style.cursor = 'move'; 1305 _this.container.style.cursor = 'grabbing'; 1306 _this.container.style.cursor = '-moz-grabbing'; 1307 _this.container.style.cursor = '-webkit-grabbing'; 1308 } 1309 //Velocity 1310 if (!velocityPrevPosition) velocityPrevPosition = _this.touches.current; 1311 if (!velocityPrevTime) velocityPrevTime = (new Date).getTime(); 1312 _this.velocity = (_this.touches.current - velocityPrevPosition)/((new Date).getTime() - velocityPrevTime)/2; 1313 1314 if (Math.abs(_this.touches.current - velocityPrevPosition)<2) _this.velocity=0; 1315 velocityPrevPosition = _this.touches.current; 1316 velocityPrevTime = (new Date).getTime(); 1317 //Callbacks 1318 _this.callPlugins('onTouchMoveEnd'); 1319 if (params.onTouchMove) params.onTouchMove(_this); 1320 1321 return false; 1322 } 1323 } 1324 function onTouchEnd(event) { 1325 //Check For scrolling 1326 if (isScrolling) { 1327 _this.swipeReset(); 1328 } 1329 // If slider is not touched exit 1330 if ( params.onlyExternal || !_this.isTouched ) return; 1331 _this.isTouched = false 1332 1333 //Return Grab Cursor 1334 if (params.grabCursor) { 1335 _this.container.style.cursor = 'move'; 1336 _this.container.style.cursor = 'grab'; 1337 _this.container.style.cursor = '-moz-grab'; 1338 _this.container.style.cursor = '-webkit-grab'; 1339 } 1340 1341 //Check for Current Position 1342 if (!_this.positions.current && _this.positions.current!==0) { 1343 _this.positions.current = _this.positions.start 1344 } 1345 1346 //For case if slider touched but not moved 1347 if (params.followFinger) { 1348 _this.setWrapperTranslate(_this.positions.current); 1349 } 1350 1351 // TouchEndTime
1352 _this.times.end = (new Date()).getTime(); 1353 1354 //Difference 1355 _this.touches.diff = _this.touches.current - _this.touches.start 1356 _this.touches.abs = Math.abs(_this.touches.diff) 1357 1358 _this.positions.diff = _this.positions.current - _this.positions.start 1359 _this.positions.abs = Math.abs(_this.positions.diff) 1360 1361 var diff = _this.positions.diff ; 1362 var diffAbs =_this.positions.abs ; 1363 var timeDiff = _this.times.end - _this.times.start 1364 1365 if(diffAbs < 5 && (timeDiff) < 300 && _this.allowLinks == false) { 1366 if (!params.freeMode && diffAbs!=0) _this.swipeReset() 1367 //Release inner links 1368 if (params.preventLinks) { 1369 _this.allowLinks = true; 1370 } 1371 if (params.onSlideClick) { 1372 _this.allowSlideClick = true; 1373 } 1374 } 1375 1376 setTimeout(function () { 1377 //Release inner links 1378 if (params.preventLinks) { 1379 _this.allowLinks = true; 1380 } 1381 if (params.onSlideClick) { 1382 _this.allowSlideClick = true; 1383 } 1384 }, 100); 1385 1386 var maxPosition = maxWrapperPosition(); 1387 1388 //Not moved or Prevent Negative Back Sliding/After-End Sliding 1389 if (!_this.isMoved && params.freeMode) { 1390 _this.isMoved = false; 1391 if (params.onTouchEnd) params.onTouchEnd(_this); 1392 _this.callPlugins('onTouchEnd'); 1393 return; 1394 } 1395 if (!_this.isMoved || _this.positions.current > 0 || _this.positions.current < -maxPosition) { 1396 _this.swipeReset(); 1397 if (params.onTouchEnd) params.onTouchEnd(_this); 1398 _this.callPlugins('onTouchEnd'); 1399 return; 1400 } 1401 1402 _this.isMoved = false; 1403 1404 //Free Mode 1405 if (params.freeMode) { 1406 if ( params.freeModeFluid ) { 1407 var momentumDuration = 1000*params.momentumRatio; 1408 var momentumDistance = _this.velocity*momentumDuration; 1409 var newPosition = _this.positions.current + momentumDistance 1410 var doBounce = false; 1411 var afterBouncePosition; 1412 var bounceAmount = Math.abs( _this.velocity )*20*params.momentumBounceRatio; 1413 if (newPosition < -maxPosition) { 1414 if (params.momentumBounce && _this.support.transitions) { 1415 if (newPosition + maxPosition < -bounceAmount) newPosition = -maxPosition-bounceAmount; 1416 afterBouncePosition = -maxPosition; 1417 doBounce=true; 1418 allowMomentumBounce = true; 1419 } 1420 else newPosition = -maxPosition; 1421 } 1422 if (newPosition > 0) { 1423 if (params.momentumBounce && _this.support.transitions) { 1424 if (newPosition>bounceAmount) newPosition = bounceAmount; 1425 afterBouncePosition = 0 1426 doBounce = true; 1427 allowMomentumBounce = true; 1428 } 1429 else newPosition = 0; 1430 } 1431 //Fix duration 1432 if (_this.velocity!=0) momentumDuration = Math.abs((newPosition - _this.positions.current)/_this.velocity) 1433 1434 _this.setWrapperTranslate(newPosition); 1435 1436 _this.setWrapperTransition( momentumDuration ); 1437 1438 if (params.momentumBounce && doBounce) { 1439 _this.wrapperTransitionEnd(function () { 1440 if (!allowMomentumBounce) return; 1441 1442 if (params.onMomentumBounce) params.onMomentumBounce(_this); 1443 1444 _this.setWrapperTranslate(afterBouncePosition); 1445 _this.setWrapperTransition(300); 1446 }) 1447 } 1448 1449 _this.updateActiveSlide(newPosition) 1450 } 1451 if (!params.freeModeFluid || timeDiff >= 300) _this.updateActiveSlide(_this.positions.current) 1452 1453 if (params.onTouchEnd) params.onTouchEnd(_this) 1454 _this.callPlugins('onTouchEnd'); 1455 return; 1456 } 1457 1458 //Direction 1459 direction = diff < 0 ? "toNext" : "toPrev" 1460 1461 //Short Touches 1462 if (direction=="toNext" && ( timeDiff <= 300 ) ) { 1463 if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset() 1464 else _this.swipeNext(true); 1465 } 1466 1467 if (direction=="toPrev" && ( timeDiff <= 300 ) ) { 1468 if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset() 1469 else _this.swipePrev(true); 1470 } 1471 1472 //Long Touches 1473 var targetSlideSize = 0; 1474 if(params.slidesPerView == 'auto') { 1475 //Define current slide's width 1476 var currentPosition = Math.abs(_this.getWrapperTranslate()); 1477 var slidesOffset = 0; 1478 var _slideSize; 1479 for (var i=0; i<_this.slides.length; i++) { 1480 _slideSize = isH ? _this.slides[i].getWidth(true) : _this.slides[i].getHeight(true); 1481 slidesOffset+= _slideSize; 1482 if (slidesOffset>currentPosition) { 1483 targetSlideSize = _slideSize; 1484 break; 1485 } 1486 }
1487 if (targetSlideSize>containerSize) targetSlideSize = containerSize; 1488 } 1489 else { 1490 targetSlideSize = slideSize * params.slidesPerView; 1491 } 1492 if (direction=="toNext" && ( timeDiff > 300 ) ) { 1493 if (diffAbs >= targetSlideSize*0.5) { 1494 _this.swipeNext(true) 1495 } 1496 else { 1497 _this.swipeReset() 1498 } 1499 } 1500 if (direction=="toPrev" && ( timeDiff > 300 ) ) { 1501 if (diffAbs >= targetSlideSize*0.5) { 1502 _this.swipePrev(true); 1503 } 1504 else { 1505 _this.swipeReset() 1506 } 1507 } 1508 if (params.onTouchEnd) params.onTouchEnd(_this) 1509 _this.callPlugins('onTouchEnd'); 1510 } 1511 1512 1513 /*================================================== 1514 noSwiping Bubble Check by Isaac Strack 1515 ====================================================*/ 1516 function noSwipingSlide(el){ 1517 /*This function is specifically designed to check the parent elements for the noSwiping class, up to the wrapper. 1518 We need to check parents because while onTouchStart bubbles, _this.isTouched is checked in onTouchStart, which stops the bubbling. 1519 So, if a text box, for example, is the initial target, and the parent slide container has the noSwiping class, the _this.isTouched 1520 check will never find it, and what was supposed to be noSwiping is able to be swiped. 1521 This function will iterate up and check for the noSwiping class in parents, up through the wrapperClass.*/ 1522 1523 // First we create a truthy variable, which is that swiping is allowd (noSwiping = false) 1524 var noSwiping = false; 1525 1526 // Now we iterate up (parentElements) until we reach the node with the wrapperClass. 1527 do{ 1528 1529 // Each time, we check to see if there's a 'swiper-no-swiping' class (noSwipingClass). 1530 if (el.className.indexOf(params.noSwipingClass)>-1) 1531 { 1532 noSwiping = true; // If there is, we set noSwiping = true; 1533 } 1534 1535 el = el.parentElement; // now we iterate up (parent node) 1536 1537 } while(!noSwiping && el.parentElement && el.className.indexOf(params.wrapperClass)==-1); // also include el.parentElement truthy, just in case. 1538 1539 // because we didn't check the wrapper itself, we do so now, if noSwiping is false: 1540 if (!noSwiping && el.className.indexOf(params.wrapperClass)>-1 && el.className.indexOf(params.noSwipingClass)>-1) 1541 noSwiping = true; // if the wrapper has the noSwipingClass, we set noSwiping = true; 1542 1543 return noSwiping; 1544 } 1545 1546 /*================================================== 1547 Swipe Functions 1548 ====================================================*/ 1549 _this.swipeNext = function(internal){ 1550 if (!internal && params.loop) _this.fixLoop(); 1551 _this.callPlugins('onSwipeNext'); 1552 var currentPosition = _this.getWrapperTranslate(); 1553 var newPosition = currentPosition; 1554 if (params.slidesPerView=='auto') { 1555 for (var i=0; i<_this.snapGrid.length; i++) { 1556 if (-currentPosition >= _this.snapGrid[i] && -currentPosition<_this.snapGrid[i+1]) { 1557 newPosition = -_this.snapGrid[i+1] 1558 break; 1559 } 1560 } 1561 } 1562 else { 1563 var groupSize = slideSize * params.slidesPerGroup; 1564 newPosition = -(Math.floor(Math.abs(currentPosition)/Math.floor(groupSize))*groupSize + groupSize); 1565 } 1566 if (newPosition < - maxWrapperPosition()) { 1567 newPosition = - maxWrapperPosition() 1568 }; 1569 1570 if (newPosition == currentPosition) return false; 1571 1572 swipeToPosition(newPosition, 'next'); 1573 return true 1574 } 1575 _this.swipePrev = function(internal){ 1576 if (!internal && params.loop) _this.fixLoop(); 1577 if (!internal && params.autoplay) _this.stopAutoplay(); 1578 _this.callPlugins('onSwipePrev'); 1579 1580 var currentPosition = Math.ceil(_this.getWrapperTranslate()); 1581 var newPosition; 1582 if (params.slidesPerView=='auto') { 1583 newPosition = 0; 1584 for (var i=1; i<_this.snapGrid.length; i++) { 1585 if (-currentPosition == _this.snapGrid[i]) { 1586 newPosition = -_this.snapGrid[i-1] 1587 break; 1588 } 1589 if (-currentPosition > _this.snapGrid[i] && -currentPosition<_this.snapGrid[i+1]) { 1590 newPosition = -_this.snapGrid[i] 1591 break; 1592 } 1593 } 1594 } 1595 else { 1596 var groupSize = slideSize * params.slidesPerGroup; 1597 newPosition = -(Math.ceil(-currentPosition/groupSize)-1)*groupSize; 1598 } 1599 1600 if (newPosition > 0) newPosition = 0; 1601 1602 if (newPosition == currentPosition) return false; 1603 swipeToPosition(newPosition, 'prev'); 1604 return true; 1605 1606 } 1607 _this.swipeReset = function(){ 1608 _this.callPlugins('onSwipeReset'); 1609 var currentPosition = _this.getWrapperTranslate(); 1610 var groupSize = slideSize * params.slidesPerGroup; 1611 var newPosition; 1612 var maxPosition = -maxWrapperPosition(); 1613 if (params.slidesPerView=='auto') { 1614 newPosition = 0; 1615 for (var i=0; i<_this.snapGrid.length; i++) { 1616 if (-currentPosition===_this.snapGrid[i]) return; 1617 if (-currentPosition >= _this.snapGrid[i] && -currentPosition<_this.snapGrid[i+1]) { 1618 if(_this.positions.diff>0) newPosition = -_this.snapGrid[i+1] 1619 else newPosition = -_this.snapGrid[i] 1620 break; 1621 } 1622 } 1623 if (-currentPosition >= _this.snapGrid[_this.snapGrid.length-1]) newPosition = -_this.snapGrid[_this.snapGrid.length-1]; 1624 if (currentPosition <= -maxWrapperPosition()) newPosition = -maxWrapperPosition() 1625 } 1626 else { 1627 newPosition = currentPosition<0 ? Math.round(currentPosition/groupSize)*groupSize : 0 1628 } 1629 if (params.scrollContainer) { 1630 newPosition = currentPosition<0 ? currentPosition : 0; 1631 } 1632 if (newPosition < -maxWrapperPosition()) { 1633 newPosition = -maxWrapperPosition() 1634 } 1635 if (params.scrollContainer && (containerSize>slideSize)) { 1636 newPosition = 0; 1637 } 1638 1639 if (newPosition == currentPosition) return false; 1640 1641 swipeToPosition(newPosition, 'reset'); 1642 return true; 1643 } 1644 1645 _this.swipeTo = function(index, speed, runCallbacks) { 1646 index = parseInt(index, 10); 1647 _this.callPlugins('onSwipeTo', {index:index, speed:speed}); 1648 if (params.loop) index = index + _this.loopedSlides; 1649 var currentPosition = _this.getWrapperTranslate(); 1650 if (index > (_this.slides.length-1) || index < 0) return; 1651 var newPosition 1652 if (params.slidesPerView=='auto') { 1653 newPosition = -_this.slidesGrid[ index ]; 1654 } 1655 else { 1656 newPosition = -index*slideSize; 1657 } 1658 if (newPosition < - maxWrapperPosition()) { 1659 newPosition = - maxWrapperPosition(); 1660 }; 1661 1662 if (newPosition == currentPosition) return false; 1663 1664 runCallbacks = runCallbacks===false ? false : true; 1665 swipeToPosition(newPosition, 'to', {index:index, speed:speed, runCallbacks:runCallbacks}); 1666 return true; 1667 } 1668 1669 function swipeToPosition(newPosition, action, toOptions) { 1670 var speed = (action=='to' && toOptions.speed >= 0) ? toOptions.speed : params.speed; 1671 1672 if (_this.support.transitions || !params.DOMAnimation) { 1673 _this.setWrapperTranslate(newPosition); 1674 _this.setWrapperTransition(speed); 1675 } 1676 else { 1677 //Try the DOM animation 1678 var currentPosition = _this.getWrapperTranslate(); 1679 var animationStep = Math.ceil( (newPosition - currentPosition)/speed*(1000/60) ); 1680 var direction = currentPosition > newPosition ? 'toNext' : 'toPrev'; 1681 var condition = direction=='toNext' ? currentPosition > newPosition : currentPosition < newPosition; 1682 if (_this._DOMAnimating) return; 1683 1684 anim(); 1685 } 1686 function anim(){ 1687 currentPosition += animationStep; 1688 condition = direction=='toNext' ? currentPosition > newPosition : currentPosition < newPosition; 1689 if (condition) { 1690 _this.setWrapperTranslate(Math.round(currentPosition)); 1691 _this._DOMAnimating = true 1692 window.setTimeout(function(){ 1693 anim() 1694 }, 1000 / 60) 1695 } 1696 else { 1697 if (params.onSlideChangeEnd) params.onSlideChangeEnd(_this); 1698 _this.setWrapperTranslate(newPosition); 1699 _this._DOMAnimating = false; 1700 } 1701 } 1702 1703 //Update Active Slide Index 1704 _this.updateActiveSlide(newPosition); 1705 1706 //Callbacks 1707 if (params.onSlideNext && action=='next') { 1708 params.onSlideNext(_this, newPosition); 1709 } 1710 if (params.onSlidePrev && action=='prev') { 1711 params.onSlidePrev(_this, newPosition); 1712 } 1713 //"Reset" Callback 1714 if (params.onSlideReset && action=='reset') { 1715 params.onSlideReset(_this, newPosition); 1716 } 1717 1718 //"Next", "Prev" and "To" Callbacks 1719 if (action=='next' || action=='prev' || (action=='to' && toOptions.runCallbacks==true)) 1720 slideChangeCallbacks(); 1721 } 1722 /*================================================== 1723 Transition Callbacks 1724 ====================================================*/ 1725 //Prevent Multiple Callbacks 1726 _this._queueStartCallbacks = false; 1727 _this._queueEndCallbacks = false; 1728 function slideChangeCallbacks() { 1729 //Transition Start Callback 1730 _this.callPlugins('onSlideChangeStart'); 1731 if (params.onSlideChangeStart) { 1732 if (params.queueStartCallbacks && _this.support.transitions) { 1733 if (_this._queueStartCallbacks) return; 1734 _this._queueStartCallbacks = true; 1735 params.onSlideChangeStart(_this) 1736 _this.wrapperTransitionEnd(function(){ 1737 _this._queueStartCallbacks = false; 1738 }) 1739 } 1740 else params.onSlideChangeStart(_this) 1741 } 1742 //Transition End Callback 1743 if (params.onSlideChangeEnd) { 1744 if (_this.support.transitions) { 1745 if (params.queueEndCallbacks) { 1746 if (_this._queueEndCallbacks) return; 1747 _this._queueEndCallbacks = true; 1748 _this.wrapperTransitionEnd(params.onSlideChangeEnd) 1749 } 1750 else { 1751 _this.wrapperTransitionEnd(function(){ _this.fixLoop(); params.onSlideChangeEnd(_this); }); 1752 } 1753 } 1754 else { 1755 if (!params.DOMAnimation) { 1756 setTimeout(function(){ 1757 params.onSlideChangeEnd(_this) 1758 },10) 1759 } 1760 } 1761 } 1762 } 1763 1764 /*================================================== 1765 Update Active Slide Index 1766 ====================================================*/ 1767 _this.updateActiveSlide = function(position) { 1768 if (!_this.initialized) return; 1769 if (_this.slides.length==0) return; 1770 _this.previousIndex = _this.activeIndex; 1771 if (typeof position=='undefined') position = _this.getWrapperTranslate(); 1772 if (position>0) position=0; 1773 1774 if (params.slidesPerView == 'auto') { 1775 var slidesOffset = 0; 1776 _this.activeIndex = _this.slidesGrid.indexOf(-position); 1777 if (_this.activeIndex<0) { 1778 for (var i=0; i<_this.slidesGrid.length-1; i++) { 1779 if (-position>_this.slidesGrid[i] && -position<_this.slidesGrid[i+1]) { 1780 break; 1781 } 1782 } 1783 var leftDistance = Math.abs( _this.slidesGrid[i] + position ) 1784 var rightDistance = Math.abs( _this.slidesGrid[i+1] + position ) 1785 if (leftDistance<=rightDistance) _this.activeIndex = i; 1786 else _this.activeIndex = i+1; 1787 } 1788 } 1789 else { 1790 _this.activeIndex = Math[params.visibilityFullFit ? 'ceil' : 'round']( -position/slideSize ); 1791 } 1792 1793 if (_this.activeIndex == _this.slides.length ) _this.activeIndex = _this.slides.length - 1; 1794 if (_this.activeIndex < 0) _this.activeIndex = 0; 1795 1796 // Check for slide 1797 if (!_this.slides[_this.activeIndex]) return; 1798 1799 // Calc Visible slides 1800 _this.calcVisibleSlides(position); 1801 1802 // Mark visible and active slides with additonal classes 1803 var activeClassRegexp = new RegExp( "\\s*" + params.slideActiveClass ); 1804 var inViewClassRegexp = new RegExp( "\\s*" + params.slideVisibleClass ); 1805 1806 for (var i = 0; i < _this.slides.length; i++) { 1807 _this.slides[ i ].className = _this.slides[ i ].className.replace( activeClassRegexp, '' ).replace( inViewClassRegexp, '' ); 1808 if ( _this.visibleSlides.indexOf( _this.slides[ i ] )>=0 ) { 1809 _this.slides[ i ].className += ' ' + params.slideVisibleClass; 1810 } 1811 1812 } 1813 _this.slides[ _this.activeIndex ].className += ' ' + params.slideActiveClass; 1814 1815 //Update loop index 1816 if (params.loop) { 1817 var ls = _this.loopedSlides; 1818 _this.activeLoopIndex = _this.activeIndex - ls; 1819 if (_this.activeLoopIndex >= _this.slides.length - ls*2 ) { 1820 _this.activeLoopIndex = _this.slides.length - ls*2 - _this.activeLoopIndex; 1821 } 1822 if (_this.activeLoopIndex<0) { 1823 _this.activeLoopIndex = _this.slides.length - ls*2 + _this.activeLoopIndex; 1824 } 1825 } 1826 else { 1827 _this.activeLoopIndex = _this.activeIndex; 1828 } 1829 //Update Pagination 1830 if (params.pagination) { 1831 _this.updatePagination(position); 1832 } 1833 } 1834 /*================================================== 1835 Pagination 1836 ====================================================*/ 1837 _this.createPagination = function (firstInit) { 1838 if (params.paginationClickable && _this.paginationButtons) { 1839 removePaginationEvents(); 1840 } 1841 var paginationHTML = ""; 1842 var numOfSlides = _this.slides.length; 1843 var numOfButtons = numOfSlides; 1844 if (params.loop) numOfButtons -= _this.loopedSlides*2 1845 for (var i = 0; i < numOfButtons; i++) { 1846 paginationHTML += '<'+params.paginationElement+' class="'+params.paginationElementClass+'"></'+params.paginationElement+'>' 1847 } 1848 _this.paginationContainer = params.pagination.nodeType ? params.pagination : $$(params.pagination)[0]; 1849 _this.paginationContainer.innerHTML = paginationHTML; 1850 _this.paginationButtons = $$('.'+params.paginationElementClass, _this.paginationContainer); 1851 if (!firstInit) _this.updatePagination() 1852 _this.callPlugins('onCreatePagination'); 1853 if (params.paginationClickable) { 1854 addPaginationEvents(); 1855 } 1856 } 1857 function removePaginationEvents() { 1858 var pagers = _this.paginationButtons; 1859 for (var i=0; i<pagers.length; i++) {
1860 _this.h.removeEventListener(pagers[i], 'click', paginationClick); 1861 } 1862 } 1863 function addPaginationEvents() { 1864 var pagers = _this.paginationButtons; 1865 for (var i=0; i<pagers.length; i++) { 1866 _this.h.addEventListener(pagers[i], 'click', paginationClick); 1867 } 1868 } 1869 function paginationClick(e){ 1870 var index; 1871 var target = e.target || e.srcElement; 1872 var pagers = _this.paginationButtons; 1873 for (var i=0; i<pagers.length; i++) { 1874 if (target===pagers[i]) index = i; 1875 } 1876 _this.swipeTo(index) 1877 } 1878 _this.updatePagination = function(position) { 1879 if (!params.pagination) return; 1880 if (_this.slides.length<1) return; 1881 1882 var activePagers = $$('.'+params.paginationActiveClass, _this.paginationContainer); 1883 if(!activePagers) return; 1884 1885 //Reset all Buttons' class to not active 1886 var pagers = _this.paginationButtons; 1887 if (pagers.length==0) return; 1888 for (var i=0; i < pagers.length; i++) { 1889 pagers[i].className = params.paginationElementClass 1890 } 1891 1892 var indexOffset = params.loop ? _this.loopedSlides : 0; 1893 if (params.paginationAsRange) { 1894 if (!_this.visibleSlides) _this.calcVisibleSlides(position) 1895 //Get Visible Indexes 1896 var visibleIndexes = []; 1897 for (var i = 0; i < _this.visibleSlides.length; i++) { 1898 var visIndex = _this.slides.indexOf( _this.visibleSlides[i] ) - indexOffset 1899 1900 if (params.loop && visIndex<0) { 1901 visIndex = _this.slides.length - _this.loopedSlides*2 + visIndex; 1902 } 1903 if (params.loop && visIndex>=_this.slides.length-_this.loopedSlides*2) { 1904 visIndex = _this.slides.length - _this.loopedSlides*2 - visIndex; 1905 visIndex = Math.abs(visIndex) 1906 } 1907 visibleIndexes.push( visIndex ) 1908 } 1909 1910 for (i=0; i<visibleIndexes.length; i++) { 1911 if (pagers[ visibleIndexes[i] ]) pagers[ visibleIndexes[i] ].className += ' ' + params.paginationVisibleClass; 1912 } 1913 1914 if (params.loop) { 1915 pagers[ _this.activeLoopIndex ].className += ' ' + params.paginationActiveClass; 1916 } 1917 else { 1918 pagers[ _this.activeIndex ].className += ' ' + params.paginationActiveClass; 1919 } 1920 1921 } 1922 else { 1923 if (params.loop) { 1924 pagers[ _this.activeLoopIndex ].className+=' '+params.paginationActiveClass+' '+params.paginationVisibleClass; 1925 } 1926 else { 1927 pagers[ _this.activeIndex ].className+=' '+params.paginationActiveClass+' '+params.paginationVisibleClass; 1928 } 1929 1930 } 1931 1932 } 1933 _this.calcVisibleSlides = function(position){ 1934 var visibleSlides = []; 1935 var _slideLeft = 0, _slideSize = 0, _slideRight = 0; 1936 if (isH && _this.wrapperLeft>0) position = position+_this.wrapperLeft; 1937 if (!isH && _this.wrapperTop>0) position = position+_this.wrapperTop; 1938 1939 for (var i=0; i<_this.slides.length; i++) { 1940 _slideLeft += _slideSize; 1941 if (params.slidesPerView == 'auto') 1942 _slideSize = isH ? _this.h.getWidth(_this.slides[i],true) : _this.h.getHeight(_this.slides[i],true); 1943 else _slideSize = slideSize; 1944 1945 _slideRight = _slideLeft + _slideSize; 1946 var isVisibile = false; 1947 if (params.visibilityFullFit) { 1948 if (_slideLeft >= -position && _slideRight <= -position+containerSize) isVisibile = true; 1949 if (_slideLeft <= -position && _slideRight >= -position+containerSize) isVisibile = true; 1950 } 1951 else { 1952 1953 if (_slideRight > -position && _slideRight <= ((-position+containerSize))) isVisibile = true; 1954 if (_slideLeft >= -position && _slideLeft < ((-position+containerSize))) isVisibile = true; 1955 if (_slideLeft < -position && _slideRight > ((-position+containerSize))) isVisibile = true; 1956 } 1957 1958 if (isVisibile) visibleSlides.push(_this.slides[i]) 1959 1960 } 1961 if (visibleSlides.length==0) visibleSlides = [ _this.slides[ _this.activeIndex ] ] 1962 1963 _this.visibleSlides = visibleSlides; 1964 } 1965 1966 /*========================================== 1967 Autoplay 1968 ============================================*/ 1969 _this.autoPlayIntervalId = undefined; 1970 _this.startAutoplay = function () { 1971 if (typeof _this.autoPlayIntervalId !== 'undefined') return false; 1972 if (params.autoplay && !params.loop) { 1973 _this.autoPlayIntervalId = setInterval(function(){ 1974 if (!_this.swipeNext(true)) _this.swipeTo(0); 1975 }, params.autoplay) 1976 } 1977 if (params.autoplay && params.loop) { 1978 _this.autoPlayIntervalId = setInterval(function(){ 1979 _this.swipeNext(); 1980 }, params.autoplay) 1981 } 1982 _this.callPlugins('onAutoplayStart'); 1983 } 1984 _this.stopAutoplay = function () { 1985 if (_this.autoPlayIntervalId) clearInterval(_this.autoPlayIntervalId); 1986 _this.autoPlayIntervalId = undefined; 1987 _this.callPlugins('onAutoplayStop'); 1988 } 1989 1990 /*================================================== 1991 Loop 1992 ====================================================*/ 1993 _this.loopCreated = false; 1994 _this.removeLoopedSlides = function(){ 1995 if (_this.loopCreated) { 1996 for (var i=0; i<_this.slides.length; i++) { 1997 if (_this.slides[i].getData('looped')===true) _this.wrapper.removeChild(_this.slides[i]); 1998 } 1999 } 2000 } 2001 2002 _this.createLoop = function() { 2003 if (_this.slides.length==0) return; 2004 2005 _this.loopedSlides = params.slidesPerView + params.loopAdditionalSlides; 2006 if (_this.loopedSlides > _this.slides.length) { 2007 _this.loopedSlides = _this.slides.length; 2008 } 2009
2010 var slideFirstHTML = '', 2011 slideLastHTML = '', 2012 i; 2013 2014 //Grab First Slides 2015 for (i=0; i<_this.loopedSlides; i++) { 2016 slideFirstHTML += _this.slides[i].outerHTML; 2017 } 2018 //Grab Last Slides 2019 for (i=_this.slides.length-_this.loopedSlides; i<_this.slides.length; i++) { 2020 slideLastHTML += _this.slides[i].outerHTML; 2021 } 2022 wrapper.innerHTML = slideLastHTML + wrapper.innerHTML + slideFirstHTML; 2023 2024 _this.loopCreated = true; 2025 _this.calcSlides(); 2026 2027 //Update Looped Slides with special class 2028 for (i=0; i<_this.slides.length; i++) { 2029 if (i<_this.loopedSlides || i>=_this.slides.length-_this.loopedSlides) _this.slides[i].setData('looped', true); 2030 } 2031 _this.callPlugins('onCreateLoop'); 2032 2033 } 2034 2035 _this.fixLoop = function() { 2036 var newIndex; 2037 //Fix For Negative Oversliding 2038 if (_this.activeIndex < _this.loopedSlides) { 2039 newIndex = _this.slides.length - _this.loopedSlides*3 + _this.activeIndex; 2040 _this.swipeTo(newIndex, 0, false); 2041 } 2042 //Fix For Positive Oversliding 2043 else if (_this.activeIndex > _this.slides.length - params.slidesPerView*2) { 2044 newIndex = -_this.slides.length + _this.activeIndex + _this.loopedSlides 2045 _this.swipeTo(newIndex, 0, false); 2046 } 2047 } 2048 2049 /*================================================== 2050 Slides Loader 2051 ====================================================*/ 2052 _this.loadSlides = function(){ 2053 var slidesHTML = ''; 2054 _this.activeLoaderIndex = 0; 2055 var slides = params.loader.slides; 2056 var slidesToLoad = params.loader.loadAllSlides ? slides.length : params.slidesPerView*(1+params.loader.surroundGroups); 2057 for (var i=0; i< slidesToLoad; i++) { 2058 if (params.loader.slidesHTMLType=='outer') slidesHTML+=slides[i]; 2059 else { 2060 slidesHTML+='<'+params.slideElement+' class="'+params.slideClass+'" data-swiperindex="'+i+'">'+slides[i]+'</'+params.slideElement+'>'; 2061 } 2062 } 2063 _this.wrapper.innerHTML = slidesHTML; 2064 _this.calcSlides(true); 2065 //Add permanent transitionEnd callback 2066 if (!params.loader.loadAllSlides) { 2067 _this.wrapperTransitionEnd(_this.reloadSlides, true); 2068 } 2069 } 2070 2071 _this.reloadSlides = function(){ 2072 var slides = params.loader.slides; 2073 var newActiveIndex = parseInt(_this.activeSlide().data('swiperindex'),10) 2074 if (newActiveIndex<0 || newActiveIndex>slides.length-1) return //<-- Exit 2075 _this.activeLoaderIndex = newActiveIndex; 2076 var firstIndex = Math.max(0, newActiveIndex - params.slidesPerView*params.loader.surroundGroups) 2077 var lastIndex = Math.min(newActiveIndex+params.slidesPerView*(1+params.loader.surroundGroups)-1, slides.length-1) 2078 //Update Transforms 2079 if (newActiveIndex>0) { 2080 var newTransform = -slideSize*(newActiveIndex-firstIndex) 2081 _this.setWrapperTranslate(newTransform); 2082 _this.setWrapperTransition(0); 2083 } 2084 //New Slides 2085 if (params.loader.logic==='reload') { 2086 _this.wrapper.innerHTML = ''; 2087 var slidesHTML = ''; 2088 for (var i = firstIndex; i<=lastIndex; i++) { 2089 slidesHTML += params.loader.slidesHTMLType == 'outer' ? slides[i] : '<'+params.slideElement+' class="'+params.slideClass+'" data-swiperindex="'+i+'">'+slides[i]+'</'+params.slideElement+'>'; 2090 } 2091 _this.wrapper.innerHTML = slidesHTML; 2092 } 2093 else { 2094 var minExistIndex=1000; 2095 var maxExistIndex=0; 2096 for (var i=0; i<_this.slides.length; i++) { 2097 var index = _this.slides[i].data('swiperindex'); 2098 if (index<firstIndex || index>lastIndex) { 2099 _this.wrapper.removeChild(_this.slides[i]); 2100 } 2101 else { 2102 minExistIndex = Math.min(index, minExistIndex) 2103 maxExistIndex = Math.max(index, maxExistIndex) 2104 } 2105 } 2106 for (var i=firstIndex; i<=lastIndex; i++) { 2107 if (i<minExistIndex) { 2108 var newSlide = document.createElement(params.slideElement); 2109 newSlide.className = params.slideClass; 2110 newSlide.setAttribute('data-swiperindex',i); 2111 newSlide.innerHTML = slides[i];
2112 _this.wrapper.insertBefore(newSlide, _this.wrapper.firstChild); 2113 } 2114 if (i>maxExistIndex) { 2115 var newSlide = document.createElement(params.slideElement); 2116 newSlide.className = params.slideClass; 2117 newSlide.setAttribute('data-swiperindex',i); 2118 newSlide.innerHTML = slides[i]; 2119 _this.wrapper.appendChild(newSlide); 2120 } 2121 } 2122 } 2123 //reInit 2124 _this.reInit(true); 2125 } 2126 2127 /*================================================== 2128 Make Swiper 2129 ====================================================*/ 2130 function makeSwiper(){ 2131 _this.calcSlides(); 2132 if (params.loader.slides.length>0 && _this.slides.length==0) { 2133 _this.loadSlides(); 2134 } 2135 if (params.loop) { 2136 _this.createLoop(); 2137 } 2138 _this.init(); 2139 initEvents(); 2140 if (params.pagination && params.createPagination) { 2141 _this.createPagination(true); 2142 } 2143 if (params.loop || params.initialSlide>0) { 2144 _this.swipeTo( params.initialSlide, 0, false ); 2145 } 2146 else { 2147 _this.updateActiveSlide(0); 2148 } 2149 if (params.autoplay) { 2150 _this.startAutoplay(); 2151 } 2152 2153 } 2154 2155 makeSwiper(); 2156} 2157 2158Swiper.prototype = { 2159 plugins : {}, 2160 2161 /*================================================== 2162 Wrapper Operations 2163 ====================================================*/ 2164 wrapperTransitionEnd : function(callback, permanent) { 2165 var a = this, 2166 el = a.wrapper, 2167 events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'], 2168 i; 2169 2170 function fireCallBack() { 2171 callback(a); 2172 if (a.params.queueEndCallbacks) a._queueEndCallbacks = false; 2173 if (!permanent) { 2174 for (i=0; i<events.length; i++) { 2175 a.h.removeEventListener(el, events[i], fireCallBack); 2176 } 2177 } 2178 } 2179 2180 if (callback) { 2181 for (i=0; i<events.length; i++) { 2182 a.h.addEventListener(el, events[i], fireCallBack); 2183 } 2184 } 2185 }, 2186 2187 getWrapperTranslate : function (axis) { 2188 var el = this.wrapper, 2189 matrix, curTransform, curStyle, transformMatrix; 2190 2191 // automatic axis detection 2192 if (typeof axis == 'undefined') { 2193 axis = this.params.mode == 'horizontal' ? 'x' : 'y'; 2194 } 2195 2196 curStyle = window.getComputedStyle(el, null); 2197 if (window.WebKitCSSMatrix) { 2198 transformMatrix = new WebKitCSSMatrix(curStyle.webkitTransform); 2199 } 2200 else { 2201 transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue("transform").replace("translate(", "matrix(1, 0, 0, 1,"); 2202 matrix = transformMatrix.toString().split(','); 2203 } 2204 2205 if (this.support.transforms && this.params.useCSS3Transforms) { 2206 if (axis=='x') { 2207 //Latest Chrome and webkits Fix 2208 if (window.WebKitCSSMatrix) 2209 curTransform = transformMatrix.m41; 2210 //Crazy IE10 Matrix 2211 else if (matrix.length==16) 2212 curTransform = parseFloat( matrix[12] ); 2213 //Normal Browsers 2214 else 2215 curTransform = parseFloat( matrix[4] ); 2216 } 2217 if (axis=='y') { 2218 //Latest Chrome and webkits Fix 2219 if (window.WebKitCSSMatrix) 2220 curTransform = transformMatrix.m42; 2221 //Crazy IE10 Matrix 2222 else if (matrix.length==16) 2223 curTransform = parseFloat( matrix[13] ); 2224 //Normal Browsers 2225 else 2226 curTransform = parseFloat( matrix[5] ); 2227 } 2228 } 2229 else { 2230 if (axis=='x') curTransform = parseFloat(el.style.left,10) || 0; 2231 if (axis=='y') curTransform = parseFloat(el.style.top,10) || 0; 2232 } 2233 return curTransform || 0; 2234 }, 2235 2236 setWrapperTranslate : function (x, y, z) { 2237 var es = this.wrapper.style, 2238 coords = {x: 0, y: 0, z: 0}, 2239 translate; 2240 2241 // passed all coordinates 2242 if (arguments.length == 3) { 2243 coords.x = x;
2244 coords.y = y; 2245 coords.z = z; 2246 } 2247 2248 // passed one coordinate and optional axis 2249 else { 2250 if (typeof y == 'undefined') { 2251 y = this.params.mode == 'horizontal' ? 'x' : 'y'; 2252 } 2253 coords[y] = x; 2254 } 2255 2256 if (this.support.transforms && this.params.useCSS3Transforms) { 2257 translate = this.support.transforms3d ? 'translate3d(' + coords.x + 'px, ' + coords.y + 'px, ' + coords.z + 'px)' : 'translate(' + coords.x + 'px, ' + coords.y + 'px)'; 2258 es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = translate; 2259 } 2260 else { 2261 es.left = coords.x + 'px'; 2262 es.top = coords.y + 'px'; 2263 } 2264 this.callPlugins('onSetWrapperTransform', coords); 2265 }, 2266 2267 setWrapperTransition : function (duration) { 2268 var es = this.wrapper.style; 2269 es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = (duration / 1000) + 's'; 2270 this.callPlugins('onSetWrapperTransition', {duration: duration}); 2271 }, 2272 2273 /*================================================== 2274 Helpers 2275 ====================================================*/ 2276 h : { 2277 getWidth: function (el, outer) { 2278 var width = window.getComputedStyle(el, null).getPropertyValue('width') 2279 var returnWidth = parseFloat(width); 2280 //IE Fixes 2281 if(isNaN(returnWidth) || width.indexOf('%')>0) { 2282 returnWidth = el.offsetWidth - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-left')) - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-right')); 2283 } 2284 if (outer) returnWidth += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-left')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-right')) 2285 2286 return returnWidth; 2287 }, 2288 getHeight: function(el, outer) { 2289 if (outer) return el.offsetHeight; 2290 2291 var height = window.getComputedStyle(el, null).getPropertyValue('height') 2292 var returnHeight = parseFloat(height); 2293 //IE Fixes 2294 if(isNaN(returnHeight) || height.indexOf('%')>0) { 2295 returnHeight = el.offsetHeight - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-top')) - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-bottom')); 2296 } 2297 if (outer) returnHeight += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-top')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-bottom')) 2298 return returnHeight; 2299 }, 2300 getOffset: function(el) { 2301 var box = el.getBoundingClientRect(); 2302 var body = document.body; 2303 var clientTop = el.clientTop || body.clientTop || 0; 2304 var clientLeft = el.clientLeft || body.clientLeft || 0; 2305 var scrollTop = window.pageYOffset || el.scrollTop; 2306 var scrollLeft = window.pageXOffset || el.scrollLeft; 2307 if (document.documentElement && !window.pageYOffset) { 2308 //IE7-8 2309 scrollTop = document.documentElement.scrollTop; 2310 scrollLeft = document.documentElement.scrollLeft; 2311 } 2312 return { 2313 top: box.top + scrollTop - clientTop, 2314 left: box.left + scrollLeft - clientLeft 2315 }; 2316 }, 2317 windowWidth : function() { 2318 if (window.innerWidth) return window.innerWidth 2319 else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth; 2320 }, 2321 windowHeight : function() { 2322 if (window.innerHeight) return window.innerHeight 2323 else if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight; 2324 }, 2325 windowScroll : function() { 2326 var left=0, top=0; 2327 if (typeof pageYOffset != 'undefined') { 2328 return { 2329 left: window.pageXOffset, 2330 top: window.pageYOffset 2331 } 2332 } 2333 else if (document.documentElement) { 2334 return { 2335 left: document.documentElement.scrollLeft, 2336 top: document.documentElement.scrollTop 2337 } 2338 } 2339 }, 2340 2341 addEventListener : function (el, event, listener, useCapture) { 2342 if (typeof useCapture == 'undefined') { 2343 useCapture = false; 2344 } 2345 2346 if (el.addEventListener) { 2347 el.addEventListener(event, listener, useCapture); 2348 } 2349 else if (el.attachEvent) { 2350 el.attachEvent('on' + event, listener); 2351 } 2352 }, 2353 2354 removeEventListener : function (el, event, listener, useCapture) { 2355 if (typeof useCapture == 'undefined') { 2356 useCapture = false; 2357 } 2358 2359 if (el.removeEventListener) { 2360 el.removeEventListener(event, listener, useCapture); 2361 } 2362 else if (el.detachEvent) { 2363 el.detachEvent('on' + event, listener); 2364 } 2365 } 2366 }, 2367 setTransform : function (el, transform) { 2368 var es = el.style 2369 es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = transform 2370 }, 2371 setTranslate : function (el, translate) { 2372 var es = el.style 2373 var pos = { 2374 x : translate.x || 0, 2375 y : translate.y || 0, 2376 z : translate.z || 0 2377 }; 2378 var transformString = this.support.transforms3d ? 'translate3d('+(pos.x)+'px,'+(pos.y)+'px,'+(pos.z)+'px)' : 'translate('+(pos.x)+'px,'+(pos.y)+'px)'; 2379 es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = transformString; 2380 if (!this.support.transforms) { 2381 es.left = pos.x+'px' 2382 es.top = pos.y+'px' 2383 } 2384 }, 2385 setTransition : function (el, duration) { 2386 var es = el.style 2387 es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = duration+'ms'; 2388 }, 2389 /*================================================== 2390 Feature Detection 2391 ====================================================*/ 2392 support: { 2393 2394 touch : (window.Modernizr && Modernizr.touch===true) || (function() { 2395 return !!(("ontouchstart" in window) || window.DocumentTouch && document instanceof DocumentTouch); 2396 })(), 2397 2398 transforms3d : (window.Modernizr && Modernizr.csstransforms3d===true) || (function() { 2399 var div = document.createElement('div').style; 2400 return ("webkitPerspective" in div || "MozPerspective" in div || "OPerspective" in div || "MsPerspective" in div || "perspective" in div); 2401 })(), 2402 2403 transforms : (window.Modernizr && Modernizr.csstransforms===true) || (function(){ 2404 var div = document.createElement('div').style; 2405 return ('transform' in div || 'WebkitTransform' in div || 'MozTransform' in div || 'msTransform' in div || 'MsTransform' in div || 'OTransform' in div); 2406 })(), 2407 2408 transitions : (window.Modernizr && Modernizr.csstransitions===true) || (function(){ 2409 var div = document.createElement('div').style; 2410 return ('transition' in div || 'WebkitTransition' in div || 'MozTransition' in div || 'msTransition' in div || 'MsTransition' in div || 'OTransition' in div); 2411 })() 2412 }, 2413 2414 browser : { 2415 2416 ie8 : (function(){ 2417 var rv = -1; // Return value assumes failure. 2418 if (navigator.appName == 'Microsoft Internet Explorer') { 2419 var ua = navigator.userAgent; 2420 var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); 2421 if (re.exec(ua) != null) 2422 rv = parseFloat(RegExp.$1); 2423 } 2424 return rv != -1 && rv < 9; 2425 })(), 2426 2427 ie10 : window.navigator.msPointerEnabled 2428 } 2429} 2430 2431/*========================= 2432 jQuery & Zepto Plugins 2433 ===========================*/ 2434if (window.jQuery||window.Zepto) { 2435 (function($){ 2436 $.fn.swiper = function(params) { 2437 var s = new Swiper($(this)[0], params) 2438 $(this).data('swiper',s); 2439 return s; 2440 } 2441 })(window.jQuery||window.Zepto) 2442} 2443 2444// component 2445if ( typeof( module ) !== 'undefined' ) 2446{ 2447 module.exports = Swiper; 2448} 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465jQuery(document).ready(function($){ 2466 2467 var doneVideoInit = false; 2468 var $captionTrans = 0; 2469 2470 //move parallax sliders to correct dom location 2471 var parallaxSlider = $('.parallax_slider_outer.first-section'); 2472 2473 function parallaxSliderPos(){ 2474 parallaxSlider.insertBefore('.container-wrap'); 2475 } 2476 2477 parallaxSliderPos(); 2478 2479 2480 var $smoothSrollWidth = ($('body').attr('data-smooth-scrolling') == '1') ? 0 : 0; //will come back to this 2481 2482 if($('body > #boxed').length == 0 && $('.nectar-slider-wrap[data-full-width="true"]').parent().attr('id') != 'portfolio-extra' && $('.nectar-slider-wrap[data-full-width="true"]').parents('#post-area:not(".span_12")').length == 0){ 2483 $('.nectar-slider-wrap[data-full-width="true"], .parallax_slider_outer.first-section .nectar-slider-wrap').css('left', -(($(window).width()-$smoothSrollWidth)/2 - $('.main-content').width()/2))+'px'; 2484 $('.nectar-slider-wrap[data-full-width="true"] .swiper-container, .nectar-slider-wrap[data-full-width="true"], .parallax_slider_outer.first-section .swiper-container, .parallax_slider_outer.first-section .nectar-slider-wrap').css('width',$(window).width()); 2485 } 2486 else if( $('.nectar-slider-wrap[data-full-width="true"]').parent().attr('id') == 'portfolio-extra' && $('#full_width_portfolio').length != 0){ 2487 $('.nectar-slider-wrap[data-full-width="true"], .parallax_slider_outer.first-section .nectar-slider-wrap').css('left', -(($(window).width()-$smoothSrollWidth)/2 - $('.main-content').width()/2))+'px'; 2488 $('.nectar-slider-wrap[data-full-width="true"] .swiper-container, .nectar-slider-wrap[data-full-width="true"], .parallax_slider_outer.first-section .swiper-container, .parallax_slider_outer.first-section .nectar-slider-wrap').css('width',$(window).width()); 2489 } 2490 else { 2491 var $container = ($('body > #boxed').length == 0) ? '#post-area' : '.container-wrap'; 2492 $('.nectar-slider-wrap[data-full-width="true"] .swiper-container, .nectar-slider-wrap[data-full-width="true"], .parallax_slider_outer.first-section .swiper-container, .parallax_slider_outer.first-section .nectar-slider-wrap').css('width',$($container).width()); 2493 } 2494 2495 //show slider once full width calcs have taken place 2496 $('.nectar-slider-wrap').show(); 2497 2498 //set bg colors / textures after js has made the slider fullwidth 2499 $('.swiper-container, .swiper-slide').css('background-color','#000'); 2500 $('.video-texture').css('opacity','1'); 2501 2502 //nectar sliders 2503 var $nectarSliders = []; 2504 2505 $('.nectar-slider-wrap').each(function(i){ 2506 var $arrows = $(this).find('.swiper-container').attr('data-arrows'); 2507 var $bullets = $(this).find('.swiper-container').attr('data-bullets'); 2508 var $swipe = $(this).find('.swiper-container').attr('data-desktop-swipe'); 2509 var $loop = $(this).find('.swiper-container').attr('data-loop'); 2510 2511 //swipe 2512 if($swipe == 'true' && $('#'+$(this).attr('id') +' .swiper-wrapper > div').length > 1 ){ 2513 var $grab = 1; 2514 var $desktopSwipe = 1; 2515 } else { 2516 var $grab = 0; 2517 var $desktopSwipe = 0; 2518 } 2519 2520 //bullets 2521 if($bullets == 'true' && $(this).find('.swiper-wrapper > div').length > 1){ 2522 $bullets = '#'+$(this).attr('id')+' .slider-pagination'; 2523 } else { 2524 $bullets = null; 2525 } 2526 2527 //loop 2528 $useLoop = ($loop == 'true' && $(this).find('.swiper-wrapper > div').length > 1 && !$('html').hasClass('no-video')) ? true : false; 2529 if($useLoop == false) $(this).find('.swiper-container').attr('data-loop','false'); 2530 2531 $nectarSliders[i] = new Swiper('#'+$(this).attr('id')+' .swiper-container', { 2532 loop: $useLoop, 2533 grabCursor: $grab, 2534 touchRatio: 0.6, 2535 speed: 525, 2536 useCSS3Transforms: false, 2537 pagination : $bullets, 2538 simulateTouch : $desktopSwipe, 2539 onSlideChangeEnd: captionTransition, 2540 onSlideChangeStart: sliderArrowCount, 2541 onTouchMove: clearAutoplay, 2542 onFirstInit: nectarInit 2543 }); 2544 2545 $nectarSliders[i].swipeReset(); 2546 2547 function nectarInit(){ 2548 if(doneVideoInit == true) return; 2549 2550 //videos 2551 $('.swiper-slide .slider-video').mediaelementplayer({ 2552 enableKeyboard: false, 2553 iPadUseNativeControls: false, 2554 pauseOtherPlayers: false, 2555 // force iPhone's native controls 2556 iPhoneUseNativeControls: false, 2557 // force Android's native controls 2558 AndroidUseNativeControls: false 2559 }); 2560 2561 2562 doneVideoInit = true; 2563 } 2564 2565 //Navigation arrows 2566 if($arrows == 'true' && $('#'+$(this).attr('id') +' .swiper-wrapper > div').length > 1 ){ 2567 2568 $('.slide-count i').transition({ scale: 0.5, opacity: 0 }); 2569 2570 //hover event 2571 $('.swiper-container .slider-prev, .swiper-container .slider-next').hover(function(){ 2572 2573 $(this).find('.slide-count i').clearQueue().stop(true,true).delay(100).transition({ scale: 1, opacity: 1 },200);
2574 2575 $(this).stop(true,true).animate({ 2576 'width' : '120px' 2577 },300,'easeOutCubic'); 2578 $(this).find('.slide-count span').clearQueue().stop().delay(100).animate({ 2579 'opacity' : '1' 2580 },225,'easeOutCubic'); 2581 },function(){ 2582 2583 $('.slide-count i').stop(true,true).transition({ scale: 0, opacity: 0 },200); 2584 2585 $(this).stop().delay(150).animate({ 2586 'width' : '64px' 2587 },300,'easeOutCubic'); 2588 $(this).find('.slide-count span').stop(true,true).animate({ 2589 'opacity' : '0' 2590 },200,'easeOutCubic'); 2591 }); 2592 2593 //add slide counts 2594 var $slideCount = ($(this).find('.swiper-container').attr('data-loop') != 'true' ) ? $('#'+$(this).attr('id') + ' .swiper-wrapper > div').length : $('#'+$(this).attr('id') + ' .swiper-wrapper > div').length - 2; 2595 2596 //ie8 2597 if($('html').hasClass('no-video')) $slideCount = $('#'+$(this).attr('id') + ' .swiper-wrapper > div').length; 2598 2599 $('#'+$(this).attr('id')+' .slider-prev .slide-count .slide-total').html( $slideCount ); 2600 $('#'+$(this).attr('id')+' .slider-next .slide-count .slide-total').html( $slideCount ); 2601 2602 //prev 2603 $('#'+$(this).attr('id')+' .slider-prev').click(function(e) { 2604 2605 if($(this).hasClass('inactive')) return false; 2606 2607 var $that = $(this); 2608 2609 //non looped slider 2610 if($(this).parents('.swiper-container').attr('data-loop') != 'true') { 2611 2612 2613 if( $(this).parents('.swiper-container').find('.swiper-slide-active').index()+1 == 1 && !$('html').hasClass('no-video')){ 2614 2615 //make sure the animation is complete 2616 var $timeout; 2617 2618 clearTimeout($timeout); 2619 $timeout = setTimeout(function(){ $that.removeClass('inactive'); } ,700); 2620 2621 $(this).parents('.swiper-container').find('.swiper-wrapper').stop(true,false).css('transition','none').animate({ 2622 'left' : parseInt($(this).parents('.swiper-container').find('.swiper-wrapper').css('left')) + 20 2623 },200,function(){ 2624 $(this).parents('.swiper-container').find('.swiper-wrapper').stop(true,false).css('transition','left,top'); 2625 $nectarSliders[i].swipeReset(); 2626 }); 2627 2628 $(this).addClass('inactive'); 2629 2630 } 2631 2632 } 2633 2634 e.preventDefault(); 2635 $nectarSliders[i].swipePrev(); 2636 }); 2637 2638 //next 2639 $('#'+$(this).attr('id')+' .slider-next').click(function(e) { 2640 2641 if($(this).hasClass('inactive')) return false; 2642 2643 var $that = $(this); 2644 var $slideNum = $(this).parents('.swiper-container').find('.swiper-wrapper > div').length; 2645 2646 //non looped slider 2647 if($(this).parents('.swiper-container').attr('data-loop') != 'true') { 2648 2649 if( $(this).parents('.swiper-container').find('.swiper-slide-active').index()+1 == $slideNum && !$('html').hasClass('no-video')) { 2650 2651 //make sure the animation is complete 2652 var $timeout; 2653 2654 clearTimeout($timeout); 2655 $timeout = setTimeout(function(){ $that.removeClass('inactive'); } ,700); 2656 2657 $(this).parents('.swiper-container').find('.swiper-wrapper').stop(true,false).css('transition','none').animate({ 2658 'left' : parseInt($(this).parents('.swiper-container').find('.swiper-wrapper').css('left')) - 20 2659 },200,function(){ 2660 $(this).parents('.swiper-container').find('.swiper-wrapper').stop(true,false).css('transition','left,top'); 2661 $nectarSliders[i].swipeReset(); 2662 }); 2663 2664 $(this).addClass('inactive'); 2665 } 2666 } 2667 2668 2669 e.preventDefault(); 2670 $nectarSliders[i].swipeNext(); 2671 2672 }); 2673 } 2674 //Clickable pagination 2675 if($bullets != null && $('#'+$(this).attr('id') +' .swiper-wrapper > div').length > 1 ){ 2676 $('#'+$(this).attr('id')+' .slider-pagination .swiper-pagination-switch').click(function(){ 2677 $nectarSliders[i].swipeTo($(this).index()); 2678 }); 2679 } 2680 }); 2681 2682 2683 2684 2685 //add class to first video slide 2686 $('.swiper-wrapper').each(function(){ 2687 if($(this).find('.swiper-slide:nth-child(2) video').length > 0) $(this).find('.swiper-slide:nth-child(2)').addClass('first_video_slide'); 2688 }); 2689 2690 2691 //initial slide load 2692 $('.nectar-slider-wrap').each(function(i){ 2693 2694 var $sliderWrapCount = $('.nectar-slider-wrap').length; 2695 var $that = $(this); 2696 2697 if($(this).find('.swiper-slide-active video').length > 0){ 2698 2699 if(!$('html').hasClass('no-video')){ 2700 2701 $(this).find('.swiper-slide-active:first video').get(0).addEventListener('canplay',function(){ 2702 2703 showSliderControls(); 2704 resizeToCover(); 2705 sliderLoadIn($that); 2706 captionTransition($nectarSliders[i]); 2707 2708 2709 2710 }); 2711 } 2712 //ie8 2713 else { 2714 showSliderControls(); 2715 resizeToCover(); 2716 sliderLoadIn($that); 2717 captionTransition($nectarSliders[i]); 2718 } 2719 } 2720 else { 2721 2722 var $firstBg = $(this).find('.swiper-slide-active').attr('style'); 2723 2724 var pattern = /url\(["']?([^'")]+)['"]?\)/; 2725 var match = pattern.exec($firstBg); 2726 if (match) { 2727 var slideImg = new Image(); 2728 slideImg.src = match[1]; 2729 2730 $(slideImg).load(function(){ 2731 showSliderControls(); 2732 sliderLoadIn($that); 2733 captionTransition($nectarSliders[i]); 2734 }); 2735 } 2736 } 2737 2738 //mobile check 2739 if(navigator.userAgent.match(/(Android|iPod|iPhone|iPad|IEMobile|Opera Mini)/)){ 2740 captionTransition($nectarSliders[i]); 2741 showSliderControls(); 2742 resizeToCover(); 2743 $('.nectar-slider-wrap').find('.nectar-slider-loading').fadeOut(800,'easeInOutExpo'); 2744 2745 $('.nectar-slider-wrap .mobile-video-image').show(); 2746 $('.nectar-slider-wrap .video-wrap').remove(); 2747 } 2748 2749 }); 2750 2751 2752 2753 2754 2755 var $animating = false; 2756 2757 //fullscreen height 2758 fullscreenSlider(); 2759 function fullscreenSlider(){ 2760 2761 var $adminBarHeight = ($('#wpadminbar').length > 0) ? 28 : 0 ; 2762 2763 $('.nectar-slider-wrap').each(function(){ 2764 if($(this).attr('data-fullscreen') == 'true' && $(this).attr('data-full-width') == 'true') { 2765 2766 //first slider on page 2767 if($(this).hasClass('first-section') && $(this).index() == 0){ 2768 $(this).find('.swiper-container').attr('data-height',$(window).height() - $(this).offset().top + 2); 2769 } 2770 //first parallax slider on page 2771 else if($(this).parents('.parallax_slider_outer').length > 0 && $(this).parents('#full_width_portfolio').length == 0){ 2772 $(this).find('.swiper-container').attr('data-height',$(window).height() - $(this).parent().offset().top + 2); 2773 } 2774 //first portfolio slider on page 2775 else if($(this).parents('#full_width_portfolio').length > 0 && $(this).attr('data-parallax') != 'true' && $(this).index() == 0){ 2776 $(this).find('.swiper-container').attr('data-height',$(window).height() - $(this).offset().top + 2); 2777 } 2778 //first portfolio parallax slider on page 2779 else if($(this).parents('#full_width_portfolio').length > 0 && $(this).attr('data-parallax') == 'true'){ 2780 2781 $(this).find('.swiper-container').attr('data-height',$(window).height() - $(this).offset().top + 2 ); 2782 } 2783 //all others 2784 else { 2785 $(this).find('.swiper-container').attr('data-height',$(window).height()); 2786 } 2787 2788 } 2789 }); 2790 } 2791 $(window).resize(fullscreenSlider); 2792 2793 2794 //responsive slider 2795 var $sliderHeights = []; 2796 //get slider heights 2797 $('.swiper-container').each(function(i){ 2798 $sliderHeights[i] = parseInt($(this).attr('data-height')); 2799 }); 2800 2801 2802 sliderSize(); 2803 $(window).resize(sliderSize); 2804 function sliderSize(){ 2805 2806 2807 //check for mobile first 2808 if( window.innerWidth < 1000 && window.innerWidth > 690 ) { 2809 2810 //fullwidth sliders 2811 $('.nectar-slider-wrap[data-full-width="true"]:not([data-fullscreen="true"]) .swiper-container').each(function(i){ 2812 $(this).attr('data-height',$sliderHeights[i]/1.4 ) 2813 }); 2814 2815 //boxed sliders 2816 $('.nectar-slider-wrap[data-full-width="false"] .swiper-container, .nectar-slider-wrap[data-full-width="boxed-full-width"] .swiper-container').each(function(i){ 2817 $(this).attr('data-height',$sliderHeights[i]/1.9 ) 2818 }); 2819 } 2820 2821 else if( window.innerWidth <= 690 ) { 2822 2823 //fullwidth sliders 2824 $('.nectar-slider-wrap[data-full-width="true"]:not([data-fullscreen="true"]) .swiper-container').each(function(i){ 2825 $(this).attr('data-height',$sliderHeights[i]/2.7 ) 2826 });
2827 2828 //boxed sliders 2829 $('.nectar-slider-wrap[data-full-width="false"] .swiper-container, .nectar-slider-wrap[data-full-width="boxed-full-width"] .swiper-container').each(function(i){ 2830 $(this).attr('data-height',$sliderHeights[i]/2.9 ) 2831 }); 2832 2833 } 2834 2835 else if( window.innerWidth < 1300 && window.innerWidth >= 1000 ) { 2836 2837 //fullwidth sliders 2838 $('.nectar-slider-wrap[data-full-width="true"]:not([data-fullscreen="true"]) .swiper-container').each(function(i){ 2839 $(this).attr('data-height',$sliderHeights[i]/1.2 ) 2840 }); 2841 2842 //boxed sliders 2843 $('.nectar-slider-wrap[data-full-width="false"] .swiper-container, .nectar-slider-wrap[data-full-width="boxed-full-width"] .swiper-container').each(function(i){ 2844 $(this).attr('data-height',$sliderHeights[i]/1.2 ) 2845 }); 2846 2847 } 2848 2849 else { 2850 2851 //fullwidth sliders 2852 $('.nectar-slider-wrap[data-full-width="true"]:not([data-fullscreen="true"]) .swiper-container').each(function(i){ 2853 $(this).attr('data-height',$sliderHeights[i] ) 2854 }); 2855 2856 //boxed sliders 2857 $('.nectar-slider-wrap[data-full-width="false"] .swiper-container, .nectar-slider-wrap[data-full-width="boxed-full-width"] .swiper-container').each(function(i){ 2858 $(this).attr('data-height',$sliderHeights[i] ) 2859 }); 2860 } 2861 2862 } 2863 2864 2865 2866 2867 2868 2869 //slider height 2870 2871 var min_w = 1500; // minimum video width allowed 2872 var vid_w_orig; // original video dimensions 2873 var vid_h_orig; 2874 2875 vid_w_orig = 1280; 2876 vid_h_orig = 720; 2877 var $headerHeight = $('header').height()-1; 2878 2879 $(window).resize(function () { resizeToCover(); slideContentPos(); }); 2880 $(window).trigger('resize'); 2881 2882 function resizeToCover() { 2883 $('.nectar-slider-wrap').each(function(i){ 2884 2885 //width resize 2886 if($('body > #boxed').length == 0 && $('.nectar-slider-wrap[data-full-width="true"]').parent().attr('id') != 'portfolio-extra' && $(this).parents('#post-area:not(".span_12")').length == 0){ 2887 $('.nectar-slider-wrap[data-full-width="true"], .parallax_slider_outer.first-section .nectar-slider-wrap').css('left', -(($(window).width()-$smoothSrollWidth)/2 - $('.main-content').width()/2))+'px'; 2888 $('.nectar-slider-wrap[data-full-width="true"] .swiper-container, .nectar-slider-wrap[data-full-width="true"], .parallax_slider_outer.first-section .swiper-container, .parallax_slider_outer.first-section .nectar-slider-wrap').css('width',$(window).width()); 2889 } 2890 else if( $('.nectar-slider-wrap[data-full-width="true"]').parent().attr('id') == 'portfolio-extra' && $('#full_width_portfolio').length != 0){ 2891 $('.nectar-slider-wrap[data-full-width="true"], .parallax_slider_outer.first-section .nectar-slider-wrap').css('left', -(($(window).width()-$smoothSrollWidth)/2 - $('.main-content').width()/2))+'px'; 2892 $('.nectar-slider-wrap[data-full-width="true"] .swiper-container, .nectar-slider-wrap[data-full-width="true"], .parallax_slider_outer.first-section .swiper-container, .parallax_slider_outer.first-section .nectar-slider-wrap').css('width',$(window).width()); 2893 } 2894 else { 2895 var $container = ($('body > #boxed').length == 0) ? '#post-area' : '.container-wrap'; 2896 $('.nectar-slider-wrap[data-full-width="true"] .swiper-container, .nectar-slider-wrap[data-full-width="true"], .parallax_slider_outer.first-section .swiper-container, .parallax_slider_outer.first-section .nectar-slider-wrap').css('width',$($container).width()); 2897 } 2898 2899 var $sliderHeight = parseInt($(this).find('.swiper-container').attr('data-height')); 2900 var isFullWidthCompatible = ($(this).attr('data-full-width') == 'true') ? 'true' : 'false'; 2901 2902 if($(this).parent().attr('id') == 'portfolio-extra' && $('#full_width_portfolio').length == 0 || $(this).parents('#post-area').length > 0) { isFullWidthCompatible = 'false'; }; 2903 2904 var $sliderWidth = (isFullWidthCompatible == 'true') ? $(window).width()-$smoothSrollWidth : $(this).width(); 2905 2906 $(this).parents('.parallax_slider_outer').css('height',$sliderHeight); 2907 $(this).css('height',$sliderHeight); 2908 $(this).find('.swiper-container, .swiper-slide').css({'height':$sliderHeight+2, 'top':'-1px'}); 2909 $(this).find('.swiper-container').css('width', $sliderWidth);
2910 //$(this).find('.swiper-slide').css('width', $sliderWidth); 2911 2912 // set the video viewport to the window size 2913 $(this).find('.video-wrap').width($sliderWidth+2); 2914 $(this).find('.video-wrap').height($sliderHeight+2); 2915 2916 // use largest scale factor of horizontal/vertical 2917 var scale_h = $sliderWidth / vid_w_orig; 2918 var scale_v = ($sliderHeight - $headerHeight) / vid_h_orig; 2919 var scale = scale_h > scale_v ? scale_h : scale_v; 2920 2921 //update minium width to never allow excess space 2922 min_w = 1280/720 * ($sliderHeight+20); 2923 2924 // don't allow scaled width < minimum video width 2925 if (scale * vid_w_orig < min_w) {scale = min_w / vid_w_orig;} 2926 2927 // now scale the video 2928 $(this).find('video, .mejs-overlay, .mejs-poster').width(Math.ceil(scale * vid_w_orig +2)); 2929 $(this).find('video, .mejs-overlay, .mejs-poster').height(Math.ceil(scale * vid_h_orig +2)); 2930 2931 // and center it by scrolling the video viewport 2932 $(this).find('.video-wrap').scrollLeft(($(this).find('video').width() - $sliderWidth) / 2); 2933 2934 $(this).find('.swiper-slide').each(function(){ 2935 2936 //video alignment 2937 if($(this).find('.video-wrap').length > 0){ 2938 //align middle 2939 if($(this).attr('data-bg-alignment') == 'center'){ 2940 $(this).find('.video-wrap, .mejs-overlay, .mejs-poster').scrollTop(($(this).find('video').height() - ($sliderHeight)) / 2); 2941 } 2942 //align bottom 2943 else if($(this).attr('data-bg-alignment') == 'bottom'){ 2944 $(this).find('.video-wrap').scrollTop(($(this).find('video').height() - ($sliderHeight+2))); 2945 } 2946 //align top 2947 else { 2948 $(this).find('.video-wrap').scrollTop(0); 2949 } 2950 } 2951 2952 }); 2953 2954 }); 2955 }; 2956 2957 //caption transitions 2958 function captionTransition(obj){ 2959 2960 resizeToCover(); 2961 2962 var $containerClass; 2963 2964 (typeof obj == 'undefined') ? $containerClass = 'div[id^=ns-id-]' : $containerClass = '#'+$(obj.container).parents('.nectar-slider-wrap').attr('id'); ; 2965 2966 var fromLeft = Math.abs(parseInt($($containerClass+' .swiper-wrapper').css('left'))); 2967 var currentSlide = Math.round(fromLeft/$($containerClass+' .swiper-slide').width()); 2968 var $slideNum = $($containerClass+':first .swiper-wrapper > div').length; 2969 2970 if(isNaN(currentSlide)) currentSlide = 0; 2971 2972 //make sure user isn't going back to same slide 2973 if( $($containerClass+' .swiper-slide:nth-child('+ (currentSlide + 1) +')').find('.content *').length > 0 ) { 2974 if($($containerClass+' .swiper-slide:nth-child('+ (currentSlide + 1) +')').find('.content *').css('opacity') != '0' && !$('html').hasClass('no-video')) { 2975 //play video if there's one 2976 playVideoBG(currentSlide + 1, $containerClass); 2977 return false; 2978 } 2979 } 2980 2981 //hide all 2982 if(!$('html').hasClass('no-video')) { 2983 $($containerClass+' .swiper-slide .content p, '+$containerClass+' .swiper-slide .content h2, '+$containerClass+' .swiper-slide .content .buttons').stop(true,true).animate({'opacity':0, 'padding-top': 25},1); 2984 } 2985 2986 //pause video if there's one 2987 $($containerClass+' .swiper-slide').each(function(){ 2988 if($(this).find('.video-wrap video').length > 0 && !$('html').hasClass('no-video')) { $(this).find('.video-wrap video').get(0).pause(); } 2989 }); 2990 $($containerClass+' .swiper-slide:not(".swiper-slide-active")').each(function(){ 2991 if($(this).find('.video-wrap video').length > 0) { 2992 2993 if($(this).find('.video-wrap video').get(0).currentTime != 0 ) $(this).find('.video-wrap video').get(0).currentTime = 0; 2994 } 2995 }); 2996 2997 2998 2999 if($($containerClass +' .swiper-container').attr('data-loop') == 'true') { 3000 3001 3002 //webkit video fix 3003 if( $($containerClass+' .swiper-slide-active').index()+1 == 2 && $($containerClass+' .swiper-slide-active video').length > 0 && !$('html').hasClass('no-video')) { 3004 3005 $($containerClass+' .swiper-slide:last-child').find('.video-wrap video').get(0).play(); 3006 $($containerClass+' .swiper-slide:last-child').find('.video-wrap video').get(0).pause(); 3007 } 3008 if( $($containerClass+' .swiper-slide-active').index()+1 == $slideNum-1 && $($containerClass+' .swiper-slide-active video').length > 0 && !$('html').hasClass('no-video')) { 3009 3010 $($containerClass+' .swiper-slide:first-child').find('.video-wrap video').get(0).play(); 3011 $($containerClass+' .swiper-slide:first-child').find('.video-wrap video').get(0).pause(); 3012 } 3013 if($($containerClass+' .swiper-slide-active').index()+1 != 2 && $($containerClass+' .swiper-slide:nth-child(2) video').length > 0 && !$('html').hasClass('no-video')) { 3014 3015 $($containerClass+' .swiper-slide:last-child').find('.video-wrap video').get(0).play(); 3016 $($containerClass+' .swiper-slide:last-child').find('.video-wrap video').get(0).pause(); 3017 3018 $($containerClass+' .swiper-slide:nth-child(2) video').get(0).pause(); 3019 if($($containerClass+' .swiper-slide:nth-child(2) video').get(0).currentTime != 0 ) $($containerClass+' .swiper-slide:nth-child(2) video').get(0).currentTime = 0; 3020 } 3021 3022 3023 //also show duplicate slide if applicable 3024 ////first 3025 if( $($containerClass+' .swiper-slide-active').index()+1 == $slideNum-1 ){ 3026 3027 $($containerClass+' .swiper-slide:nth-child(1)').find('.content').children().each(function(i){ 3028 3029 $(this).stop().delay(i*90).animate({ 3030 'opacity' : 1, 3031 'padding-top' : 0 3032 },{ duration: 400, easing: 'easeOutQuad'}); 3033 });
3034 3035 } 3036 3037 ////last 3038 if( $($containerClass+' .swiper-slide-active').index()+1 == 2 ){ 3039 $($containerClass+' .swiper-slide:nth-child('+ ($slideNum) + ')').find('.content').children().each(function(i){ 3040 $(this).stop().delay(i*90).animate({ 3041 'opacity' : 1, 3042 'padding-top' : 0 3043 },{ duration: 400, easing: 'easeOutQuad'}); 3044 }); 3045 3046 } 3047 3048 }//if using loop 3049 3050 //play video if there's one 3051 playVideoBG(currentSlide + 1, $containerClass); 3052 3053 //fadeIn active slide 3054 $($containerClass+' .swiper-slide:nth-child('+ (currentSlide + 1) +')').find('.content').children().each(function(i){ 3055 3056 $(this).stop().delay(i*90).animate({ 3057 'opacity' : 1, 3058 'padding-top' : 0 3059 },{ duration: 400, easing: 'easeOutQuad'}); 3060 }); 3061 3062 3063 3064 3065 //light and dark controls 3066 if($($containerClass+' .swiper-slide:nth-child('+ (currentSlide + 1) +')').attr('data-color-scheme') == 'dark') { 3067 $($containerClass).find('.slider-pagination').addClass('dark-cs'); 3068 $($containerClass).find('.slider-prev, .slider-next').addClass('dark-cs'); 3069 } else { 3070 $($containerClass).find('.slider-pagination').removeClass('dark-cs'); 3071 $($containerClass).find('.slider-prev, .slider-next').removeClass('dark-cs'); 3072 } 3073 3074 $captionTrans++; 3075 if($captionTrans == $('.swiper-wrapper').length) { $('div.first_video_slide').addClass('nulled') } 3076 3077 3078 } 3079 3080 //used in caption transition 3081 function playVideoBG(nthChild, containerClass){ 3082 3083 if($(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.video-wrap video').length > 0){ 3084 3085 if(!$('html').hasClass('no-video')) $(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.video-wrap video').get(0).play(); 3086 3087 if(!$(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.mejs-overlay.mejs-overlay-play').hasClass('playing') && $(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.mejs-overlay.mejs-overlay-play').hasClass('mobile-played')) { $(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.mejs-overlay.mejs-overlay-play').addClass('playing'); } 3088 if(!$(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.mejs-poster').hasClass('playing') && $(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.mejs-poster').hasClass('mobile-played')) $(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.mejs-poster').addClass('playing'); 3089 3090 var $that = $(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.mejs-overlay.mejs-overlay-play'); 3091 var $that2 = $(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.mejs-poster'); 3092 3093 if($that.hasClass('playing') && $that.hasClass('mobile-played')) { 3094 setTimeout(function(){ $that.addClass('behind-buttons'); $that2.addClass('behind-buttons');},200); 3095 } else { 3096 $that.removeClass('behind-buttons'); $that2.removeClass('behind-buttons'); 3097 } 3098 } 3099 3100 } 3101 3102 3103 var $startingSlide = null; 3104 3105 3106 3107 function slideContentPos(){ 3108 3109 $('.swiper-wrapper').each(function(){ 3110 3111 //etxra space if first slider in section 3112 var $extraHeight = ($(this).parents('.nectar-slider-wrap').hasClass('first-section') || $(this).parents('.parallax_slider_outer').hasClass('first-section')) ? 30 : 0; 3113 3114 var $sliderHeight = parseInt($(this).parents('.swiper-container').attr('data-height')); 3115 3116 $(this).find('.swiper-slide').each(function(){ 3117 3118 var $contentHeight = $(this).find('.content').height(); 3119 var $contentItems = $(this).find('.content > *').length; 3120 3121 if($(this).find('.content > *').css('padding-top') == '25px') $contentHeight = $contentHeight - 25*$contentItems; 3122 3123 if($(this).attr('data-y-pos') == 'top'){ 3124 var $topHeight = ($contentHeight/2) < (($sliderHeight/4) - 30) ? (($sliderHeight/4) - ($contentHeight/2)) + 20 : $sliderHeight/8; 3125 $(this).find('.content').css('top', $topHeight + 'px'); 3126 } 3127 else if($(this).attr('data-y-pos') == 'middle') { 3128 3129 $(this).find('.content').css('top', ($sliderHeight/2) - ($contentHeight/2) + 'px'); 3130 } 3131 else { 3132 if($contentHeight > 180) { 3133 $(this).find('.content').css('top', ($sliderHeight/2) - ($contentHeight/10) + 'px'); 3134 } else { 3135 $(this).find('.content').css('top', ($sliderHeight/2) + ($contentHeight/9) + 'px'); 3136 } 3137 } 3138 }); 3139 }); 3140 } 3141 3142 3143 3144 function showSliderControls() { 3145 $('.swiper-container .slider-prev, .swiper-container .slider-next, .slider-pagination').animate({'opacity':1},550,'easeOutSine'); 3146 } 3147 3148 3149 var sliderLength = $('.swiper-container').length; 3150 var sliderLoadedLength = 0; 3151 3152 function sliderLoadIn(slider) { 3153 3154 slider.find('.nectar-slider-loading').fadeOut(800,'easeInOutExpo'); 3155 3156 ///make sure to init smooth scrolling after slider height exists 3157 var $smoothActive = $('body').attr('data-smooth-scrolling'); 3158 if( $smoothActive == 1 && $(window).width() > 690 && $('body').outerHeight(true) > $(window).height() && $('#ascrail2000').length == 0){ niceScrollInit(); resizeToCover(); } 3159 3160 //check for sliders in tabbed 3161 sliderLoadedLength++; 3162 if($('.tabbed').find('.swiper-container').length > 0 && sliderLoadedLength == sliderLength) { 3163 $('.tabbed > ul li:first-child a').click(); 3164 } 3165 3166 } 3167 3168 3169 //play video user is hovering over 3170 $('.swiper-slide').mouseover(function(){ 3171 if($(this).find('video').length > 0 && $(this).find('video').get(0).paused == true && $animating == false){ 3172 $(this).find('video').get(0).play(); 3173 } 3174 }); 3175 3176 3177 //mobile play event 3178 $('body').on('click', '.mejs-overlay.mejs-overlay-play',function(){ 3179 $(this).toggleClass('playing'); 3180 $(this).addClass('mobile-played'); 3181 3182 $(this).parent().find('.mejs-poster').toggleClass('playing'); 3183 $(this).parent().find('.mejs-poster').addClass('mobile-played'); 3184 3185 var $that = $(this); 3186 var $that2 = $(this).parent().find('.mejs-poster'); 3187 3188 if($(this).hasClass('playing') && $(this).hasClass('mobile-played')) { 3189 3190 setTimeout(function(){ $that.addClass('behind-buttons'); $that2.addClass('behind-buttons'); },200);
3191 } else { 3192 setTimeout(function(){ $that.removeClass('behind-buttons'); $that2.removeClass('behind-buttons'); },1); 3193 } 3194 }); 3195 3196 3197 //autoplay 3198 var autoplay = []; 3199 var sliderAutoplayCount = -1; 3200 var $sliderHeight = parseInt($(this).find('.swiper-container').attr('data-height')); 3201 var portfolioHeaderHeight = ($('.project-title.parallax-effect').length > 0) ? 100 : 0; 3202 3203 $('.nectar-slider-wrap').each(function(i){ 3204 var $autoplayVal = $(this).attr('data-autorotate'); 3205 var $that = $(this); 3206 var $sliderNum = i; 3207 3208 if(typeof $autoplayVal !='undefined' && $autoplayVal.length != '0' && parseInt($autoplayVal)) { 3209 nectarSlideRotateInit($that,$autoplayVal,$sliderNum); 3210 } 3211 }); 3212 3213 function nectarSlideRotateInit(slider,interval,sliderNum){ 3214 3215 autoplay[sliderAutoplayCount] = setInterval(function(){ nectarSlideRotate(slider, sliderNum); } ,interval); 3216 3217 $('#'+slider.attr('id')).attr('autoplay-id',sliderAutoplayCount); 3218 3219 $('#'+slider.attr('id') + ' a.slider-prev, #'+slider.attr('id') + ' a.slider-next, #' + slider.attr('id') + ' .slider-pagination span').click(function(e){ 3220 if(typeof e.clientY != 'undefined'){ 3221 clearInterval(autoplay[$('#'+slider.attr('id')).attr('autoplay-id')]); 3222 } 3223 }); 3224 3225 sliderAutoplayCount++; 3226 } 3227 3228 function nectarSlideRotate(slider, sliderNum){ 3229 3230 if($nectarSliders[sliderNum].activeIndex + 1 < $(slider).find('.swiper-wrapper > div.swiper-slide').length){ 3231 $nectarSliders[sliderNum].swipeNext(); 3232 } else { 3233 $nectarSliders[sliderNum].swipeTo(0,800); 3234 } 3235 } 3236 3237 function clearAutoplay(e){ 3238 var $autoplayVal = $('#'+$(e.container).parent().attr('id')).attr('data-autorotate'); 3239 3240 if(typeof $autoplayVal !='undefined' && $autoplayVal.length != '0' && parseInt($autoplayVal)) { 3241 clearInterval(autoplay[$('#'+$(e.container).parent().attr('id')).attr('autoplay-id')]); 3242 } 3243 } 3244 3245 var animationQueue = null; 3246 3247 function sliderArrowCount(e){ 3248 3249 //cache slider obj 3250 var $obj = e; 3251 3252 $animating = true; 3253 3254 var $slideNum = $($obj.container).find('.swiper-wrapper > div').length; 3255 3256 $activeIndex = ($($obj.container).attr('data-loop') == 'true') ? $obj.activeIndex : $obj.activeIndex + 1; 3257 3258 3259 //add slide counts 3260 $($obj.container).find('.slider-prev .slide-count .slide-current').html( $activeIndex ); 3261 $($obj.container).find('.slider-next .slide-count .slide-current').html( $activeIndex ); 3262 3263 if($($obj.container).attr('data-loop') == 'true'){ 3264 //duplicate first slide 3265 if( $($obj.container).find('.swiper-slide-active').index()+1 == 1) { 3266 $($obj.container).find('.slider-next .slide-count .slide-current, .slider-prev .slide-count .slide-current').html( $slideNum - 2 ); 3267 } 3268 //duplicate last slide 3269 else if( $($obj.container).find('.swiper-slide-active').index()+1 == $slideNum) { 3270 $($obj.container).find('.slider-next .slide-count .slide-current, .slider-prev .slide-count .slide-current').html( 1 ); 3271 } 3272 } 3273 3274 if($obj.activeIndex >= 10) { $($obj.container).find('.slider-next .slide-count .slide-current').addClass('double-digits'); } else { 3275 $($obj.container).find('.slider-next .slide-count .slide-current').removeClass('double-digits'); 3276 } 3277 3278 3279 $($obj.container).find('.swiper-slide:not(".swiper-slide-active")').each(function(){ 3280 if($(this).find('.video-wrap video').length > 0) { 3281 3282 if($(this).find('.video-wrap video').get(0).currentTime != 0 ) $(this).find('.video-wrap video').get(0).currentTime = 0; 3283 } 3284 }); 3285 3286 3287 //don't allow swiping on duplicate transition 3288 if($($obj.container).attr('data-loop') == 'true'){ 3289 if($obj.previousIndex == 1 && $obj.activeIndex == 0 || $obj.previousIndex == $slideNum - 2 && $obj.activeIndex == $slideNum - 1 ){ 3290 $('.swiper-slide').addClass('duplicate-transition'); 3291 } 3292 } 3293 3294 3295 clearTimeout(animationQueue); 3296 animationQueue = setTimeout(function(){ $animating = false; $('.swiper-slide').removeClass('duplicate-transition'); },800) 3297 3298 } 3299 3300 3301 //functions to add or remove slider for webkit parallax fix 3302 function hideSlider() { 3303 if( $(window).scrollTop()/($sliderHeight + portfolioHeaderHeight + 125) >= 1){ 3304 $('.parallax_slider_outer .nectar-slider-wrap, .project-title.parallax-effect').css('visibility','hidden').hide(); 3305 3306 $(window).bind('scroll',showSlider); 3307 $(window).unbind('scroll',hideSlider); 3308 } 3309 } 3310 3311 function showSlider() { 3312 if( $(window).scrollTop()/($sliderHeight + portfolioHeaderHeight + 125) <= 1){ 3313 3314 $('.parallax_slider_outer .nectar-slider-wrap, .project-title.parallax-effect').css('visibility','visible').show(); 3315 slideContentPos(); 3316 resizeToCover(); 3317 3318 $(window).bind('scroll',hideSlider); 3319 $(window).unbind('scroll',showSlider); 3320 3321 } 3322 } 3323 3324 3325 var $sliderHeight = parseInt($('.parallax_slider_outer.first-section .swiper-container').attr('data-height')); 3326
3327 function sliderParallaxInit() { 3328 3329 3330 if($('#portfolio-extra').length > 0 && $('#full_width_portfolio').length == 0) { return false; } 3331 3332 $(window).scroll(function(){ 3333 3334 if($('#boxed').length == 0) { 3335 3336 if(navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) { return false; } 3337 3338 $('.parallax_slider_outer.first-section .nectar-slider-wrap[data-parallax="true"]').stop(true,true).transition({ y: $(window).scrollTop()*-.2 },0); 3339 $('.parallax_slider_outer.first-section .swiper-slide:not(".static") .content, .parallax_slider_outer.first-section .nectar-slider-wrap[data-parallax="true"] .swiper-container .slider-next, .parallax_slider_outer.first-section .nectar-slider-wrap[data-parallax="true"] .swiper-container .slider-prev').stop(true,true).transition({ y: $(window).scrollTop()*-.14 },0); 3340 3341 $('#full_width_portfolio .project-title.parallax-effect').transition({ y: $(window).scrollTop()*-.2 },0); 3342 3343 $('.parallax_slider_outer.first-section .swiper-slide .content, .parallax_slider_outer.first-section .nectar-slider-wrap[data-parallax="true"] .swiper-container .slider-next, .parallax_slider_outer.first-section .nectar-slider-wrap[data-parallax="true"] .swiper-container .slider-prev').css('opacity', 1-($(window).scrollTop()/($sliderHeight-120)) ); 3344 } 3345 }); 3346 3347 3348 //hide slider to not mess up parallax section 3349 var portfolioHeaderHeight = ($('.project-title.parallax-effect').length > 0) ? 100 : 0; 3350 3351 if( $(window).scrollTop()/($sliderHeight + portfolioHeaderHeight + 90) >= 1){ 3352 $(window).bind('scroll', hideSlider); 3353 } else { 3354 $(window).bind('scroll', showSlider); 3355 } 3356 3357 3358 3359 $('.page-header-no-bg, #page-header-wrap, #page-header-bg').remove(); 3360 3361 var $adminBarHeight = ($('#wpadminbar').length > 0) ? 28 : 0 ; 3362 3363 $('.project-title').addClass('parallax-effect').css({ 3364 'top': $('#header-space').outerHeight() + $adminBarHeight + 'px' 3365 }); 3366 3367 //caption alignment if portfolio fullwidth parallax 3368 if($('.project-title.parallax-effect').length > 0) { 3369 $('.parallax_slider_outer.first-section .swiper-slide .content, .nectar-slider-wrap.first-section .swiper-slide .content').css('margin-top','0px'); 3370 $('.swiper-container .slider-prev, .swiper-container .slider-next').css('margin-top','-28px'); 3371 } 3372 3373 //if using wooCommerce sitewide notice 3374 if($('.demo_store').length > 0) $('.project-title.parallax-effect').css('margin-top','-25px'); 3375 3376 if($('#full_width_portfolio').length > 0){ 3377 $('.parallax_slider_outer.first-section').css('margin-top','93px'); 3378 } 3379 3380 $(window).resize(function(){ 3381 $sliderHeight = parseInt($('.parallax_slider_outer.first-section .swiper-container').attr('data-height')); 3382 3383 $('.project-title').css({ 3384 'top': $('#header-space').outerHeight() + $adminBarHeight + 'px' 3385 }); 3386 }); 3387 3388 } 3389 3390 //parallax 3391 if($('.parallax_slider_outer').length > 0 && !navigator.userAgent.match(/(Android|iPod|iPhone|iPad|IEMobile|Opera Mini)/)){ 3392 sliderParallaxInit(); 3393 3394 } else if($('.parallax_slider_outer').length > 0 && navigator.userAgent.match(/(Android|iPod|iPhone|iPad|IEMobile|Opera Mini)/)) { 3395 $('.project-title').addClass('parallax-effect').css({ 3396 'top': $('#header-space').outerHeight() + $adminBarHeight + 'px' 3397 }); 3398 } 3399 3400 3401 function niceScrollInit(){ 3402 $("html").niceScroll({ 3403 scrollspeed: 60, 3404 mousescrollstep: 40, 3405 cursorwidth: 15, 3406 cursorborder: 0, 3407 cursorcolor: '#2D3032', 3408 cursorborderradius: 6, 3409 autohidemode: false, 3410 horizrailenabled: false 3411 }); 3412 3413 if($('#boxed').length == 0){ 3414 $('body, body #header-outer, body #header-secondary-outer, body #search-outer').css('padding-right','16px'); 3415 } 3416 3417 $('html').addClass('no-overflow-y'); 3418 } 3419 3420 //pause video backgrounds if popup video player is started 3421 $('.portfolio-items a.pp:contains(Video), .swiper-container .buttons a.pp').click(function(){ 3422 $('.swiper-slide').each(function(){ 3423 if($(this).find('.video-wrap video').length > 0) { 3424 $(this).find('.video-wrap video').get(0).pause(); 3425 } 3426 }); 3427 }); 3428 3429 3430 3431 3432}); 3433
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.