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 //vc gallery when using lightbox fix 1119 if(jQuery(event.target).parents('.swiper-container').attr('data-desktop-swipe') == 'false' && !Modernizr.touch) return false; 1120 1121 //deactivate touch if only one slide 1122 if(jQuery(event.target).parents('.swiper-container').find('.swiper-slide').length == 1) return false; 1123 1124 //deactivate touch for duplicate transitions 1125 if(jQuery(event.target).parents('.swiper-container').find('.swiper-slide.duplicate-transition').length > 0) return false; 1126 1127 if (params.preventLinks) _this.allowLinks = true; 1128 //Exit if slider is already was touched 1129 if (_this.isTouched || params.onlyExternal) { 1130 return false; 1131 } 1132 1133 if (params.noSwiping && (event.target || event.srcElement) && noSwipingSlide(event.target || event.srcElement)) return false; 1134 allowMomentumBounce = false; 1135 1136 //Check For Nested Swipers 1137 _this.isTouched = true; 1138 isTouchEvent = event.type=='touchstart'; 1139 1140 if (!isTouchEvent || event.targetTouches.length == 1 ) { 1141 _this.callPlugins('onTouchStartBegin'); 1142 1143 if(!isTouchEvent) { 1144 if(event.preventDefault) event.preventDefault(); 1145 else event.returnValue = false; 1146 } 1147 1148 var pageX = isTouchEvent ? event.targetTouches[0].pageX : (event.pageX || event.clientX); 1149 var pageY = isTouchEvent ? event.targetTouches[0].pageY : (event.pageY || event.clientY); 1150 1151 //Start Touches to check the scrolling 1152 _this.touches.startX = _this.touches.currentX = pageX; 1153 _this.touches.startY = _this.touches.currentY = pageY; 1154 1155 _this.touches.start = _this.touches.current = isH ? pageX : pageY; 1156 1157 //Set Transition Time to 0 1158 _this.setWrapperTransition(0); 1159 1160 //Get Start Translate Position 1161 _this.positions.start = _this.positions.current = _this.getWrapperTranslate(); 1162 1163 //Set Transform 1164 _this.setWrapperTranslate(_this.positions.start); 1165 1166 //TouchStartTime 1167 _this.times.start = (new Date()).getTime(); 1168 1169 //Unset Scrolling 1170 isScrolling = undefined; 1171 1172 //Set Treshold 1173 if (params.moveStartThreshold>0) allowThresholdMove = false; 1174 1175 //CallBack 1176 if (params.onTouchStart) params.onTouchStart(_this); 1177 _this.callPlugins('onTouchStartEnd'); 1178 1179 } 1180 } 1181 var velocityPrevPosition, velocityPrevTime; 1182 function onTouchMove(event) { 1183 // If slider is not touched - exit 1184 if (!_this.isTouched || params.onlyExternal) return; 1185 if (isTouchEvent && event.type=='mousemove') return; 1186 1187 var pageX = isTouchEvent ? event.targetTouches[0].pageX : (event.pageX || event.clientX); 1188 var pageY = isTouchEvent ? event.targetTouches[0].pageY : (event.pageY || event.clientY); 1189 1190 //check for scrolling
1191 if ( typeof isScrolling === 'undefined' && isH) { 1192 isScrolling = !!( isScrolling || Math.abs(pageY - _this.touches.startY) > Math.abs( pageX - _this.touches.startX ) ); 1193 } 1194 if ( typeof isScrolling === 'undefined' && !isH) { 1195 isScrolling = !!( isScrolling || Math.abs(pageY - _this.touches.startY) < Math.abs( pageX - _this.touches.startX ) ); 1196 } 1197 if (isScrolling ) { 1198 _this.isTouched = false; 1199 return; 1200 } 1201 1202 //Check For Nested Swipers 1203 if (event.assignedToSwiper) { 1204 _this.isTouched = false; 1205 return; 1206 } 1207 event.assignedToSwiper = true; 1208 1209 //Block inner links 1210 if (params.preventLinks) { 1211 _this.allowLinks = false; 1212 } 1213 if (params.onSlideClick) { 1214 _this.allowSlideClick = false; 1215 } 1216 1217 //Stop AutoPlay if exist 1218 if (params.autoplay) { 1219 _this.stopAutoplay(); 1220 } 1221 if (!isTouchEvent || event.touches.length == 1) { 1222 1223 //Moved Flag 1224 if (!_this.isMoved) { 1225 _this.callPlugins('onTouchMoveStart'); 1226 1227 if (params.loop) { 1228 _this.fixLoop(); 1229 _this.positions.start = _this.getWrapperTranslate(); 1230 } 1231 if (params.onTouchMoveStart) params.onTouchMoveStart(_this); 1232 } 1233 _this.isMoved = true; 1234 1235 // cancel event 1236 if(event.preventDefault) event.preventDefault(); 1237 else event.returnValue = false; 1238 1239 _this.touches.current = isH ? pageX : pageY ; 1240 1241 _this.positions.current = (_this.touches.current - _this.touches.start) * params.touchRatio + _this.positions.start; 1242 1243 //Resistance Callbacks 1244 if(_this.positions.current > 0 && params.onResistanceBefore) { 1245 params.onResistanceBefore(_this, _this.positions.current); 1246 } 1247 if(_this.positions.current < -maxWrapperPosition() && params.onResistanceAfter) { 1248 params.onResistanceAfter(_this, Math.abs(_this.positions.current + maxWrapperPosition())); 1249 } 1250 //Resistance 1251 if (params.resistance && params.resistance!='100%') { 1252 //Resistance for Negative-Back sliding 1253 if(_this.positions.current > 0) { 1254 var resistance = 1 - _this.positions.current/containerSize/2; 1255 if (resistance < 0.5) 1256 _this.positions.current = (containerSize/2); 1257 else 1258 _this.positions.current = _this.positions.current * resistance; 1259 } 1260 //Resistance for After-End Sliding 1261 if ( _this.positions.current < -maxWrapperPosition() ) { 1262 1263 var diff = (_this.touches.current - _this.touches.start)*params.touchRatio + (maxWrapperPosition()+_this.positions.start); 1264 var resistance = (containerSize+diff)/(containerSize); 1265 var newPos = _this.positions.current-diff*(1-resistance)/2; 1266 var stopPos = -maxWrapperPosition() - containerSize/2; 1267 1268 if (newPos < stopPos || resistance<=0) 1269 _this.positions.current = stopPos; 1270 else 1271 _this.positions.current = newPos; 1272 } 1273 } 1274 if (params.resistance && params.resistance=='100%') { 1275 //Resistance for Negative-Back sliding 1276 if(_this.positions.current > 0 && !(params.freeMode&&!params.freeModeFluid)) { 1277 _this.positions.current = 0; 1278 } 1279 //Resistance for After-End Sliding 1280 if ( (_this.positions.current) < -maxWrapperPosition() && !(params.freeMode&&!params.freeModeFluid)) { 1281 _this.positions.current = -maxWrapperPosition(); 1282 } 1283 } 1284 //Move Slides 1285 if (!params.followFinger) return; 1286 1287 if (!params.moveStartThreshold) { 1288 _this.setWrapperTranslate(_this.positions.current); 1289 } 1290 else { 1291 if ( Math.abs(_this.touches.current - _this.touches.start)>params.moveStartThreshold || allowThresholdMove) { 1292 allowThresholdMove = true; 1293 _this.setWrapperTranslate(_this.positions.current); 1294 } 1295 else { 1296 _this.positions.current = _this.positions.start; 1297 } 1298 } 1299 1300 if (params.freeMode || params.watchActiveIndex) { 1301 _this.updateActiveSlide(_this.positions.current); 1302 } 1303 1304 //Grab Cursor 1305 //Grab Cursor 1306 if (params.grabCursor) { 1307 _this.container.style.cursor = 'move'; 1308 _this.container.style.cursor = 'grabbing'; 1309 _this.container.style.cursor = '-moz-grabbing'; 1310 _this.container.style.cursor = '-webkit-grabbing'; 1311 } 1312 //Velocity 1313 if (!velocityPrevPosition) velocityPrevPosition = _this.touches.current; 1314 if (!velocityPrevTime) velocityPrevTime = (new Date).getTime(); 1315 _this.velocity = (_this.touches.current - velocityPrevPosition)/((new Date).getTime() - velocityPrevTime)/2; 1316 1317 if (Math.abs(_this.touches.current - velocityPrevPosition)<2) _this.velocity=0; 1318 velocityPrevPosition = _this.touches.current; 1319 velocityPrevTime = (new Date).getTime(); 1320 //Callbacks 1321 _this.callPlugins('onTouchMoveEnd'); 1322 if (params.onTouchMove) params.onTouchMove(_this); 1323 1324 return false; 1325 } 1326 } 1327 function onTouchEnd(event) { 1328 //Check For scrolling 1329 if (isScrolling) { 1330 _this.swipeReset(); 1331 } 1332 // If slider is not touched exit 1333 if ( params.onlyExternal || !_this.isTouched ) return; 1334 _this.isTouched = false 1335 1336 //Return Grab Cursor 1337 if (params.grabCursor) { 1338 _this.container.style.cursor = 'move'; 1339 _this.container.style.cursor = 'grab'; 1340 _this.container.style.cursor = '-moz-grab'; 1341 _this.container.style.cursor = '-webkit-grab'; 1342 } 1343 1344 //Check for Current Position 1345 if (!_this.positions.current && _this.positions.current!==0) { 1346 _this.positions.current = _this.positions.start 1347 } 1348 1349 //For case if slider touched but not moved 1350 if (params.followFinger) { 1351 _this.setWrapperTranslate(_this.positions.current); 1352 } 1353 1354 // TouchEndTime
1355 _this.times.end = (new Date()).getTime(); 1356 1357 //Difference 1358 _this.touches.diff = _this.touches.current - _this.touches.start 1359 _this.touches.abs = Math.abs(_this.touches.diff) 1360 1361 _this.positions.diff = _this.positions.current - _this.positions.start 1362 _this.positions.abs = Math.abs(_this.positions.diff) 1363 1364 var diff = _this.positions.diff ; 1365 var diffAbs =_this.positions.abs ; 1366 var timeDiff = _this.times.end - _this.times.start 1367 1368 if(diffAbs < 5 && (timeDiff) < 300 && _this.allowLinks == false) { 1369 if (!params.freeMode && diffAbs!=0) _this.swipeReset() 1370 //Release inner links 1371 if (params.preventLinks) { 1372 _this.allowLinks = true; 1373 } 1374 if (params.onSlideClick) { 1375 _this.allowSlideClick = true; 1376 } 1377 } 1378 1379 setTimeout(function () { 1380 //Release inner links 1381 if (params.preventLinks) { 1382 _this.allowLinks = true; 1383 } 1384 if (params.onSlideClick) { 1385 _this.allowSlideClick = true; 1386 } 1387 }, 100); 1388 1389 var maxPosition = maxWrapperPosition(); 1390 1391 //Not moved or Prevent Negative Back Sliding/After-End Sliding 1392 if (!_this.isMoved && params.freeMode) { 1393 _this.isMoved = false; 1394 if (params.onTouchEnd) params.onTouchEnd(_this); 1395 _this.callPlugins('onTouchEnd'); 1396 return; 1397 } 1398 if (!_this.isMoved || _this.positions.current > 0 || _this.positions.current < -maxPosition) { 1399 _this.swipeReset(); 1400 if (params.onTouchEnd) params.onTouchEnd(_this); 1401 _this.callPlugins('onTouchEnd'); 1402 return; 1403 } 1404 1405 _this.isMoved = false; 1406 1407 //Free Mode 1408 if (params.freeMode) { 1409 if ( params.freeModeFluid ) { 1410 var momentumDuration = 1000*params.momentumRatio; 1411 var momentumDistance = _this.velocity*momentumDuration; 1412 var newPosition = _this.positions.current + momentumDistance 1413 var doBounce = false; 1414 var afterBouncePosition; 1415 var bounceAmount = Math.abs( _this.velocity )*20*params.momentumBounceRatio; 1416 if (newPosition < -maxPosition) { 1417 if (params.momentumBounce && _this.support.transitions) { 1418 if (newPosition + maxPosition < -bounceAmount) newPosition = -maxPosition-bounceAmount; 1419 afterBouncePosition = -maxPosition; 1420 doBounce=true; 1421 allowMomentumBounce = true; 1422 } 1423 else newPosition = -maxPosition; 1424 } 1425 if (newPosition > 0) { 1426 if (params.momentumBounce && _this.support.transitions) { 1427 if (newPosition>bounceAmount) newPosition = bounceAmount; 1428 afterBouncePosition = 0 1429 doBounce = true; 1430 allowMomentumBounce = true; 1431 } 1432 else newPosition = 0; 1433 } 1434 //Fix duration 1435 if (_this.velocity!=0) momentumDuration = Math.abs((newPosition - _this.positions.current)/_this.velocity) 1436 1437 _this.setWrapperTranslate(newPosition); 1438 1439 _this.setWrapperTransition( momentumDuration ); 1440 1441 if (params.momentumBounce && doBounce) { 1442 _this.wrapperTransitionEnd(function () { 1443 if (!allowMomentumBounce) return; 1444 1445 if (params.onMomentumBounce) params.onMomentumBounce(_this); 1446 1447 _this.setWrapperTranslate(afterBouncePosition); 1448 _this.setWrapperTransition(300); 1449 }) 1450 } 1451 1452 _this.updateActiveSlide(newPosition) 1453 } 1454 if (!params.freeModeFluid || timeDiff >= 300) _this.updateActiveSlide(_this.positions.current) 1455 1456 if (params.onTouchEnd) params.onTouchEnd(_this) 1457 _this.callPlugins('onTouchEnd'); 1458 return; 1459 } 1460 1461 //Direction 1462 direction = diff < 0 ? "toNext" : "toPrev" 1463 1464 //Short Touches 1465 if (direction=="toNext" && ( timeDiff <= 300 ) ) { 1466 if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset() 1467 else _this.swipeNext(true); 1468 } 1469 1470 if (direction=="toPrev" && ( timeDiff <= 300 ) ) { 1471 if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset() 1472 else _this.swipePrev(true); 1473 } 1474 1475 //Long Touches 1476 var targetSlideSize = 0; 1477 if(params.slidesPerView == 'auto') { 1478 //Define current slide's width 1479 var currentPosition = Math.abs(_this.getWrapperTranslate()); 1480 var slidesOffset = 0; 1481 var _slideSize; 1482 for (var i=0; i<_this.slides.length; i++) { 1483 _slideSize = isH ? _this.slides[i].getWidth(true) : _this.slides[i].getHeight(true); 1484 slidesOffset+= _slideSize; 1485 if (slidesOffset>currentPosition) { 1486 targetSlideSize = _slideSize; 1487 break; 1488 } 1489 }
1490 if (targetSlideSize>containerSize) targetSlideSize = containerSize; 1491 } 1492 else { 1493 targetSlideSize = slideSize * params.slidesPerView; 1494 } 1495 if (direction=="toNext" && ( timeDiff > 300 ) ) { 1496 if (diffAbs >= targetSlideSize*0.5) { 1497 _this.swipeNext(true) 1498 } 1499 else { 1500 _this.swipeReset() 1501 } 1502 } 1503 if (direction=="toPrev" && ( timeDiff > 300 ) ) { 1504 if (diffAbs >= targetSlideSize*0.5) { 1505 _this.swipePrev(true); 1506 } 1507 else { 1508 _this.swipeReset() 1509 } 1510 } 1511 if (params.onTouchEnd) params.onTouchEnd(_this) 1512 _this.callPlugins('onTouchEnd'); 1513 } 1514 1515 1516 /*================================================== 1517 noSwiping Bubble Check by Isaac Strack 1518 ====================================================*/ 1519 function noSwipingSlide(el){ 1520 /*This function is specifically designed to check the parent elements for the noSwiping class, up to the wrapper. 1521 We need to check parents because while onTouchStart bubbles, _this.isTouched is checked in onTouchStart, which stops the bubbling. 1522 So, if a text box, for example, is the initial target, and the parent slide container has the noSwiping class, the _this.isTouched 1523 check will never find it, and what was supposed to be noSwiping is able to be swiped. 1524 This function will iterate up and check for the noSwiping class in parents, up through the wrapperClass.*/ 1525 1526 // First we create a truthy variable, which is that swiping is allowd (noSwiping = false) 1527 var noSwiping = false; 1528 1529 // Now we iterate up (parentElements) until we reach the node with the wrapperClass. 1530 do{ 1531 1532 // Each time, we check to see if there's a 'swiper-no-swiping' class (noSwipingClass). 1533 if (el.className.indexOf(params.noSwipingClass)>-1) 1534 { 1535 noSwiping = true; // If there is, we set noSwiping = true; 1536 } 1537 1538 el = el.parentElement; // now we iterate up (parent node) 1539 1540 } while(!noSwiping && el.parentElement && el.className.indexOf(params.wrapperClass)==-1); // also include el.parentElement truthy, just in case. 1541 1542 // because we didn't check the wrapper itself, we do so now, if noSwiping is false: 1543 if (!noSwiping && el.className.indexOf(params.wrapperClass)>-1 && el.className.indexOf(params.noSwipingClass)>-1) 1544 noSwiping = true; // if the wrapper has the noSwipingClass, we set noSwiping = true; 1545 1546 return noSwiping; 1547 } 1548 1549 /*================================================== 1550 Swipe Functions 1551 ====================================================*/ 1552 _this.swipeNext = function(internal){ 1553 if (!internal && params.loop) _this.fixLoop(); 1554 _this.callPlugins('onSwipeNext'); 1555 var currentPosition = _this.getWrapperTranslate(); 1556 var newPosition = currentPosition; 1557 if (params.slidesPerView=='auto') { 1558 for (var i=0; i<_this.snapGrid.length; i++) { 1559 if (-currentPosition >= _this.snapGrid[i] && -currentPosition<_this.snapGrid[i+1]) { 1560 newPosition = -_this.snapGrid[i+1] 1561 break; 1562 } 1563 } 1564 } 1565 else { 1566 var groupSize = slideSize * params.slidesPerGroup; 1567 newPosition = -(Math.floor(Math.abs(currentPosition)/Math.floor(groupSize))*groupSize + groupSize); 1568 } 1569 if (newPosition < - maxWrapperPosition()) { 1570 newPosition = - maxWrapperPosition() 1571 }; 1572 1573 if (newPosition == currentPosition) return false; 1574 1575 swipeToPosition(newPosition, 'next'); 1576 return true 1577 } 1578 _this.swipePrev = function(internal){ 1579 if (!internal && params.loop) _this.fixLoop(); 1580 if (!internal && params.autoplay) _this.stopAutoplay(); 1581 _this.callPlugins('onSwipePrev'); 1582 1583 var currentPosition = Math.ceil(_this.getWrapperTranslate()); 1584 var newPosition; 1585 if (params.slidesPerView=='auto') { 1586 newPosition = 0; 1587 for (var i=1; i<_this.snapGrid.length; i++) { 1588 if (-currentPosition == _this.snapGrid[i]) { 1589 newPosition = -_this.snapGrid[i-1] 1590 break; 1591 } 1592 if (-currentPosition > _this.snapGrid[i] && -currentPosition<_this.snapGrid[i+1]) { 1593 newPosition = -_this.snapGrid[i] 1594 break; 1595 } 1596 } 1597 } 1598 else { 1599 var groupSize = slideSize * params.slidesPerGroup; 1600 newPosition = -(Math.ceil(-currentPosition/groupSize)-1)*groupSize; 1601 } 1602 1603 if (newPosition > 0) newPosition = 0; 1604 1605 if (newPosition == currentPosition) return false; 1606 swipeToPosition(newPosition, 'prev'); 1607 return true; 1608 1609 } 1610 _this.swipeReset = function(){ 1611 _this.callPlugins('onSwipeReset'); 1612 var currentPosition = _this.getWrapperTranslate(); 1613 var groupSize = slideSize * params.slidesPerGroup; 1614 var newPosition; 1615 var maxPosition = -maxWrapperPosition(); 1616 if (params.slidesPerView=='auto') { 1617 newPosition = 0; 1618 for (var i=0; i<_this.snapGrid.length; i++) { 1619 if (-currentPosition===_this.snapGrid[i]) return; 1620 if (-currentPosition >= _this.snapGrid[i] && -currentPosition<_this.snapGrid[i+1]) { 1621 if(_this.positions.diff>0) newPosition = -_this.snapGrid[i+1] 1622 else newPosition = -_this.snapGrid[i] 1623 break; 1624 } 1625 } 1626 if (-currentPosition >= _this.snapGrid[_this.snapGrid.length-1]) newPosition = -_this.snapGrid[_this.snapGrid.length-1]; 1627 if (currentPosition <= -maxWrapperPosition()) newPosition = -maxWrapperPosition() 1628 } 1629 else { 1630 newPosition = currentPosition<0 ? Math.round(currentPosition/groupSize)*groupSize : 0 1631 } 1632 if (params.scrollContainer) { 1633 newPosition = currentPosition<0 ? currentPosition : 0; 1634 } 1635 if (newPosition < -maxWrapperPosition()) { 1636 newPosition = -maxWrapperPosition() 1637 } 1638 if (params.scrollContainer && (containerSize>slideSize)) { 1639 newPosition = 0; 1640 } 1641 1642 if (newPosition == currentPosition) return false; 1643 1644 swipeToPosition(newPosition, 'reset'); 1645 return true; 1646 } 1647 1648 _this.swipeTo = function(index, speed, runCallbacks) { 1649 index = parseInt(index, 10); 1650 _this.callPlugins('onSwipeTo', {index:index, speed:speed}); 1651 if (params.loop) index = index + _this.loopedSlides; 1652 var currentPosition = _this.getWrapperTranslate(); 1653 if (index > (_this.slides.length-1) || index < 0) return; 1654 var newPosition 1655 if (params.slidesPerView=='auto') { 1656 newPosition = -_this.slidesGrid[ index ]; 1657 } 1658 else { 1659 newPosition = -index*slideSize; 1660 } 1661 if (newPosition < - maxWrapperPosition()) { 1662 newPosition = - maxWrapperPosition(); 1663 }; 1664 1665 if (newPosition == currentPosition) return false; 1666 1667 runCallbacks = runCallbacks===false ? false : true; 1668 swipeToPosition(newPosition, 'to', {index:index, speed:speed, runCallbacks:runCallbacks}); 1669 return true; 1670 } 1671 1672 function swipeToPosition(newPosition, action, toOptions) { 1673 var speed = (action=='to' && toOptions.speed >= 0) ? toOptions.speed : params.speed; 1674 1675 if (_this.support.transitions || !params.DOMAnimation) { 1676 _this.setWrapperTranslate(newPosition); 1677 _this.setWrapperTransition(speed); 1678 } 1679 else { 1680 //Try the DOM animation 1681 var currentPosition = _this.getWrapperTranslate(); 1682 var animationStep = Math.ceil( (newPosition - currentPosition)/speed*(1000/60) ); 1683 var direction = currentPosition > newPosition ? 'toNext' : 'toPrev'; 1684 var condition = direction=='toNext' ? currentPosition > newPosition : currentPosition < newPosition; 1685 if (_this._DOMAnimating) return; 1686 1687 anim(); 1688 } 1689 function anim(){ 1690 currentPosition += animationStep; 1691 condition = direction=='toNext' ? currentPosition > newPosition : currentPosition < newPosition; 1692 if (condition) { 1693 _this.setWrapperTranslate(Math.round(currentPosition)); 1694 _this._DOMAnimating = true 1695 window.setTimeout(function(){ 1696 anim() 1697 }, 1000 / 60) 1698 } 1699 else { 1700 if (params.onSlideChangeEnd) params.onSlideChangeEnd(_this); 1701 _this.setWrapperTranslate(newPosition); 1702 _this._DOMAnimating = false; 1703 } 1704 } 1705 1706 //Update Active Slide Index 1707 _this.updateActiveSlide(newPosition); 1708 1709 //Callbacks 1710 if (params.onSlideNext && action=='next') { 1711 params.onSlideNext(_this, newPosition); 1712 } 1713 if (params.onSlidePrev && action=='prev') { 1714 params.onSlidePrev(_this, newPosition); 1715 } 1716 //"Reset" Callback 1717 if (params.onSlideReset && action=='reset') { 1718 params.onSlideReset(_this, newPosition); 1719 } 1720 1721 //"Next", "Prev" and "To" Callbacks 1722 if (action=='next' || action=='prev' || (action=='to' && toOptions.runCallbacks==true)) 1723 slideChangeCallbacks(); 1724 } 1725 /*================================================== 1726 Transition Callbacks 1727 ====================================================*/ 1728 //Prevent Multiple Callbacks 1729 _this._queueStartCallbacks = false; 1730 _this._queueEndCallbacks = false; 1731 function slideChangeCallbacks() { 1732 //Transition Start Callback 1733 _this.callPlugins('onSlideChangeStart'); 1734 if (params.onSlideChangeStart) { 1735 if (params.queueStartCallbacks && _this.support.transitions) { 1736 if (_this._queueStartCallbacks) return; 1737 _this._queueStartCallbacks = true; 1738 params.onSlideChangeStart(_this) 1739 _this.wrapperTransitionEnd(function(){ 1740 _this._queueStartCallbacks = false; 1741 }) 1742 } 1743 else params.onSlideChangeStart(_this) 1744 } 1745 //Transition End Callback 1746 if (params.onSlideChangeEnd) { 1747 if (_this.support.transitions) { 1748 if (params.queueEndCallbacks) { 1749 if (_this._queueEndCallbacks) return; 1750 _this._queueEndCallbacks = true; 1751 _this.wrapperTransitionEnd(params.onSlideChangeEnd) 1752 } 1753 else { 1754 _this.wrapperTransitionEnd(function(){ _this.fixLoop(); params.onSlideChangeEnd(_this); }); 1755 } 1756 } 1757 else { 1758 if (!params.DOMAnimation) { 1759 setTimeout(function(){ 1760 params.onSlideChangeEnd(_this) 1761 },10) 1762 } 1763 } 1764 } 1765 } 1766 1767 /*================================================== 1768 Update Active Slide Index 1769 ====================================================*/ 1770 _this.updateActiveSlide = function(position) { 1771 if (!_this.initialized) return; 1772 if (_this.slides.length==0) return; 1773 _this.previousIndex = _this.activeIndex; 1774 if (typeof position=='undefined') position = _this.getWrapperTranslate(); 1775 if (position>0) position=0; 1776 1777 if (params.slidesPerView == 'auto') { 1778 var slidesOffset = 0; 1779 _this.activeIndex = _this.slidesGrid.indexOf(-position); 1780 if (_this.activeIndex<0) { 1781 for (var i=0; i<_this.slidesGrid.length-1; i++) { 1782 if (-position>_this.slidesGrid[i] && -position<_this.slidesGrid[i+1]) { 1783 break; 1784 } 1785 } 1786 var leftDistance = Math.abs( _this.slidesGrid[i] + position ) 1787 var rightDistance = Math.abs( _this.slidesGrid[i+1] + position ) 1788 if (leftDistance<=rightDistance) _this.activeIndex = i; 1789 else _this.activeIndex = i+1; 1790 } 1791 } 1792 else { 1793 _this.activeIndex = Math[params.visibilityFullFit ? 'ceil' : 'round']( -position/slideSize ); 1794 } 1795 1796 if (_this.activeIndex == _this.slides.length ) _this.activeIndex = _this.slides.length - 1; 1797 if (_this.activeIndex < 0) _this.activeIndex = 0; 1798 1799 // Check for slide 1800 if (!_this.slides[_this.activeIndex]) return; 1801 1802 // Calc Visible slides 1803 _this.calcVisibleSlides(position); 1804 1805 // Mark visible and active slides with additonal classes 1806 var activeClassRegexp = new RegExp( "\\s*" + params.slideActiveClass ); 1807 var inViewClassRegexp = new RegExp( "\\s*" + params.slideVisibleClass ); 1808 1809 for (var i = 0; i < _this.slides.length; i++) { 1810 _this.slides[ i ].className = _this.slides[ i ].className.replace( activeClassRegexp, '' ).replace( inViewClassRegexp, '' ); 1811 if ( _this.visibleSlides.indexOf( _this.slides[ i ] )>=0 ) { 1812 _this.slides[ i ].className += ' ' + params.slideVisibleClass; 1813 } 1814 1815 } 1816 _this.slides[ _this.activeIndex ].className += ' ' + params.slideActiveClass; 1817 1818 //Update loop index 1819 if (params.loop) { 1820 var ls = _this.loopedSlides; 1821 _this.activeLoopIndex = _this.activeIndex - ls; 1822 if (_this.activeLoopIndex >= _this.slides.length - ls*2 ) { 1823 _this.activeLoopIndex = _this.slides.length - ls*2 - _this.activeLoopIndex; 1824 } 1825 if (_this.activeLoopIndex<0) { 1826 _this.activeLoopIndex = _this.slides.length - ls*2 + _this.activeLoopIndex; 1827 } 1828 } 1829 else { 1830 _this.activeLoopIndex = _this.activeIndex; 1831 } 1832 //Update Pagination 1833 if (params.pagination) { 1834 _this.updatePagination(position); 1835 } 1836 } 1837 /*================================================== 1838 Pagination 1839 ====================================================*/ 1840 _this.createPagination = function (firstInit) { 1841 if (params.paginationClickable && _this.paginationButtons) { 1842 removePaginationEvents(); 1843 } 1844 var paginationHTML = ""; 1845 var numOfSlides = _this.slides.length; 1846 var numOfButtons = numOfSlides; 1847 if (params.loop) numOfButtons -= _this.loopedSlides*2 1848 for (var i = 0; i < numOfButtons; i++) { 1849 paginationHTML += '<'+params.paginationElement+' class="'+params.paginationElementClass+'"></'+params.paginationElement+'>' 1850 } 1851 _this.paginationContainer = params.pagination.nodeType ? params.pagination : $$(params.pagination)[0]; 1852 _this.paginationContainer.innerHTML = paginationHTML; 1853 _this.paginationButtons = $$('.'+params.paginationElementClass, _this.paginationContainer); 1854 if (!firstInit) _this.updatePagination() 1855 _this.callPlugins('onCreatePagination'); 1856 if (params.paginationClickable) { 1857 addPaginationEvents(); 1858 } 1859 } 1860 function removePaginationEvents() { 1861 var pagers = _this.paginationButtons; 1862 for (var i=0; i<pagers.length; i++) {
1863 _this.h.removeEventListener(pagers[i], 'click', paginationClick); 1864 } 1865 } 1866 function addPaginationEvents() { 1867 var pagers = _this.paginationButtons; 1868 for (var i=0; i<pagers.length; i++) { 1869 _this.h.addEventListener(pagers[i], 'click', paginationClick); 1870 } 1871 } 1872 function paginationClick(e){ 1873 var index; 1874 var target = e.target || e.srcElement; 1875 var pagers = _this.paginationButtons; 1876 for (var i=0; i<pagers.length; i++) { 1877 if (target===pagers[i]) index = i; 1878 } 1879 _this.swipeTo(index) 1880 } 1881 _this.updatePagination = function(position) { 1882 if (!params.pagination) return; 1883 if (_this.slides.length<1) return; 1884 1885 var activePagers = $$('.'+params.paginationActiveClass, _this.paginationContainer); 1886 if(!activePagers) return; 1887 1888 //Reset all Buttons' class to not active 1889 var pagers = _this.paginationButtons; 1890 if (pagers.length==0) return; 1891 for (var i=0; i < pagers.length; i++) { 1892 pagers[i].className = params.paginationElementClass 1893 } 1894 1895 var indexOffset = params.loop ? _this.loopedSlides : 0; 1896 if (params.paginationAsRange) { 1897 if (!_this.visibleSlides) _this.calcVisibleSlides(position) 1898 //Get Visible Indexes 1899 var visibleIndexes = []; 1900 for (var i = 0; i < _this.visibleSlides.length; i++) { 1901 var visIndex = _this.slides.indexOf( _this.visibleSlides[i] ) - indexOffset 1902 1903 if (params.loop && visIndex<0) { 1904 visIndex = _this.slides.length - _this.loopedSlides*2 + visIndex; 1905 } 1906 if (params.loop && visIndex>=_this.slides.length-_this.loopedSlides*2) { 1907 visIndex = _this.slides.length - _this.loopedSlides*2 - visIndex; 1908 visIndex = Math.abs(visIndex) 1909 } 1910 visibleIndexes.push( visIndex ) 1911 } 1912 1913 for (i=0; i<visibleIndexes.length; i++) { 1914 if (pagers[ visibleIndexes[i] ]) pagers[ visibleIndexes[i] ].className += ' ' + params.paginationVisibleClass; 1915 } 1916 1917 if (params.loop) { 1918 pagers[ _this.activeLoopIndex ].className += ' ' + params.paginationActiveClass; 1919 } 1920 else { 1921 pagers[ _this.activeIndex ].className += ' ' + params.paginationActiveClass; 1922 } 1923 1924 } 1925 else { 1926 if (params.loop) { 1927 pagers[ _this.activeLoopIndex ].className+=' '+params.paginationActiveClass+' '+params.paginationVisibleClass; 1928 } 1929 else { 1930 pagers[ _this.activeIndex ].className+=' '+params.paginationActiveClass+' '+params.paginationVisibleClass; 1931 } 1932 1933 } 1934 1935 } 1936 _this.calcVisibleSlides = function(position){ 1937 var visibleSlides = []; 1938 var _slideLeft = 0, _slideSize = 0, _slideRight = 0; 1939 if (isH && _this.wrapperLeft>0) position = position+_this.wrapperLeft; 1940 if (!isH && _this.wrapperTop>0) position = position+_this.wrapperTop; 1941 1942 for (var i=0; i<_this.slides.length; i++) { 1943 _slideLeft += _slideSize; 1944 if (params.slidesPerView == 'auto') 1945 _slideSize = isH ? _this.h.getWidth(_this.slides[i],true) : _this.h.getHeight(_this.slides[i],true); 1946 else _slideSize = slideSize; 1947 1948 _slideRight = _slideLeft + _slideSize; 1949 var isVisibile = false; 1950 if (params.visibilityFullFit) { 1951 if (_slideLeft >= -position && _slideRight <= -position+containerSize) isVisibile = true; 1952 if (_slideLeft <= -position && _slideRight >= -position+containerSize) isVisibile = true; 1953 } 1954 else { 1955 1956 if (_slideRight > -position && _slideRight <= ((-position+containerSize))) isVisibile = true; 1957 if (_slideLeft >= -position && _slideLeft < ((-position+containerSize))) isVisibile = true; 1958 if (_slideLeft < -position && _slideRight > ((-position+containerSize))) isVisibile = true; 1959 } 1960 1961 if (isVisibile) visibleSlides.push(_this.slides[i]) 1962 1963 } 1964 if (visibleSlides.length==0) visibleSlides = [ _this.slides[ _this.activeIndex ] ] 1965 1966 _this.visibleSlides = visibleSlides; 1967 } 1968 1969 /*========================================== 1970 Autoplay 1971 ============================================*/ 1972 _this.autoPlayIntervalId = undefined; 1973 _this.startAutoplay = function () { 1974 if (typeof _this.autoPlayIntervalId !== 'undefined') return false; 1975 if (params.autoplay && !params.loop) { 1976 _this.autoPlayIntervalId = setInterval(function(){ 1977 if (!_this.swipeNext(true)) _this.swipeTo(0); 1978 }, params.autoplay) 1979 } 1980 if (params.autoplay && params.loop) { 1981 _this.autoPlayIntervalId = setInterval(function(){ 1982 _this.swipeNext(); 1983 }, params.autoplay) 1984 } 1985 _this.callPlugins('onAutoplayStart'); 1986 } 1987 _this.stopAutoplay = function () { 1988 if (_this.autoPlayIntervalId) clearInterval(_this.autoPlayIntervalId); 1989 _this.autoPlayIntervalId = undefined; 1990 _this.callPlugins('onAutoplayStop'); 1991 } 1992 1993 /*================================================== 1994 Loop 1995 ====================================================*/ 1996 _this.loopCreated = false; 1997 _this.removeLoopedSlides = function(){ 1998 if (_this.loopCreated) { 1999 for (var i=0; i<_this.slides.length; i++) { 2000 if (_this.slides[i].getData('looped')===true) _this.wrapper.removeChild(_this.slides[i]); 2001 } 2002 } 2003 } 2004 2005 _this.createLoop = function() { 2006 if (_this.slides.length==0) return; 2007 2008 _this.loopedSlides = params.slidesPerView + params.loopAdditionalSlides; 2009 if (_this.loopedSlides > _this.slides.length) { 2010 _this.loopedSlides = _this.slides.length; 2011 } 2012
2013 var slideFirstHTML = '', 2014 slideLastHTML = '', 2015 i; 2016 2017 //Grab First Slides 2018 for (i=0; i<_this.loopedSlides; i++) { 2019 slideFirstHTML += _this.slides[i].outerHTML; 2020 } 2021 //Grab Last Slides 2022 for (i=_this.slides.length-_this.loopedSlides; i<_this.slides.length; i++) { 2023 slideLastHTML += _this.slides[i].outerHTML; 2024 } 2025 wrapper.innerHTML = slideLastHTML + wrapper.innerHTML + slideFirstHTML; 2026 2027 _this.loopCreated = true; 2028 _this.calcSlides(); 2029 2030 //Update Looped Slides with special class 2031 for (i=0; i<_this.slides.length; i++) { 2032 if (i<_this.loopedSlides || i>=_this.slides.length-_this.loopedSlides) _this.slides[i].setData('looped', true); 2033 } 2034 _this.callPlugins('onCreateLoop'); 2035 2036 } 2037 2038 _this.fixLoop = function() { 2039 2040 if(_this.params.loop == true) { 2041 2042 var newIndex; 2043 //Fix For Negative Oversliding 2044 if (_this.activeIndex < _this.loopedSlides) { 2045 newIndex = _this.slides.length - _this.loopedSlides*3 + _this.activeIndex; 2046 _this.swipeTo(newIndex, 0, false); 2047 } 2048 //Fix For Positive Oversliding 2049 else if (_this.activeIndex > _this.slides.length - params.slidesPerView*2) { 2050 newIndex = -_this.slides.length + _this.activeIndex + _this.loopedSlides 2051 _this.swipeTo(newIndex, 0, false); 2052 } 2053 } 2054 2055 } 2056 2057 /*================================================== 2058 Slides Loader 2059 ====================================================*/ 2060 _this.loadSlides = function(){ 2061 var slidesHTML = ''; 2062 _this.activeLoaderIndex = 0; 2063 var slides = params.loader.slides; 2064 var slidesToLoad = params.loader.loadAllSlides ? slides.length : params.slidesPerView*(1+params.loader.surroundGroups); 2065 for (var i=0; i< slidesToLoad; i++) { 2066 if (params.loader.slidesHTMLType=='outer') slidesHTML+=slides[i]; 2067 else { 2068 slidesHTML+='<'+params.slideElement+' class="'+params.slideClass+'" data-swiperindex="'+i+'">'+slides[i]+'</'+params.slideElement+'>'; 2069 } 2070 } 2071 _this.wrapper.innerHTML = slidesHTML; 2072 _this.calcSlides(true); 2073 //Add permanent transitionEnd callback 2074 if (!params.loader.loadAllSlides) { 2075 _this.wrapperTransitionEnd(_this.reloadSlides, true); 2076 } 2077 } 2078 2079 _this.reloadSlides = function(){ 2080 var slides = params.loader.slides; 2081 var newActiveIndex = parseInt(_this.activeSlide().data('swiperindex'),10) 2082 if (newActiveIndex<0 || newActiveIndex>slides.length-1) return //<-- Exit 2083 _this.activeLoaderIndex = newActiveIndex; 2084 var firstIndex = Math.max(0, newActiveIndex - params.slidesPerView*params.loader.surroundGroups) 2085 var lastIndex = Math.min(newActiveIndex+params.slidesPerView*(1+params.loader.surroundGroups)-1, slides.length-1) 2086 //Update Transforms 2087 if (newActiveIndex>0) { 2088 var newTransform = -slideSize*(newActiveIndex-firstIndex) 2089 _this.setWrapperTranslate(newTransform); 2090 _this.setWrapperTransition(0); 2091 } 2092 //New Slides 2093 if (params.loader.logic==='reload') { 2094 _this.wrapper.innerHTML = ''; 2095 var slidesHTML = ''; 2096 for (var i = firstIndex; i<=lastIndex; i++) { 2097 slidesHTML += params.loader.slidesHTMLType == 'outer' ? slides[i] : '<'+params.slideElement+' class="'+params.slideClass+'" data-swiperindex="'+i+'">'+slides[i]+'</'+params.slideElement+'>'; 2098 } 2099 _this.wrapper.innerHTML = slidesHTML; 2100 } 2101 else { 2102 var minExistIndex=1000; 2103 var maxExistIndex=0; 2104 for (var i=0; i<_this.slides.length; i++) { 2105 var index = _this.slides[i].data('swiperindex'); 2106 if (index<firstIndex || index>lastIndex) { 2107 _this.wrapper.removeChild(_this.slides[i]); 2108 } 2109 else { 2110 minExistIndex = Math.min(index, minExistIndex) 2111 maxExistIndex = Math.max(index, maxExistIndex) 2112 } 2113 } 2114 for (var i=firstIndex; i<=lastIndex; i++) { 2115 if (i<minExistIndex) { 2116 var newSlide = document.createElement(params.slideElement); 2117 newSlide.className = params.slideClass; 2118 newSlide.setAttribute('data-swiperindex',i); 2119 newSlide.innerHTML = slides[i];
2120 _this.wrapper.insertBefore(newSlide, _this.wrapper.firstChild); 2121 } 2122 if (i>maxExistIndex) { 2123 var newSlide = document.createElement(params.slideElement); 2124 newSlide.className = params.slideClass; 2125 newSlide.setAttribute('data-swiperindex',i); 2126 newSlide.innerHTML = slides[i]; 2127 _this.wrapper.appendChild(newSlide); 2128 } 2129 } 2130 } 2131 //reInit 2132 _this.reInit(true); 2133 } 2134 2135 /*================================================== 2136 Make Swiper 2137 ====================================================*/ 2138 function makeSwiper(){ 2139 _this.calcSlides(); 2140 if (params.loader.slides.length>0 && _this.slides.length==0) { 2141 _this.loadSlides(); 2142 } 2143 if (params.loop) { 2144 _this.createLoop(); 2145 } 2146 _this.init(); 2147 initEvents(); 2148 if (params.pagination && params.createPagination) { 2149 _this.createPagination(true); 2150 } 2151 if (params.loop || params.initialSlide>0) { 2152 _this.swipeTo( params.initialSlide, 0, false ); 2153 } 2154 else { 2155 _this.updateActiveSlide(0); 2156 } 2157 if (params.autoplay) { 2158 _this.startAutoplay(); 2159 } 2160 2161 } 2162 2163 makeSwiper(); 2164} 2165 2166Swiper.prototype = { 2167 plugins : {}, 2168 2169 /*================================================== 2170 Wrapper Operations 2171 ====================================================*/ 2172 wrapperTransitionEnd : function(callback, permanent) { 2173 var a = this, 2174 el = a.wrapper, 2175 events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'], 2176 i; 2177 2178 function fireCallBack() { 2179 callback(a); 2180 if (a.params.queueEndCallbacks) a._queueEndCallbacks = false; 2181 if (!permanent) { 2182 for (i=0; i<events.length; i++) { 2183 a.h.removeEventListener(el, events[i], fireCallBack); 2184 } 2185 } 2186 } 2187 2188 if (callback) { 2189 for (i=0; i<events.length; i++) { 2190 a.h.addEventListener(el, events[i], fireCallBack); 2191 } 2192 } 2193 }, 2194 2195 getWrapperTranslate : function (axis) { 2196 var el = this.wrapper, 2197 matrix, curTransform, curStyle, transformMatrix; 2198 2199 // automatic axis detection 2200 if (typeof axis == 'undefined') { 2201 axis = this.params.mode == 'horizontal' ? 'x' : 'y'; 2202 } 2203 2204 curStyle = window.getComputedStyle(el, null); 2205 if (window.WebKitCSSMatrix) { 2206 transformMatrix = new WebKitCSSMatrix(curStyle.webkitTransform); 2207 } 2208 else { 2209 transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue("transform").replace("translate(", "matrix(1, 0, 0, 1,"); 2210 matrix = transformMatrix.toString().split(','); 2211 } 2212 2213 if (this.support.transforms && this.params.useCSS3Transforms) { 2214 if (axis=='x') { 2215 //Latest Chrome and webkits Fix 2216 if (window.WebKitCSSMatrix) 2217 curTransform = transformMatrix.m41; 2218 //Crazy IE10 Matrix 2219 else if (matrix.length==16) 2220 curTransform = parseFloat( matrix[12] ); 2221 //Normal Browsers 2222 else 2223 curTransform = parseFloat( matrix[4] ); 2224 } 2225 if (axis=='y') { 2226 //Latest Chrome and webkits Fix 2227 if (window.WebKitCSSMatrix) 2228 curTransform = transformMatrix.m42; 2229 //Crazy IE10 Matrix 2230 else if (matrix.length==16) 2231 curTransform = parseFloat( matrix[13] ); 2232 //Normal Browsers 2233 else 2234 curTransform = parseFloat( matrix[5] ); 2235 } 2236 } 2237 else { 2238 if (axis=='x') curTransform = parseFloat(el.style.left,10) || 0; 2239 if (axis=='y') curTransform = parseFloat(el.style.top,10) || 0; 2240 } 2241 return curTransform || 0; 2242 }, 2243 2244 setWrapperTranslate : function (x, y, z) { 2245 var es = this.wrapper.style, 2246 coords = {x: 0, y: 0, z: 0}, 2247 translate; 2248 2249 // passed all coordinates 2250 if (arguments.length == 3) { 2251 coords.x = x;
2252 coords.y = y; 2253 coords.z = z; 2254 } 2255 2256 // passed one coordinate and optional axis 2257 else { 2258 if (typeof y == 'undefined') { 2259 y = this.params.mode == 'horizontal' ? 'x' : 'y'; 2260 } 2261 coords[y] = x; 2262 } 2263 2264 if (this.support.transforms && this.params.useCSS3Transforms) { 2265 translate = this.support.transforms3d ? 'translate3d(' + coords.x + 'px, ' + coords.y + 'px, ' + coords.z + 'px)' : 'translate(' + coords.x + 'px, ' + coords.y + 'px)'; 2266 es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = translate; 2267 } 2268 else { 2269 es.left = coords.x + 'px'; 2270 es.top = coords.y + 'px'; 2271 } 2272 this.callPlugins('onSetWrapperTransform', coords); 2273 }, 2274 2275 setWrapperTransition : function (duration) { 2276 var es = this.wrapper.style; 2277 es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = (duration / 1000) + 's'; 2278 this.callPlugins('onSetWrapperTransition', {duration: duration}); 2279 }, 2280 2281 /*================================================== 2282 Helpers 2283 ====================================================*/ 2284 h : { 2285 getWidth: function (el, outer) { 2286 var width = window.getComputedStyle(el, null).getPropertyValue('width') 2287 var returnWidth = parseFloat(width); 2288 //IE Fixes 2289 if(isNaN(returnWidth) || width.indexOf('%')>0) { 2290 returnWidth = el.offsetWidth - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-left')) - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-right')); 2291 } 2292 if (outer) returnWidth += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-left')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-right')) 2293 2294 return returnWidth; 2295 }, 2296 getHeight: function(el, outer) { 2297 if (outer) return el.offsetHeight; 2298 2299 var height = window.getComputedStyle(el, null).getPropertyValue('height') 2300 var returnHeight = parseFloat(height); 2301 //IE Fixes 2302 if(isNaN(returnHeight) || height.indexOf('%')>0) { 2303 returnHeight = el.offsetHeight - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-top')) - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-bottom')); 2304 } 2305 if (outer) returnHeight += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-top')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-bottom')) 2306 return returnHeight; 2307 }, 2308 getOffset: function(el) { 2309 var box = el.getBoundingClientRect(); 2310 var body = document.body; 2311 var clientTop = el.clientTop || body.clientTop || 0; 2312 var clientLeft = el.clientLeft || body.clientLeft || 0; 2313 var scrollTop = window.pageYOffset || el.scrollTop; 2314 var scrollLeft = window.pageXOffset || el.scrollLeft; 2315 if (document.documentElement && !window.pageYOffset) { 2316 //IE7-8 2317 scrollTop = document.documentElement.scrollTop; 2318 scrollLeft = document.documentElement.scrollLeft; 2319 } 2320 return { 2321 top: box.top + scrollTop - clientTop, 2322 left: box.left + scrollLeft - clientLeft 2323 }; 2324 }, 2325 windowWidth : function() { 2326 if (window.innerWidth) return window.innerWidth 2327 else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth; 2328 }, 2329 windowHeight : function() { 2330 if (window.innerHeight) return window.innerHeight 2331 else if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight; 2332 }, 2333 windowScroll : function() { 2334 var left=0, top=0; 2335 if (typeof pageYOffset != 'undefined') { 2336 return { 2337 left: window.pageXOffset, 2338 top: window.pageYOffset 2339 } 2340 } 2341 else if (document.documentElement) { 2342 return { 2343 left: document.documentElement.scrollLeft, 2344 top: document.documentElement.scrollTop 2345 } 2346 } 2347 }, 2348 2349 addEventListener : function (el, event, listener, useCapture) { 2350 if (typeof useCapture == 'undefined') { 2351 useCapture = false; 2352 } 2353 2354 if (el.addEventListener) { 2355 el.addEventListener(event, listener, useCapture); 2356 } 2357 else if (el.attachEvent) { 2358 el.attachEvent('on' + event, listener); 2359 } 2360 }, 2361 2362 removeEventListener : function (el, event, listener, useCapture) { 2363 if (typeof useCapture == 'undefined') { 2364 useCapture = false; 2365 } 2366 2367 if (el.removeEventListener) { 2368 el.removeEventListener(event, listener, useCapture); 2369 } 2370 else if (el.detachEvent) { 2371 el.detachEvent('on' + event, listener); 2372 } 2373 } 2374 }, 2375 setTransform : function (el, transform) { 2376 var es = el.style 2377 es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = transform 2378 }, 2379 setTranslate : function (el, translate) { 2380 var es = el.style 2381 var pos = { 2382 x : translate.x || 0, 2383 y : translate.y || 0, 2384 z : translate.z || 0 2385 }; 2386 var transformString = this.support.transforms3d ? 'translate3d('+(pos.x)+'px,'+(pos.y)+'px,'+(pos.z)+'px)' : 'translate('+(pos.x)+'px,'+(pos.y)+'px)'; 2387 es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = transformString; 2388 if (!this.support.transforms) { 2389 es.left = pos.x+'px' 2390 es.top = pos.y+'px' 2391 } 2392 }, 2393 setTransition : function (el, duration) { 2394 var es = el.style 2395 es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = duration+'ms'; 2396 }, 2397 /*================================================== 2398 Feature Detection 2399 ====================================================*/ 2400 support: { 2401 2402 touch : (window.Modernizr && Modernizr.touch===true) || (function() { 2403 return !!(("ontouchstart" in window) || window.DocumentTouch && document instanceof DocumentTouch); 2404 })(), 2405 2406 transforms3d : (window.Modernizr && Modernizr.csstransforms3d===true) || (function() { 2407 var div = document.createElement('div').style; 2408 return ("webkitPerspective" in div || "MozPerspective" in div || "OPerspective" in div || "MsPerspective" in div || "perspective" in div); 2409 })(), 2410 2411 transforms : (window.Modernizr && Modernizr.csstransforms===true) || (function(){ 2412 var div = document.createElement('div').style; 2413 return ('transform' in div || 'WebkitTransform' in div || 'MozTransform' in div || 'msTransform' in div || 'MsTransform' in div || 'OTransform' in div); 2414 })(), 2415 2416 transitions : (window.Modernizr && Modernizr.csstransitions===true) || (function(){ 2417 var div = document.createElement('div').style; 2418 return ('transition' in div || 'WebkitTransition' in div || 'MozTransition' in div || 'msTransition' in div || 'MsTransition' in div || 'OTransition' in div); 2419 })() 2420 }, 2421 2422 browser : { 2423 2424 ie8 : (function(){ 2425 var rv = -1; // Return value assumes failure. 2426 if (navigator.appName == 'Microsoft Internet Explorer') { 2427 var ua = navigator.userAgent; 2428 var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); 2429 if (re.exec(ua) != null) 2430 rv = parseFloat(RegExp.$1); 2431 } 2432 return rv != -1 && rv < 9; 2433 })(), 2434 2435 ie10 : window.navigator.msPointerEnabled 2436 } 2437} 2438 2439/*========================= 2440 jQuery & Zepto Plugins 2441 ===========================*/ 2442if (window.jQuery||window.Zepto) { 2443 (function($){ 2444 $.fn.swiper = function(params) { 2445 var s = new Swiper($(this)[0], params) 2446 $(this).data('swiper',s); 2447 return s; 2448 } 2449 })(window.jQuery||window.Zepto) 2450} 2451 2452// component 2453if ( typeof( module ) !== 'undefined' ) 2454{ 2455 module.exports = Swiper; 2456} 2457 2458 2459 2460Array.prototype.getKeyByValue = function( value ) { 2461 for( var prop in this ) { 2462 if( this.hasOwnProperty( prop ) ) { 2463 if( this[ prop ] === value ) 2464 return prop; 2465 } 2466 } 2467} 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481jQuery(document).ready(function($){ 2482 2483 var doneVideoInit = false; 2484 var $captionTrans = 0; 2485 2486 //handle slider loading pos when trasparent header is being used 2487 if($('body #header-outer[data-transparent-header="true"]').length > 0) { 2488 2489 if($('#page-header-bg').length == 0) { 2490 2491 $('.nectar-slider-wrap.first-section .swiper-container .swiper-wrapper .swiper-slide').addClass('not-loaded'); 2492 2493 if($('.container-wrap .main-content > .row > div').find('.nectar-slider-wrap.first-section')) { 2494 $('.container-wrap .main-content > .row > div').first().css('padding-top','0'); 2495 } 2496 2497 2498 $('body #header-outer[data-transparent-header="true"] .ns-loading-cover').show(); 2499 2500 //if not using flexible/fullscreen height - calculate the loading / bg pos early (if using the option calculates later) 2501 if($('.first-section .nectar-slider-wrap[data-flexible-height="true"]').length == 0 && $('.first-section .nectar-slider-wrap[data-fullscreen="true"]').length == 0) { 2502 $('.first-section .nectar-slider-loading').css({ 2503 'top': $('#header-space').height(), 2504 'background-position' : 'center ' + ((($('.first-section .swiper-container').height()/2) + 15) - $('#header-space').height()) +'px' 2505 }); 2506 } else { 2507 var $loading_bg_storage = $('.first-section .nectar-slider-loading').css('background-image'); 2508 2509 $('.first-section .nectar-slider-loading').css({ 2510 'top': $('#header-space').height(), 2511 'background-image': 'none' 2512 }); 2513 } 2514 2515 } 2516 } 2517 2518 //move parallax sliders to correct dom location 2519 var parallaxSlider = $('.parallax_slider_outer.first-section'); 2520 2521 function parallaxSliderPos(){ 2522 if(parallaxSlider.parent().attr('class') == 'wpb_wrapper') { parallaxSlider.parents('.wpb_row').remove(); } 2523 parallaxSlider.insertBefore('.container-wrap'); 2524 } 2525 2526 ////remove parallax if using page header on projects/posts 2527 if($('body.single #page-header-bg').length > 0) $('.parallax_slider_outer').removeClass('parallax_slider_outer').addClass('no-left-margin'); 2528 2529 parallaxSliderPos(); 2530 2531 //remove boxed full width attr when not needed 2532 $('.nectar-slider-wrap[data-full-width="boxed-full-width"]').each(function(){ if($(this).parents('.wpb_column').length > 0 && $(this).parents('.full-width-content').length > 0) $(this).attr('data-full-width','false') }); 2533 2534 2535 //initial cals 2536 var $smoothSrollWidth = ($('body').attr('data-smooth-scrolling') == '1') ? 0 : 0; //will come back to this 2537 2538 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){ 2539 $('.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'; 2540 $('.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()); 2541 } 2542 else if( $('.nectar-slider-wrap[data-full-width="true"]').parent().attr('id') == 'portfolio-extra' && $('#full_width_portfolio').length != 0){ 2543 $('.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'; 2544 $('.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()); 2545 } 2546 else { 2547 var $container = ($('body > #boxed').length == 0) ? '#post-area' : '.container-wrap';
2548 //backup incase only slider is used with nothing else in boxed mode 2549 if($($container).width() == '0' && $('body > #boxed').length > 0) $container = '#boxed'; 2550 $('.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()); 2551 } 2552 2553 //show slider once full width calcs have taken place 2554 $('.nectar-slider-wrap').show(); 2555 2556 //set bg colors / textures after js has made the slider fullwidth 2557 $('.swiper-container, .swiper-slide').css('background-color','#000'); 2558 $('.video-texture').css('opacity','1'); 2559 2560 2561 /*========================= 2562 Begin Nectar Slider Main Construction 2563 ===========================*/ 2564 var $nectarSliders = []; 2565 2566 $('.nectar-slider-wrap').each(function(i){ 2567 var $arrows = $(this).find('.swiper-container').attr('data-arrows'); 2568 var $bullets = $(this).find('.swiper-container').attr('data-bullets'); 2569 var $swipe = $(this).find('.swiper-container').attr('data-desktop-swipe'); 2570 var $loop = $(this).find('.swiper-container').attr('data-loop'); 2571 2572 //swipe 2573 if($swipe == 'true' && $('#'+$(this).attr('id') +' .swiper-wrapper > div').length > 1 ){ 2574 var $grab = 1; 2575 var $desktopSwipe = 1; 2576 } else { 2577 var $grab = 0; 2578 var $desktopSwipe = 0; 2579 } 2580 2581 //bullets 2582 if($bullets == 'true' && $(this).find('.swiper-wrapper > div').length > 1){ 2583 $bullets = '#'+$(this).attr('id')+' .slider-pagination'; 2584 } else { 2585 $bullets = null; 2586 } 2587 2588 //loop 2589 $useLoop = ($loop == 'true' && $(this).find('.swiper-wrapper > div').length > 1 && !$('html').hasClass('no-video')) ? true : false; 2590 if($useLoop == false) $(this).find('.swiper-container').attr('data-loop','false'); 2591 2592 $nectarSliders[i] = new Swiper('#'+$(this).attr('id')+' .swiper-container', { 2593 loop: $useLoop, 2594 grabCursor: $grab, 2595 touchRatio: 0.6, 2596 speed: 525, 2597 useCSS3Transforms: false, 2598 pagination : $bullets, 2599 simulateTouch: $desktopSwipe, 2600 onSlideChangeEnd: captionTransition, 2601 onSlideChangeStart: sliderArrowCount, 2602 onTouchMove: clearAutoplay, 2603 onFirstInit: nectarInit 2604 }); 2605 2606 $nectarSliders[i].swipeReset(); 2607 2608 2609 //webkit looped slider first video fix 2610 if(navigator.userAgent.indexOf('Chrome') > 0) { 2611 if( jQuery(this).find('.swiper-slide:nth-child(2) video').length > 0 && jQuery(this).find('.swiper-container').attr('data-loop') == 'true') { 2612 2613 var webmSource = jQuery(this).find('.swiper-slide:nth-child(2) video source[type="video/webm"]').attr('src') + "?id="+Math.ceil(Math.random()*10000); 2614 var firstVideo = jQuery(this).find('.swiper-slide:nth-child(2) video').get(0); 2615 firstVideo.src = webmSource; 2616 firstVideo.load(); 2617 2618 var webmSource2 = jQuery(this).find('.swiper-slide:nth-child(2) video source[type="video/webm"]').attr('src') + "?id="+Math.ceil(Math.random()*10000); 2619 var lastVideo = jQuery(this).find('.swiper-slide:last-child video').get(0); 2620 lastVideo.src = webmSource2; 2621 lastVideo.load(); 2622 } 2623 } 2624 2625 function nectarInit(){ 2626 if(doneVideoInit == true) return; 2627 2628 //videos 2629 /*$('.swiper-slide .slider-video').mediaelementplayer({ 2630 enableKeyboard: false, 2631 iPadUseNativeControls: false, 2632 pauseOtherPlayers: false, 2633 // force iPhone's native controls 2634 iPhoneUseNativeControls: false, 2635 // force Android's native controls 2636 AndroidUseNativeControls: false 2637 });*/ 2638 2639 //if using pp - init it after slide loads 2640 if($().prettyPhoto) prettyPhotoInit(); 2641 2642 2643 doneVideoInit = true; 2644 } 2645 2646 //Navigation arrows 2647 if($arrows == 'true' && $('#'+$(this).attr('id') +' .swiper-wrapper > div').length > 1 ){ 2648 2649 $('.slide-count i').transition({ scale: 0.5, opacity: 0 }); 2650 2651 //hover event 2652 $('.swiper-container .slider-prev, .swiper-container .slider-next').hover(function(){ 2653 2654 $(this).find('.slide-count i').clearQueue().stop(true,true).delay(110).transition({ scale: 1, opacity: 1 },200);
2655 2656 $(this).stop(true,true).animate({ 2657 'width' : '100px' 2658 },300,'easeOutCubic'); 2659 $(this).find('.slide-count span').clearQueue().stop().delay(100).animate({ 2660 'opacity' : '1' 2661 },225,'easeOutCubic'); 2662 },function(){ 2663 2664 $('.slide-count i').stop(true,true).transition({ scale: 0, opacity: 0 },200); 2665 2666 $(this).stop().delay(150).animate({ 2667 'width' : '50px' 2668 },300,'easeOutCubic'); 2669 $(this).find('.slide-count span').stop(true,true).animate({ 2670 'opacity' : '0' 2671 },200,'easeOutCubic'); 2672 }); 2673 2674 //add slide counts 2675 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; 2676 2677 //ie8 2678 if($('html').hasClass('no-video')) $slideCount = $('#'+$(this).attr('id') + ' .swiper-wrapper > div').length; 2679 2680 $('#'+$(this).attr('id')+' .slider-prev .slide-count .slide-total').html( $slideCount ); 2681 $('#'+$(this).attr('id')+' .slider-next .slide-count .slide-total').html( $slideCount ); 2682 2683 //prev 2684 $('#'+$(this).attr('id')+' .slider-prev').click(function(e) { 2685 2686 if($(this).hasClass('inactive')) return false; 2687 2688 var $that = $(this); 2689 2690 //non looped slider 2691 if($(this).parents('.swiper-container').attr('data-loop') != 'true') { 2692 2693 2694 if( $(this).parents('.swiper-container').find('.swiper-slide-active').index()+1 == 1 && !$('html').hasClass('no-video')){ 2695 2696 //make sure the animation is complete 2697 var $timeout; 2698 2699 clearTimeout($timeout); 2700 $timeout = setTimeout(function(){ $that.removeClass('inactive'); } ,700); 2701 2702 $(this).parents('.swiper-container').find('.swiper-wrapper').stop(true,false).css('transition','none').animate({ 2703 'left' : parseInt($(this).parents('.swiper-container').find('.swiper-wrapper').css('left')) + 20 2704 },200,function(){ 2705 $(this).parents('.swiper-container').find('.swiper-wrapper').stop(true,false).css('transition','left,top'); 2706 $nectarSliders[i].swipeReset(); 2707 }); 2708 2709 $(this).addClass('inactive'); 2710 2711 } 2712 2713 } 2714 2715 e.preventDefault(); 2716 $nectarSliders[i].swipePrev(); 2717 }); 2718 2719 //next 2720 $('#'+$(this).attr('id')+' .slider-next').click(function(e) { 2721 2722 if($(this).hasClass('inactive')) return false; 2723 2724 var $that = $(this); 2725 var $slideNum = $(this).parents('.swiper-container').find('.swiper-wrapper > div').length; 2726 2727 //non looped slider 2728 if($(this).parents('.swiper-container').attr('data-loop') != 'true') { 2729 2730 if( $(this).parents('.swiper-container').find('.swiper-slide-active').index()+1 == $slideNum && !$('html').hasClass('no-video')) { 2731 2732 //make sure the animation is complete 2733 var $timeout; 2734 2735 clearTimeout($timeout); 2736 $timeout = setTimeout(function(){ $that.removeClass('inactive'); } ,700); 2737 2738 $(this).parents('.swiper-container').find('.swiper-wrapper').stop(true,false).css('transition','none').animate({ 2739 'left' : parseInt($(this).parents('.swiper-container').find('.swiper-wrapper').css('left')) - 20 2740 },200,function(){ 2741 $(this).parents('.swiper-container').find('.swiper-wrapper').stop(true,false).css('transition','left,top'); 2742 $nectarSliders[i].swipeReset(); 2743 }); 2744 2745 $(this).addClass('inactive'); 2746 } 2747 } 2748 2749 2750 e.preventDefault(); 2751 $nectarSliders[i].swipeNext(); 2752 2753 }); 2754 } 2755 //Clickable pagination 2756 if($bullets != null && $('#'+$(this).attr('id') +' .swiper-wrapper > div').length > 1 ){ 2757 $('#'+$(this).attr('id')+' .slider-pagination .swiper-pagination-switch').click(function(){ 2758 $nectarSliders[i].swipeTo($(this).index()); 2759 }); 2760 } 2761 }); 2762 2763 2764 2765 2766 //add class to first video slide 2767 $('.swiper-wrapper').each(function(){ 2768 if($(this).find('.swiper-slide:nth-child(2) video').length > 0) $(this).find('.swiper-slide:nth-child(2)').addClass('first_video_slide'); 2769 }); 2770 2771 2772 //initial slide load 2773 $('.nectar-slider-wrap').each(function(i){ 2774 2775 var $sliderWrapCount = $('.nectar-slider-wrap').length; 2776 var $that = $(this); 2777 2778 if($(this).find('.swiper-slide-active video').length > 0){ 2779 2780 if(!$('html').hasClass('no-video')){ 2781 $(this).find('.swiper-slide-active:first video').get(0).load(); 2782 $(this).find('.swiper-slide-active:first video').get(0).addEventListener('loadeddata',function(){ 2783 2784 showSliderControls(); 2785 resizeToCover(); 2786 slideContentPos(); 2787 sliderLoadIn($that); 2788 captionTransition($nectarSliders[i]); 2789 2790 2791 }); 2792 2793 } 2794 //ie8 2795 else { 2796 showSliderControls(); 2797 resizeToCover(); 2798 slideContentPos(); 2799 sliderLoadIn($that); 2800 captionTransition($nectarSliders[i]); 2801 } 2802 } 2803 else { 2804 2805 var $firstBg = $(this).find('.swiper-slide-active').attr('style'); 2806 var pattern = /url\(["']?([^'")]+)['"]?\)/; 2807 var match = pattern.exec($firstBg); 2808 if (match) { 2809 2810 var slideImg = new Image(); 2811 slideImg.src = match[1]; 2812 2813 $(slideImg).load(function(){ 2814 showSliderControls(); 2815 resizeToCover(); 2816 slideContentPos(); 2817 sliderLoadIn($that); 2818 captionTransition($nectarSliders[i]); 2819 }); 2820 } 2821 } 2822 2823 //mobile check 2824 if(navigator.userAgent.match(/(Android|iPod|iPhone|iPad|IEMobile|Opera Mini)/)){ 2825 captionTransition($nectarSliders[i]); 2826 showSliderControls(); 2827 resizeToCover(); 2828 slideContentPos(); 2829 2830 setTimeout(function(){ resizeToCover(); slideContentPos(); },400); 2831 2832 $('.nectar-slider-wrap').find('.nectar-slider-loading').fadeOut(800,'easeInOutExpo'); 2833 $('body #header-outer[data-transparent-header="true"] .ns-loading-cover').fadeOut(800,'easeInOutExpo',function(){ 2834 $('.nectar-slider-wrap.first-section .swiper-container .swiper-wrapper .swiper-slide').removeClass('not-loaded'); 2835 }); 2836 2837 $('.nectar-slider-wrap .mobile-video-image').show(); 2838 $('.nectar-slider-wrap .video-wrap').remove(); 2839 } 2840 2841 }); 2842 2843 2844 2845 2846 2847 var $animating = false; 2848 2849 2850 //responsive slider 2851 var $sliderHeights = []; 2852 var $existingSliders = []; 2853 2854 ////get slider heights 2855 $('.swiper-container').each(function(i){ 2856 $sliderHeights[i] = parseInt($(this).attr('data-height')); 2857 $existingSliders[i] = $(this).parent().attr('id'); 2858 }); 2859 2860 2861 //dynamic height sliders 2862 dynamicHeightSliders(); 2863 function dynamicHeightSliders(){ 2864 2865 var $adminBarHeight = ($('#wpadminbar').length > 0) ? 28 : 0 ; 2866 2867 $('.nectar-slider-wrap').each(function(){ 2868
2869 var $heightCalc; 2870 var $minHeight = $('.swiper-container').attr('data-min-height'); 2871 2872 //fullscreen 2873 if($(this).attr('data-fullscreen') == 'true' && $(this).attr('data-full-width') == 'true') { 2874 2875 //first slider on page 2876 if($(this).hasClass('first-section') && $(this).index() == 0){ 2877 2878 //min height 2879 $heightCal = ( ($(window).height() - $(this).offset().top + 2) <= $minHeight ) ? $minHeight : $(window).height() - $(this).offset().top + 2; 2880 $(this).find('.swiper-container').attr('data-height',$heightCal); 2881 2882 } 2883 //first parallax slider on page 2884 else if($(this).parents('.parallax_slider_outer').length > 0 && $(this).parents('#full_width_portfolio').length == 0){ 2885 2886 //min height 2887 $heightCal = ( ($(window).height() - $(this).parent().offset().top + 2) <= $minHeight ) ? $minHeight : $(window).height() - $(this).parent().offset().top + 2; 2888 $(this).find('.swiper-container').attr('data-height',$heightCal); 2889 2890 } 2891 //first portfolio slider on page 2892 else if($(this).parents('#full_width_portfolio').length > 0 && $(this).attr('data-parallax') != 'true' && $(this).index() == 0){ 2893 2894 //min height 2895 $heightCal = ( ($(window).height() - $(this).offset().top + 2) <= $minHeight ) ? $minHeight : $(window).height() - $(this).offset().top + 2; 2896 $(this).find('.swiper-container').attr('data-height',$heightCal); 2897 2898 } 2899 //first portfolio parallax slider on page 2900 else if($(this).parents('#full_width_portfolio').length > 0 && $(this).attr('data-parallax') == 'true'){ 2901 2902 //min height 2903 $heightCal = ( ($(window).height() - $(this).offset().top + 2) <= $minHeight ) ? $minHeight : $(window).height() - $(this).offset().top + 2; 2904 $(this).find('.swiper-container').attr('data-height',$heightCal); 2905 } 2906 //all others 2907 else { 2908 2909 //min height 2910 $heightCal = ( $(window).height() <= $minHeight ) ? $minHeight : $(window).height(); 2911 $(this).find('.swiper-container').attr('data-height',$heightCal); 2912 } 2913 2914 //transparent header loading icon center 2915 if($('body #header-outer[data-transparent-header="true"]').length > 0 2916 && $('.first-section .nectar-slider-wrap[data-fullscreen="true"]').length > 0 2917 && $('#page-header-bg').length == 0) { 2918 2919 $('.first-section .nectar-slider-loading').css({ 2920 'background-image': $loading_bg_storage, 2921 'background-position' : 'center ' + ((($(window).height() /2) + 15) - $('#header-space').height()) +'px' 2922 }); 2923 } 2924 2925 } 2926 2927 //flexible height 2928 if($(this).attr('data-flexible-height') == 'true' && $(this).attr('data-fullscreen') != 'true') { 2929 2930 //escape if not placed in a flexible ready position 2931 if($(this).parents('.wpb_row.full-width-content').length == 0 && $(this).attr('data-full-width') == 'false') { $(this).attr('data-flexible-height','false'); return false; } 2932 2933 var $minHeight = $('.swiper-container').attr('data-min-height'); 2934 2935 var currentKey = $existingSliders.getKeyByValue($(this).attr('id')); 2936 var $windowWidth = $(window).width(); 2937 var $definedHeight = $sliderHeights[currentKey]; 2938 2939 var dif = $(window).width() / 1600; 2940 2941 if( window.innerWidth > 1000 && $('#boxed').length == 0) { 2942 $(this).find('.swiper-container').attr('data-height',$definedHeight*dif); 2943 } else { 2944 2945 //column sliders 2946 var $parentCol = ($(this).parents('.wpb_column').length > 0) ? $(this).parents('.wpb_column') : $(this).parents('.col') ; 2947 if($parentCol.length == 0) $parentCol = $('.main-content'); 2948 2949 if(!$parentCol.hasClass('vc_span12') && !$parentCol.hasClass('main-content') && !$parentCol.hasClass('span_12') ) { 2950 2951 var $parentColWidth = sliderColumnDesktopWidth($parentCol); 2952 var $parentColRatio = 1100/$parentColWidth; 2953 2954 //min height 2955 if( $definedHeight*dif <= $minHeight ){ 2956 $(this).find('.swiper-container').attr('data-height',$minHeight); 2957 } else { 2958 $(this).find('.swiper-container').attr('data-height',$parentColRatio*$definedHeight*dif); 2959 } 2960 2961 } 2962 2963 2964 //boxed 2965 else if($('#boxed').length > 0){ 2966 2967 var dif = $('#boxed').width() / 1600; 2968 2969 if( window.innerWidth > 1300 ) { 2970 2971 if($('body[data-ext-responsive="true"]').length > 0){ 2972 2973 if($(this).has('[data-full-width="boxed-full-width"]')) { 2974 ($('#boxed').width() < 1400) ? $(this).find('.swiper-container').attr('data-height',$definedHeight*dif) : $(this).find('.swiper-container').attr('data-height',$definedHeight*(1400/1600)); 2975 } 2976 2977 } else { 2978 if($(this).has('[data-full-width="boxed-full-width"]')) $(this).find('.swiper-container').attr('data-height',$definedHeight*(1200/1600)); 2979 } 2980 2981 } else if( window.innerWidth <= 1300 && window.innerWidth >= 1000 ) { 2982 2983 if($('body[data-ext-responsive="true"]').length > 0){ 2984 $(this).find('.swiper-container').attr('data-height',$definedHeight*dif); 2985 } else { 2986 if($(this).has('[data-full-width="boxed-full-width"]')) $(this).find('.swiper-container').attr('data-height',$definedHeight*(980/1600)); 2987 } 2988 2989 } else if( window.innerWidth < 1000 && window.innerWidth > 690 ) { 2990
2991 var $heightCalc = ( $definedHeight*(679/1600) <= $minHeight ) ? $minHeight : $definedHeight*(679/1600); 2992 if($(this).has('[data-full-width="boxed-full-width"]')) $(this).find('.swiper-container').attr('data-height',$minHeight); 2993 2994 } else if( window.innerWidth <= 690 && window.innerWidth >= 470 ) { 2995 2996 var $heightCalc = ( $definedHeight*(410/1600) <= $minHeight ) ? $minHeight : $definedHeight*(410/1600); 2997 if($(this).has('[data-full-width="boxed-full-width"]')) $(this).find('.swiper-container').attr('data-height', $heightCalc); 2998 2999 } else if( window.innerWidth < 470 ) { 3000 3001 var $heightCalc = ( $definedHeight*(318/1600) <= $minHeight ) ? $minHeight : $definedHeight*(318/1600); 3002 if($(this).has('[data-full-width="boxed-full-width"]')) $(this).find('.swiper-container').attr('data-height', $heightCalc); 3003 3004 } 3005 3006 } 3007 3008 3009 //regular 3010 else { 3011 3012 //min height 3013 if( $definedHeight*dif <= $minHeight ){ 3014 $(this).find('.swiper-container').attr('data-height',$minHeight); 3015 } else { 3016 $(this).find('.swiper-container').attr('data-height',$definedHeight*dif); 3017 } 3018 3019 } 3020 3021 } 3022 3023 3024 //transparent header loading icon center 3025 if($('body #header-outer[data-transparent-header="true"]').length > 0 && 3026 $('.first-section .nectar-slider-wrap[data-flexible-height="true"]').length > 0) { 3027 3028 $('.first-section .nectar-slider-loading').css({ 3029 'background-image': $loading_bg_storage, 3030 'background-position' : 'center ' + (((($definedHeight*dif)/2) + 15) - $('#header-space').height()) +'px' 3031 }); 3032 } 3033 3034 } 3035 }); 3036 } 3037 3038 if(window.innerWidth > 690){ 3039 $(window).resize(dynamicHeightSliders); 3040 } else { 3041 3042 //stop mobile browsers from firing the resize event on scroll (when toolbar hides) 3043 var $windowWidth = $(window).width(), $windowHeight = $(window).height(); 3044 3045 $(window).resize(function(){ 3046 if($(window).width() != $windowWidth && $(window).height != $windowHeight){ 3047 dynamicHeightSliders(); 3048 } 3049 }); 3050 } 3051 3052 3053 3054 ////helper function 3055 function sliderColumnDesktopWidth(parentCol) { 3056 3057 var $parentColWidth = 1100; 3058 var $columnNumberParsed = $(parentCol).attr('class').match(/\d+/); 3059 3060 if($columnNumberParsed == '2') { $parentColWidth = 170 } 3061 else if($columnNumberParsed == '3') { $parentColWidth = 260 } 3062 else if($columnNumberParsed == '4') { $parentColWidth = 340 } 3063 else if($columnNumberParsed == '6') { $parentColWidth = 530 } 3064 else if($columnNumberParsed == '8') { $parentColWidth = 700 } 3065 else if($columnNumberParsed == '9') { $parentColWidth = 805 } 3066 else if($columnNumberParsed == '10') { $parentColWidth = 916.3 } 3067 else if($columnNumberParsed == '12') { $parentColWidth = 1100 } 3068 3069 return $parentColWidth; 3070 } 3071 3072 3073 sliderSize(); 3074 $(window).resize(sliderSize); 3075 3076 function sliderSize(){ 3077 3078 3079 //check for mobile first 3080 if( window.innerWidth < 1000 && window.innerWidth > 690 ) { 3081 3082 //fullwidth sliders 3083 $('.nectar-slider-wrap[data-full-width="true"]:not([data-fullscreen="true"],[data-flexible-height="true"])').each(function(i){ 3084 currentKey = $existingSliders.getKeyByValue($(this).attr('id')); 3085 $(this).find('.swiper-container').attr('data-height',$sliderHeights[currentKey]/1.4 ) 3086 }); 3087 3088 //column sliders 3089 $('.nectar-slider-wrap[data-full-width="false"]:not([data-flexible-height="true"])').each(function(i){ 3090 currentKey = $existingSliders.getKeyByValue($(this).attr('id')); 3091 3092 var $currentSliderHeight = $sliderHeights[currentKey]; 3093 var $parentCol = ($(this).parents('.wpb_column').length > 0) ? $(this).parents('.wpb_column') : $(this).parents('.col'); 3094 3095 //fullwidth but inside the span_9 post area 3096 if($(this).parents('#post-area').length > 0 && $(this).parents('.vc_span12').length > 0) $parentCol = $(this).parents('#post-area'); 3097 3098 //last resort 3099 if($parentCol.length == 0) $parentCol = $('.main-content'); 3100 3101 var $parentColWidth = sliderColumnDesktopWidth($parentCol); 3102 3103 var $aspectRatio = $currentSliderHeight/$parentColWidth; 3104 3105 $(this).find('.swiper-container').attr('data-height',$aspectRatio*$parentCol.width()); 3106 }); 3107 3108 //boxed sliders 3109 $('.nectar-slider-wrap[data-full-width="boxed-full-width"]:not([data-flexible-height="true"])').each(function(i){ 3110 currentKey = $existingSliders.getKeyByValue($(this).attr('id')); 3111 $(this).find('.swiper-container').attr('data-height',$sliderHeights[currentKey]/1.9 ) 3112 }); 3113 } 3114 3115 else if( window.innerWidth <= 690 ) { 3116 3117 //fullwidth sliders 3118 $('.nectar-slider-wrap[data-full-width="true"]:not([data-fullscreen="true"],[data-flexible-height="true"])').each(function(i){ 3119 currentKey = $existingSliders.getKeyByValue($(this).attr('id')); 3120 $(this).find('.swiper-container').attr('data-height',$sliderHeights[currentKey]/2.7 ) 3121 });
3122 3123 //column sliders 3124 $('.nectar-slider-wrap[data-full-width="false"]:not([data-flexible-height="true"])').each(function(i){ 3125 currentKey = $existingSliders.getKeyByValue($(this).attr('id')); 3126 3127 var $currentSliderHeight = $sliderHeights[currentKey]; 3128 var $parentCol = ($(this).parents('.wpb_column').length > 0) ? $(this).parents('.wpb_column') : $(this).parents('.col'); 3129 3130 //fullwidth but inside the span_9 post area 3131 if($(this).parents('#post-area').length > 0 && $(this).parents('.vc_span12').length > 0) $parentCol = $(this).parents('#post-area'); 3132 3133 //last resort 3134 if($parentCol.length == 0) $parentCol = $('.main-content'); 3135 3136 var $parentColWidth = sliderColumnDesktopWidth($parentCol); 3137 3138 var $aspectRatio = $currentSliderHeight/$parentColWidth; 3139 3140 $(this).find('.swiper-container').attr('data-height',$aspectRatio*$parentCol.width()); 3141 }); 3142 3143 //boxed sliders 3144 $('.nectar-slider-wrap[data-full-width="boxed-full-width"]:not([data-flexible-height="true"])').each(function(i){ 3145 currentKey = $existingSliders.getKeyByValue($(this).attr('id')); 3146 $(this).find('.swiper-container').attr('data-height',$sliderHeights[currentKey]/2.9 ) 3147 }); 3148 3149 } 3150 3151 else if( window.innerWidth < 1300 && window.innerWidth >= 1000 ) { 3152 3153 //fullwidth sliders 3154 $('.nectar-slider-wrap[data-full-width="true"]:not([data-fullscreen="true"],[data-flexible-height="true"])').each(function(i){ 3155 currentKey = $existingSliders.getKeyByValue($(this).attr('id')); 3156 $(this).find('.swiper-container').attr('data-height',$sliderHeights[currentKey]/1.2 ) 3157 }); 3158 3159 //column sliders 3160 $('.nectar-slider-wrap[data-full-width="false"]:not([data-flexible-height="true"])').each(function(i){ 3161 currentKey = $existingSliders.getKeyByValue($(this).attr('id')); 3162 3163 var $currentSliderHeight = $sliderHeights[currentKey]; 3164 var $parentCol = ($(this).parents('.wpb_column').length > 0) ? $(this).parents('.wpb_column') : $(this).parents('.col') ; 3165 3166 //fullwidth but inside the span_9 post area 3167 if($(this).parents('#post-area').length > 0 && $(this).parents('.vc_span12').length > 0) $parentCol = $(this).parents('#post-area'); 3168 3169 //last resort 3170 if($parentCol.length == 0) $parentCol = $('.main-content'); 3171 3172 var $parentColWidth = sliderColumnDesktopWidth($parentCol); 3173 3174 var $aspectRatio = $currentSliderHeight/$parentColWidth; 3175 3176 $(this).find('.swiper-container').attr('data-height',$aspectRatio*$parentCol.width()); 3177 3178 }); 3179 3180 //boxed sliders 3181 $('.nectar-slider-wrap[data-full-width="boxed-full-width"]:not([data-flexible-height="true"])').each(function(i){ 3182 currentKey = $existingSliders.getKeyByValue($(this).attr('id')); 3183 $(this).find('.swiper-container').attr('data-height',$sliderHeights[currentKey]/1.2 ) 3184 }); 3185 3186 } 3187 3188 else { 3189 3190 //fullwidth sliders 3191 $('.nectar-slider-wrap[data-full-width="true"]:not([data-fullscreen="true"],[data-flexible-height="true"])').each(function(i){ 3192 currentKey = $existingSliders.getKeyByValue($(this).attr('id')); 3193 if($(this).attr('data-flexible-height') != 'true') $(this).find('.swiper-container').attr('data-height',$sliderHeights[currentKey]) 3194 }); 3195 3196 //boxed sliders 3197 $('.nectar-slider-wrap[data-full-width="false"], .nectar-slider-wrap[data-full-width="boxed-full-width"]:not([data-flexible-height="true"])').each(function(i){ 3198 currentKey = $existingSliders.getKeyByValue($(this).attr('id')); 3199 if($(this).attr('data-flexible-height') != 'true') $(this).find('.swiper-container').attr('data-height',$sliderHeights[currentKey] ) 3200 }); 3201 } 3202 3203 } 3204 3205 3206 3207 3208 3209 3210 //slider height 3211 3212 var min_w = 1500; // minimum video width allowed 3213 var vid_w_orig; // original video dimensions 3214 var vid_h_orig; 3215 3216 vid_w_orig = 1280; 3217 vid_h_orig = 720; 3218 var $headerHeight = $('header').height()-1; 3219 3220 $(window).resize(function (e) { if(e.originalEvent) { resizeToCover(); slideContentPos(); } }); 3221 $(window).trigger('resize'); 3222 3223 function resizeToCover() { 3224 $('.nectar-slider-wrap').each(function(i){ 3225 3226 //width resize 3227 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){ 3228 $('.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'; 3229 $('.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()); 3230 } 3231 else if( $('.nectar-slider-wrap[data-full-width="true"]').parent().attr('id') == 'portfolio-extra' && $('#full_width_portfolio').length != 0){ 3232 $('.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'; 3233 $('.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()); 3234 } 3235 else { 3236 var $container = ($('body > #boxed').length == 0) ? '#post-area' : '.container-wrap';
3237 //backup incase only slider is used with nothing else in boxed mode 3238 if($($container).width() == '0' && $('body > #boxed').length > 0) $container = '#boxed'; 3239 $('.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()); 3240 } 3241 3242 var $sliderHeight = parseInt($(this).find('.swiper-container').attr('data-height')); 3243 var isFullWidthCompatible = ($(this).attr('data-full-width') == 'true') ? 'true' : 'false'; 3244 3245 if($(this).parent().attr('id') == 'portfolio-extra' && $('#full_width_portfolio').length == 0 || $(this).parents('#post-area').length > 0) { isFullWidthCompatible = 'false'; }; 3246 3247 var $sliderWidth = (isFullWidthCompatible == 'true') ? $(window).width()-$smoothSrollWidth : $(this).width(); 3248 3249 $(this).parents('.parallax_slider_outer').css('height',$sliderHeight); 3250 $(this).css('height',$sliderHeight); 3251 $(this).find('.swiper-container, .swiper-slide').css({'height':$sliderHeight+2, 'top':'-1px'}); 3252 $(this).find('.swiper-container').css('width', $sliderWidth); 3253 //$(this).find('.swiper-slide').css('width', $sliderWidth); 3254 3255 // set the video viewport to the window size 3256 $(this).find('.video-wrap').width($sliderWidth+2); 3257 $(this).find('.video-wrap').height($sliderHeight+2); 3258 3259 // use largest scale factor of horizontal/vertical 3260 var scale_h = $sliderWidth / vid_w_orig; 3261 var scale_v = ($sliderHeight - $headerHeight) / vid_h_orig; 3262 var scale = scale_h > scale_v ? scale_h : scale_v; 3263 3264 //update minium width to never allow excess space 3265 min_w = 1280/720 * ($sliderHeight+20); 3266 3267 // don't allow scaled width < minimum video width 3268 if (scale * vid_w_orig < min_w) {scale = min_w / vid_w_orig;} 3269 3270 // now scale the video 3271 $(this).find('video, .mejs-overlay, .mejs-poster').width(Math.ceil(scale * vid_w_orig +2)); 3272 $(this).find('video, .mejs-overlay, .mejs-poster').height(Math.ceil(scale * vid_h_orig +2)); 3273 3274 // and center it by scrolling the video viewport 3275 $(this).find('.video-wrap').scrollLeft(($(this).find('video').width() - $sliderWidth) / 2); 3276 3277 $(this).find('.swiper-slide').each(function(){ 3278 3279 //video alignment 3280 if($(this).find('.video-wrap').length > 0){ 3281 //align middle 3282 if($(this).attr('data-bg-alignment') == 'center'){ 3283 $(this).find('.video-wrap, .mejs-overlay, .mejs-poster').scrollTop(($(this).find('video').height() - ($sliderHeight)) / 2); 3284 } 3285 //align bottom 3286 else if($(this).attr('data-bg-alignment') == 'bottom'){ 3287 $(this).find('.video-wrap').scrollTop(($(this).find('video').height() - ($sliderHeight+2))); 3288 } 3289 //align top 3290 else { 3291 $(this).find('.video-wrap').scrollTop(0); 3292 } 3293 } 3294 3295 }); 3296 3297 }); 3298 }; 3299 3300 ////initial call 3301 resizeToCover(); 3302 3303 3304 //caption transitions 3305 function captionTransition(obj){ 3306 3307 resizeToCover(); 3308 3309 var $containerClass; 3310 3311 (typeof obj == 'undefined') ? $containerClass = 'div[id^=ns-id-]' : $containerClass = '#'+$(obj.container).parents('.nectar-slider-wrap').attr('id'); ; 3312 3313 var fromLeft = Math.abs(parseInt($($containerClass+' .swiper-wrapper').css('left'))); 3314 var currentSlide = Math.round(fromLeft/$($containerClass+' .swiper-slide').width()); 3315 var $slideNum = $($containerClass+':first .swiper-wrapper > div').length; 3316 3317 if(isNaN(currentSlide)) currentSlide = 0; 3318 3319 //make sure user isn't going back to same slide 3320 if( $($containerClass+' .swiper-slide:nth-child('+ (currentSlide + 1) +')').find('.content *').length > 0 ) { 3321 if($($containerClass+' .swiper-slide:nth-child('+ (currentSlide + 1) +')').find('.content *').css('opacity') != '0' && !$('html').hasClass('no-video')) { 3322 //play video if there's one 3323 playVideoBG(currentSlide + 1, $containerClass); 3324 3325 if(!$($containerClass+' .swiper-slide:nth-child('+ (currentSlide + 1) +')').hasClass('autorotate-shown')) { 3326 return false; 3327 } else { 3328 $($containerClass+' .swiper-slide').removeClass('autorotate-shown'); 3329 } 3330 3331 } 3332 } 3333 3334 //hide all 3335 if(!$('html').hasClass('no-video')) { 3336 $($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); 3337 } 3338 3339 //pause video if there's one 3340 $($containerClass+' .swiper-slide').each(function(){ 3341 if($(this).find('.video-wrap video').length > 0 && !$('html').hasClass('no-video')) { $(this).find('.video-wrap video').get(0).pause(); } 3342 }); 3343 $($containerClass+' .swiper-slide:not(".swiper-slide-active")').each(function(){ 3344 if($(this).find('.video-wrap video').length > 0) { 3345 3346 if($(this).find('.video-wrap video').get(0).currentTime != 0 ) $(this).find('.video-wrap video').get(0).currentTime = 0; 3347 } 3348 }); 3349 3350 3351 3352 if($($containerClass +' .swiper-container').attr('data-loop') == 'true') { 3353 3354 3355 //webkit video fix 3356 if( $($containerClass+' .swiper-slide-active').index()+1 == 2 && $($containerClass+' .swiper-slide-active video').length > 0 && !$('html').hasClass('no-video')) { 3357 3358 $($containerClass+' .swiper-slide:last-child').find('.video-wrap video').get(0).play(); 3359 $($containerClass+' .swiper-slide:last-child').find('.video-wrap video').get(0).pause(); 3360 } 3361 if( $($containerClass+' .swiper-slide-active').index()+1 == $slideNum-1 && $($containerClass+' .swiper-slide-active video').length > 0 && !$('html').hasClass('no-video')) { 3362 3363 $($containerClass+' .swiper-slide:first-child').find('.video-wrap video').get(0).play(); 3364 $($containerClass+' .swiper-slide:first-child').find('.video-wrap video').get(0).pause(); 3365 } 3366 if($($containerClass+' .swiper-slide-active').index()+1 != 2 && $($containerClass+' .swiper-slide:nth-child(2) video').length > 0 && !$('html').hasClass('no-video')) { 3367 3368 $($containerClass+' .swiper-slide:last-child').find('.video-wrap video').get(0).play(); 3369 $($containerClass+' .swiper-slide:last-child').find('.video-wrap video').get(0).pause(); 3370 3371 $($containerClass+' .swiper-slide:nth-child(2) video').get(0).pause(); 3372 if($($containerClass+' .swiper-slide:nth-child(2) video').get(0).currentTime != 0 ) $($containerClass+' .swiper-slide:nth-child(2) video').get(0).currentTime = 0; 3373 } 3374 3375 3376 //also show duplicate slide if applicable 3377 ////first 3378 if( $($containerClass+' .swiper-slide-active').index()+1 == $slideNum-1 ){ 3379 3380 $($containerClass+' .swiper-slide:nth-child(1)').find('.content').children().each(function(i){ 3381 3382 $(this).stop().delay(i*90).animate({ 3383 'opacity' : 1, 3384 'padding-top' : 0 3385 },{ duration: 400, easing: 'easeOutQuad'}); 3386 });
3387 3388 } 3389 3390 ////last 3391 if( $($containerClass+' .swiper-slide-active').index()+1 == 2 ){ 3392 $($containerClass+' .swiper-slide:nth-child('+ ($slideNum) + ')').find('.content').children().each(function(i){ 3393 $(this).stop().delay(i*90).animate({ 3394 'opacity' : 1, 3395 'padding-top' : 0 3396 },{ duration: 400, easing: 'easeOutQuad'}); 3397 }); 3398 3399 } 3400 3401 }//if using loop 3402 3403 //play video if there's one 3404 playVideoBG(currentSlide + 1, $containerClass); 3405 3406 //fadeIn active slide 3407 $($containerClass+' .swiper-slide:nth-child('+ (currentSlide + 1) +')').find('.content').children().each(function(i){ 3408 3409 $(this).stop().delay(i*90).animate({ 3410 'opacity' : 1, 3411 'padding-top' : 0 3412 },{ duration: 400, easing: 'easeOutQuad'}); 3413 }); 3414 3415 3416 3417 3418 //light and dark controls 3419 if($($containerClass+' .swiper-slide:nth-child('+ (currentSlide + 1) +')').attr('data-color-scheme') == 'dark') { 3420 $($containerClass).find('.slider-pagination').addClass('dark-cs'); 3421 $($containerClass).find('.slider-prev, .slider-next').addClass('dark-cs'); 3422 } else { 3423 $($containerClass).find('.slider-pagination').removeClass('dark-cs'); 3424 $($containerClass).find('.slider-prev, .slider-next').removeClass('dark-cs'); 3425 } 3426 3427 $captionTrans++; 3428 if($captionTrans == $('.swiper-wrapper').length) { $('div.first_video_slide').addClass('nulled') } 3429 3430 3431 } 3432 3433 //used in caption transition 3434 function playVideoBG(nthChild, containerClass){ 3435 3436 if($(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.video-wrap video').length > 0){ 3437 3438 if(!$('html').hasClass('no-video')) $(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.video-wrap video').get(0).play(); 3439 3440 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'); } 3441 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'); 3442 3443 var $that = $(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.mejs-overlay.mejs-overlay-play'); 3444 var $that2 = $(containerClass+' .swiper-slide:nth-child('+ (nthChild) +')').find('.mejs-poster'); 3445 3446 if($that.hasClass('playing') && $that.hasClass('mobile-played')) { 3447 setTimeout(function(){ $that.addClass('behind-buttons'); $that2.addClass('behind-buttons');},200); 3448 } else { 3449 $that.removeClass('behind-buttons'); $that2.removeClass('behind-buttons'); 3450 } 3451 } 3452 3453 } 3454 3455 3456 var $startingSlide = null; 3457 3458 3459 3460 function slideContentPos(){ 3461 3462 $('.swiper-wrapper').each(function(){ 3463 3464 //etxra space if first slider in section 3465 var $extraHeight = ($(this).parents('.nectar-slider-wrap').hasClass('first-section') || $(this).parents('.parallax_slider_outer').hasClass('first-section')) ? 30 : 0; 3466 3467 var $sliderHeight = parseInt($(this).parents('.swiper-container').attr('data-height')); 3468 3469 var $transparentHeader = ($('#header-outer[data-transparent-header="true"]').length > 0) ? $('#header-space').height() : null ; 3470 if($(this).parents('.first-section').length == 0 || window.innerWidth < 1000) $transparentHeader = null; 3471 3472 $(this).find('.swiper-slide').each(function(){ 3473 3474 var $contentHeight = $(this).find('.content').height(); 3475 var $contentItems = $(this).find('.content > *').length; 3476 3477 if($(this).find('.content > *').css('padding-top') == '25px') $contentHeight = $contentHeight - 25*$contentItems; 3478 3479 if($(this).attr('data-y-pos') == 'top'){ 3480 var $topHeight = ($contentHeight/2) < ((($sliderHeight+ $transparentHeader)/4) - 30) ? ((($sliderHeight+ $transparentHeader)/4) - ($contentHeight/2)) + 20 : ($sliderHeight+ $transparentHeader)/8; 3481 $(this).find('.content').css('top', $topHeight + 'px'); 3482 } 3483 else if($(this).attr('data-y-pos') == 'middle') { 3484 $(this).find('.content').css('top', ((($sliderHeight + $transparentHeader)/2) - ($contentHeight/2)) + 'px'); 3485 } 3486 else { 3487 if($contentHeight > 180) { 3488 $(this).find('.content').css('top', ((($sliderHeight + $transparentHeader)/2) - ($contentHeight/10)) +'px'); 3489 } else { 3490 $(this).find('.content').css('top', ((($sliderHeight + $transparentHeader)/2) + ($contentHeight/9)) + 'px'); 3491 } 3492 } 3493 }); 3494 }); 3495 } 3496 3497 3498 3499 function showSliderControls() { 3500 $('.swiper-container .slider-prev, .swiper-container .slider-next, .slider-pagination').animate({'opacity':1},550,'easeOutSine'); 3501 } 3502 3503 3504 var sliderLength = $('.swiper-container').length; 3505 var sliderLoadedLength = 0; 3506 3507 function sliderLoadIn(slider) { 3508 3509 slider.find('.nectar-slider-loading').fadeOut(800,'easeInOutExpo'); 3510 $('body #header-outer[data-transparent-header="true"] .ns-loading-cover').fadeOut(800,'easeInOutExpo',function(){ 3511 $(this).remove(); 3512 $('.nectar-slider-wrap.first-section .swiper-container .swiper-wrapper .swiper-slide').removeClass('not-loaded'); 3513 }); 3514 3515 slider.find('span.ie-fix').remove(); 3516 3517 ///make sure to init smooth scrolling after slider height exists 3518 var $smoothActive = $('body').attr('data-smooth-scrolling'); 3519 if( $smoothActive == 1 && $(window).width() > 690 && $('body').outerHeight(true) > $(window).height() && $('#ascrail2000').length == 0 && !navigator.userAgent.match(/(Android|iPod|iPhone|iPad|IEMobile|Opera Mini)/)){ niceScrollInit(); resizeToCover(); } 3520 3521 //check for sliders in tabbed 3522 sliderLoadedLength++; 3523 if($('.tabbed').find('.swiper-container').length > 0 && sliderLoadedLength == sliderLength) { 3524 setTimeout(function(){ $('.tabbed > ul li:first-child a').click(); }, 200); 3525 } 3526 3527 } 3528 3529 3530 //play video user is hovering over 3531 $('.swiper-slide').mouseover(function(){ 3532 if($(this).find('video').length > 0 && $(this).find('video').get(0).paused == true && $animating == false){ 3533 $(this).find('video').get(0).play(); 3534 } 3535 }); 3536 3537 3538 //mobile play event 3539 $('body').on('click', '.mejs-overlay.mejs-overlay-play',function(){ 3540 $(this).toggleClass('playing'); 3541 $(this).addClass('mobile-played'); 3542 3543 $(this).parent().find('.mejs-poster').toggleClass('playing'); 3544 $(this).parent().find('.mejs-poster').addClass('mobile-played'); 3545 3546 var $that = $(this); 3547 var $that2 = $(this).parent().find('.mejs-poster'); 3548 3549 if($(this).hasClass('playing') && $(this).hasClass('mobile-played')) { 3550 3551 setTimeout(function(){ $that.addClass('behind-buttons'); $that2.addClass('behind-buttons'); },200);
3552 } else { 3553 setTimeout(function(){ $that.removeClass('behind-buttons'); $that2.removeClass('behind-buttons'); },1); 3554 } 3555 }); 3556 3557 3558 //autoplay 3559 var autoplay = []; 3560 var sliderAutoplayCount = -1; 3561 var $sliderHeight = parseInt($(this).find('.swiper-container').attr('data-height')); 3562 var portfolioHeaderHeight = ($('.project-title.parallax-effect').length > 0) ? 100 : 0; 3563 3564 $('.nectar-slider-wrap').each(function(i){ 3565 var $autoplayVal = $(this).attr('data-autorotate'); 3566 var $that = $(this); 3567 var $sliderNum = i; 3568 3569 if(typeof $autoplayVal !='undefined' && $autoplayVal.length != '0' && parseInt($autoplayVal)) { 3570 nectarSlideRotateInit($that,$autoplayVal,$sliderNum); 3571 } 3572 }); 3573 3574 function nectarSlideRotateInit(slider,interval,sliderNum){ 3575 3576 autoplay[sliderAutoplayCount] = setInterval(function(){ nectarSlideRotate(slider, sliderNum); } ,interval); 3577 3578 $('#'+slider.attr('id')).attr('autoplay-id',sliderAutoplayCount); 3579 3580 $('#'+slider.attr('id') + ' a.slider-prev, #'+slider.attr('id') + ' a.slider-next, #' + slider.attr('id') + ' .slider-pagination span').click(function(e){ 3581 if(typeof e.clientY != 'undefined'){ 3582 clearInterval(autoplay[$('#'+slider.attr('id')).attr('autoplay-id')]); 3583 } 3584 }); 3585 3586 sliderAutoplayCount++; 3587 } 3588 3589 function nectarSlideRotate(slider, sliderNum){ 3590 3591 if($nectarSliders[sliderNum].activeIndex + 1 < $(slider).find('.swiper-wrapper > div.swiper-slide').length){ 3592 $nectarSliders[sliderNum].swipeNext(); 3593 } else { 3594 $nectarSliders[sliderNum].swipeTo(0,800); 3595 } 3596 } 3597 3598 function clearAutoplay(e){ 3599 var $autoplayVal = $('#'+$(e.container).parent().attr('id')).attr('data-autorotate'); 3600 3601 if(typeof $autoplayVal !='undefined' && $autoplayVal.length != '0' && parseInt($autoplayVal)) { 3602 clearInterval(autoplay[$('#'+$(e.container).parent().attr('id')).attr('autoplay-id')]); 3603 } 3604 } 3605 3606 var animationQueue = null; 3607 3608 function sliderArrowCount(e){ 3609 3610 //cache slider obj 3611 var $obj = e; 3612 3613 $animating = true; 3614 3615 var $slideNum = $($obj.container).find('.swiper-wrapper > div').length; 3616 3617 $activeIndex = ($($obj.container).attr('data-loop') == 'true') ? $obj.activeIndex : $obj.activeIndex + 1; 3618 3619 3620 //add slide counts 3621 $($obj.container).find('.slider-prev .slide-count .slide-current').html( $activeIndex ); 3622 $($obj.container).find('.slider-next .slide-count .slide-current').html( $activeIndex ); 3623 3624 if($($obj.container).attr('data-loop') == 'true'){ 3625 //duplicate first slide 3626 if( $($obj.container).find('.swiper-slide-active').index()+1 == 1) { 3627 $($obj.container).find('.slider-next .slide-count .slide-current, .slider-prev .slide-count .slide-current').html( $slideNum - 2 ); 3628 } 3629 //duplicate last slide 3630 else if( $($obj.container).find('.swiper-slide-active').index()+1 == $slideNum) { 3631 $($obj.container).find('.slider-next .slide-count .slide-current, .slider-prev .slide-count .slide-current').html( 1 ); 3632 } 3633 } 3634 3635 if($obj.activeIndex >= 10) { $($obj.container).find('.slider-next .slide-count .slide-current').addClass('double-digits'); } else { 3636 $($obj.container).find('.slider-next .slide-count .slide-current').removeClass('double-digits'); 3637 } 3638 3639 3640 $($obj.container).find('.swiper-slide:not(".swiper-slide-active")').each(function(){ 3641 if($(this).find('.video-wrap video').length > 0) { 3642 3643 if($(this).find('.video-wrap video').get(0).currentTime != 0 ) $(this).find('.video-wrap video').get(0).currentTime = 0; 3644 } 3645 }); 3646 3647 3648 //don't allow swiping on duplicate transition 3649 if($($obj.container).attr('data-loop') == 'true'){ 3650 if($obj.previousIndex == 1 && $obj.activeIndex == 0 || $obj.previousIndex == $slideNum - 2 && $obj.activeIndex == $slideNum - 1 ){ 3651 $('.swiper-slide').addClass('duplicate-transition'); 3652 } 3653 } 3654 3655 3656 clearTimeout(animationQueue); 3657 animationQueue = setTimeout(function(){ $animating = false; $('.swiper-slide').removeClass('duplicate-transition'); },800) 3658 3659 } 3660 3661 3662 //functions to add or remove slider for webkit parallax fix 3663 function hideSlider() { 3664 if( $(window).scrollTop()/($sliderHeight + portfolioHeaderHeight + 125) >= 1){ 3665 $('.parallax_slider_outer .nectar-slider-wrap, .project-title.parallax-effect').css('visibility','hidden').hide(); 3666 3667 $(window).bind('scroll',showSlider); 3668 $(window).unbind('scroll',hideSlider); 3669 } 3670 } 3671 3672 function showSlider() { 3673 if( $(window).scrollTop()/($sliderHeight + portfolioHeaderHeight + 125) <= 1){ 3674 3675 $('.parallax_slider_outer .nectar-slider-wrap, .project-title.parallax-effect').css('visibility','visible').show(); 3676
3677 //resize iframes incase user resized window when out of view 3678 $('.swiper-slide iframe[data-aspectRatio]').each(function() { 3679 var newWidth = $(this).parent().width(); 3680 var $el = $(this); 3681 if($(this).is(':visible')) $el.width(newWidth).height(newWidth * $el.attr('data-aspectRatio')); 3682 3683 }); 3684 3685 3686 slideContentPos(); 3687 resizeToCover(); 3688 3689 //show content on current slide - could have been hidden from autorotate when slider was hidden 3690 if($('.parallax_slider_outer').length > 0) { 3691 var fromLeft = Math.abs(parseInt($('.parallax_slider_outer .nectar-slider-wrap .swiper-wrapper').css('left'))); 3692 var currentSlide = Math.round(fromLeft/$('.parallax_slider_outer .nectar-slider-wrap .swiper-slide').width()); 3693 3694 $('.parallax_slider_outer .swiper-wrapper .swiper-slide:eq(' + currentSlide + ')').find('.content').children().each(function(i){ 3695 $(this).stop(true,true).css({ 'opacity' : 1, 'padding-top' : 0 }); 3696 }); 3697 3698 $('.parallax_slider_outer .swiper-wrapper .swiper-slide:eq(' + currentSlide + ')').addClass('autorotate-shown'); 3699 } 3700 3701 $(window).bind('scroll',hideSlider); 3702 $(window).unbind('scroll',showSlider); 3703 3704 } 3705 } 3706 3707 function sliderCorrectDisplayCheck() { 3708 if( $(window).scrollTop()/($sliderHeight + portfolioHeaderHeight + 125) >= 1){ 3709 hideSlider(); 3710 } 3711 $(window).unbind('scroll',sliderCorrectDisplayCheck); 3712 } 3713 3714 3715 3716 3717 3718 var $sliderHeight = parseInt($('.parallax_slider_outer.first-section .swiper-container').attr('data-height')); 3719 var $adminBarHeight = ($('#wpadminbar').length > 0) ? 28 : 0; 3720 3721 function sliderParallaxInit() { 3722 3723 3724 if($('#portfolio-extra').length > 0 && $('#full_width_portfolio').length == 0) { return false; } 3725 3726 $(window).scroll(function(){ 3727 3728 if($('#boxed').length == 0) { 3729 3730 if(navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) { return false; } 3731 3732 $('.parallax_slider_outer.first-section .nectar-slider-wrap[data-parallax="true"]').stop(true,true).transition({ y: $(window).scrollTop()*-.2 },0); 3733 $('.parallax_slider_outer.first-section .swiper-slide:not(".static"):not(".caption-no-fade") .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, .swiper-wrapper .slider-down-arrow').stop(true,true).transition({ y: $(window).scrollTop()*-.14 },0); 3734 3735 $('#full_width_portfolio .project-title.parallax-effect').transition({ y: $(window).scrollTop()*-.2 },0); 3736 3737 $('.parallax_slider_outer.first-section .swiper-slide:not(".caption-no-fade") .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, .swiper-wrapper .slider-down-arrow').css('opacity', 1-($(window).scrollTop()/($sliderHeight-120)) ); 3738 } 3739 }); 3740 3741 3742 //hide slider to not mess up parallax section 3743 var portfolioHeaderHeight = ($('.project-title.parallax-effect').length > 0) ? 100 : 0; 3744 3745 function displayParallaxSliderInit() { 3746 if( $(window).scrollTop()/($sliderHeight + portfolioHeaderHeight + 90) >= 1){ 3747 $(window).bind('scroll', hideSlider); 3748 $(window).unbind('scroll',showSlider); 3749 } else { 3750 $(window).bind('scroll', showSlider); 3751 $(window).unbind('scroll', hideSlider); 3752 } 3753 } 3754 3755 displayParallaxSliderInit(); 3756 3757 $(window).bind('scroll',sliderCorrectDisplayCheck); 3758 3759 3760 $('body:not(".single") .page-header-no-bg, body:not(".single") #page-header-wrap, body:not(".single") #page-header-bg').remove(); 3761 3762 $('.project-title').addClass('parallax-effect').css({ 3763 'top': $('#header-space').outerHeight() + $adminBarHeight + 'px' 3764 }); 3765 3766 //caption alignment if portfolio fullwidth parallax 3767 if($('.project-title.parallax-effect').length > 0) { 3768 $('.parallax_slider_outer.first-section .swiper-slide .content, .nectar-slider-wrap.first-section .swiper-slide .content').css('margin-top','0px'); 3769 $('.swiper-container .slider-prev, .swiper-container .slider-next').css('margin-top','-28px'); 3770 } 3771 3772 //if using wooCommerce sitewide notice 3773 if($('.demo_store').length > 0) $('.project-title.parallax-effect').css('margin-top','-25px'); 3774 3775 if($('#full_width_portfolio').length > 0){ 3776 $('.parallax_slider_outer.first-section').css('margin-top','93px'); 3777 } 3778 3779 $(window).resize(function(){ 3780 $sliderHeight = parseInt($('.parallax_slider_outer.first-section .swiper-container').attr('data-height')); 3781 3782 $('.project-title').css({ 3783 'top': $('#header-space').outerHeight() + $adminBarHeight + 'px' 3784 }); 3785 }); 3786 3787 } 3788 3789 //parallax 3790 if($('.parallax_slider_outer').length > 0 && !navigator.userAgent.match(/(Android|iPod|iPhone|iPad|IEMobile|Opera Mini)/)){
3791 sliderParallaxInit(); 3792 3793 } else if($('.parallax_slider_outer').length > 0 && navigator.userAgent.match(/(Android|iPod|iPhone|iPad|IEMobile|Opera Mini)/)) { 3794 $('.project-title').addClass('parallax-effect').css({ 3795 'top': $('#header-space').outerHeight() + $adminBarHeight + 'px' 3796 }); 3797 } 3798 3799 3800 function niceScrollInit(){ 3801 $("html").niceScroll({ 3802 scrollspeed: 60, 3803 mousescrollstep: 40, 3804 cursorwidth: 15, 3805 cursorborder: 0, 3806 cursorcolor: '#303030', 3807 cursorborderradius: 6, 3808 autohidemode: false, 3809 horizrailenabled: false 3810 }); 3811 3812 if($('#boxed').length == 0){ 3813 $('body, body #header-outer, body #header-secondary-outer, body #search-outer').css('padding-right','16px'); 3814 } 3815 3816 $('html').addClass('no-overflow-y'); 3817 } 3818 3819 //pause video backgrounds if popup video player is started 3820 $('.portfolio-items a.pp:contains(Video), .swiper-container .buttons a.pp').click(function(){ 3821 $('.swiper-slide').each(function(){ 3822 if($(this).find('.video-wrap video').length > 0) { 3823 $(this).find('.video-wrap video').get(0).pause(); 3824 } 3825 }); 3826 }); 3827 3828 3829 //solid button hover effect 3830 $.cssHooks.backgroundColor = { 3831 get: function(elem) { 3832 if (elem.currentStyle) 3833 var bg = elem.currentStyle["backgroundColor"]; 3834 else if (window.getComputedStyle) 3835 var bg = document.defaultView.getComputedStyle(elem, 3836 null).getPropertyValue("background-color"); 3837 if (bg.search("rgb") == -1) 3838 return bg; 3839 else { 3840 bg = bg.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); 3841 function hex(x) { 3842 return ("0" + parseInt(x).toString(16)).slice(-2); 3843 } 3844 if(bg) { 3845 return "#" + hex(bg[1]) + hex(bg[2]) + hex(bg[3]); 3846 } 3847 } 3848 } 3849 } 3850 3851 function shadeColor(color, shade) { 3852 var colorInt = parseInt(color.substring(1),16); 3853 3854 var R = (colorInt & 0xFF0000) >> 16; 3855 var G = (colorInt & 0x00FF00) >> 8; 3856 var B = (colorInt & 0x0000FF) >> 0; 3857 3858 R = R + Math.floor((shade/255)*R); 3859 G = G + Math.floor((shade/255)*G); 3860 B = B + Math.floor((shade/255)*B); 3861 3862 var newColorInt = (R<<16) + (G<<8) + (B); 3863 var newColorStr = "#"+newColorInt.toString(16); 3864 3865 return newColorStr; 3866 } 3867 3868 $('.swiper-slide').each(function(){ 3869 $(this).find('.solid_color').each(function(){ 3870 var $currentColor = $(this).find('a').css('background-color'); 3871 var $hoverColor = shadeColor($currentColor, -16); 3872 $(this).find('a').hover(function(){ 3873 $(this).attr('style','background-color:'+$hoverColor+'!important;'); 3874 },function(){ 3875 $(this).attr('style',''); 3876 }); 3877 }); 3878 }); 3879 3880 3881 //slider down arrow 3882 var logoHeight = parseInt($('#header-outer').attr('data-logo-height')); 3883 var headerPadding = parseInt($('#header-outer').attr('data-padding')); 3884 var shrinkNum = 8; 3885 3886 if (logoHeight >= 40 && logoHeight < 60) shrinkNum = 8; 3887 else if (logoHeight >= 60 && logoHeight < 80) shrinkNum = 10; 3888 else if (logoHeight >= 80 ) shrinkNum = 14; 3889 3890 headerPadding = headerPadding - headerPadding/1.8; 3891 3892 $('.slider-down-arrow').click(function(){ 3893 3894 var $currentSlider = $(this).parents('.swiper-container'); 3895 var $topDistance = $currentSlider.attr('data-height'); 3896 var $offset = ($currentSlider.parents('.first-section').length == 0 || $('body[data-transparent-header="false"]').length > 0) ? $currentSlider.offset().top : 0; 3897 3898 if(!$('body').hasClass('mobile')){ 3899 $('body,html').stop().animate({ 3900 scrollTop: $topDistance - $('#header-space').height() + shrinkNum + headerPadding*2 + $offset + 1 3901 },1000,'easeInOutCubic') 3902 } else { 3903 $('body,html').stop().animate({ 3904 scrollTop: parseInt($topDistance) + parseInt($currentSlider.offset().top) + 1 3905 },1000,'easeInOutCubic') 3906 } 3907 return false; 3908 }); 3909 3910 function prettyPhotoInit(){ 3911 3912 $(".nectar-slider-wrap a[rel^='prettyPhoto']").prettyPhoto({ 3913 theme: 'dark_rounded', 3914 allow_resize: true, 3915 default_width: 690, 3916 opacity: 0.85, 3917 animation_speed: 'normal', 3918 default_height: 388, 3919 social_tools: '', 3920 markup: '<div class="pp_pic_holder"> \ 3921 <div class="ppt"> </div> \ 3922 <div class="pp_details"> \ 3923 <div class="pp_nav"> \ 3924 <a href="#" class="pp_arrow_previous"> <i class="icon-salient-left-arrow-thin icon-default-style"></i> </a> \ 3925 <a href="#" class="pp_arrow_next"> <i class="icon-salient-right-arrow-thin icon-default-style"></i> </a> \ 3926 <p class="currentTextHolder">0/0</p> \ 3927 </div> \ 3928 <a class="pp_close" href="#">Close</a> \ 3929 </div> \ 3930 <div class="pp_content_container"> \ 3931 <div class="pp_left"> \ 3932 <div class="pp_right"> \ 3933 <div class="pp_content"> \ 3934 <div class="pp_fade"> \ 3935 <div class="pp_hoverContainer"> \ 3936 </div> \ 3937 <div id="pp_full_res"></div> \ 3938 </div> \ 3939 </div> \ 3940 </div> \ 3941 </div> \ 3942 </div> \ 3943 </div> \ 3944 <div class="pp_loaderIcon"></div> \ 3945 <div class="pp_overlay"></div>' 3946 }); 3947 3948 } 3949 3950 3951 3952 3953}); 3954
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.