1/*! lightslider - v1.1.6 - 2016-10-25 2* https://github.com/sachinchoolur/lightslider 3* Copyright (c) 2016 Sachin N; Licensed MIT */ 4(function ($, undefined) { 5 'use strict'; 6 var defaults = { 7 item: 3, 8 autoWidth: false, 9 slideMove: 1, 10 slideMargin: 10, 11 addClass: '', 12 mode: 'slide', 13 useCSS: true, 14 cssEasing: 'ease', //'cubic-bezier(0.25, 0, 0.25, 1)', 15 easing: 'linear', //'for jquery animation',// 16 speed: 400, //ms' 17 auto: false, 18 pauseOnHover: false, 19 loop: false, 20 slideEndAnimation: true, 21 pause: 2000, 22 keyPress: false, 23 controls: true, 24 prevHtml: '', 25 nextHtml: '', 26 rtl: false, 27 adaptiveHeight: false, 28 vertical: false, 29 verticalHeight: 500, 30 vThumbWidth: 100, 31 thumbItem: 10, 32 pager: true, 33 gallery: false, 34 galleryMargin: 5, 35 thumbMargin: 5, 36 currentPagerPosition: 'middle', 37 enableTouch: true, 38 enableDrag: true, 39 freeMove: true, 40 swipeThreshold: 40
vendor: 14,744 bytes, lines 40-368
40, 41 responsive: [], 42 /* jshint ignore:start */ 43 onBeforeStart: function ($el) {}, 44 onSliderLoad: function ($el) {}, 45 onBeforeSlide: function ($el, scene) {}, 46 onAfterSlide: function ($el, scene) {}, 47 onBeforeNextSlide: function ($el, scene) {}, 48 onBeforePrevSlide: function ($el, scene) {} 49 /* jshint ignore:end */ 50 }; 51 $.fn.lightSlider = function (options) { 52 if (this.length === 0) { 53 return this; 54 } 55 56 if (this.length > 1) { 57 this.each(function () { 58 $(this).lightSlider(options); 59 }); 60 return this; 61 } 62 63 var plugin = {}, 64 settings = $.extend(true, {}, defaults, options), 65 settingsTemp = {}, 66 $el = this; 67 plugin.$el = this; 68 69 if (settings.mode === 'fade') { 70 settings.vertical = false; 71 } 72 var $children = $el.children(), 73 windowW = $(window).width(), 74 breakpoint = null, 75 resposiveObj = null, 76 length = 0, 77 w = 0, 78 on = false, 79 elSize = 0, 80 $slide = '', 81 scene = 0, 82 property = (settings.vertical === true) ? 'height' : 'width', 83 gutter = (settings.vertical === true) ? 'margin-bottom' : 'margin-right', 84 slideValue = 0, 85 pagerWidth = 0, 86 slideWidth = 0, 87 thumbWidth = 0, 88 interval = null, 89 isTouch = ('ontouchstart' in document.documentElement); 90 var refresh = {}; 91 92 refresh.chbreakpoint = function () { 93 windowW = $(window).width(); 94 if (settings.responsive.length) { 95 var item; 96 if (settings.autoWidth === false) { 97 item = settings.item; 98 } 99 if (windowW < settings.responsive[0].breakpoint) { 100 for (var i = 0; i < settings.responsive.length; i++) { 101 if (windowW < settings.responsive[i].breakpoint) { 102 breakpoint = settings.responsive[i].breakpoint; 103 resposiveObj = settings.responsive[i]; 104 } 105 } 106 } 107 if (typeof resposiveObj !== 'undefined' && resposiveObj !== null) { 108 for (var j in resposiveObj.settings) { 109 if (resposiveObj.settings.hasOwnProperty(j)) { 110 if (typeof settingsTemp[j] === 'undefined' || settingsTemp[j] === null) { 111 settingsTemp[j] = settings[j]; 112 } 113 settings[j] = resposiveObj.settings[j]; 114 } 115 } 116 } 117 if (!$.isEmptyObject(settingsTemp) && windowW > settings.responsive[0].breakpoint) { 118 for (var k in settingsTemp) { 119 if (settingsTemp.hasOwnProperty(k)) { 120 settings[k] = settingsTemp[k]; 121 } 122 } 123 } 124 if (settings.autoWidth === false) { 125 if (slideValue > 0 && slideWidth > 0) { 126 if (item !== settings.item) { 127 scene = Math.round(slideValue / ((slideWidth + settings.slideMargin) * settings.slideMove)); 128 } 129 } 130 } 131 } 132 }; 133 134 refresh.calSW = function () { 135 if (settings.autoWidth === false) { 136 slideWidth = (elSize - ((settings.item * (settings.slideMargin)) - settings.slideMargin)) / settings.item; 137 } 138 }; 139 140 refresh.calWidth = function (cln) { 141 var ln = cln === true ? $slide.find('.lslide').length : $children.length; 142 if (settings.autoWidth === false) { 143 w = ln * (slideWidth + settings.slideMargin); 144 } else { 145 w = 0; 146 for (var i = 0; i < ln; i++) { 147 w += (parseInt($children.eq(i).width()) + settings.slideMargin); 148 } 149 } 150 return w; 151 }; 152 plugin = { 153 doCss: function () { 154 var support = function () { 155 var transition = ['transition', 'MozTransition', 'WebkitTransition', 'OTransition', 'msTransition', 'KhtmlTransition']; 156 var root = document.documentElement; 157 for (var i = 0; i < transition.length; i++) { 158 if (transition[i] in root.style) { 159 return true; 160 } 161 } 162 }; 163 if (settings.useCSS && support()) { 164 return true; 165 } 166 return false; 167 }, 168 keyPress: function () { 169 if (settings.keyPress) { 170 $(document).on('keyup.lightslider', function (e) { 171 if (!$(':focus').is('input, textarea')) { 172 if (e.preventDefault) { 173 e.preventDefault(); 174 } else { 175 e.returnValue = false; 176 } 177 if (e.keyCode === 37) { 178 $el.goToPrevSlide(); 179 } else if (e.keyCode === 39) { 180 $el.goToNextSlide(); 181 } 182 } 183 }); 184 } 185 }, 186 controls: function () { 187 if (settings.controls) { 188 $el.after('<div class="lSAction"><a class="lSPrev">' + settings.prevHtml + '</a><a class="lSNext">' + settings.nextHtml + '</a></div>'); 189 if (!settings.autoWidth) { 190 if (length <= settings.item) { 191 $slide.find('.lSAction').hide(); 192 } 193 } else { 194 if (refresh.calWidth(false) < elSize) { 195 $slide.find('.lSAction').hide(); 196 } 197 } 198 $slide.find('.lSAction a').on('click', function (e) { 199 if (e.preventDefault) { 200 e.preventDefault(); 201 } else { 202 e.returnValue = false; 203 } 204 if ($(this).attr('class') === 'lSPrev') { 205 $el.goToPrevSlide(); 206 } else { 207 $el.goToNextSlide(); 208 } 209 return false; 210 }); 211 } 212 }, 213 initialStyle: function () { 214 var $this = this; 215 if (settings.mode === 'fade') { 216 settings.autoWidth = false; 217 settings.slideEndAnimation = false; 218 } 219 if (settings.auto) { 220 settings.slideEndAnimation = false; 221 } 222 if (settings.autoWidth) { 223 settings.slideMove = 1; 224 settings.item = 1; 225 } 226 if (settings.loop) { 227 settings.slideMove = 1; 228 settings.freeMove = false; 229 } 230 settings.onBeforeStart.call(this, $el); 231 refresh.chbreakpoint(); 232 $el.addClass('lightSlider').wrap('<div class="lSSlideOuter ' + settings.addClass + '"><div class="lSSlideWrapper"></div></div>'); 233 $slide = $el.parent('.lSSlideWrapper'); 234 if (settings.rtl === true) { 235 $slide.parent().addClass('lSrtl'); 236 } 237 if (settings.vertical) { 238 $slide.parent().addClass('vertical'); 239 elSize = settings.verticalHeight; 240 $slide.css('height', elSize + 'px'); 241 } else { 242 elSize = $el.outerWidth(); 243 } 244 $children.addClass('lslide'); 245 if (settings.loop === true && settings.mode === 'slide') { 246 refresh.calSW(); 247 refresh.clone = function () { 248 if (refresh.calWidth(true) > elSize) { 249 /**/ 250 var tWr = 0, 251 tI = 0; 252 for (var k = 0; k < $children.length; k++) { 253 tWr += (parseInt($el.find('.lslide').eq(k).width()) + settings.slideMargin); 254 tI++; 255 if (tWr >= (elSize + settings.slideMargin)) { 256 break; 257 } 258 } 259 var tItem = settings.autoWidth === true ? tI : settings.item; 260 261 /**/ 262 if (tItem < $el.find('.clone.left').length) { 263 for (var i = 0; i < $el.find('.clone.left').length - tItem; i++) { 264 $children.eq(i).remove(); 265 } 266 } 267 if (tItem < $el.find('.clone.right').length) { 268 for (var j = $children.length - 1; j > ($children.length - 1 - $el.find('.clone.right').length); j--) { 269 scene--; 270 $children.eq(j).remove(); 271 } 272 } 273 /**/ 274 for (var n = $el.find('.clone.right').length; n < tItem; n++) { 275 $el.find('.lslide').eq(n).clone().removeClass('lslide').addClass('clone right').appendTo($el); 276 scene++; 277 } 278 for (var m = $el.find('.lslide').length - $el.find('.clone.left').length; m > ($el.find('.lslide').length - tItem); m--) { 279 $el.find('.lslide').eq(m - 1).clone().removeClass('lslide').addClass('clone left').prependTo($el); 280 } 281 $children = $el.children(); 282 } else { 283 if ($children.hasClass('clone')) { 284 $el.find('.clone').remove(); 285 $this.move($el, 0); 286 } 287 } 288 }; 289 refresh.clone(); 290 } 291 refresh.sSW = function () { 292 length = $children.length; 293 if (settings.rtl === true && settings.vertical === false) { 294 gutter = 'margin-left'; 295 } 296 if (settings.autoWidth === false) { 297 $children.css(property, slideWidth + 'px'); 298 } 299 $children.css(gutter, settings.slideMargin + 'px'); 300 w = refresh.calWidth(false); 301 $el.css(property, w + 'px'); 302 if (settings.loop === true && settings.mode === 'slide') { 303 if (on === false) { 304 scene = $el.find('.clone.left').length; 305 } 306 } 307 }; 308 refresh.calL = function () { 309 $children = $el.children(); 310 length = $children.length; 311 }; 312 if (this.doCss()) { 313 $slide.addClass('usingCss'); 314 } 315 refresh.calL(); 316 if (settings.mode === 'slide') { 317 refresh.calSW(); 318 refresh.sSW(); 319 if (settings.loop === true) { 320 slideValue = $this.slideValue(); 321 this.move($el, slideValue); 322 } 323 if (settings.vertical === false) { 324 this.setHeight($el, false); 325 } 326 327 } else { 328 this.setHeight($el, true); 329 $el.addClass('lSFade'); 330 if (!this.doCss()) { 331 $children.fadeOut(0); 332 $children.eq(scene).fadeIn(0); 333 } 334 } 335 if (settings.loop === true && settings.mode === 'slide') { 336 $children.eq(scene).addClass('active'); 337 } else { 338 $children.first().addClass('active'); 339 } 340 }, 341 pager: function () { 342 var $this = this; 343 refresh.createPager = function () { 344 thumbWidth = (elSize - ((settings.thumbItem * (settings.thumbMargin)) - settings.thumbMargin)) / settings.thumbItem; 345 var $children = $slide.find('.lslide'); 346 var length = $slide.find('.lslide').length; 347 var i = 0, 348 pagers = '', 349 v = 0; 350 for (i = 0; i < length; i++) { 351 if (settings.mode === 'slide') { 352 // calculate scene * slide value 353 if (!settings.autoWidth) { 354 v = i * ((slideWidth + settings.slideMargin) * settings.slideMove); 355 } else { 356 v += ((parseInt($children.eq(i).width()) + settings.slideMargin) * settings.slideMove); 357 } 358 } 359 var thumb = $children.eq(i * settings.slideMove).attr('data-thumb'); 360 if (settings.gallery === true) { 361 pagers += '<li style="width:100%;' + property + ':' + thumbWidth + 'px;' + gutter + ':' + settings.thumbMargin + 'px"><a href="#"><img src="' + thumb + '" /></a></li>'; 362 } else { 363 pagers += '<li><a href="#">' + (i + 1) + '</a></li>'; 364 } 365 if (settings.mode === 'slide') { 366 if ((v) >= w - elSize - settings.slideMargin) { 367 i = i + 1; 368 var minPgr =
3682
vendor: 32,365 bytes, lines 368-1143
368; 369 if (settings.autoWidth) { 370 pagers += '<li><a href="#">' + (i + 1) + '</a></li>'; 371 minPgr = 1; 372 } 373 if (i < minPgr) { 374 pagers = null; 375 $slide.parent().addClass('noPager'); 376 } else { 377 $slide.parent().removeClass('noPager'); 378 } 379 break; 380 } 381 } 382 } 383 var $cSouter = $slide.parent(); 384 $cSouter.find('.lSPager').html(pagers); 385 if (settings.gallery === true) { 386 if (settings.vertical === true) { 387 // set Gallery thumbnail width 388 $cSouter.find('.lSPager').css('width', settings.vThumbWidth + 'px'); 389 } 390 pagerWidth = (i * (settings.thumbMargin + thumbWidth)) + 0.5; 391 $cSouter.find('.lSPager').css({ 392 property: pagerWidth + 'px', 393 'transition-duration': settings.speed + 'ms' 394 }); 395 if (settings.vertical === true) { 396 $slide.parent().css('padding-right', (settings.vThumbWidth + settings.galleryMargin) + 'px'); 397 } 398 $cSouter.find('.lSPager').css(property, pagerWidth + 'px'); 399 } 400 var $pager = $cSouter.find('.lSPager').find('li'); 401 $pager.first().addClass('active'); 402 $pager.on('click', function () { 403 if (settings.loop === true && settings.mode === 'slide') { 404 scene = scene + ($pager.index(this) - $cSouter.find('.lSPager').find('li.active').index()); 405 } else { 406 scene = $pager.index(this); 407 } 408 $el.mode(false); 409 if (settings.gallery === true) { 410 $this.slideThumb(); 411 } 412 return false; 413 }); 414 }; 415 if (settings.pager) { 416 var cl = 'lSpg'; 417 if (settings.gallery) { 418 cl = 'lSGallery'; 419 } 420 $slide.after('<ul class="lSPager ' + cl + '"></ul>'); 421 var gMargin = (settings.vertical) ? 'margin-left' : 'margin-top'; 422 $slide.parent().find('.lSPager').css(gMargin, settings.galleryMargin + 'px'); 423 refresh.createPager(); 424 } 425 426 setTimeout(function () { 427 refresh.init(); 428 }, 0); 429 }, 430 setHeight: function (ob, fade) { 431 var obj = null, 432 $this = this; 433 if (settings.loop) { 434 obj = ob.children('.lslide ').first(); 435 } else { 436 obj = ob.children().first(); 437 } 438 var setCss = function () { 439 var tH = obj.outerHeight(), 440 tP = 0, 441 tHT = tH; 442 if (fade) { 443 tH = 0; 444 tP = ((tHT) * 100) / elSize; 445 } 446 ob.css({ 447 'height': tH + 'px', 448 'padding-bottom': tP + '%' 449 }); 450 }; 451 setCss(); 452 if (obj.find('img').length) { 453 if ( obj.find('img')[0].complete) { 454 setCss(); 455 if (!interval) { 456 $this.auto(); 457 } 458 }else{ 459 obj.find('img').on('load', function () { 460 setTimeout(function () { 461 setCss(); 462 if (!interval) { 463 $this.auto(); 464 } 465 }, 100); 466 }); 467 } 468 }else{ 469 if (!interval) { 470 $this.auto(); 471 } 472 } 473 }, 474 active: function (ob, t) { 475 if (this.doCss() && settings.mode === 'fade') { 476 $slide.addClass('on'); 477 } 478 var sc = 0; 479 if (scene * settings.slideMove < length) { 480 ob.removeClass('active'); 481 if (!this.doCss() && settings.mode === 'fade' && t === false) { 482 ob.fadeOut(settings.speed); 483 } 484 if (t === true) { 485 sc = scene; 486 } else { 487 sc = scene * settings.slideMove; 488 } 489 //t === true ? sc = scene : sc = scene * settings.slideMove; 490 var l, nl; 491 if (t === true) { 492 l = ob.length; 493 nl = l - 1; 494 if (sc + 1 >= l) { 495 sc = nl; 496 } 497 } 498 if (settings.loop === true && settings.mode === 'slide') { 499 //t === true ? sc = scene - $el.find('.clone.left').length : sc = scene * settings.slideMove; 500 if (t === true) { 501 sc = scene - $el.find('.clone.left').length; 502 } else { 503 sc = scene * settings.slideMove; 504 } 505 if (t === true) { 506 l = ob.length; 507 nl = l - 1; 508 if (sc + 1 === l) { 509 sc = nl; 510 } else if (sc + 1 > l) { 511 sc = 0; 512 } 513 } 514 } 515 516 if (!this.doCss() && settings.mode === 'fade' && t === false) { 517 ob.eq(sc).fadeIn(settings.speed); 518 } 519 ob.eq(sc).addClass('active'); 520 } else { 521 ob.removeClass('active'); 522 ob.eq(ob.length - 1).addClass('active'); 523 if (!this.doCss() && settings.mode === 'fade' && t === false) { 524 ob.fadeOut(settings.speed); 525 ob.eq(sc).fadeIn(settings.speed); 526 } 527 } 528 }, 529 move: function (ob, v) { 530 if (settings.rtl === true) { 531 v = -v; 532 } 533 if (this.doCss()) { 534 if (settings.vertical === true) { 535 ob.css({ 536 'transform': 'translate3d(0px, ' + (-v) + 'px, 0px)', 537 '-webkit-transform': 'translate3d(0px, ' + (-v) + 'px, 0px)' 538 }); 539 } else { 540 ob.css({ 541 'transform': 'translate3d(' + (-v) + 'px, 0px, 0px)', 542 '-webkit-transform': 'translate3d(' + (-v) + 'px, 0px, 0px)', 543 }); 544 } 545 } else { 546 if (settings.vertical === true) { 547 ob.css('position', 'relative').animate({ 548 top: -v + 'px' 549 }, settings.speed, settings.easing); 550 } else { 551 ob.css('position', 'relative').animate({ 552 left: -v + 'px' 553 }, settings.speed, settings.easing); 554 } 555 } 556 var $thumb = $slide.parent().find('.lSPager').find('li'); 557 this.active($thumb, true); 558 }, 559 fade: function () { 560 this.active($children, false); 561 var $thumb = $slide.parent().find('.lSPager').find('li'); 562 this.active($thumb, true); 563 }, 564 slide: function () { 565 var $this = this; 566 refresh.calSlide = function () { 567 if (w > elSize) { 568 slideValue = $this.slideValue(); 569 $this.active($children, false); 570 if ((slideValue) > w - elSize - settings.slideMargin) { 571 slideValue = w - elSize - settings.slideMargin; 572 } else if (slideValue < 0) { 573 slideValue = 0; 574 } 575 $this.move($el, slideValue); 576 if (settings.loop === true && settings.mode === 'slide') { 577 if (scene >= (length - ($el.find('.clone.left').length / settings.slideMove))) { 578 $this.resetSlide($el.find('.clone.left').length); 579 } 580 if (scene === 0) { 581 $this.resetSlide($slide.find('.lslide').length); 582 } 583 } 584 } 585 }; 586 refresh.calSlide(); 587 }, 588 resetSlide: function (s) { 589 var $this = this; 590 $slide.find('.lSAction a').addClass('disabled'); 591 setTimeout(function () { 592 scene = s; 593 $slide.css('transition-duration', '0ms'); 594 slideValue = $this.slideValue(); 595 $this.active($children, false); 596 plugin.move($el, slideValue); 597 setTimeout(function () { 598 $slide.css('transition-duration', settings.speed + 'ms'); 599 $slide.find('.lSAction a').removeClass('disabled'); 600 }, 50); 601 }, settings.speed + 100); 602 }, 603 slideValue: function () { 604 var _sV = 0; 605 if (settings.autoWidth === false) { 606 _sV = scene * ((slideWidth + settings.slideMargin) * settings.slideMove); 607 } else { 608 _sV = 0; 609 for (var i = 0; i < scene; i++) { 610 _sV += (parseInt($children.eq(i).width()) + settings.slideMargin); 611 } 612 } 613 return _sV; 614 }, 615 slideThumb: function () { 616 var position; 617 switch (settings.currentPagerPosition) { 618 case 'left': 619 position = 0; 620 break; 621 case 'middle': 622 position = (elSize / 2) - (thumbWidth / 2); 623 break; 624 case 'right': 625 position = elSize - thumbWidth; 626 } 627 var sc = scene - $el.find('.clone.left').length; 628 var $pager = $slide.parent().find('.lSPager'); 629 if (settings.mode === 'slide' && settings.loop === true) { 630 if (sc >= $pager.children().length) { 631 sc = 0; 632 } else if (sc < 0) { 633 sc = $pager.children().length; 634 } 635 } 636 var thumbSlide = sc * ((thumbWidth + settings.thumbMargin)) - (position); 637 if ((thumbSlide + elSize) > pagerWidth) { 638 thumbSlide = pagerWidth - elSize - settings.thumbMargin; 639 } 640 if (thumbSlide < 0) { 641 thumbSlide = 0; 642 } 643 this.move($pager, thumbSlide); 644 }, 645 auto: function () { 646 if (settings.auto) { 647 clearInterval(interval); 648 interval = setInterval(function () { 649 $el.goToNextSlide(); 650 }, settings.pause); 651 } 652 }, 653 pauseOnHover: function(){ 654 var $this = this; 655 if (settings.auto && settings.pauseOnHover) { 656 $slide.on('mouseenter', function(){ 657 $(this).addClass('ls-hover'); 658 $el.pause(); 659 settings.auto = true; 660 }); 661 $slide.on('mouseleave',function(){ 662 $(this).removeClass('ls-hover'); 663 if (!$slide.find('.lightSlider').hasClass('lsGrabbing')) { 664 $this.auto(); 665 } 666 }); 667 } 668 }, 669 touchMove: function (endCoords, startCoords) { 670 $slide.css('transition-duration', '0ms'); 671 if (settings.mode === 'slide') { 672 var distance = endCoords - startCoords; 673 var swipeVal = slideValue - distance; 674 if ((swipeVal) >= w - elSize - settings.slideMargin) { 675 if (settings.freeMove === false) { 676 swipeVal = w - elSize - settings.slideMargin; 677 } else { 678 var swipeValT = w - elSize - settings.slideMargin; 679 swipeVal = swipeValT + ((swipeVal - swipeValT) / 5); 680 681 } 682 } else if (swipeVal < 0) { 683 if (settings.freeMove === false) { 684 swipeVal = 0; 685 } else { 686 swipeVal = swipeVal / 5; 687 } 688 } 689 this.move($el, swipeVal); 690 } 691 }, 692 693 touchEnd: function (distance) { 694 $slide.css('transition-duration', settings.speed + 'ms'); 695 if (settings.mode === 'slide') { 696 var mxVal = false; 697 var _next = true; 698 slideValue = slideValue - distance; 699 if ((slideValue) > w - elSize - settings.slideMargin) { 700 slideValue = w - elSize - settings.slideMargin; 701 if (settings.autoWidth === false) { 702 mxVal = true; 703 } 704 } else if (slideValue < 0) { 705 slideValue = 0; 706 } 707 var gC = function (next) { 708 var ad = 0; 709 if (!mxVal) { 710 if (next) { 711 ad = 1; 712 } 713 } 714 if (!settings.autoWidth) { 715 var num = slideValue / ((slideWidth + settings.slideMargin) * settings.slideMove); 716 scene = parseInt(num) + ad; 717 if (slideValue >= (w - elSize - settings.slideMargin)) { 718 if (num % 1 !== 0) { 719 scene++; 720 } 721 } 722 } else { 723 var tW = 0; 724 for (var i = 0; i < $children.length; i++) { 725 tW += (parseInt($children.eq(i).width()) + settings.slideMargin); 726 scene = i + ad; 727 if (tW >= slideValue) { 728 break; 729 } 730 } 731 } 732 }; 733 if (distance >= settings.swipeThreshold) { 734 gC(false); 735 _next = false; 736 } else if (distance <= -settings.swipeThreshold) { 737 gC(true); 738 _next = false; 739 } 740 $el.mode(_next); 741 this.slideThumb(); 742 } else { 743 if (distance >= settings.swipeThreshold) { 744 $el.goToPrevSlide(); 745 } else if (distance <= -settings.swipeThreshold) { 746 $el.goToNextSlide(); 747 } 748 } 749 }, 750 751 752 753 enableDrag: function () { 754 var $this = this; 755 if (!isTouch) { 756 var startCoords = 0, 757 endCoords = 0, 758 isDraging = false; 759 $slide.find('.lightSlider').addClass('lsGrab'); 760 $slide.on('mousedown', function (e) { 761 if (w < elSize) { 762 if (w !== 0) { 763 return false; 764 } 765 } 766 if ($(e.target).attr('class') !== ('lSPrev') && $(e.target).attr('class') !== ('lSNext')) { 767 startCoords = (settings.vertical === true) ? e.pageY : e.pageX; 768 isDraging = true; 769 if (e.preventDefault) { 770 e.preventDefault(); 771 } else { 772 e.returnValue = false; 773 } 774 // ** Fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723 775 $slide.scrollLeft += 1; 776 $slide.scrollLeft -= 1; 777 // * 778 $slide.find('.lightSlider').removeClass('lsGrab').addClass('lsGrabbing'); 779 clearInterval(interval); 780 } 781 }); 782 $(window).on('mousemove', function (e) { 783 if (isDraging) { 784 endCoords = (settings.vertical === true) ? e.pageY : e.pageX; 785 $this.touchMove(endCoords, startCoords); 786 } 787 }); 788 $(window).on('mouseup', function (e) { 789 if (isDraging) { 790 $slide.find('.lightSlider').removeClass('lsGrabbing').addClass('lsGrab'); 791 isDraging = false; 792 endCoords = (settings.vertical === true) ? e.pageY : e.pageX; 793 var distance = endCoords - startCoords; 794 if (Math.abs(distance) >= settings.swipeThreshold) { 795 $(window).on('click.ls', function (e) { 796 if (e.preventDefault) { 797 e.preventDefault(); 798 } else { 799 e.returnValue = false; 800 } 801 e.stopImmediatePropagation(); 802 e.stopPropagation(); 803 $(window).off('click.ls'); 804 }); 805 } 806 807 $this.touchEnd(distance); 808 809 } 810 }); 811 } 812 }, 813 814 815 816 817 enableTouch: function () { 818 var $this = this; 819 if (isTouch) { 820 var startCoords = {}, 821 endCoords = {}; 822 $slide.on('touchstart', function (e) { 823 endCoords = e.originalEvent.targetTouches[0]; 824 startCoords.pageX = e.originalEvent.targetTouches[0].pageX; 825 startCoords.pageY = e.originalEvent.targetTouches[0].pageY; 826 clearInterval(interval); 827 }); 828 $slide.on('touchmove', function (e) { 829 if (w < elSize) { 830 if (w !== 0) { 831 return false; 832 } 833 } 834 var orig = e.originalEvent; 835 endCoords = orig.targetTouches[0]; 836 var xMovement = Math.abs(endCoords.pageX - startCoords.pageX); 837 var yMovement = Math.abs(endCoords.pageY - startCoords.pageY); 838 if (settings.vertical === true) { 839 if ((yMovement * 3) > xMovement) { 840 e.preventDefault(); 841 } 842 $this.touchMove(endCoords.pageY, startCoords.pageY); 843 } else { 844 if ((xMovement * 3) > yMovement) { 845 e.preventDefault(); 846 } 847 $this.touchMove(endCoords.pageX, startCoords.pageX); 848 } 849 850 }); 851 $slide.on('touchend', function () { 852 if (w < elSize) { 853 if (w !== 0) { 854 return false; 855 } 856 } 857 var distance; 858 if (settings.vertical === true) { 859 distance = endCoords.pageY - startCoords.pageY; 860 } else { 861 distance = endCoords.pageX - startCoords.pageX; 862 } 863 $this.touchEnd(distance); 864 }); 865 } 866 }, 867 build: function () { 868 var $this = this; 869 $this.initialStyle(); 870 if (this.doCss()) { 871 872 if (settings.enableTouch === true) { 873 $this.enableTouch(); 874 } 875 if (settings.enableDrag === true) { 876 $this.enableDrag(); 877 } 878 } 879 880 $(window).on('focus', function(){ 881 $this.auto(); 882 }); 883 884 $(window).on('blur', function(){ 885 clearInterval(interval); 886 }); 887 888 $this.pager(); 889 $this.pauseOnHover(); 890 $this.controls(); 891 $this.keyPress(); 892 } 893 }; 894 plugin.build(); 895 refresh.init = function () { 896 refresh.chbreakpoint(); 897 if (settings.vertical === true) { 898 if (settings.item > 1) { 899 elSize = settings.verticalHeight; 900 } else { 901 elSize = $children.outerHeight(); 902 } 903 $slide.css('height', elSize + 'px'); 904 } else { 905 elSize = $slide.outerWidth(); 906 } 907 if (settings.loop === true && settings.mode === 'slide') { 908 refresh.clone(); 909 } 910 refresh.calL(); 911 if (settings.mode === 'slide') { 912 $el.removeClass('lSSlide'); 913 } 914 if (settings.mode === 'slide') { 915 refresh.calSW(); 916 refresh.sSW(); 917 } 918 setTimeout(function () { 919 if (settings.mode === 'slide') { 920 $el.addClass('lSSlide'); 921 } 922 }, 1000); 923 if (settings.pager) { 924 refresh.createPager(); 925 } 926 if (settings.adaptiveHeight === true && settings.vertical === false) { 927 $el.css('height', $children.eq(scene).outerHeight(true)); 928 } 929 if (settings.adaptiveHeight === false) { 930 if (settings.mode === 'slide') { 931 if (settings.vertical === false) { 932 plugin.setHeight($el, false); 933 }else{ 934 plugin.auto(); 935 } 936 } else { 937 plugin.setHeight($el, true); 938 } 939 } 940 if (settings.gallery === true) { 941 plugin.slideThumb(); 942 } 943 if (settings.mode === 'slide') { 944 plugin.slide(); 945 } 946 if (settings.autoWidth === false) { 947 if ($children.length <= settings.item) { 948 $slide.find('.lSAction').hide(); 949 } else { 950 $slide.find('.lSAction').show(); 951 } 952 } else { 953 if ((refresh.calWidth(false) < elSize) && (w !== 0)) { 954 $slide.find('.lSAction').hide(); 955 } else { 956 $slide.find('.lSAction').show(); 957 } 958 } 959 }; 960 $el.goToPrevSlide = function () { 961 if (scene > 0) { 962 settings.onBeforePrevSlide.call(this, $el, scene); 963 scene--; 964 $el.mode(false); 965 if (settings.gallery === true) { 966 plugin.slideThumb(); 967 } 968 } else { 969 if (settings.loop === true) { 970 settings.onBeforePrevSlide.call(this, $el, scene); 971 if (settings.mode === 'fade') { 972 var l = (length - 1); 973 scene = parseInt(l / settings.slideMove); 974 } 975 $el.mode(false); 976 if (settings.gallery === true) { 977 plugin.slideThumb(); 978 } 979 } else if (settings.slideEndAnimation === true) { 980 $el.addClass('leftEnd'); 981 setTimeout(function () { 982 $el.removeClass('leftEnd'); 983 }, 400); 984 } 985 } 986 }; 987 $el.goToNextSlide = function () { 988 var nextI = true; 989 if (settings.mode === 'slide') { 990 var _slideValue = plugin.slideValue(); 991 nextI = _slideValue < w - elSize - settings.slideMargin; 992 } 993 if (((scene * settings.slideMove) < length - settings.slideMove) && nextI) { 994 settings.onBeforeNextSlide.call(this, $el, scene); 995 scene++; 996 $el.mode(false); 997 if (settings.gallery === true) { 998 plugin.slideThumb(); 999 } 1000 } else { 1001 if (settings.loop === true) { 1002 settings.onBeforeNextSlide.call(this, $el, scene); 1003 scene = 0; 1004 $el.mode(false); 1005 if (settings.gallery === true) { 1006 plugin.slideThumb(); 1007 } 1008 } else if (settings.slideEndAnimation === true) { 1009 $el.addClass('rightEnd'); 1010 setTimeout(function () { 1011 $el.removeClass('rightEnd'); 1012 }, 400); 1013 } 1014 } 1015 }; 1016 $el.mode = function (_touch) { 1017 if (settings.adaptiveHeight === true && settings.vertical === false) { 1018 $el.css('height', $children.eq(scene).outerHeight(true)); 1019 } 1020 if (on === false) { 1021 if (settings.mode === 'slide') { 1022 if (plugin.doCss()) { 1023 $el.addClass('lSSlide'); 1024 if (settings.speed !== '') { 1025 $slide.css('transition-duration', settings.speed + 'ms'); 1026 } 1027 if (settings.cssEasing !== '') { 1028 $slide.css('transition-timing-function', settings.cssEasing); 1029 } 1030 } 1031 } else { 1032 if (plugin.doCss()) { 1033 if (settings.speed !== '') { 1034 $el.css('transition-duration', settings.speed + 'ms'); 1035 } 1036 if (settings.cssEasing !== '') { 1037 $el.css('transition-timing-function', settings.cssEasing); 1038 } 1039 } 1040 } 1041 } 1042 if (!_touch) { 1043 settings.onBeforeSlide.call(this, $el, scene); 1044 } 1045 if (settings.mode === 'slide') { 1046 plugin.slide(); 1047 } else { 1048 plugin.fade(); 1049 } 1050 if (!$slide.hasClass('ls-hover')) { 1051 plugin.auto(); 1052 } 1053 setTimeout(function () { 1054 if (!_touch) { 1055 settings.onAfterSlide.call(this, $el, scene); 1056 } 1057 }, settings.speed); 1058 on = true; 1059 }; 1060 $el.play = function () { 1061 $el.goToNextSlide(); 1062 settings.auto = true; 1063 plugin.auto(); 1064 }; 1065 $el.pause = function () { 1066 settings.auto = false; 1067 clearInterval(interval); 1068 }; 1069 $el.refresh = function () { 1070 refresh.init(); 1071 }; 1072 $el.getCurrentSlideCount = function () { 1073 var sc = scene; 1074 if (settings.loop) { 1075 var ln = $slide.find('.lslide').length, 1076 cl = $el.find('.clone.left').length; 1077 if (scene <= cl - 1) { 1078 sc = ln + (scene - cl); 1079 } else if (scene >= (ln + cl)) { 1080 sc = scene - ln - cl; 1081 } else { 1082 sc = scene - cl; 1083 } 1084 } 1085 return sc + 1; 1086 }; 1087 $el.getTotalSlideCount = function () { 1088 return $slide.find('.lslide').length; 1089 }; 1090 $el.goToSlide = function (s) { 1091 if (settings.loop) { 1092 scene = (s + $el.find('.clone.left').length - 1); 1093 } else { 1094 scene = s; 1095 } 1096 $el.mode(false); 1097 if (settings.gallery === true) { 1098 plugin.slideThumb(); 1099 } 1100 }; 1101 $el.destroy = function () { 1102 if ($el.lightSlider) { 1103 $el.goToPrevSlide = function(){}; 1104 $el.goToNextSlide = function(){}; 1105 $el.mode = function(){}; 1106 $el.play = function(){}; 1107 $el.pause = function(){}; 1108 $el.refresh = function(){}; 1109 $el.getCurrentSlideCount = function(){}; 1110 $el.getTotalSlideCount = function(){}; 1111 $el.goToSlide = function(){}; 1112 $el.lightSlider = null; 1113 refresh = { 1114 init : function(){} 1115 }; 1116 $el.parent().parent().find('.lSAction, .lSPager').remove(); 1117 $el.removeClass('lightSlider lSFade lSSlide lsGrab lsGrabbing leftEnd right').removeAttr('style').unwrap().unwrap(); 1118 $el.children().removeAttr('style'); 1119 $children.removeClass('lslide active'); 1120 $el.find('.clone').remove(); 1121 $children = null; 1122 interval = null; 1123 on = false; 1124 scene = 0; 1125 } 1126 1127 }; 1128 setTimeout(function () { 1129 settings.onSliderLoad.call(this, $el); 1130 }, 10); 1131 $(window).on('resize orientationchange', function (e) { 1132 setTimeout(function () { 1133 if (e.preventDefault) { 1134 e.preventDefault(); 1135 } else { 1136 e.returnValue = false; 1137 } 1138 refresh.init(); 1139 }, 200); 1140 }); 1141 return this; 1142 }; 1143}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.