1/* 2 * FancyBox - jQuery Plugin 3 * Simple and fancy lightbox alternative 4 * 5 * Examples and documentation at: http://fancybox.net 6 * 7 * Copyright (c) 2008 - 2010 Janis Skarnelis 8 * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated. 9 * 10 * Version: 1.3.4 (11/11/2010) 11 * Requires: jQuery v1.3+ 12 * 13 * Dual licensed under the MIT and GPL licenses: 14 * http://www.opensource.org/licenses/mit-license.php 15 * http://www.gnu.org/licenses/gpl.html 16 */ 17BONZ.onGlobalLoaded(function() { 18 (function($) { 19 var tmp, loading, overlay, wrap, outer, content, close, title, nav_left, nav_right, 20 21 selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [], 22 23 ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i, 24 25 loadingTimer, loadingFrame = 1, 26 27 titleHeight = 0, titleStr = '', start_pos, final_pos, busy = false, fx
27= $.extend($('<div/>')[0], { prop: 0 }), 28 29 isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest, 30 31 /* 32 * Private methods 33 */ 34 35 _abort = function() { 36 loading.hide(); 37 38 imgPreloader.onerror = imgPreloader.onload = null; 39 40 if (ajaxLoader) { 41 ajaxLoader.abort(); 42 } 43 44 tmp.empty(); 45 }, 46 47 _error = function() { 48 if (false === selectedOpts.onError(selectedArray, selectedIndex, selectedOpts)) { 49 loading.hide(); 50 busy = false; 51 return; 52 } 53 54 selectedOpts.titleShow = false; 55 56 selectedOpts.width = 'auto'; 57 selectedOpts.height = 'auto'; 58 59 tmp.html( '<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>' ); 60 61 _process_inline(); 62 }, 63 64 _start = function() { 65 var obj = selectedArray[ selectedIndex ], 66 href, 67 type, 68 title, 69 str, 70 emb, 71 ret; 72 73 _abort(); 74 75 selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox'))); 76 77 ret = selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts); 78 79 if (ret === false) { 80 busy = false; 81 return; 82 } else if (typeof ret == 'object') { 83 selectedOpts = $.extend(selectedOpts, ret); 84 } 85 86 title = selectedOpts.title || (obj.nodeName ? $(obj).attr('title') : obj.title) || ''; 87 88 if (obj.nodeName && !selectedOpts.orig) { 89 selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj); 90 } 91 92 if (title === '' && selectedOpts.orig && selectedOpts.titleFromAlt) { 93 title = selectedOpts.orig.attr('alt'); 94 } 95 96 href = selectedOpts.href || (obj.nodeName ? $(obj).attr('href') : obj.href) || null; 97 98 if ((/^(?:javascript)/i).test(href) || href == '#') { 99 href = null; 100 } 101 102 if (selectedOpts.type) { 103 type = selectedOpts.type; 104 105 if (!href) { 106 href = selectedOpts.content; 107 } 108 109 } else if (selectedOpts.content) { 110 type = 'html'; 111 112 } else if (href) { 113 if (href.match(imgRegExp)) { 114 type = 'image'; 115 116 } else if (href.match(swfRegExp)) { 117 type = 'swf'; 118 119 } else if ($(obj).hasClass("iframe")) { 120 type = 'iframe'; 121 122 } else if (href.indexOf("#") === 0) { 123 type = 'inline'; 124 125 } else { 126 type = 'ajax'; 127 } 128 } 129 130 if (!type) { 131 _error(); 132 return; 133 } 134 135 if (type == 'inline') { 136 obj = href.substr(href.indexOf("#")); 137 type = $(obj).length > 0 ? 'inline' : 'ajax'; 138 } 139 140 selectedOpts.type = type; 141 selectedOpts.href = href; 142 selectedOpts.title = title; 143 144 if (selectedOpts.autoDimensions) { 145 if (selectedOpts.type == 'html' || selectedOpts.type == 'inline' || selectedOpts.type == 'ajax') { 146 selectedOpts.width = 'auto'; 147 selectedOpts.height = 'auto'; 148 } else { 149 selectedOpts.autoDimensions = false; 150 } 151 } 152 153 if (selectedOpts.modal) { 154 selectedOpts.overlayShow = true; 155 selectedOpts.hideOnOverlayClick = false; 156 selectedOpts.hideOnContentClick = false; 157 selectedOpts.enableEscapeButton = false; 158 selectedOpts.showCloseButton = false; 159 } 160 161 selectedOpts.padding = parseInt(selectedOpts.padding, 10); 162 selectedOpts.margin = parseInt(selectedOpts.margin, 10); 163 164 tmp.css('padding', (selectedOpts.padding + selectedOpts.margin)); 165 166 $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() { 167 $(this).replaceWith(content.children()); 168 }); 169 170 switch (type) { 171 case 'html' : 172 tmp.html( selectedOpts.content ); 173 _process_inline(); 174 break; 175 176 case 'inline' : 177 if ( $(obj).parent().is('#fancybox-content') === true) { 178 busy = false;
179 return; 180 } 181 182 $('<div class="fancybox-inline-tmp" />') 183 .hide() 184 .insertBefore( $(obj) ) 185 .bind('fancybox-cleanup', function() { 186 $(this).replaceWith(content.children()); 187 }).bind('fancybox-cancel', function() { 188 $(this).replaceWith(tmp.children()); 189 }); 190 191 $(obj).appendTo(tmp); 192 193 _process_inline(); 194 break; 195 196 case 'image': 197 busy = false; 198 199 $.fancybox.showActivity(); 200 201 imgPreloader = new Image(); 202 203 imgPreloader.onerror = function() { 204 _error(); 205 }; 206 207 imgPreloader.onload = function() { 208 busy = true; 209 210 imgPreloader.onerror = imgPreloader.onload = null; 211 212 _process_image(); 213 }; 214 215 imgPreloader.src = href; 216 break; 217 218 case 'swf': 219 selectedOpts.scrolling = 'no'; 220 221 str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"><param name="movie" value="' + href + '"></param>'; 222 emb = ''; 223 224 $.each(selectedOpts.swf, function(name, val) { 225 str += '<param name="' + name + '" value="' + val + '"></param>'; 226 emb += ' ' + name + '="' + val + '"'; 227 }); 228 229 str += '<embed src="' + href + '" type="application/x-shockwave-flash" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"' + emb + '></embed></object>'; 230 231 tmp.html(str); 232 233 _process_inline(); 234 break; 235 236 case 'ajax': 237 busy = false; 238 239 $.fancybox.showActivity(); 240 241 selectedOpts.ajax.win = selectedOpts.ajax.success; 242 243 ajaxLoader = $.ajax($.extend({}, selectedOpts.ajax, { 244 url : href, 245 data : selectedOpts.ajax.data || {}, 246 error : function(XMLHttpRequest, textStatus, errorThrown) { 247 if ( XMLHttpRequest.status > 0 ) { 248 _error(); 249 } 250 }, 251 success : function(data, textStatus, XMLHttpRequest) { 252 var o = typeof XMLHttpRequest == 'object' ? XMLHttpRequest : ajaxLoader; 253 if (o.status == 200) { 254 if ( typeof selectedOpts.ajax.win == 'function' ) { 255 ret = selectedOpts.ajax.win(href, data, textStatus, XMLHttpRequest); 256 257 if (ret === false) { 258 loading.hide(); 259 return; 260 } else if (typeof ret == 'string' || typeof ret == 'object') { 261 data = ret; 262 } 263 } 264 265 tmp.html( data ); 266 _process_inline(); 267 } 268 } 269 })); 270 271 break; 272 273 case 'iframe': 274 _show(); 275 break; 276 } 277 }, 278 279 _process_inline = function() { 280 var 281 w = selectedOpts.width, 282 h = selectedOpts.height; 283 284 if (w.toString().indexOf('%') > -1) { 285 w = parseInt( ($(window).width() - (selectedOpts.margin * 2)) * parseFloat(w) / 100, 10) + 'px'; 286 287 } else { 288 w = w == 'auto' ? 'auto' : w + 'px'; 289 } 290 291 if (h.toString().indexOf('%') > -1) { 292 h = parseInt( ($(window).height() - (selectedOpts.margin * 2)) * parseFloat(h) / 100, 10) + 'px'; 293 294 } else { 295 h = h == 'auto' ? 'auto' : h + 'px'; 296 } 297 298 tmp.wrapInner('<div style="width:' + w + ';height:' + h + ';overflow: ' + (selectedOpts.scrolling == 'auto' ? 'auto' : (selectedOpts.scrolling == 'yes' ? 'scroll' : 'hidden')) + ';position:relative;"></div>'); 299 300 selectedOpts.width = tmp.width(); 301 selectedOpts.height = tmp.height(); 302 303 _show(); 304 }, 305 306 _process_image = function() { 307 selectedOpts.width = imgPreloader.width; 308 selectedOpts.height = imgPreloader.height; 309 310 $("<img />").attr({ 311 'id' : 'fancybox-img', 312 'src' : imgPreloader.src, 313 'alt' : selectedOpts.title 314 }).appendTo( tmp ); 315 316 _show(); 317 }, 318 319 _show = function() { 320 var pos, equal; 321 322 currentArray = selectedArray; 323 currentIndex = selectedIndex; 324 currentOpts = selectedOpts; 325 326 loading.hide(); 327 328 if (wrap.is(":visible") && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) { 329 $.event.trigger('fancybox-cancel'); 330 331 busy = false;
332 return; 333 } 334 335 busy = true; 336 337 $(content.add( overlay )).unbind(); 338 339 $(window).unbind("resize.fb scroll.fb"); 340 $(document).unbind('keydown.fb'); 341 342 if (wrap.is(":visible") && currentOpts.titlePosition !== 'outside') { 343 wrap.css('height', wrap.height()); 344 } 345 346 if (currentOpts.overlayShow) { 347 overlay.css({ 348 'background-color' : currentOpts.overlayColor, 349 'opacity' : currentOpts.overlayOpacity, 350 'cursor' : currentOpts.hideOnOverlayClick ? 'pointer' : 'auto', 351 'height' : $(document).height() 352 }); 353 354 if (!overlay.is(':visible')) { 355 if (isIE6) { 356 $('select:not(#fancybox-tmp select)').filter(function() { 357 return this.style.visibility !== 'hidden'; 358 }).css({'visibility' : 'hidden'}).one('fancybox-cleanup', function() { 359 this.style.visibility = 'inherit'; 360 }); 361 } 362 363 overlay.show(); 364 } 365 } else { 366 overlay.hide(); 367 } 368 369 final_pos = _get_zoom_to(); 370 371 _process_title(); 372 373 if (wrap.is(":visible")) { 374 $( close.add( nav_left ).add( nav_right ) ).hide(); 375 376 pos = wrap.position(), 377 378 start_pos = { 379 top : pos.top, 380 left : pos.left, 381 width : wrap.width(), 382 height : wrap.height() 383 }; 384 385 equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height); 386 387 content.fadeTo(currentOpts.changeFade, 0.3, function() { 388 var finish_resizing = function() { 389 content.html( tmp.contents() ).fadeTo(currentOpts.changeFade, 1, _finish); 390 }; 391 392 $.event.trigger('fancybox-change'); 393 394 content 395 .empty() 396 .removeAttr('filter') 397 .css({ 398 'border-width' : currentOpts.padding, 399 'width' : final_pos.width - currentOpts.padding * 2, 400 'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2 401 }); 402 403 if (equal) { 404 finish_resizing(); 405 406 } else { 407 fx.prop = 0; 408 409 $(fx).animate({prop: 1}, { 410 duration : currentOpts.changeSpeed, 411 easing : currentOpts.easingChange, 412 step : _draw, 413 complete : finish_resizing 414 }); 415 } 416 }); 417 418 return; 419 } 420 421 wrap.removeAttr("style"); 422 423 content.css('border-width', currentOpts.padding); 424 425 if (currentOpts.transitionIn == 'elastic') { 426 start_pos = _get_zoom_from(); 427 428 content.html( tmp.contents() ); 429 430 wrap.show(); 431 432 if (currentOpts.opacity) { 433 final_pos.opacity = 0; 434 } 435 436 fx.prop = 0; 437 438 $(fx).animate({prop: 1}, { 439 duration : currentOpts.speedIn, 440 easing : currentOpts.easingIn, 441 step : _draw, 442 complete : _finish 443 }); 444 445 return; 446 } 447 448 if (currentOpts.titlePosition == 'inside' && titleHeight > 0) { 449 title.show(); 450 } 451 452 content 453 .css({ 454 'width' : final_pos.width - currentOpts.padding * 2, 455 'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2 456 }) 457 .html( tmp.contents() ); 458 459 wrap 460 .css(final_pos) 461 .fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish ); 462 }, 463 464 _format_title = function(title) { 465 if (title && title.length) { 466 if (currentOpts.titlePosition == 'float') { 467 return '<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">' + title + '</td><td id="fancybox-title-float-right"></td></tr></table>'; 468 } 469 470 return '<div id="fancybox-title-' + currentOpts.titlePosition + '">' + title + '</div>'; 471 } 472 473 return false;
474 }, 475 476 _process_title = function() { 477 titleStr = currentOpts.title || ''; 478 titleHeight = 0; 479 480 title 481 .empty() 482 .removeAttr('style') 483 .removeClass(); 484 485 if (currentOpts.titleShow === false) { 486 title.hide(); 487 return; 488 } 489 490 titleStr = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(titleStr, currentArray, currentIndex, currentOpts) : _format_title(titleStr); 491 492 if (!titleStr || titleStr === '') { 493 title.hide(); 494 return; 495 } 496 497 title 498 .addClass('fancybox-title-' + currentOpts.titlePosition) 499 .html( titleStr ) 500 .appendTo( 'body' ) 501 .show(); 502 503 switch (currentOpts.titlePosition) { 504 case 'inside': 505 title 506 .css({ 507 'width' : final_pos.width - (currentOpts.padding * 2), 508 'marginLeft' : currentOpts.padding, 509 'marginRight' : currentOpts.padding 510 }); 511 512 titleHeight = title.outerHeight(true); 513 514 title.appendTo( outer ); 515 516 final_pos.height += titleHeight; 517 break; 518 519 case 'over': 520 title 521 .css({ 522 'marginLeft' : currentOpts.padding, 523 'width' : final_pos.width - (currentOpts.padding * 2), 524 'bottom' : currentOpts.padding 525 }) 526 .appendTo( outer ); 527 break; 528 529 case 'float': 530 title 531 .css('left', parseInt((title.width() - final_pos.width - 40)/ 2, 10) * -1) 532 .appendTo( wrap ); 533 break; 534 535 default: 536 title 537 .css({ 538 'width' : final_pos.width - (currentOpts.padding * 2), 539 'paddingLeft' : currentOpts.padding, 540 'paddingRight' : currentOpts.padding 541 }) 542 .appendTo( wrap ); 543 break; 544 } 545 546 title.hide(); 547 }, 548 549 _set_navigation = function() { 550 if (currentOpts.enableEscapeButton || currentOpts.enableKeyboardNav) { 551 $(document).bind('keydown.fb', function(e) { 552 if (e.keyCode == 27 && currentOpts.enableEscapeButton) { 553 e.preventDefault(); 554 $.fancybox.close(); 555 556 } else if ((e.keyCode == 37 || e.keyCode == 39) && currentOpts.enableKeyboardNav && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') { 557 e.preventDefault(); 558 $.fancybox[ e.keyCode == 37 ? 'prev' : 'next'](); 559 } 560 }); 561 } 562 563 if (!currentOpts.showNavArrows) { 564 nav_left.hide(); 565 nav_right.hide(); 566 return; 567 } 568 569 if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) { 570 nav_left.show(); 571 } 572 573 if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) { 574 nav_right.show(); 575 } 576 }, 577 578 _finish = function () { 579 if (!$.support.opacity) { 580 content.get(0).style.removeAttribute('filter'); 581 wrap.get(0).style.removeAttribute('filter'); 582 } 583 584 if (selectedOpts.autoDimensions) { 585 content.css('height', 'auto'); 586 } 587 588 wrap.css('height', 'auto'); 589 590 if (titleStr && titleStr.length) { 591 title.show(); 592 } 593 594 if (currentOpts.showCloseButton) { 595 close.show(); 596 } 597 598 _set_navigation(); 599 600 if (currentOpts.hideOnContentClick) { 601 content.bind('click', $.fancybox.close); 602 } 603 604 if (currentOpts.hideOnOverlayClick) { 605 overlay.bind('click', $.fancybox.close); 606 } 607 608 $(window).bind("resize.fb", $.fancybox.resize); 609 610 if (currentOpts.centerOnScroll) { 611 $(window).bind("scroll.fb", $.fancybox.center); 612 } 613 614 if (currentOpts.type == 'iframe') { 615 $('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" ' + ($.browser.msie ? 'allowtransparency="true""' : '') + ' scrolling="' + selectedOpts.scrolling + '" src="' + currentOpts.href + '"></iframe>').appendTo(content); 616 } 617 618 wrap.show(); 619 620 busy = false;
621 622 $.fancybox.center(); 623 624 currentOpts.onComplete(currentArray, currentIndex, currentOpts); 625 626 _preload_images(); 627 }, 628 629 _preload_images = function() { 630 var href, 631 objNext; 632 633 if ((currentArray.length -1) > currentIndex) { 634 href = currentArray[ currentIndex + 1 ].href; 635 636 if (typeof href !== 'undefined' && href.match(imgRegExp)) { 637 objNext = new Image(); 638 objNext.src = href; 639 } 640 } 641 642 if (currentIndex > 0) { 643 href = currentArray[ currentIndex - 1 ].href; 644 645 if (typeof href !== 'undefined' && href.match(imgRegExp)) { 646 objNext = new Image(); 647 objNext.src = href; 648 } 649 } 650 }, 651 652 _draw = function(pos) { 653 var dim = { 654 width : parseInt(start_pos.width + (final_pos.width - start_pos.width) * pos, 10), 655 height : parseInt(start_pos.height + (final_pos.height - start_pos.height) * pos, 10), 656 657 top : parseInt(start_pos.top + (final_pos.top - start_pos.top) * pos, 10), 658 left : parseInt(start_pos.left + (final_pos.left - start_pos.left) * pos, 10) 659 }; 660 661 if (typeof final_pos.opacity !== 'undefined') { 662 dim.opacity = pos < 0.5 ? 0.5 : pos; 663 } 664 665 wrap.css(dim); 666 667 content.css({ 668 'width' : dim.width - currentOpts.padding * 2, 669 'height' : dim.height - (titleHeight * pos) - currentOpts.padding * 2 670 }); 671 }, 672 673 _get_viewport = function() { 674 return [ 675 $(window).width() - (currentOpts.margin * 2), 676 $(window).height() - (currentOpts.margin * 2), 677 $(document).scrollLeft() + currentOpts.margin, 678 $(document).scrollTop() + currentOpts.margin 679 ]; 680 }, 681 682 _get_zoom_to = function () { 683 var view = _get_viewport(), 684 to = {}, 685 resize = currentOpts.autoScale, 686 double_padding = currentOpts.padding * 2, 687 ratio; 688 689 if (currentOpts.width.toString().indexOf('%') > -1) { 690 to.width = parseInt((view[0] * parseFloat(currentOpts.width)) / 100, 10); 691 } else { 692 to.width = currentOpts.width + double_padding; 693 } 694 695 if (currentOpts.height.toString().indexOf('%') > -1) { 696 to.height = parseInt((view[1] * parseFloat(currentOpts.height)) / 100, 10); 697 } else { 698 to.height = currentOpts.height + double_padding; 699 } 700 701 if (resize && (to.width > view[0] || to.height > view[1])) { 702 if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') { 703 ratio = (currentOpts.width ) / (currentOpts.height ); 704 705 if ((to.width ) > view[0]) { 706 to.width = view[0]; 707 to.height = parseInt(((to.width - double_padding) / ratio) + double_padding, 10); 708 } 709 710 if ((to.height) > view[1]) { 711 to.height = view[1]; 712 to.width = parseInt(((to.height - double_padding) * ratio) + double_padding, 10); 713 } 714 715 } else { 716 to.width = Math.min(to.width, view[0]); 717 to.height = Math.min(to.height, view[1]); 718 } 719 } 720 721 to.top = parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - to.height - 40) * 0.5)), 10); 722 to.left = parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - to.width - 40) * 0.5)), 10); 723 724 return to; 725 }, 726 727 _get_obj_pos = function(obj) { 728 var pos = obj.offset(); 729 730 pos.top += parseInt( obj.css('paddingTop'), 10 ) || 0; 731 pos.left += parseInt( obj.css('paddingLeft'), 10 ) || 0; 732 733 pos.top += parseInt( obj.css('border-top-width'), 10 ) || 0; 734 pos.left += parseInt( obj.css('border-left-width'), 10 ) || 0; 735 736 pos.width = obj.width(); 737 pos.height = obj.height(); 738 739 return pos; 740 }, 741 742 _get_zoom_from = function() { 743 var orig = selectedOpts.orig ? $(selectedOpts.orig) : false, 744 from = {}, 745 pos, 746 view; 747 748 if (orig && orig.length) { 749 pos = _get_obj_pos(orig); 750 751 from = { 752 width : pos.width + (currentOpts.padding * 2), 753 height : pos.height + (currentOpts.padding * 2), 754 top : pos.top - currentOpts.padding - 20, 755 left : pos.left - currentOpts.padding - 20 756 }; 757 758 } else { 759 view = _get_viewport(); 760 761 from = { 762 width : currentOpts.padding * 2, 763 height : currentOpts.padding * 2,
764 top : parseInt(view[3] + view[1] * 0.5, 10), 765 left : parseInt(view[2] + view[0] * 0.5, 10) 766 }; 767 } 768 769 return from; 770 }, 771 772 _animate_loading = function() { 773 if (!loading.is(':visible')){ 774 clearInterval(loadingTimer); 775 return; 776 } 777 778 $('div', loading).css('top', (loadingFrame * -40) + 'px'); 779 780 loadingFrame = (loadingFrame + 1) % 12; 781 }; 782 783 /* 784 * Public methods 785 */ 786 787 $.fn.fancybox = function(options) { 788 if (!$(this).length) { 789 return this; 790 } 791 792 $(this) 793 .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {}))) 794 .unbind('click.fb') 795 .bind('click.fb', function(e) { 796 e.preventDefault(); 797 798 if (busy) { 799 return; 800 } 801 802 busy = true; 803 804 $(this).blur(); 805 806 selectedArray = []; 807 selectedIndex = 0; 808 809 var rel = $(this).attr('rel') || ''; 810 811 if (!rel || rel == '' || rel === 'nofollow') { 812 selectedArray.push(this); 813 814 } else { 815 selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]"); 816 selectedIndex = selectedArray.index( this ); 817 } 818 819 _start(); 820 821 return; 822 }); 823 824 return this; 825 }; 826 827 $.fancybox = function(obj) { 828 var opts; 829 830 if (busy) { 831 return; 832 } 833 834 busy = true; 835 opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {}; 836 837 selectedArray = []; 838 selectedIndex = parseInt(opts.index, 10) || 0; 839 840 if ($.isArray(obj)) { 841 for (var i = 0, j = obj.length; i < j; i++) { 842 if (typeof obj[i] == 'object') { 843 $(obj[i]).data('fancybox', $.extend({}, opts, obj[i])); 844 } else { 845 obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts)); 846 } 847 } 848 849 selectedArray = jQuery.merge(selectedArray, obj); 850 851 } else { 852 if (typeof obj == 'object') { 853 $(obj).data('fancybox', $.extend({}, opts, obj)); 854 } else { 855 obj = $({}).data('fancybox', $.extend({content : obj}, opts)); 856 } 857 858 selectedArray.push(obj); 859 } 860 861 if (selectedIndex > selectedArray.length || selectedIndex < 0) { 862 selectedIndex = 0; 863 } 864 865 _start(); 866 }; 867 868 $.fancybox.showActivity = function() { 869 clearInterval(loadingTimer); 870 871 loading.show(); 872 loadingTimer = setInterval(_animate_loading, 66); 873 }; 874 875 $.fancybox.hideActivity = function() { 876 loading.hide(); 877 }; 878 879 $.fancybox.next = function() { 880 return $.fancybox.pos( currentIndex + 1); 881 }; 882 883 $.fancybox.prev = function() { 884 return $.fancybox.pos( currentIndex - 1); 885 }; 886 887 $.fancybox.pos = function(pos) { 888 if (busy) { 889 return; 890 } 891 892 pos = parseInt(pos); 893 894 selectedArray = currentArray; 895 896 if (pos > -1 && pos < currentArray.length) { 897 selectedIndex = pos; 898 _start(); 899 900 } else if (currentOpts.cyclic && currentArray.length > 1) { 901 selectedIndex = pos >= currentArray.length ? 0 : currentArray.length - 1; 902 _start(); 903 } 904 905 return; 906 }; 907 908 $.fancybox.cancel = function() { 909 if (busy) { 910 return; 911 } 912 913 busy = true; 914 915 $.event.trigger('fancybox-cancel'); 916 917 _abort(); 918 919 selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts); 920 921 busy = false; 922 }; 923 924 // Note: within an iframe use - parent.$.fancybox.close(); 925 $.fancybox.close = function() { 926 if (busy || wrap.is(':hidden')) { 927 return; 928 } 929 930 busy = true; 931 932 if (currentOpts && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) { 933 busy = false; 934 return; 935 } 936 937 _abort(); 938 939 $(close.add( nav_left ).add( nav_right )).hide(); 940 941 $(content.add( overlay )).unbind(); 942 943 $(window).unbind("resize.fb scroll.fb"); 944 $(document).unbind('keydown.fb'); 945 946 content.find('iframe').attr('src', isIE6 && /^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank'); 947 948 if (currentOpts.titlePosition !== 'inside') { 949 title.empty(); 950 } 951 952 wrap.stop(); 953 954 function _cleanup() { 955 overlay.fadeOut('fast'); 956 957 title.empty().hide(); 958 wrap.hide(); 959 960 $.event.trigger('fancybox-cleanup'); 961 962 content.empty(); 963 964 currentOpts.onClosed(currentArray, currentIndex, currentOpts); 965 966 currentArray = selectedOpts = []; 967 currentIndex = selectedIndex = 0; 968 currentOpts = selectedOpts = {}; 969 970 busy = false;
971 } 972 973 if (currentOpts.transitionOut == 'elastic') { 974 start_pos = _get_zoom_from(); 975 976 var pos = wrap.position(); 977 978 final_pos = { 979 top : pos.top , 980 left : pos.left, 981 width : wrap.width(), 982 height : wrap.height() 983 }; 984 985 if (currentOpts.opacity) { 986 final_pos.opacity = 1; 987 } 988 989 title.empty().hide(); 990 991 fx.prop = 1; 992 993 $(fx).animate({ prop: 0 }, { 994 duration : currentOpts.speedOut, 995 easing : currentOpts.easingOut, 996 step : _draw, 997 complete : _cleanup 998 }); 999 1000 } else { 1001 wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup); 1002 } 1003 }; 1004 1005 $.fancybox.resize = function() { 1006 if (overlay.is(':visible')) { 1007 overlay.css('height', $(document).height()); 1008 } 1009 1010 $.fancybox.center(true); 1011 }; 1012 1013 $.fancybox.center = function() { 1014 var view, align; 1015 1016 if (busy) { 1017 return; 1018 } 1019 1020 align = arguments[0] === true ? 1 : 0; 1021 view = _get_viewport(); 1022 1023 if (!align && (wrap.width() > view[0] || wrap.height() > view[1])) { 1024 return; 1025 } 1026 1027 wrap 1028 .stop() 1029 .animate({ 1030 'top' : parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - content.height() - 40) * 0.5) - currentOpts.padding)), 1031 'left' : parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - content.width() - 40) * 0.5) - currentOpts.padding)) 1032 }, typeof arguments[0] == 'number' ? arguments[0] : 200); 1033 }; 1034 1035 $.fancybox.init = function() { 1036 if ($("#fancybox-wrap").length) { 1037 return; 1038 } 1039 1040 $('body').append( 1041 tmp = $('<div id="fancybox-tmp"></div>'), 1042 loading = $('<div id="fancybox-loading"><div></div></div>'), 1043 overlay = $('<div id="fancybox-overlay"></div>'), 1044 wrap = $('<div id="fancybox-wrap"></div>') 1045 ); 1046 1047 outer = $('<div id="fancybox-outer"></div>') 1048 .append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>') 1049 .appendTo( wrap ); 1050 1051 outer.append( 1052 content = $('<div id="fancybox-content"></div>'), 1053 close = $('<a id="fancybox-close"><img src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="1" height="1" alt="Close popup" /></a>'), 1054 title = $('<div id="fancybox-title"></div>'), 1055 1056 nav_left = $('<a href="javascript:;" id="fancybox-left"><img src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="1" height="1" alt="Navigate left" /><span class="fancy-ico" id="fancybox-left-ico"></span></a>'), 1057 nav_right = $('<a href="javascript:;" id="fancybox-right"><img src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="1" height="1" alt="Navigate right" /><span class="fancy-ico" id="fancybox-right-ico"></span></a>') 1058 ); 1059 1060 close.click($.fancybox.close); 1061 loading.click($.fancybox.cancel); 1062 1063 nav_left.click(function(e) { 1064 e.preventDefault(); 1065 $.fancybox.prev(); 1066 }); 1067 1068 nav_right.click(function(e) { 1069 e.preventDefault(); 1070 $.fancybox.next(); 1071 }); 1072 1073 if ($.fn.mousewheel) { 1074 wrap.bind('mousewheel.fb', function(e, delta) { 1075 if (busy) { 1076 e.preventDefault(); 1077 1078 } else if ($(e.target).get(0).clientHeight == 0 || $(e.target).get(0).scrollHeight === $(e.target).get(0).clientHeight) { 1079 e.preventDefault(); 1080 $.fancybox[ delta > 0 ? 'prev' : 'next'](); 1081 } 1082 }); 1083 } 1084 1085 if (!$.support.opacity) { 1086 wrap.addClass('fancybox-ie'); 1087 } 1088 1089 if (isIE6) { 1090 loading.addClass('fancybox-ie6'); 1091 wrap.addClass('fancybox-ie6'); 1092 1093 $('<iframe id="fancybox-hide-sel-frame" src="' + (/^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank' ) + '" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(outer); 1094 } 1095 }; 1096 1097 $.fn.fancybox.defaults = { 1098 padding : 10, 1099 margin : 40, 1100 opacity : false, 1101 modal : false, 1102 cyclic : false, 1103 scrolling : 'auto', // 'auto', 'yes' or 'no' 1104 1105 width : 560, 1106 height : 340, 1107 1108 autoScale : true, 1109 autoDimensions : true, 1110 centerOnScroll : false, 1111 1112 ajax : {}, 1113 swf : { wmode: 'transparent' }, 1114 1115 hideOnOverlayClick : true, 1116 hideOnContentClick : false, 1117 1118 overlayShow : true, 1119 overlayOpacity : 0.7, 1120 overlayColor : '#777', 1121 1122 titleShow : true, 1123 titlePosition : 'float', // 'float', 'outside', 'inside' or 'over' 1124 titleFormat : null, 1125 titleFromAlt : false, 1126 1127 transitionIn : 'fade', // 'elastic', 'fade' or 'none' 1128 transitionOut : 'fade', // 'elastic', 'fade' or 'none' 1129 1130 speedIn : 300, 1131 speedOut : 300, 1132 1133 changeSpeed : 300, 1134 changeFade : 'fast', 1135 1136 easingIn : 'swing', 1137 easingOut : 'swing', 1138 1139 showCloseButton : true, 1140 showNavArrows : true, 1141 enableEscapeButton : true, 1142 enableKeyboardNav : true, 1143 1144 onStart : function(){}, 1145 onCancel : function(){}, 1146 onComplete : function(){}, 1147 onCleanup : function(){}, 1148 onClosed : function(){}, 1149 onError : function(){} 1150 }; 1151 1152 $(document).ready(function() { 1153 $.fancybox.init(); 1154 }); 1155 1156 })(jQuery); 1157}); 1158 1159BONZ.FancyBox = (function() { 1160 var exports = this; 1161 1162 //-------------------------------------------------------------------------- 1163 exports.initialize = function(targets, type, options) { 1164 $(targets).each(function() { 1165 $(this).fancybox(getParams($(this), type, options)); 1166 }); 1167 }; 1168 1169 // -------------------------------------------------------------------------- 1170 // private 1171 // -------------------------------------------------------------------------- 1172 1173 //-------------------------------------------------------------------------- 1174 var getParams = function(anchor, type, options) { 1175 var params = { 1176 hideOnContentClick : false, 1177 hideOnOverlayClick : true, 1178 overlayOpacity : 0.5, 1179 autoScale : true, 1180 autoDimensions : false, 1181 centerOnScroll : false, 1182 type : type, 1183 padding: 0, 1184 onComplete : function(a, b, c) { 1185 // If we've specified some additional onComplete callback functionality 1186 if (typeof(options) != 'undefined' && typeof(options.onComplete) != 'undefined') { 1187 options.onComplete(anchor); 1188 } 1189 } 1190 }; 1191 1192 if (type == 'iframe') { 1193 params.href = anchor.attr('href').replace(new RegExp('watch\\?v=', 'i'), 'embed/') + "?autoplay=1&fs=1&hd=1&showinfo=0&rel=0"; 1194 params.height = 496; 1195 params.width = 680; 1196 params.showNavArrows = false;
1197 } 1198 return params; 1199 }; 1200 1201 return exports; 1202}()); 1203 1204BONZ.AddToCartComplete = (function() { 1205 var exports = {}; 1206 1207 // -------------------------------------------------------------------------- 1208 exports.initialize = function() { 1209 initWarrantyModule(); 1210 1211 BONZ.ItemRecommendations.initialize(true); 1212 BONZ.NewsletterSubscriptionBanner.initialize(); 1213 }; 1214 1215 // ----------------------------------------------------------------------------- 1216 // private 1217 // ----------------------------------------------------------------------------- 1218 1219 // ----------------------------------------------------------------------------- 1220 var initWarrantyModule = function() { 1221 $(".warranty_expandable_link").click(function(e) { 1222 e.preventDefault(); 1223 1224 $(this).toggleClass("is_open"); 1225 $(".warranty_terms_container").slideToggle(); 1226 }); 1227 }; 1228 1229 // -------------------------------------------------------------------------- 1230 return exports; 1231}()); 1232 1233BONZ.ItemShow = (function() { 1234 var SOCIAL_SHARE_OPTIONS = [ "facebook", "pinterest", "twitter" ]; 1235 var exports = {}; 1236 1237 // ---------------------------------------------------------------------------- 1238 exports.initializeAdwordsLabel = function(itemId, adwordsLabelId, currentTime) { 1239 if (store.enabled) { 1240 var containerString = "item_" + itemId; 1241 store.set(containerString, { 1242 adwords_label_id: adwordsLabelId, 1243 set_on: currentTime 1244 }); 1245 } 1246 }; 1247 1248 // ---------------------------------------------------------------------------- 1249 exports.initializePaypalPaymentMethods = function() { 1250 if (typeof(paypal) === "undefined") { 1251 // TODO handle this 1252 console.log("paypal undefined"); 1253 } 1254 else { 1255 var fundingSources = {}; 1256 var creditEligible = false; 1257 1258 fundingSources[paypal.FUNDING.VENMO] = "venmo"; 1259 fundingSources[paypal.FUNDING.CREDIT] = "paypal_credit"; 1260 fundingSources[paypal.FUNDING.PAYLATER] = "paypal_credit"; 1261 1262 // Loop over each funding source / payment method 1263 $(Object.keys(fundingSources)).each(function(_index) { 1264 // Initialize the buttons 1265 var button = paypal.Buttons({ 1266 fundingSource: this.valueOf() 1267 }); 1268 1269 // If the button is eligible, show the corresponding funding icon 1270 if (button.isEligible()) { 1271 $("." + fundingSources[this]).removeClass("unavailable"); 1272 1273 if (this == paypal.FUNDING.CREDIT || this == paypal.FUNDING.PAYLATER) { 1274 creditEligible = true; 1275 } 1276 } 1277 }); 1278 1279 if (!creditEligible) { 1280 $(".paypal_credit_message").addClass("unavailable"); 1281 } 1282 } 1283 }; 1284 1285 // ---------------------------------------------------------------------------- 1286 exports.initialize = function() { 1287 BONZ.ItemShow.AddToCart.initialize(); 1288 1289 // email popup 1290 initEmailPopup(); 1291 1292 // quantity select 1293 initItemQuantitySelect(); 1294 1295 // item personalization 1296 initItemPersonalization(); 1297 1298 // follow seller 1299 initFollowSellerButton(); 1300 1301 // expandable item details 1302 initItemDetailsExpansion(); 1303 1304 // show complete details 1305 initFullItemDetailsExpansion(); 1306 1307 // related items 1308 initRelatedItems(".item_listing_related_booth_items"); 1309 1310 // gift cards 1311 initRelatedItems(".gift_card_items"); 1312 1313 // ad banner items 1314 initAdBannerItems(); 1315 1316 // discounts banner 1317 initDiscountsBanner(); 1318 1319 // social share links 1320 initSocialShareLinks(); 1321 1322 // shipping calculation 1323 initShippingCalculation(); 1324 1325 // init report as miscataloged popup 1326 initReportMiscataloged(); 1327 1328 // item traits section 1329 initItemTraits(); 1330 1331 // hand picked list actions 1332 intiHandPickedListActions(); 1333 1334 // curated guide actions 1335 initCuratedGuideActions(); 1336 1337 // item description 1338 initItemDescription(); 1339 1340 // item referral box edit 1341 initItemReferralBoxEditPopup(); 1342 1343 // "Find item reviews on eBay" 1344 initEbayReviewLink(); 1345 }; 1346 1347 // ---------------------------------------------------------------------------- 1348 // private 1349 // ---------------------------------------------------------------------------- 1350 1351 // ----------------------------------------------------------------------------- 1352 var initEmailPopup = function() { 1353 if (BONZ.isMobile) { return; } 1354 1355 $('.contact_seller').click(function(e) { 1356 e.preventDefault(); 1357 $("#email_form").jqm({ modal: true }).jqmShow(); 1358 }); 1359 1360 $(".email_cancel_button").click(function(e) { 1361 e.preventDefault(); 1362 BONZ.Application.hideAllPopups(); 1363 }); 1364 }; 1365 1366 // ----------------------------------------------------------------------------- 1367 var initFollowSellerButton = function() { 1368 var allFollowButtons = $(".seller_details_contact_button.follow_seller"); 1369 allFollowButtons.click(function(e) { 1370 e.preventDefault(); 1371 1372 var button = $(this); 1373 var newClass = button.hasClass("following") ? "not_following" : "following"; 1374 1375 allFollowButtons.removeClass("following not_following").addClass("loading"); 1376 1377 $.ajax({ 1378 url: button.attr("href"), 1379 dataType: "json", 1380 complete: function() { 1381 allFollowButtons.removeClass("loading").addClass(newClass); 1382 allFollowButtons.find(".not_following_text, .following_text").toggleClass("is_hidden"); 1383 } 1384 }); 1385 }); 1386 }; 1387 1388 // ----------------------------------------------------------------------------- 1389 var initSocialShareLinks = function() { 1390 $(".additional_action_link.social_share").click(function(e) { 1391 e.preventDefault(); 1392 $(".social_share_options_container").slideToggle(); 1393 }); 1394 1395 $(".social_share_options a").click(function() { 1396 var clickedButton = $(this); 1397 var buttonClass = clickedButton.attr("class"); 1398 var shareContainer = clickedButton.parents(".social_share_options");
1399 var shouldRecordShare = shareContainer.data("booth-owner-sharing") && 1400 SOCIAL_SHARE_OPTIONS.indexOf(buttonClass) >= 0; 1401 1402 // track the share 1403 if (buttonClass != "email_share") { 1404 var capitalizedClass = buttonClass.charAt(0).toUpperCase() + buttonClass.slice(1); 1405 1406 if (typeof(gtag) !== "undefined") { 1407 gtag('event', "social_share", { action: "Click-item", medium: capitalizedClass }); 1408 } 1409 } 1410 1411 // we record when a seller shares their own item via social media 1412 // so we can give them credit on their seller checklist 1413 if (shouldRecordShare) { 1414 $.ajax("/booths/set", { 1415 type: "POST", 1416 data: { "_method": "PUT", "id": shareContainer.data("booth-id"), "key": "shared_own_item_on_social_media", "value": true } 1417 }); 1418 } 1419 }); 1420 }; 1421 1422 // ---------------------------------------------------------------------------- 1423 var updateQuantityButtons = function(quantityButtons, proposedQuantity, maxQuantity) { 1424 var addButton = quantityButtons.filter(".add"); 1425 var subtractButton = quantityButtons.filter(".subtract"); 1426 1427 if (proposedQuantity == maxQuantity) { 1428 addButton.addClass("disabled"); 1429 subtractButton.removeClass("disabled"); 1430 } else if (proposedQuantity == 1) { 1431 subtractButton.addClass("disabled"); 1432 if (maxQuantity > 1) { 1433 addButton.removeClass("disabled"); 1434 } 1435 } else { 1436 quantityButtons.removeClass("disabled"); 1437 } 1438 }; 1439 1440 // ---------------------------------------------------------------------------- 1441 var initItemQuantitySelect = function() { 1442 var quantitySelectContainer = $(".add_item_to_cart_form .item_quantity_select"); 1443 var quantityButtons = $(".quantity_button", quantitySelectContainer); 1444 var quantityDropdown = $(".quantity_dropdown", quantitySelectContainer); 1445 var quantityField = $("#item_to_add_quantity", quantitySelectContainer); 1446 var maxQuantity = parseInt(quantitySelectContainer.data("max-quantity")); 1447 1448 quantityDropdown.change(function() { 1449 var proposedQuantity = parseInt(quantityDropdown.val()); 1450 updateQuantityButtons(quantityButtons, proposedQuantity, maxQuantity); 1451 }); 1452 1453 quantityButtons.click(function() { 1454 var button = $(this); 1455 1456 if (button.hasClass("disabled")) { return; } 1457 1458 var currentQuantity = parseInt(quantityDropdown.val()); 1459 var proposedQuantity = button.hasClass("add") ? currentQuantity + 1 : currentQuantity - 1; 1460 1461 if (proposedQuantity > maxQuantity || proposedQuantity < 1) { 1462 proposedQuantity = currentQuantity; 1463 } else { 1464 updateQuantityButtons(quantityButtons, proposedQuantity, maxQuantity); 1465 } 1466 1467 if (quantityDropdown.children("option[value='" + proposedQuantity + "']").length > 0) { 1468 quantityDropdown.val(proposedQuantity); 1469 } else { 1470 quantityDropdown.append($('<option>', { 1471 value: proposedQuantity, 1472 text: proposedQuantity, 1473 selected: true 1474 })); 1475 } 1476 quantityField.val(proposedQuantity); 1477 }); 1478 }; 1479 1480 // ---------------------------------------------------------------------------- 1481 var initItemPersonalization = function() { 1482 var colorTimeout = null; 1483 1484 $(".personal_input").on("change keyup paste input", function(){ 1485 var inputField = $(this); 1486 var maxCharsContainer = inputField.siblings(".max_characters_label"); 1487 var maxChars = parseInt(maxCharsContainer.children(".max_characters").text()); 1488 1489 if(inputField.val().length > maxChars) { 1490 inputField.val(inputField.val().slice(0, maxChars)); 1491 clearTimeout(colorTimeout); 1492 maxCharsContainer.addClass("maximum"); 1493 colorTimeout = setTimeout(function() { maxCharsContainer.removeClass("maximum") } , 800); 1494 } else if (inputField.val().length < maxChars) { 1495 clearTimeout(colorTimeout); 1496 maxCharsContainer.removeClass("maximum"); 1497 } 1498 }); 1499 }; 1500 1501 // ---------------------------------------------------------------------------- 1502 var initFullItemDetailsExpansion = function() { 1503 $(".show_full_listing").click(function(e) { 1504 e.preventDefault(); 1505 1506 $(".item_listing_full_info").show(); 1507 $(this).hide(); 1508 }); 1509 }; 1510 1511 // ---------------------------------------------------------------------------- 1512 var initItemDetailsExpansion = function() { 1513 $(".expandable_details_link").click(function(e) { 1514 e.preventDefault(); 1515 1516 var link = $(this); 1517 1518 link.toggleClass("is_open"); 1519 link.parents(".additional_detail").next(".additional_details_subsection.expandable").slideToggle(); 1520 }); 1521 }; 1522 1523 // ---------------------------------------------------------------------------- 1524 var initShippingCalculation = function() { 1525 // we know user's zip - they just need to click a link 1526 $(".get_shipping_cost_link").click(function(e) { 1527 e.preventDefault(); 1528 1529 var link = $(this); 1530 var linkContainer = link.parent(); 1531 var spinner = linkContainer.siblings(".additional_details_spinner"); 1532 1533 linkContainer.hide(); 1534 spinner.removeClass("is_hidden"); 1535 1536 $.ajax({ 1537 url: link.attr("href"), 1538 type: "POST", 1539 dataType: "HTML", 1540 success: function(response) { 1541 linkContainer.text(response); 1542 spinner.addClass("is_hidden"); 1543 linkContainer.show(); 1544 } 1545 }); 1546 }); 1547 1548 // we don't know user's zip - they had to enter it into a form 1549 $(".postal_code_form").submit(function(e) { 1550 e.preventDefault(); 1551 1552 var form = $(this); 1553 var formContainer = form.parent(); 1554 var errorContainer = $(".postal_code_form_error_container"); 1555 var submitButton = $(".postal_code_form_submit_button", form); 1556 var spinner = $(".additional_details_spinner", form); 1557 var zipFieldVal = form.find(".zip_field").val(); 1558 1559 // if they left the form blank, do nothing 1560 if (!zipFieldVal) { return; } 1561 1562 submitButton.hide(); 1563 spinner.removeClass("is_hidden"); 1564 1565 $.ajax({ 1566 url: form.attr("action"), 1567 type: "POST", 1568 dataType: "JSON", 1569 data: { get_zip_form: { zip: zipFieldVal } }, 1570 success: function(response) { 1571 if (response["shipping_text"]) { 1572 formContainer.prev(".additional_detail").find(".details_text").text(response["shipping_text"]); 1573 formContainer.hide(); 1574 } else { 1575 errorContainer.text(response["error"]).show(); 1576 spinner.addClass("is_hidden"); 1577 submitButton.show(); 1578 } 1579 } 1580 }); 1581 }); 1582 }; 1583 1584 // -------------------------------------------------------------------------- 1585 // Fills all item_listing_related_booth_items containers on the page with the 1586 // same items; means there is only one call to grab related items. 1587 // You can specify data-max-items on the container to have it show fewer items. 1588 var initRelatedItems = function(container_selector) { 1589 var containers = $(container_selector || ".item_listing_related_booth_items"); 1590 if (containers.length == 0) { 1591 return; 1592 } 1593 1594 $.ajax({ 1595 type: "GET", 1596 url: containers.first().data("url"), 1597 dataType: "html", 1598 success: function(response) { 1599 var responseObject = $(response); 1600 var relatedItemsCount = responseObject.children(".related_booth_item_container").length; 1601 1602 // fill in each container with the items we were given 1603 if (relatedItemsCount > 0) { 1604 containers.each(function(index, container) { 1605 var containerObject = $(container); 1606 var maxItems = parseInt(containerObject.data("max-items")); 1607 1608 if (maxItems > 0 && relatedItemsCount > maxItems) { 1609 // if the container has specified max items, we'll remove any extras 1610 var responseClone = responseObject.clone(); 1611 var responseCloneChildren = responseClone.children(".related_booth_item_container").not(".booth_item_count"); 1612 1613 // remove any items beyond the specified max 1614 responseCloneChildren.slice(maxItems, responseCloneChildren.length).remove(); 1615 1616 containerObject.append(responseClone); 1617 } else { 1618 containerObject.append(responseObject.clone()); 1619 } 1620 1621 // special HTML class for styling containers that only have a few items 1622 if (relatedItemsCount <= 3) { 1623 containerObject.addClass("small_item_count") 1624 } 1625 1626 containerObject.find(".loading").hide(); 1627 }); 1628 } else { 1629 containers.remove(); 1630 } 1631 }, 1632 error: function() { 1633 BONZ.Application.suppressAjaxError = true; 1634 containers.remove(); 1635 } 1636 }); 1637 }; 1638 1639 // -------------------------------------------------------------------------- 1640 // Fills all item_listing_related_booth_items containers on the page with the 1641 // same items; means there is only one call to grab related items. 1642 // You can specify data-max-items on the container to have it show fewer items. 1643 var initAdBannerItems = function() { 1644 var containers = $(".ad_banner_items"); 1645 if (containers.length === 0) { 1646 return; 1647 } 1648 1649 $.ajax({ 1650 type: "GET", 1651 url: containers.first().data("url"), 1652 dataType: "html", 1653 success: function(response) { 1654 var responseObject = $(response); 1655 var relatedItemsCount = responseObject.children(".related_booth_item_container").length; 1656 1657 // fill in each container with the items we were given 1658 if (relatedItemsCount > 0) { 1659 containers.each(function(index, container) { 1660 var containerObject = $(container); 1661 var maxItems = parseInt(containerObject.data("max-items")); 1662 1663 if (maxItems > 0 && relatedItemsCount > maxItems) { 1664 // if the container has specified max items, we'll remove any extras 1665 var responseClone = responseObject.clone(); 1666 var responseCloneChildren = responseClone.children(".related_booth_item_container").not(".booth_item_count"); 1667 1668 // remove any items beyond the specified max 1669 responseCloneChildren.slice(maxItems, responseCloneChildren.length).remove(); 1670 1671 containerObject.append(responseClone); 1672 } else { 1673 containerObject.append(responseObject.clone()); 1674 } 1675 1676 // special HTML class for styling containers that only have a few items 1677 if (relatedItemsCount <= 3) { 1678 containerObject.addClass("small_item_count") 1679 } 1680 1681 containerObject.find(".loading").hide(); 1682 }); 1683 } else { 1684 containers.remove(); 1685 } 1686 }, 1687 error: function() { 1688 BONZ.Application.suppressAjaxError = true; 1689 containers.remove(); 1690 } 1691 }); 1692 }; 1693 1694 // -------------------------------------------------------------------------- 1695 var initDiscountsBanner = function() { 1696 $('.discounts_expander').click(function() { 1697 $('.discount_list').slideToggle(); 1698 $('.expander_label_open').toggle(); 1699 $('.expander_label_closed').toggle(); 1700 $('.discounts_expander').toggleClass("closed open"); 1701 }); 1702 }; 1703 1704 // -------------------------------------------------------------------------- 1705 var initReportMiscataloged = function() { 1706 var hidePopup = function() { $('#miscatalog_popup_container').jqmHide() }; 1707 $(".report_miscataloged_button").click(function() { 1708 $.ajax({ 1709 type: "POST", 1710 url: $(this).data("url"), 1711 before: function() { $('#miscatalog_spin').show(); }, 1712 complete: function(response) { 1713 $('#miscatalog_popup_container'). 1714 html('Thanks for your report! We will review your feedback shortly.'). 1715 delay(2000). 1716 fadeOut('fast', hidePopup) 1717 } 1718 }); 1719 });
1720 $(".report_miscatalog_cancel").click(hidePopup); 1721 BONZ.Application.setupPopup("#miscatalog_popup_container", { modal: false }). 1722 jqmAddTrigger(".report_miscataloged"); 1723 }; 1724 1725 // -------------------------------------------------------------------------- 1726 var initItemDescription = function() { 1727 // cap the item description load time to 10s, so as to not let the user wait too long 1728 setTimeout(function() { 1729 BONZ.Util.resizeIframe($("#item_description_iframe")); 1730 }, 10000); 1731 1732 var descriptionContainer = $(".item_listing_item_description .item_description_inner"); 1733 var plainTextParent = descriptionContainer.children(".plain_text_description_container"); 1734 var plainTextDescription = plainTextParent.children(".plain_text_description"); 1735 if (plainTextDescription.length > 0) { 1736 var plainTextDescriptionUrl = plainTextDescription.data("url"); 1737 1738 // plain text description is loaded async 1739 // as the work to convert the description can be heavy 1740 $(window).load(function() { 1741 $.ajax({ 1742 type: "GET", 1743 url: plainTextDescriptionUrl, 1744 complete: function(response) { 1745 plainTextDescription.html(response[ "responseText" ]); 1746 1747 // determine if we need the links to expand/collapse description 1748 var plainTextEl = plainTextDescription[ 0 ]; 1749 if (plainTextEl.scrollHeight > plainTextEl.offsetHeight) { 1750 $(".description_toggle_links_container").removeClass("disabled"); 1751 } 1752 1753 // remove loading classes 1754 plainTextParent.removeClass("loading"); 1755 plainTextDescription.removeClass("loading"); 1756 1757 // plain text is the only description on mobile, 1758 // so it needs to control the loading overlay 1759 // (normally the iframe/html description does) 1760 if (BONZ.isMobile) { 1761 plainTextParent.siblings(".loading_overlay").hide(); 1762 plainTextParent.show(); 1763 descriptionContainer.css("min-height", 0); 1764 } 1765 } 1766 }); 1767 }); 1768 } 1769 1770 // swap between plain text/html descriptions 1771 $(".description_format_link").click(function(e) { 1772 e.preventDefault(); 1773 1774 var link = $(this); 1775 1776 link.siblings(".description_format_link").removeClass("selected"); 1777 link.addClass("selected"); 1778 1779 $(".html_description_container").toggleClass("is_hidden"); 1780 $(".plain_text_description_container").toggleClass("is_visible"); 1781 }); 1782 1783 // expand collapse full item_description_inner container 1784 $(".description_headline").click(function() { 1785 // expand/collapse description section is only for wider screens 1786 if ($(window).width() < 960) { return; } 1787 1788 var link = $(this); 1789 1790 link.toggleClass("is_open"); 1791 link.parent().siblings(".item_description_inner").slideToggle(); 1792 }); 1793 1794 // expand/collapse plain text description 1795 $(".description_toggle_link").click(function(e) { 1796 e.preventDefault(); 1797 toggleSectionHeight($(this), plainTextDescription, 105); 1798 }); 1799 }; 1800 1801 // ---------------------------------------------------------------------------- 1802 var initItemTraits = function() { 1803 var traitsTableContainer = $(".item_traits_table_container"); 1804 var tableContainerEl = traitsTableContainer[0]; 1805 var traitsTable = traitsTableContainer.children(".extended_info_table"); 1806 var expandableTraitRows = traitsTable.find(".extended_info_row.expandable"); 1807 var maxContainerHeight = 120; 1808 1809 // if the table has expandable traits, we'll set the max-height to 1810 // the position of the first expandable trait row or 120, whichever is smaller 1811 if (expandableTraitRows.length > 0) { 1812 var firstTraitHeight = expandableTraitRows.first().offset().top - traitsTableContainer.offset().top; 1813 1814 if (firstTraitHeight < maxContainerHeight) { 1815 maxContainerHeight = firstTraitHeight; 1816 traitsTableContainer.css("max-height", maxContainerHeight); 1817 } 1818 } 1819 1820 // determine whether or not we need to display the 1821 // "See all traits" link at smaller screen widths 1822 if (tableContainerEl && tableContainerEl.scrollHeight > tableContainerEl.offsetHeight) { 1823 $(".item_traits_toggle_link_container").removeClass("disabled"); 1824 } 1825 1826 traitsTableContainer.removeClass("loading"); 1827 1828 // expand traits that have too many details to display in the table 1829 $(".extended_info_expandable_link").click(function(e) { 1830 e.preventDefault(); 1831 1832 var link = $(this); 1833 link.toggleClass("is_open"); 1834 link.parent().siblings(".extended_info_expandable_details_section").slideToggle(); 1835 }); 1836 1837 // expand/collapse full traits section 1838 $(".item_traits_toggle_link").click(function(e) { 1839 e.preventDefault(); 1840 toggleSectionHeight($(this), traitsTableContainer, maxContainerHeight); 1841 }); 1842 }; 1843 1844 // ---------------------------------------------------------------------------- 1845 var toggleSectionHeight = function(link, section, maxHeight) { 1846 var isOpen = link.hasClass("is_open"); 1847 var currText = link.text(); 1848 var newHeight = isOpen ? maxHeight : "100%"; 1849 1850 link.toggleClass("is_open"); 1851 link.text(link.data("alt-text")); 1852 link.data("alt-text", currText); 1853 1854 section.css("max-height", newHeight); 1855 }; 1856 1857 // ---------------------------------------------------------------------------- 1858 var intiHandPickedListActions = function() { 1859 // add to hand picked list 1860 $(".hand_picked_list_selector").change(function(){ 1861 var selector = $(this); 1862 var container = selector.parent(); 1863 var spinner = selector.siblings(".extended_info_action_spinner"); 1864 var removalLink = selector.siblings(".remove_from_hpl_link"); 1865 1866 selector.hide(); 1867 spinner.show(); 1868 1869 $.ajax({ 1870 type: "POST", 1871 url: selector.data("url"), 1872 data: { id: selector.val(), item_id: selector.data("item-id"), sparse_response: true }, 1873 dataType: "json", 1874 success: function(response) { 1875 spinner.hide(); 1876 container.prepend(response["message"]); 1877 if (response["removal_url"]) { 1878 removalLink.attr("href", response["removal_url"]).removeClass("is_hidden"); 1879 } 1880 }, 1881 error: function() { 1882 spinner.hide(); 1883 container.prepend("<div class='extended_info_action_message error'>There was an error adding this item to your list.</div>") 1884 } 1885 }); 1886 }); 1887 1888 // remove from hand picked list 1889 $(".remove_from_hpl_link").click(function(e){ 1890 e.preventDefault(); 1891 1892 var link = $(this); 1893 var spinner = link.siblings(".extended_info_action_spinner"); 1894 1895 link.siblings(".hpl_success, .hpl_title").remove(); 1896 link.addClass("is_hidden"); 1897 spinner.show(); 1898 1899 $.ajax({ 1900 type: "DELETE", 1901 url: link.attr("href"), 1902 dataType: "json", 1903 success: function() { 1904 spinner.hide(); 1905 link.siblings(".hand_picked_list_selector").val(-1).show(); 1906 }, 1907 error: function() { 1908 spinner.hide(); 1909 link.parent().prepend("<div class='extended_info_action_message error'>There was an error removing this item from your list.</div>") 1910 } 1911 }); 1912 }); 1913 }; 1914 1915 // ---------------------------------------------------------------------------- 1916 var initCuratedGuideActions = function() { 1917 $(".gift_guide_selector").change(function(){ 1918 var selector = $(this); 1919 var spinner = selector.siblings(".extended_info_action_spinner"); 1920 1921 selector.hide(); 1922 spinner.show(); 1923 1924 $.ajax({ 1925 type: "POST", 1926 url: selector.data("url"), 1927 data: { id: selector.val(), item_id: selector.data("item-id") }, 1928 dataType: "json", 1929 complete: function() { 1930 spinner.hide(); 1931 selector.parent().prepend("<div class='extended_info_action_message'>Item successfully removed.</div>") 1932 } 1933 }); 1934 }); 1935 }; 1936 1937 // ---------------------------------------------------------------------------- 1938 var initItemReferralBoxEditPopup = function() { 1939 var itemReferralEditPopup = $("#item_referral_box_edit_popup"); 1940 1941 itemReferralEditPopup.jqm().jqmAddClose(".popup_close_control"); 1942 1943 $(".item_referral_box_edit_link").click(function(e) { 1944 e.preventDefault(); 1945 1946 itemReferralEditPopup.jqmShow(); 1947 }); 1948 1949 $(".item_referral_popup_expandable_link").click(function(e) { 1950 e.preventDefault(); 1951 1952 var link = $(this); 1953 1954 link.toggleClass("is_open"); 1955 link.siblings(".item_referral_popup_expandable_container").slideToggle(); 1956 }); 1957 1958 $(".item_referral_cancel_button").click(function(e) { 1959 e.preventDefault(); 1960 1961 itemReferralEditPopup.jqmHide(); 1962 }); 1963 1964 $(".item_referral_edit_form_container input[type='radio']").click(function(){ 1965 $(".item_referral_item_id_container").toggleClass("is_hidden", $(this).val() == "1"); 1966 }); 1967 1968 $(".item_referral_edit_form_container form").submit(function(e) { 1969 e.preventDefault(); 1970 1971 var form = $(this); 1972 var loading = itemReferralEditPopup.children(".loading"); 1973 var errorMessage = $(".item_referral_edit_error_message"); 1974 1975 errorMessage.hide(); 1976 loading.show(); 1977 1978 $.ajax({ 1979 type: "POST", 1980 url: form.attr("action"), 1981 data: form.serialize(), 1982 success: function(response) { 1983 1984 if (response["error"]) { 1985 loading.hide(); 1986 errorMessage.show(); 1987 } else { 1988 var referralBoxContent = $(".booth_item_box.item_referral").find(".item_referral_container"); 1989 var imageContainer = referralBoxContent.children(".item_referral_image"); 1990 var descriptionContainer = referralBoxContent.children(".item_referral_description"); 1991 var descriptionTextContainer = descriptionContainer.children(".item_description_text_container"); 1992 1993 descriptionContainer.children(".item_title").text(response["title"]); 1994 descriptionContainer.children(".item_price").text(response["price"]); 1995 1996 descriptionTextContainer.children(".description_text").text(response["description"]); 1997 descriptionTextContainer.children(".item_link").attr("href", response["item_url"]); 1998 1999 imageContainer.children("a").attr("href", response["item_url"]); 2000 imageContainer.find("img").attr({ 2001 src: response["image_source"], 2002 title: response["title"] + " - " + response["price"], 2003 alt: response["title"] 2004 }); 2005 2006 $(".item_referral_box_edit_link").hide(); 2007 $(".item_referral_box_update_success").show(); 2008 itemReferralEditPopup.jqmHide(); 2009 } 2010 } 2011 }); 2012 }) 2013 }; 2014 2015 // ---------------------------------------------------------------------------- 2016 var initEbayReviewLink = function() { 2017 var linkElement = $(".ebay_item_reviews_link"); 2018 var reviewLinkSection = linkElement.closest(".item_listing_additional_details_section"); 2019 2020 if (!linkElement.data("find-review-url")) return; 2021 2022 $.ajax({ 2023 url: linkElement.data("find-review-url"), 2024 data: { item_id: linkElement.data("item-id") }, 2025 dataType: "json", 2026 success: function(data) { 2027 if (data.url === null) { 2028 // Known issue: the previous section will have a possibly erroneous bottom border 2029 // until the AJAX completes. 2030 reviewLinkSection.remove(); 2031 } 2032 else { 2033 linkElement.attr("href", data.url); 2034 reviewLinkSection.removeClass("hidden"); 2035 } 2036 } 2037 }); 2038 }; 2039 2040 // ----------------------------------------------------------------------------- 2041 return exports; 2042}()); 2043 2044BONZ.ItemShow = BONZ.ItemShow || {}; 2045 2046BONZ.ItemShow.AddToCart = (function () { 2047 var exports = {}; 2048 2049 // ----------------------------------------------------------------------------- 2050 exports.locked = false;
2051 2052 // ----------------------------------------------------------------------------- 2053 // NOTE: This code is used on webstore product pages as well. 2054 exports.initialize = function () { 2055 initVariations(); 2056 initAddToCart(); 2057 }; 2058 2059 // ----------------------------------------------------------------------------- 2060 // private 2061 // ----------------------------------------------------------------------------- 2062 2063 // ----------------------------------------------------------------------------- 2064 // Show "similar items" popup when "add to cart" button is clicked 2065 var initAddToCart = function() { 2066 $(".add_to_cart_button").click(function(e) { 2067 e.preventDefault(); 2068 2069 var el = $(this); 2070 2071 var params = BONZ.Util.params; 2072 // Webstores only have popup configured, so we'll rely on their data attribute to send 2073 // us to correct destination 2074 if(el.data("popup-similar")) { 2075 doPostCartPopup(el); 2076 } else { 2077 // Non-webstores go to separate "related items" page 2078 if($(".add_item_to_cart_form").get(0)) { 2079 $(".add_item_to_cart_form").submit(); 2080 } else { 2081 window.location = el.attr("href"); 2082 } 2083 } 2084 }); 2085 }; 2086 2087 // ----------------------------------------------------------------------------- 2088 var doPostCartPopup = function(el) { 2089 var href = el.data("checkout-similar-url"); 2090 var itemId = el.data("item-id"); 2091 2092 beforeAddToCart("#item_action_buttons"); 2093 2094 $.ajax(href, { 2095 data: { item_to_add: BONZ.Application.addToCartData("#item_action_buttons") }, 2096 success: function(response) { 2097 $("#similar_checkout_items").html(response); 2098 cartAddComplete(itemId); 2099 }, 2100 error: function(request) { 2101 if(request.getAllResponseHeaders().indexOf("Content-Type: text/plain") !== -1) { 2102 BONZ.Util.alert(request.responseText); 2103 } else { 2104 BONZ.Util.popupDefaultAlert(); 2105 } 2106 2107 if (!exports.locked) { $("#add_to_cart_popup").jqmHide(); } 2108 } 2109 }); 2110 }; 2111 2112 // ----------------------------------------------------------------------------- 2113 // Setup mutable trait dropdown for add to cart button 2114 var initVariations = function() { 2115 var traitSelectionContainer = null; 2116 var priceTextContainer = null; 2117 var isDiscounted = false; 2118 var discountContainer = null; 2119 2120 var onWebstoreListingPage = $(".item_listing_main").length == 0; 2121 2122 // items/show and webstores have 2123 // 2 different layouts at the moment, so we need to 2124 // look for different elements depending where we are 2125 if (onWebstoreListingPage) { 2126 traitSelectionContainer = $("#item_action_buttons .multi_trait_cart_button_container"); 2127 priceTextContainer = $(".item_price_text", traitSelectionContainer.closest(".item_meta")); 2128 setupQuantityDropdown($(".quantity_selector").data("quantity")); 2129 } else { 2130 traitSelectionContainer = $(".item_trait_select"); 2131 priceTextContainer = $(".item_status_and_price_content").children(".item_price"); 2132 setupQuantityButtons($(".item_quantity_select").data("max-quantity")); 2133 discountContainer = $(".item_status_and_price_content").children(".nondiscount_price"); 2134 } 2135 2136 if (traitSelectionContainer.length > 0) { 2137 traitSelectionContainer.find(".item_trait_mutation_select").change(function() { 2138 var selectedTraitEl = $("select option:selected", traitSelectionContainer); 2139 2140 // Update item price to be valid for mutation 2141 var priceText = selectedTraitEl.data("price") || ""; 2142 var quantity = selectedTraitEl.data("quantity"); 2143 2144 isDiscounted = selectedTraitEl.data("discounted") || false; 2145 2146 if (priceText.length > 0) { 2147 priceTextContainer.text(priceText); 2148 } 2149 2150 if(isDiscounted) { 2151 var nondiscountPrice = selectedTraitEl.data("nondiscount-price"); 2152 if (nondiscountPrice) { 2153 discountContainer.text(nondiscountPrice); 2154 } 2155 } 2156 2157 priceTextContainer.toggleClass("discounted", isDiscounted); 2158 discountContainer.toggle(isDiscounted); 2159 discountContainer.siblings(".tooltip").children(".inline_icon").toggle(isDiscounted); 2160 2161 if (onWebstoreListingPage) { 2162 setupQuantityDropdown(quantity); 2163 } else { 2164 setupQuantityButtons(quantity); 2165 } 2166 }); 2167 } 2168 }; 2169 2170 // ----------------------------------------------------------------------------- 2171 var beforeAddToCart = function(el) { 2172 if (!validateCustomText()) { return false; } 2173 2174 var addToCartPopup = $('#add_to_cart_popup'); 2175 if (addToCartPopup.length > 0) { 2176 exports.locked = true; 2177
2178 // If for whatever reason we couldn't show the extra items in 3 seconds, just let them proceed 2179 $.timer(3000, function(timer) { 2180 exports.locked = false; 2181 timer.stop(); 2182 }); 2183 2184 addToCartPopup.jqmShow(); 2185 BONZ.Util.ensureFixedElementIsVisibile(addToCartPopup); 2186 2187 // Log the popup view to GA 2188 if (typeof(gtag) != 'undefined') { gtag('send', 'pageview', 'item_show/add_to_cart_popup'); } 2189 } 2190 2191 return true; 2192 }; 2193 2194 // ----------------------------------------------------------------------------- 2195 var cartAddComplete = function(itemId) { 2196 exports.locked = false; 2197 2198 BONZ.Util.ensureFixedElementIsVisibile($('#add_to_cart_popup')); 2199 $.ajax({ 2200 type: "GET", 2201 url: "/offers/cart_add_complete", 2202 data: { item_id: itemId } 2203 }); 2204 }; 2205 2206 // ----------------------------------------------------------------------------- 2207 // For items that can be personalized, buyers must enter the messages before adding to cart. 2208 var validateCustomText = function() { 2209 var customTextEl = $("#custom_item_text_count"); 2210 2211 // Maybe no personalization option for this item? 2212 if(customTextEl.length === 0) { return true; } 2213 2214 var textLines = []; 2215 var confirmMsg = "Is your personalization entered exactly as you'd like it to appear?\n\n"; 2216 var allFilled = true; 2217 $("#personalize_options input:text").each(function(index, el){ 2218 if(!el.value || el.value === "") { 2219 allFilled = false; 2220 }else{ 2221 textLines.push(el.value); 2222 confirmMsg += el.value + "\n"; 2223 } 2224 }); 2225 2226 if(!allFilled) { 2227 BONZ.Util.alert("Please enter your personalized text before adding this item to your cart."); 2228 return false; 2229 } 2230 else { 2231 return BONZ.Util.confirm(confirmMsg); 2232 } 2233 }; 2234 2235 // ----------------------------------------------------------------------------- 2236 var setupQuantityDropdown = function(quantity) { 2237 if (quantity !== undefined && quantity !== null && quantity > 1) { 2238 var quantitySelector = $(".quantity_selector"); 2239 quantitySelector.show(); 2240 var select = quantitySelector.find("select"); 2241 $(".item_trait_mutation_select").css("width", "58%"); 2242 2243 // hide options above the quantity that we have available 2244 if (select.val() > quantity) { select.val("1"); } 2245 select.find("option").each(function() { 2246 var option = $(this); 2247 if (option.val() > quantity) { 2248 // IE workaround: Hide this option by wrapping it in a hidden span 2249 option.wrap("<span>").hide(); 2250 } else { 2251 var optionParent = option.parent(); 2252 if (optionParent.is("span")) { // IE workaround: Show this option by unwrapping it from its hidden span 2253 option.show(); 2254 optionParent.replaceWith(option); 2255 } 2256 } 2257 }); 2258 } else { 2259 $(".quantity_selector").hide(); 2260 $(".item_trait_mutation_select").css("width", "100%"); 2261 } 2262 }; 2263 2264 // ----------------------------------------------------------------------------- 2265 var setupQuantityButtons = function(maxQuantity) { 2266 var quantityContainer = $(".item_quantity_select"); 2267 var quantityButtons = quantityContainer.children(".quantity_button"); 2268 var addButton = quantityButtons.filter(".add"); 2269 var subtractButton = quantityButtons.filter(".subtract"); 2270 var quantityInput = quantityContainer.children("#item_to_add_quantity"); 2271 var quantityDisplay = quantityContainer.children(".quantity_display"); 2272 var maxQuantityValue = parseInt(maxQuantity); 2273 var currentQuantityValue = parseInt(quantityInput.val()); 2274 2275 quantityContainer.data("max-quantity", maxQuantityValue); 2276 2277 if (currentQuantityValue > 1) { 2278 if (currentQuantityValue > maxQuantity) { 2279 quantityInput.val(maxQuantity); 2280 quantityDisplay.text(maxQuantity); 2281 addButton.addClass("disabled"); 2282 subtractButton.toggleClass("disabled", maxQuantity == 1); 2283 } else { 2284 quantityButtons.removeClass("disabled"); 2285 } 2286 } else { 2287 subtractButton.addClass("disabled"); 2288 addButton.toggleClass("disabled", maxQuantity == 1); 2289 } 2290 }; 2291 2292 // ----------------------------------------------------------------------------- 2293 return exports; 2294}()); 2295 2296BONZ.ItemShow = BONZ.ItemShow || {}; 2297 2298BONZ.ItemShow.BuyerReminders = (function() { 2299 var exports = {}; 2300 2301 // ---------------------------------------------------------------------------- 2302 exports.initialize = function() { 2303 prepWishListPopup(); 2304 prepRemindMeLaterPopup(); 2305 }; 2306 2307 // ---------------------------------------------------------------------------- 2308 // private 2309 // ---------------------------------------------------------------------------- 2310 2311 // ---------------------------------------------------------------------------- 2312 var prepWishListPopup = function() { 2313 // Intercept the submit or page navigation event and hit the "sign_in_to_add_to_wishlist" path 2314 // This ensures that the correct return-to and auto-add info is added for a successful round-trip to sign in
2315 var roundTripDataSet = false; 2316 var wishListAutoAddIntercept = function(e) { 2317 if (roundTripDataSet) { return true; } 2318 e.preventDefault(); 2319 $.ajax($(".additional_action_link.wish_list").data("auto-add")); 2320 roundTripDataSet = true; 2321 }; 2322 2323 BONZ.Application.setupPopup('#add_to_wishlist_popup', { modal: true }); 2324 $(document).on("click", ".add_to_wishlist_trigger, .additional_action_link.wish_list, .additional_action_link.wish_list_added", function(e) { 2325 e.preventDefault(); 2326 2327 var link = $(this); 2328 2329 // close any popup window that may be open (could be the source of the trigger link) 2330 swal.close(); 2331 $(".jqm-init").jqmHide(); 2332 2333 $("#login_nag_popup").one("click", ".link_to_login", function(e) { 2334 wishListAutoAddIntercept(e); 2335 this.click(); // native JS #click actually performs a navigation, jQuery's does not 2336 }); 2337 2338 $("#login_nag_popup").one("submit", ".user_session_form", function(e) { 2339 wishListAutoAddIntercept(e); 2340 $(this).submit(); 2341 }); 2342 2343 $.ajax(link.attr("href"), { 2344 complete: function(response) { 2345 var json = $.parseJSON(response.responseText); 2346 if (json["launch_login"]) { 2347 BONZ.Application.openGlobalLoginPopup(json["form_params"]); 2348 } else { 2349 link.toggleClass("wish_list_added").toggleClass("wish_list"); 2350 link.children(".inline_icon").toggleClass("fa-star-o").toggleClass("fa-check-circle"); 2351 if (link.hasClass("wish_list_added")) { 2352 $("#add_to_wishlist_popup").jqmShow(); 2353 } 2354 } 2355 } 2356 }); 2357 }); 2358 2359 // Wish-list button will be flagged with an "auto_add" class if we're returning from a sign-in round-trip via the 2360 // anon add-to-wish-list modal 2361 $(".additional_action_link.wish_list.auto_add").click(); 2362 }; 2363 2364 // ---------------------------------------------------------------------------- 2365 var prepRemindMeLaterPopup = function() { 2366 var remindMeLaterPopup = $(".remind_me_later_form"); 2367 if (remindMeLaterPopup.length === 0) { return; } 2368 2369 // non-iOS mobile platforms have issues with the autofocus on the modal that pops up, so in such cases, we explicitly 2370 // bypass that functionality with an override of the onShow function 2371 if (BONZ.isMobile && BONZ.Mobile && !BONZ.MobileUtil.isiOS()) { 2372 var jqmOptions = { onShow: function() { remindMeLaterPopup.show(); } }; 2373 } 2374 remindMeLaterPopup.jqm(jqmOptions). 2375 jqmAddTrigger(".additional_action_link.remind_me_later"). 2376 jqmAddClose(".popup_close_control"); 2377 2378 $("form", remindMeLaterPopup).validationEngine({ scroll: false }); 2379 2380 // ---------------------------------------------------------------------------- 2381 // Email address confirmation preview area 2382 // Load our selectors ahead of time to avoid DOM query during `keyup` 2383 var emailConfirmationContainer = $(".reminder_email_confirm"); 2384 var emailConfirmationInner = $(".email_confirm_display", remindMeLaterPopup); 2385 var emailInput = $("#remind_me_later_email_address", remindMeLaterPopup); 2386 emailInput.keyup(function() { 2387 var inputVal = emailInput.val().trim(); 2388 emailConfirmationContainer.toggleClass("hidden", inputVal.length === 0); 2389 emailConfirmationInner.val(inputVal); 2390 }); 2391 2392 remindMeLaterPopup.submit(function(e) { 2393 e.preventDefault(); 2394 2395 remindMeLaterPopup.addClass("loading"); 2396 var thisForm = $("form", remindMeLaterPopup); 2397 2398 $.ajax({ 2399 url: thisForm.attr("action"), 2400 dataType: "JSON", 2401 type: "POST", 2402 data: thisForm.serializeArray(), 2403 2404 success: function(data) { 2405 2406 if (data["msg"]) { 2407 remindMeLaterPopup.jqmHide().removeClass("loading"); 2408 swal({ 2409 title: "Thanks!", 2410 text: data["msg"], 2411 type: "success", 2412 html: true 2413 }); 2414 2415 } else if (data["sign_in_message"]) { 2416 remindMeLaterPopup.removeClass("loading"); 2417 swal({ 2418 title: data["popup_title"] || "Oh no!", 2419 text: data["sign_in_message"], 2420 type: "info", 2421 html: true,
2422 showConfirmButton: false, 2423 showCancelButton: true, 2424 cancelButtonText: "Try again." 2425 }); 2426 } 2427 }, 2428 2429 error: function(error) { 2430 $(remindMeLaterPopup).removeClass("loading"); 2431 swal({ 2432 title: error.statusText === "Forbidden" ? "Whoops!" : "Try again.", 2433 text: JSON.parse(error.responseText)["errors"], 2434 type: "warning", 2435 html: true 2436 }); 2437 } 2438 }); 2439 }); 2440 }; 2441 2442 return exports; 2443})(); 2444 2445BONZ.ItemShow.Images = (function() { 2446 var exports = {}; 2447 2448 var mainImageContainer = null; 2449 var imageThumbnails = null; 2450 var imageCarousel = null; 2451 var zoomSpace = null; 2452 2453 // ---------------------------------------------------------------------------- 2454 exports.initialize = function() { 2455 mainImageContainer = $(".item_listing_images .main_image_container"); 2456 imageThumbnails = $(".item_image_thumbnails .image_thumbnail_container"); 2457 imageCarousel = $(".item_listing_images .item_image_carousel"); 2458 zoomSpace = $(".item_image_zoom_space"); 2459 2460 // add "fancybox" modal image gallery modal trigger to main image 2461 initImageGalleryModal(); 2462 2463 // thumbnail hover 2464 initThumbnailHover(); 2465 2466 // variations 2467 initVariations(); 2468 2469 // image zoom on hover 2470 initZoom(); 2471 2472 // initialize carousel 2473 imageCarousel.slick({ 2474 dots: true, 2475 variableWidth: false, 2476 infinite: false, 2477 arrows: imageCarousel.data("show-arrows"), 2478 speed: 200 2479 }); 2480 2481 // image reporting 2482 initImageReporting(); 2483 }; 2484 2485 // ---------------------------------------------------------------------------- 2486 // private 2487 // ---------------------------------------------------------------------------- 2488 2489 // ---------------------------------------------------------------------------- 2490 var initImageGalleryModal = function() { 2491 BONZ.FancyBox.initialize(".fancybox_trigger", "image"); 2492 2493 mainImageContainer.children("a").click(function(e) { 2494 e.preventDefault(); 2495 2496 var mainImage = $(this); 2497 2498 // if the main image is the only image available, we don't 2499 // need to do anything else to bring up the fancybox 2500 if (mainImage.hasClass("fancybox_trigger")) { return; } 2501 2502 $(".fancybox_trigger").each(function(i, anchor) { 2503 if ($(anchor).attr("href") === mainImage.find("img").attr("src")) $(anchor).trigger("click"); 2504 }); 2505 }); 2506 }; 2507 2508 // ---------------------------------------------------------------------------- 2509 var initThumbnailHover = function() { 2510 // for touch devices, there is no "hover", so we'll make click do the same thing 2511 imageThumbnails.on("hover, click", function() { 2512 var selectedImage = $(this); 2513 selectImageThumbnail(selectedImage); 2514 }); 2515 }; 2516 2517 // ---------------------------------------------------------------------------- 2518 var selectImageThumbnail = function(selectedImage) { 2519 var newImageSrc = selectedImage.children(".photo_thumb").attr("href"); 2520 var selectedImageIndex = selectedImage.data("index"); 2521 var oldImage = selectedImage.siblings(".current"); 2522 2523 if (newImageSrc === mainImageContainer.find("img").attr("src")) { return; } 2524 2525 oldImage.removeClass("current"); 2526 selectedImage.addClass("current"); 2527 2528 mainImageContainer.find("img").attr("src", newImageSrc); 2529 zoomSpace.find("img").attr("src", newImageSrc); 2530 2531 // Update the slick carousel in tandem to support full responsiveness 2532 imageCarousel.slick("slickGoTo", selectedImageIndex, true); 2533 } 2534 2535 // ---------------------------------------------------------------------------- 2536 var initVariations = function() { 2537 var variationSelect = $("select.item_trait_mutation_select"); 2538 if (!variationSelect) return; 2539 2540 variationSelect.change(function() { 2541 var selected = $("select.item_trait_mutation_select option:selected"); 2542 if (!selected) return; 2543 2544 var imageId = selected.data("imageId"); 2545 var selectedImage = $(".image_thumbnail_container[data-image-id='" + imageId + "']"); 2546 2547 selectImageThumbnail(selectedImage); 2548 }); 2549 } 2550 2551 // ---------------------------------------------------------------------------- 2552 var initZoom = function() { 2553 var primaryImage = mainImageContainer.find("img"); 2554 if (primaryImage.length === 0) { return; } 2555
2556 var zoomEventContainer = mainImageContainer.find(".zoom_event_container"); 2557 var zoomCursorContainer = mainImageContainer.find(".zoom_cursor_container"); 2558 var zoomCursor = zoomCursorContainer.find(".zoom_cursor"); 2559 var zoomIcon = zoomEventContainer.find(".zoom_icon"); 2560 2561 var fullImage = zoomSpace.find("img"); 2562 var fullImageOverflow = null; 2563 var zoomRatio = null; 2564 2565 // determine how much our fully-zoomed-in image overflows the zoomSpace. 2566 recalcImageOverflow(); 2567 BONZ.Util.smartResize(recalcImageOverflow); 2568 2569 // show the zoomSpace when hovering over the photo_large image. 2570 zoomEventContainer.hover(updateZoomSpace, function() { 2571 zoomSpace.hide(); 2572 zoomCursor.hide(); 2573 zoomIcon.hide(); 2574 }); 2575 2576 zoomEventContainer.mousemove(updateZoomSpace); 2577 2578 // because we put an event container on top of the image, it won't fancybox automatically. 2579 zoomEventContainer.click(function() { 2580 mainImageContainer.children("a").trigger("click"); 2581 }); 2582 2583 // whenever the displayed image changes without a resize, we should recalculate our overflow 2584 imageThumbnails.on("hover, click", function() { recalcImageOverflow(); }); 2585 2586 function recalcImageOverflow() { 2587 zoomSpace.show(); 2588 fullImage.css({ 2589 "margin-top": 0, 2590 "margin-left": 0 2591 }); 2592 2593 fullImageOverflow = { 2594 top: parseInt(zoomSpace.height() - fullImage.height()), 2595 left: parseInt(zoomSpace.width() - fullImage.width()) 2596 }; 2597 2598 if (fullImageOverflow.top > 0) fullImageOverflow.top = 0; 2599 if (fullImageOverflow.left > 0) fullImageOverflow.left = 0; 2600 zoomRatio = primaryImage.height() / fullImage.height(); 2601 zoomSpace.hide(); 2602 2603 // position our containers. 2604 var containerCSS = { 2605 height: primaryImage.height(), 2606 width: primaryImage.width() 2607 }; 2608 2609 zoomEventContainer.css(containerCSS); 2610 zoomCursorContainer.css(containerCSS); 2611 } 2612 2613 function updateZoomSpace(e) { 2614 // show this if the zoomed-in image is ready and reasonably larger. 2615 if (!fullImageOverflow || zoomRatio > 0.7) return; 2616 2617 // This allows the zoom region to move outside each edge by this amount, so it is easier to move the cursor up 2618 // to the edge of the image without moving off the image 2619 var edgeBuffer = 40; 2620 2621 zoomIcon.show(); 2622 2623 // position the image in the zoomSpace. 2624 zoomSpace.show(); 2625 var imageOffset = primaryImage.offset(); 2626 var relativeCursorLocation = { 2627 top: parseInt(e.pageY - (imageOffset.top + edgeBuffer)) / parseInt(primaryImage.height() - edgeBuffer * 2), 2628 left: parseInt(e.pageX - (imageOffset.left + edgeBuffer)) / parseInt(primaryImage.width() - edgeBuffer * 2) 2629 }; 2630 if (fullImageOverflow.top < 0) fullImage.css("margin-top", fullImageOverflow.top * relativeCursorLocation.top); 2631 if (fullImageOverflow.left < 0) fullImage.css("margin-left", fullImageOverflow.left * relativeCursorLocation.left); 2632 2633 // position the cursor. 2634 zoomCursor.show(); 2635 zoomCursor.css({ 2636 height: zoomSpace.height() * zoomRatio, 2637 width: zoomSpace.width() * zoomRatio, 2638 "margin-top": fullImageOverflow.top * zoomRatio * relativeCursorLocation.top * -1, 2639 "margin-left": fullImageOverflow.left * zoomRatio * relativeCursorLocation.left * -1 2640 }); 2641 } 2642 }; 2643 2644 // ---------------------------------------------------------------------------- 2645 // Users (and admins) can mark pictures as bad 2646 var initImageReporting = function() { 2647 var reportImagePopup = $("#report_image_popup").jqm(); 2648 var flagImageLinks = $(".item_image_thumbnails .flag_image_link, .main_image_container .flag_image_link"); 2649 2650 if (flagImageLinks.length == 0) { return; } 2651 2652 flagImageLinks.click(function(e) { 2653 e.preventDefault(); 2654 2655 var link = $(this); 2656 var href = link.attr("href"); 2657 2658 $.fancybox.close(); 2659 reportImagePopup.html("").addClass("loading").jqmShow(); 2660 $.ajax({ 2661 url: href, 2662 type: "GET", 2663 dataType: "json", 2664 complete: function(response) { 2665 reportImagePopup.removeClass("loading").html(response.responseText).jqmAddClose(".popup_close_control, .button_medium.red"); 2666 var imageReportForm = $("#new_bad_image_report"); 2667 2668 imageReportForm.submit(function(e) { 2669 e.preventDefault(); 2670 $.ajax({ 2671 url: imageReportForm.attr("action"), 2672 data: imageReportForm.serialize(), 2673 type: "POST", 2674 dataType: "json", 2675 complete: function(response) { 2676 imageReportForm.replaceWith(response.responseText); 2677 } 2678 }); 2679 }); 2680 } 2681 }); 2682 }); 2683 }; 2684 2685 // ------------------------------------------------------------------------- 2686 return exports; 2687}()); 2688 2689BONZ.ItemRecommendations = (function() { 2690 var exports = {}; 2691 var trackImpressions = false;
2692 var suggestionModules = null; 2693 2694 // -------------------------------------------------------------------------- 2695 exports.initialize = function(shouldTrackImpressions) { 2696 initSuggestionModules(); 2697 initAddToCart(); 2698 2699 trackImpressions = shouldTrackImpressions; 2700 2701 if (trackImpressions) { 2702 suggestionModules = $(".item_recommendation_module, .cart_complete_recently_viewed"); 2703 $(window).bind("smartscroll.SuggestionModuleImpressions", trackSuggestionModuleImpressions); 2704 trackSuggestionModuleImpressions(); 2705 } 2706 }; 2707 2708 // ----------------------------------------------------------------------------- 2709 // private 2710 // ----------------------------------------------------------------------------- 2711 2712 // -------------------------------------------------------------------------- 2713 var initAddToCart = function() { 2714 $(document).on("click", ".cart_adder", function() { 2715 var clickedItem = $(this); 2716 $(this).closest(".quick_add_to_cart").find(".hidden_spinner").show(); 2717 2718 $.ajax({ 2719 url: clickedItem.data("url"), 2720 complete: function() { 2721 var viewCartLink = $("<a>View cart</a>").attr("href", "/offers/cart_summary"); 2722 clickedItem.closest(".quick_add_to_cart").html($("<div>Added! </div>").append(viewCartLink)); 2723 } 2724 }) 2725 }) 2726 }; 2727 2728 // ----------------------------------------------------------------------------- 2729 var initSuggestionModules = function() { 2730 $(".item_recommendation_module").each(function() { 2731 var module = $(this); 2732 2733 if (!module.data("action")) { 2734 return; 2735 } 2736 2737 var data = {}; 2738 var discountHeader = module.children(".seller_discounts_header"); 2739 var discountRibbon = discountHeader.find(".seller_discounts_ribbon"); 2740 2741 // if this is the seller discount section, we need some additional data 2742 if (discountHeader.length > 0) { 2743 var threshold = discountHeader.find(".money_til_discount").text(); 2744 2745 data["discount"] = { 2746 threshold: threshold, 2747 discount_type: discountHeader.data("discount-type"), 2748 discount_id: discountHeader.data("discount-id"), 2749 has_discount: threshold.length == 0 2750 }; 2751 2752 if (discountRibbon.hasClass("discount")) { 2753 data["discount"]["discount_ribbon_text"] = discountRibbon.text(); 2754 } 2755 } 2756 2757 $.ajax({ 2758 type: "GET", 2759 url: module.data("action"), 2760 data: data, 2761 responseType: "html", 2762 success: function(response) { 2763 if (response.length > 1) { 2764 var responseObj = $(response); 2765 var items = responseObj.filter(".item_recommendation_module_items"); 2766 2767 if (items.length == 0) { 2768 module.remove(); 2769 } else { 2770 if (!module.hasClass("seller_discount")) { 2771 module.find(".module_header_button_container").html(responseObj.filter(".module_header_button")); 2772 } 2773 2774 module.children(".loading").remove(); 2775 module.append(items); 2776 module.append(responseObj.filter(".mobile_post_cart_module_button")); 2777 2778 // After the module has loaded, check to see if it's onscreen. 2779 module.data("loaded", true); 2780 if (trackImpressions) { 2781 trackSuggestionModuleImpressions(); 2782 } 2783 } 2784 } else { 2785 module.remove(); 2786 } 2787 } 2788 }).fail(function() { 2789 BONZ.Application.suppressAjaxError = true; 2790 2791 module.remove(); 2792 2793 return false; 2794 }); 2795 }); 2796 }; 2797 2798 // ----------------------------------------------------------------------------- 2799 var trackSuggestionModuleImpressions = function() { 2800 suggestionModules.each(function() { 2801 var module = $(this); 2802 if (module.data("loaded") && !module.data("tracked") && BONZ.Util.isScrolledIntoView(module)) { 2803 module.data("tracked", true); 2804 $.ajax({ 2805 type: "POST", 2806 url: module.data("impression-url"), 2807 data: { funnel: module.data("funnel") } 2808 }); 2809 } 2810 }); 2811 }; 2812 2813 // -------------------------------------------------------------------------- 2814 return exports; 2815}()); 2816 2817BONZ.ItemUnavailable = (function() { 2818 var exports = {}; 2819 2820 // -------------------------------------------------------------------------- 2821 exports.initialize = function() { 2822 BONZ.ItemRecommendations.initialize(false); 2823 BONZ.NewsletterSubscriptionBanner.initialize(); 2824 }; 2825 2826 // -------------------------------------------------------------------------- 2827 return exports; 2828}()); 2829 2830BONZ.NewsletterSubscriptionBanner = (function() { 2831 var exports = {}; 2832 2833 // -------------------------------------------------------------------------- 2834 exports.initialize = function(form_selector, message_selector, try_again_selector) { 2835 // submit form 2836 $(form_selector || ".newsletter_subscription_banner .subscription_banner_form").submit(function(e) { 2837 e.preventDefault(); 2838 2839 var form = $(this); 2840 var container = form.parent(); 2841 var msg = message_selector ? $(message_selector) : container.siblings(".subscription_banner_message"); 2842 2843 container.fadeOut(200, function () { 2844 $.ajax({ 2845 type: "POST", 2846 url: form.attr("action"), 2847 data: form.serializeArray(), 2848 responseType: "json", 2849 success: function (response) { 2850 var msgToShow = {}; 2851 if (response["notice"]) { 2852 msgToShow = msg.filter(".success"); 2853 } else if (response["error"]) { 2854 msgToShow = msg.filter(".error"); 2855 var msgText = response["error"]; 2856
2857 if (msgText.indexOf("<br />") >= 0) { 2858 msgText = msgText.substr(0, msgText.indexOf("<br />")); 2859 } 2860 2861 try { 2862 msgToShow.children(".message_text").html(msgText); 2863 2864 var signInLink = msgToShow.children(".sign_in_text"); 2865 var tryAgainLink = $(".subscription_banner_try_again"); 2866 var tryAgainText = tryAgainLink.text(); 2867 if (response["outcome"] == "user_exists") { 2868 signInLink.show(); 2869 tryAgainLink.text(tryAgainText.toLowerCase()); 2870 } else { 2871 signInLink.hide(); 2872 tryAgainLink.text(tryAgainText[0].toUpperCase() + tryAgainText.slice(1)); 2873 } 2874 } catch (e) { 2875 console.error('Showing error message failed: ' + e); 2876 } 2877 } 2878 2879 msgToShow.fadeIn(); 2880 } 2881 }); 2882 }); 2883 }); 2884 2885 // try again link 2886 $(try_again_selector || ".newsletter_subscription_banner .subscription_banner_try_again").click(function(e) { 2887 e.preventDefault(); 2888 $(message_selector || ".subscription_banner_message").hide(); 2889 $((form_selector || ".subscription_banner_form") + " input[type=text]").val(""); 2890 $((form_selector || ".subscription_banner_form") + " *[type=submit]").removeAttr('disabled'); 2891 $(form_selector ? $(form_selector).parent() : ".subscription_banner_form_container").show(); 2892 }); 2893 }; 2894 2895 // -------------------------------------------------------------------------- 2896 return exports; 2897}()); 2898 2899BONZ.User = new function User() { 2900 var self = this; 2901 var guestCheckoutReferer = null; 2902 2903 // --------------------------------------------------------------------------- 2904 self.initialize = function() { 2905 $('.cancellation_link').on('click', function(e) { 2906 e.preventDefault(); 2907 var el = $(this); 2908 BONZ.Util.confirm(el.data("confirmation-text"), function() { 2909 el.data('method', 'post'); 2910 $.rails.handleMethod(el); 2911 }); 2912 }); 2913 2914 BONZ.Application.setupBubbletipHover($('.top_rated_stellar_seller_little'), $('.top_rated_stellar_seller_bubbletip')); 2915 }; 2916 2917 // ---------------------------------------------------------------------------- 2918 self.launchCollectZip = function(referer) { 2919 guestCheckoutReferer = referer; 2920 launchCollectZipPopup(); 2921 }; 2922 2923 // ---------------------------------------------------------------------------- 2924 self.initCollectZipForm = function() { 2925 var popup = $("#collect_zip"); 2926 var form = popup.find(".collect_zip_form"); 2927 var submitContainer = $(".submit", form); 2928 var submitButton = $(".calculate_shipping_submit", submitContainer); 2929 var errorMessage = $("#collect_zip_error"); 2930 var emailField = $("#checkout_user_email", form); 2931 var emailConsentCheckbox = $("#checkout_user_email_consent", form); 2932 var emailConsentExplanation = $(".email_capture_explanation_container", form); 2933 var keepShoppingLink = $(".keep_browsing a", form); 2934 var loadingOverlay = $(".loading_overlay", popup); 2935 var offerContainers = $(".cart_offer"); 2936 2937 // hide some of the extraneous header/footer sugar from mobile 2938 $("#mobile_footer").hide(); 2939 2940 // chosen-ify country select 2941 $(".checkout_country", form).chosen({ width: "100%" }); 2942 2943 // set the referer url on the "Keep Shopping" link 2944 if (!keepShoppingLink.attr("href") || keepShoppingLink.attr("href") == "#") { 2945 keepShoppingLink.attr("href", guestCheckoutReferer); 2946 } 2947 2948 // enable/disable form submit if there is an email address present 2949 // and the consent checkbox is not checked (GDPR compliance) 2950 emailField.on("change keyup paste", function() { 2951 var disableSubmit = !emailConsentCheckbox.is(":checked"); 2952 if (emailField.val().length > 0) { 2953 emailConsentExplanation.toggleClass("highlight", disableSubmit); 2954 submitButton.toggleClass("disabled", disableSubmit).prop("disabled", disableSubmit); 2955 } else { 2956 emailConsentExplanation.removeClass("highlight"); 2957 submitButton.removeClass("disabled").prop("disabled", false); 2958 } 2959 }); 2960 2961 emailConsentCheckbox.change(function() { 2962 var disableSubmit = !emailConsentCheckbox.is(":checked") && emailField.val().length > 0; 2963 emailConsentExplanation.toggleClass("highlight", disableSubmit); 2964 submitButton.toggleClass("disabled", disableSubmit).prop("disabled", disableSubmit); 2965 }); 2966 2967 // form submit 2968 form.submit(function(e) { 2969 e.preventDefault(); 2970 2971 if (submitButton.hasClass("disabled")) { return; } 2972 2973 if (loadingOverlay.length > 0) { 2974 loadingOverlay.removeClass("is_hidden"); 2975 } else { 2976 popup.jqmHide();
2977 BONZ.Offer.showOfferOverlay(offerContainers); 2978 } 2979 2980 // response possibilities: 2981 // 404 - not found 2982 // 406 - not acceptable 2983 // 201 - created 2984 $.ajax({ 2985 type: "POST", 2986 url: form.attr("action"), 2987 data: form.serialize(), 2988 complete: function(response) { 2989 var statusCode = response.status; 2990 2991 if (statusCode == 404 || statusCode == 406) { 2992 handleZipError(statusCode); 2993 } else { 2994 location.href = location.href.split("#")[0]; 2995 } 2996 } 2997 }); 2998 }); 2999 3000 function handleZipError(statusCode) { 3001 var errorText = ""; 3002 3003 if (statusCode == 404) { 3004 errorText = "We couldn't figure out where in the world that postal code is from. Please try again, or contact [email protected] if you believe you've reached this message in error."; 3005 } else { 3006 errorText = "We couldn't understand your country and/or postal code. Please try again."; 3007 } 3008 3009 errorMessage.html(errorText); 3010 enableSubmit(submitButton); 3011 3012 if (loadingOverlay.length > 0) { 3013 $(window).scrollTop(errorMessage.offset().top); 3014 loadingOverlay.addClass("is_hidden"); 3015 } else { 3016 BONZ.Offer.hideOfferOverlay(offerContainers); 3017 popup.jqmShow(); 3018 } 3019 } 3020 }; 3021 3022 // --------------------------------------------------------------------------- 3023 self.launchUnvalidatedUserLogin = function () { 3024 BONZ.Application.launchPopup(".unvalidated_user_popup"); 3025 3026 $(document).on('submit', '#new_unvalidated_user', function(e) { 3027 e.preventDefault(); 3028 3029 var form = $(this); 3030 $('#confirm_email_spin').show(); 3031 $.ajax(form.attr('action'), { 3032 type: 'POST', 3033 data: form.serialize(), 3034 complete: function(response) { self.unverifiedUserCallbackComplete(form, response); } 3035 }); 3036 }); 3037 }; 3038 3039 // --------------------------------------------------------------------------- 3040 self.launchLogin = function (setTriggerName) { 3041 if (setTriggerName === "forBoothChat") { 3042 $("#chat_window").submit(function(e) { 3043 e.preventDefault(); 3044 BONZ.Application.openGlobalLoginPopup("", "message_seller"); 3045 }); 3046 3047 } else if (typeof(setTriggerName) != "undefined") { 3048 $(setTriggerName).click(function() { 3049 BONZ.Application.openGlobalLoginPopup(); 3050 }); 3051 3052 } else { 3053 BONZ.Application.openGlobalLoginPopup(); 3054 } 3055 }; 3056 3057 // ---------------------------------------------------------------------------- 3058 self.launchNewShippingAddress = function() { 3059 BONZ.Application.launchPopup("#new_shipping_address"); 3060 }; 3061 3062 //----------------------------------------------------------------------------- 3063 self.unverifiedUserCallbackComplete = function(form, response) { 3064 var json = jQuery.parseJSON(response.responseText); 3065 3066 if (json.success) { 3067 if (self.postNewUnverifiedUserCallback) { 3068 self.postNewUnverifiedUserCallback(); 3069 } 3070 } else { 3071 // re-enables the <input type="submit"> so user can try again 3072 $('input[type="submit"]', form).attr("disabled", false); 3073 3074 $('#confirm_email_spin').hide(); 3075 $(".global_login_popup_validate .error_box_top").html(json.message).show(); 3076 } 3077 }; 3078 3079 //----------------------------------------------------------------------------- 3080 // Stubbed callback -- individual instances may override this method. 3081 self.postLoginCallback = function() { 3082 window.parent.location.href = window.parent.location.href.split('#')[0]; 3083 }; 3084 3085 //----------------------------------------------------------------------------- 3086 // Stubbed callback -- individual instances may override this method. 3087 self.postNewUnverifiedUserCallback = function() { 3088 window.parent.location.href = window.parent.location.href.split('#')[0]; 3089 }; 3090 3091 // ---------------------------------------------------------------------------- 3092 // private 3093 // ---------------------------------------------------------------------------- 3094 3095 // ---------------------------------------------------------------------------- 3096 var launchCollectZipPopup = function() { 3097 BONZ.Application.hideAllPopups(); 3098 var collectZip = $('#collect_zip'); 3099 3100 if (collectZip.length > 0) { 3101 collectZip.jqmShow(); 3102 self.initCollectZipForm(); 3103 } else { 3104 collectZip = $('<div id="collect_zip" class="collect_zip_popup_container responsive_popup_container"></div>'); 3105 collectZip.html('<h3>Loading...</h3><div class="popup_loading"></div>'); 3106 collectZip.find('h3').append(generatePopupSpinner()); 3107 $('body').append(collectZip); 3108 3109 $.get("/users/collect_zip?return_to=" + window.location.href, function(response) { 3110 collectZip.html(response); 3111 collectZip.find(".checkout_zip").focus(); 3112 }); 3113 3114 BONZ.Application.launchPopup(collectZip, { modal: true, popupOpenClass: "external_scroll_popup_open" }); 3115 } 3116 }; 3117 3118 // ---------------------------------------------------------------------------- 3119 var generatePopupSpinner = function() { 3120 return $('<div class="popup_spinner"></div>'); 3121 }; 3122 3123 // ---------------------------------------------------------------------------- 3124 var removePopupSpinner = function() { 3125 $('.popup_spinner').remove(); 3126 }; 3127 3128 // ---------------------------------------------------------------------------- 3129 var enableSubmit = function(submitControl) { 3130 // Rails automatically disables some form elements to prevent duplicate submissions 3131 // but we need to reenable them so that users can submit again after correcting errors 3132 $(submitControl).prop("disabled", false); 3133 $(submitControl).show(); 3134 } 3135 3136 self.HighVolumeSeller = { 3137 init: function() { 3138 window.uploadSizeCheck = function(field) { 3139 if (field.get(0).files.length > 0 && field.get(0).files[0].size > 20 * 1024 * 1024) { 3140 return 'Maximum allowed file size of 20 MB exceeded'; 3141 } 3142 } 3143 3144 function lettersNumbersNoSpaces(maxSize, field, rules, i, options) { 3145 if (/^[\w\-\d]+$/.test(field.val()) === false) { 3146 return 'Only numbers, letters and - are allowed'; 3147 } else { 3148 if (field.val().replace(/[^\w\d]/g, '').length > maxSize) { 3149 return 'Maximum ' + maxSize + ' characters required'; 3150 } 3151 } 3152 } 3153 3154 window.lettersNumbersNoSpacesMaxSize30 = function(field, rules, i, options) { 3155 return lettersNumbersNoSpaces(30, field, rules, i, options); 3156 } 3157 3158 window.lettersNumbersNoSpacesMaxSize9 = function(field, rules, i, options) { 3159 return lettersNumbersNoSpaces(9, field, rules, i, options); 3160 } 3161 3162 window.lettersNumbersNoSpacesMaxSize24 = function(field, rules, i, options) { 3163 return lettersNumbersNoSpaces(24, field, rules, i, options); 3164 } 3165 3166 // mark the high volume seller info tab when link from email (having #highvolumesellerinfo in url) 3167 if (document.location.hash.indexOf('highvolumesellerinfo') > -1) { 3168 $(document).ready(function () { 3169 $('#highvolumesellerinfo').parent().addClass('bg-lightblue'); 3170 }); 3171 } 3172 }, 3173 3174 verify: function(verified, userId) { 3175 $.ajax('/users/' + userId + '/verify_high_volume_info', { 3176 type: 'PUT', 3177 data: { status: verified ? 1 : 0 } 3178 }).always(function(data, textStatus, jqXHR) { 3179 if (jqXHR.status === 204) { 3180 window.location.reload(); 3181 } else { 3182 alert(data.responseText); 3183 } 3184 }); 3185 }, 3186 3187 allowUpdate: function(userId) { 3188 $.ajax('/users/' + userId + '/allow_hv_update', { 3189 type: 'PUT' 3190 }).always(function(data, textStatus, jqXHR) { 3191 if (jqXHR.status === 204) { 3192 window.location.reload(); 3193 } else { 3194 alert(data.responseText); 3195 } 3196 }); 3197 } 3198 } 3199}; 3200 3201jQuery(BONZ.wrap(BONZ.User.initialize)); 3202 3203/* 3204 _ _ _ _ 3205 ___| (_) ___| | __ (_)___ 3206/ __| | |/ __| |/ / | / __| 3207\__ \ | | (__| < _ | \__ \ 3208|___/_|_|\___|_|\_(_)/ |___/ 3209 |__/ 3210 3211 Version: 1.8.0 3212 Author: Ken Wheeler 3213 Website: http://kenwheeler.github.io 3214 Docs: http://kenwheeler.github.io/slick 3215 Repo: http://github.com/kenwheeler/slick 3216 Issues: http://github.com/kenwheeler/slick/issues 3217 3218 */ 3219/* global window, document, define, jQuery, setInterval, clearInterval */ 3220;(function(factory) { 3221 'use strict'; 3222 if (typeof define === 'function' && define.amd) { 3223 define(['jquery'], factory); 3224 } else if (typeof exports !== 'undefined') { 3225 module.exports = factory(require('jquery')); 3226 } else { 3227 factory(jQuery); 3228 } 3229 3230}(function($) { 3231 'use strict'; 3232 var Slick = window.Slick || {}; 3233 3234 Slick = (function() { 3235 3236 var instanceUid = 0; 3237 3238 function Slick(element, settings) { 3239 3240 var _ = this, dataSettings; 3241 3242 _.defaults = { 3243 accessibility: true, 3244 adaptiveHeight: false, 3245 appendArrows: $(element), 3246 appendDots: $(element), 3247 arrows: true, 3248 asNavFor: null, 3249 prevArrow: '<button class="slick-prev" aria-label="Previous" type="button">Previous</button>', 3250 nextArrow: '<button class="slick-next" aria-label="Next" type="button">Next</button>', 3251 autoplay: false, 3252 autoplaySpeed: 3000, 3253 centerMode: false, 3254 centerPadding: '50px', 3255 cssEase: 'ease', 3256 customPaging: function(slider, i) { 3257 return $('<button type="button" />').text(i + 1); 3258 }, 3259 dots: false, 3260 dotsClass: 'slick-dots', 3261 draggable: true, 3262 easing: 'linear', 3263 edgeFriction: 0.35, 3264 fade: false, 3265 focusOnSelect: false, 3266 focusOnChange: false, 3267 infinite: true, 3268 initialSlide: 0, 3269 lazyLoad: 'ondemand', 3270 mobileFirst: false, 3271 pauseOnHover: true, 3272 pauseOnFocus: true, 3273 pauseOnDotsHover: false, 3274 respondTo: 'window', 3275 responsive: null, 3276 rows: 1, 3277 rtl: false, 3278 slide: '', 3279 slidesPerRow: 1, 3280 slidesToShow: 1, 3281 slidesToScroll: 1, 3282 speed: 500, 3283 swipe: true, 3284 swipeToSlide: false, 3285 touchMove: true, 3286 touchThreshold: 5, 3287 useCSS: true, 3288 useTransform: true, 3289 variableWidth: false, 3290 vertical: false, 3291 verticalSwiping: false, 3292 waitForAnimate: true, 3293 zIndex: 1000 3294 }; 3295 3296 _.initials = { 3297 animating: false, 3298 dragging: false, 3299 autoPlayTimer: null, 3300 currentDirection: 0, 3301 currentLeft: null, 3302 currentSlide: 0, 3303 direction: 1, 3304 $dots: null, 3305 listWidth: null, 3306 listHeight: null, 3307 loadIndex: 0, 3308 $nextArrow: null, 3309 $prevArrow: null, 3310 scrolling: false, 3311 slideCount: null, 3312 slideWidth: null, 3313 $slideTrack: null, 3314 $slides: null, 3315 sliding: false, 3316 slideOffset: 0, 3317 swipeLeft: null, 3318 swiping: false, 3319 $list: null, 3320 touchObject: {}, 3321 transformsEnabled: false,
3322 unslicked: false 3323 }; 3324 3325 $.extend(_, _.initials); 3326 3327 _.activeBreakpoint = null; 3328 _.animType = null; 3329 _.animProp = null; 3330 _.breakpoints = []; 3331 _.breakpointSettings = []; 3332 _.cssTransitions = false; 3333 _.focussed = false; 3334 _.interrupted = false; 3335 _.hidden = 'hidden'; 3336 _.paused = true; 3337 _.positionProp = null; 3338 _.respondTo = null; 3339 _.rowCount = 1; 3340 _.shouldClick = true; 3341 _.$slider = $(element); 3342 _.$slidesCache = null; 3343 _.transformType = null; 3344 _.transitionType = null; 3345 _.visibilityChange = 'visibilitychange'; 3346 _.windowWidth = 0; 3347 _.windowTimer = null; 3348 3349 dataSettings = $(element).data('slick') || {}; 3350 3351 _.options = $.extend({}, _.defaults, settings, dataSettings); 3352 3353 _.currentSlide = _.options.initialSlide; 3354 3355 _.originalSettings = _.options; 3356 3357 if (typeof document.mozHidden !== 'undefined') { 3358 _.hidden = 'mozHidden'; 3359 _.visibilityChange = 'mozvisibilitychange'; 3360 } else if (typeof document.webkitHidden !== 'undefined') { 3361 _.hidden = 'webkitHidden'; 3362 _.visibilityChange = 'webkitvisibilitychange'; 3363 } 3364 3365 _.autoPlay = $.proxy(_.autoPlay, _); 3366 _.autoPlayClear = $.proxy(_.autoPlayClear, _); 3367 _.autoPlayIterator = $.proxy(_.autoPlayIterator, _); 3368 _.changeSlide = $.proxy(_.changeSlide, _); 3369 _.clickHandler = $.proxy(_.clickHandler, _); 3370 _.selectHandler = $.proxy(_.selectHandler, _); 3371 _.setPosition = $.proxy(_.setPosition, _); 3372 _.swipeHandler = $.proxy(_.swipeHandler, _); 3373 _.dragHandler = $.proxy(_.dragHandler, _); 3374 _.keyHandler = $.proxy(_.keyHandler, _); 3375 3376 _.instanceUid = instanceUid++; 3377 3378 // A simple way to check for HTML strings 3379 // Strict HTML recognition (must start with <) 3380 // Extracted from jQuery v1.11 source 3381 _.htmlExpr = /^(?:\s*(<[\w\W]+>)[^>]*)$/; 3382 3383 3384 _.registerBreakpoints(); 3385 _.init(true); 3386 3387 } 3388 3389 return Slick; 3390 3391 }()); 3392 3393 Slick.prototype.activateADA = function() { 3394 var _ = this; 3395 3396 _.$slideTrack.find('.slick-active').attr({ 3397 'aria-hidden': 'false' 3398 }).find('a, input, button, select').attr({ 3399 'tabindex': '0' 3400 }); 3401 3402 }; 3403 3404 Slick.prototype.addSlide = Slick.prototype.slickAdd = function(markup, index, addBefore) { 3405 3406 var _ = this; 3407 3408 if (typeof(index) === 'boolean') { 3409 addBefore = index; 3410 index = null; 3411 } else if (index < 0 || (index >= _.slideCount)) { 3412 return false; 3413 } 3414 3415 _.unload(); 3416 3417 if (typeof(index) === 'number') { 3418 if (index === 0 && _.$slides.length === 0) { 3419 $(markup).appendTo(_.$slideTrack); 3420 } else if (addBefore) { 3421 $(markup).insertBefore(_.$slides.eq(index)); 3422 } else { 3423 $(markup).insertAfter(_.$slides.eq(index)); 3424 } 3425 } else { 3426 if (addBefore === true) { 3427 $(markup).prependTo(_.$slideTrack); 3428 } else { 3429 $(markup).appendTo(_.$slideTrack); 3430 } 3431 } 3432 3433 _.$slides = _.$slideTrack.children(this.options.slide); 3434 3435 _.$slideTrack.children(this.options.slide).detach(); 3436 3437 _.$slideTrack.append(_.$slides); 3438 3439 _.$slides.each(function(index, element) { 3440 $(element).attr('data-slick-index', index); 3441 }); 3442 3443 _.$slidesCache = _.$slides; 3444 3445 _.reinit(); 3446 3447 }; 3448 3449 Slick.prototype.animateHeight = function() { 3450 var _ = this; 3451 if (_.options.slidesToShow === 1 && _.options.adaptiveHeight === true && _.options.vertical === false) { 3452 var targetHeight = _.$slides.eq(_.currentSlide).outerHeight(true); 3453 _.$list.animate({ 3454 height: targetHeight 3455 }, _.options.speed); 3456 } 3457 }; 3458 3459 Slick.prototype.animateSlide = function(targetLeft, callback) { 3460 3461 var animProps = {}, 3462 _ = this; 3463 3464 _.animateHeight(); 3465 3466 if (_.options.rtl === true && _.options.vertical === false) { 3467 targetLeft = -targetLeft; 3468 } 3469 if (_.transformsEnabled === false) { 3470 if (_.options.vertical === false) { 3471 _.$slideTrack.animate({ 3472 left: targetLeft 3473 }, _.options.speed, _.options.easing, callback); 3474 } else { 3475 _.$slideTrack.animate({ 3476 top: targetLeft 3477 }, _.options.speed, _.options.easing, callback); 3478 } 3479 3480 } else { 3481 3482 if (_.cssTransitions === false) { 3483 if (_.options.rtl === true) { 3484 _.currentLeft = -(_.currentLeft); 3485 } 3486 $({ 3487 animStart: _.currentLeft 3488 }).animate({ 3489 animStart: targetLeft 3490 }, { 3491 duration: _.options.speed, 3492 easing: _.options.easing, 3493 step: function(now) { 3494 now = Math.ceil(now); 3495 if (_.options.vertical === false) { 3496 animProps[_.animType] = 'translate(' + 3497 now + 'px, 0px)'; 3498 _.$slideTrack.css(animProps); 3499 } else { 3500 animProps[_.animType] = 'translate(0px,' + 3501 now + 'px)'; 3502 _.$slideTrack.css(animProps); 3503 } 3504 }, 3505 complete: function() { 3506 if (callback) { 3507 callback.call(); 3508 } 3509 } 3510 }); 3511 3512 } else { 3513 3514 _.applyTransition();
3515 targetLeft = Math.ceil(targetLeft); 3516 3517 if (_.options.vertical === false) { 3518 animProps[_.animType] = 'translate3d(' + targetLeft + 'px, 0px, 0px)'; 3519 } else { 3520 animProps[_.animType] = 'translate3d(0px,' + targetLeft + 'px, 0px)'; 3521 } 3522 _.$slideTrack.css(animProps); 3523 3524 if (callback) { 3525 setTimeout(function() { 3526 3527 _.disableTransition(); 3528 3529 callback.call(); 3530 }, _.options.speed); 3531 } 3532 3533 } 3534 3535 } 3536 3537 }; 3538 3539 Slick.prototype.getNavTarget = function() { 3540 3541 var _ = this, 3542 asNavFor = _.options.asNavFor; 3543 3544 if ( asNavFor && asNavFor !== null ) { 3545 asNavFor = $(asNavFor).not(_.$slider); 3546 } 3547 3548 return asNavFor; 3549 3550 }; 3551 3552 Slick.prototype.asNavFor = function(index) { 3553 3554 var _ = this, 3555 asNavFor = _.getNavTarget(); 3556 3557 if ( asNavFor !== null && typeof asNavFor === 'object' ) { 3558 asNavFor.each(function() { 3559 var target = $(this).slick('getSlick'); 3560 if(!target.unslicked) { 3561 target.slideHandler(index, true); 3562 } 3563 }); 3564 } 3565 3566 }; 3567 3568 Slick.prototype.applyTransition = function(slide) { 3569 3570 var _ = this, 3571 transition = {}; 3572 3573 if (_.options.fade === false) { 3574 transition[_.transitionType] = _.transformType + ' ' + _.options.speed + 'ms ' + _.options.cssEase; 3575 } else { 3576 transition[_.transitionType] = 'opacity ' + _.options.speed + 'ms ' + _.options.cssEase; 3577 } 3578 3579 if (_.options.fade === false) { 3580 _.$slideTrack.css(transition); 3581 } else { 3582 _.$slides.eq(slide).css(transition); 3583 } 3584 3585 }; 3586 3587 Slick.prototype.autoPlay = function() { 3588 3589 var _ = this; 3590 3591 _.autoPlayClear(); 3592 3593 if ( _.slideCount > _.options.slidesToShow ) { 3594 _.autoPlayTimer = setInterval( _.autoPlayIterator, _.options.autoplaySpeed ); 3595 } 3596 3597 }; 3598 3599 Slick.prototype.autoPlayClear = function() { 3600 3601 var _ = this; 3602 3603 if (_.autoPlayTimer) { 3604 clearInterval(_.autoPlayTimer); 3605 } 3606 3607 }; 3608 3609 Slick.prototype.autoPlayIterator = function() { 3610 3611 var _ = this, 3612 slideTo = _.currentSlide + _.options.slidesToScroll; 3613 3614 if ( !_.paused && !_.interrupted && !_.focussed ) { 3615 3616 if ( _.options.infinite === false ) { 3617 3618 if ( _.direction === 1 && ( _.currentSlide + 1 ) === ( _.slideCount - 1 )) { 3619 _.direction = 0; 3620 } 3621 3622 else if ( _.direction === 0 ) { 3623 3624 slideTo = _.currentSlide - _.options.slidesToScroll; 3625 3626 if ( _.currentSlide - 1 === 0 ) { 3627 _.direction = 1; 3628 } 3629 3630 } 3631 3632 } 3633 3634 _.slideHandler( slideTo ); 3635 3636 } 3637 3638 }; 3639 3640 Slick.prototype.buildArrows = function() { 3641 3642 var _ = this; 3643 3644 if (_.options.arrows === true ) { 3645 3646 _.$prevArrow = $(_.options.prevArrow).addClass('slick-arrow'); 3647 _.$nextArrow = $(_.options.nextArrow).addClass('slick-arrow'); 3648 3649 if( _.slideCount > _.options.slidesToShow ) { 3650 3651 _.$prevArrow.removeClass('slick-hidden').removeAttr('aria-hidden tabindex'); 3652 _.$nextArrow.removeClass('slick-hidden').removeAttr('aria-hidden tabindex'); 3653 3654 if (_.htmlExpr.test(_.options.prevArrow)) { 3655 _.$prevArrow.prependTo(_.options.appendArrows); 3656 } 3657 3658 if (_.htmlExpr.test(_.options.nextArrow)) { 3659 _.$nextArrow.appendTo(_.options.appendArrows); 3660 } 3661 3662 if (_.options.infinite !== true) { 3663 _.$prevArrow 3664 .addClass('slick-disabled') 3665 .attr('aria-disabled', 'true'); 3666 } 3667 3668 } else { 3669 3670 _.$prevArrow.add( _.$nextArrow ) 3671 3672 .addClass('slick-hidden') 3673 .attr({ 3674 'aria-disabled': 'true', 3675 'tabindex': '-1' 3676 }); 3677 3678 } 3679 3680 } 3681 3682 }; 3683 3684 Slick.prototype.buildDots = function() { 3685 3686 var _ = this, 3687 i, dot; 3688 3689 if (_.options.dots === true && _.slideCount > _.options.slidesToShow) { 3690 3691 _.$slider.addClass('slick-dotted'); 3692 3693 dot = $('<ul />').addClass(_.options.dotsClass); 3694 3695 for (i = 0; i <= _.getDotCount(); i += 1) { 3696 dot.append($('<li />').append(_.options.customPaging.call(this, _, i))); 3697 } 3698 3699 _.$dots = dot.appendTo(_.options.appendDots); 3700 3701 _.$dots.find('li').first().addClass('slick-active'); 3702 3703 } 3704 3705 }; 3706 3707 Slick.prototype.buildOut = function() { 3708 3709 var _ = this; 3710 3711 _.$slides = 3712 _.$slider 3713 .children( _.options.slide + ':not(.slick-cloned)') 3714 .addClass('slick-slide'); 3715 3716 _.slideCount = _.$slides.length; 3717 3718 _.$slides.each(function(index, element) { 3719 $(element) 3720 .attr('data-slick-index', index) 3721 .data('originalStyling', $(element).attr('style') || ''); 3722 }); 3723 3724 _.$slider.addClass('slick-slider'); 3725 3726 _.$slideTrack = (_.slideCount === 0) ? 3727 $('<div class="slick-track"/>').appendTo(_.$slider) : 3728 _.$slides.wrapAll('<div class="slick-track"/>').parent(); 3729 3730 _.$list = _.$slideTrack.wrap( 3731 '<div class="slick-list"/>').parent(); 3732 _.$slideTrack.css('opacity', 0); 3733 3734 if (_.options.centerMode === true || _.options.swipeToSlide === true) {
3735 _.options.slidesToScroll = 1; 3736 } 3737 3738 $('img[data-lazy]', _.$slider).not('[src]').addClass('slick-loading'); 3739 3740 _.setupInfinite(); 3741 3742 _.buildArrows(); 3743 3744 _.buildDots(); 3745 3746 _.updateDots(); 3747 3748 3749 _.setSlideClasses(typeof _.currentSlide === 'number' ? _.currentSlide : 0); 3750 3751 if (_.options.draggable === true) { 3752 _.$list.addClass('draggable'); 3753 } 3754 3755 }; 3756 3757 Slick.prototype.buildRows = function() { 3758 3759 var _ = this, a, b, c, newSlides, numOfSlides, originalSlides,slidesPerSection; 3760 3761 newSlides = document.createDocumentFragment(); 3762 originalSlides = _.$slider.children(); 3763 3764 if(_.options.rows > 0) { 3765 3766 slidesPerSection = _.options.slidesPerRow * _.options.rows; 3767 numOfSlides = Math.ceil( 3768 originalSlides.length / slidesPerSection 3769 ); 3770 3771 for(a = 0; a < numOfSlides; a++){ 3772 var slide = document.createElement('div'); 3773 for(b = 0; b < _.options.rows; b++) { 3774 var row = document.createElement('div'); 3775 for(c = 0; c < _.options.slidesPerRow; c++) { 3776 var target = (a * slidesPerSection + ((b * _.options.slidesPerRow) + c)); 3777 if (originalSlides.get(target)) { 3778 row.appendChild(originalSlides.get(target)); 3779 } 3780 } 3781 slide.appendChild(row); 3782 } 3783 newSlides.appendChild(slide); 3784 } 3785 3786 _.$slider.empty().append(newSlides); 3787 _.$slider.children().children().children() 3788 .css({ 3789 'width':(100 / _.options.slidesPerRow) + '%', 3790 'display': 'inline-block' 3791 }); 3792 3793 } 3794 3795 }; 3796 3797 Slick.prototype.checkResponsive = function(initial, forceUpdate) { 3798 3799 var _ = this, 3800 breakpoint, targetBreakpoint, respondToWidth, triggerBreakpoint = false; 3801 var sliderWidth = _.$slider.width(); 3802 var windowWidth = window.innerWidth || $(window).width(); 3803 3804 if (_.respondTo === 'window') { 3805 respondToWidth = windowWidth; 3806 } else if (_.respondTo === 'slider') { 3807 respondToWidth = sliderWidth; 3808 } else if (_.respondTo === 'min') { 3809 respondToWidth = Math.min(windowWidth, sliderWidth); 3810 } 3811 3812 if ( _.options.responsive && 3813 _.options.responsive.length && 3814 _.options.responsive !== null) { 3815 3816 targetBreakpoint = null; 3817 3818 for (breakpoint in _.breakpoints) { 3819 if (_.breakpoints.hasOwnProperty(breakpoint)) { 3820 if (_.originalSettings.mobileFirst === false) { 3821 if (respondToWidth < _.breakpoints[breakpoint]) { 3822 targetBreakpoint = _.breakpoints[breakpoint]; 3823 } 3824 } else { 3825 if (respondToWidth > _.breakpoints[breakpoint]) { 3826 targetBreakpoint = _.breakpoints[breakpoint]; 3827 } 3828 } 3829 } 3830 } 3831 3832 if (targetBreakpoint !== null) { 3833 if (_.activeBreakpoint !== null) { 3834 if (targetBreakpoint !== _.activeBreakpoint || forceUpdate) { 3835 _.activeBreakpoint = 3836 targetBreakpoint; 3837 if (_.breakpointSettings[targetBreakpoint] === 'unslick') { 3838 _.unslick(targetBreakpoint); 3839 } else { 3840 _.options = $.extend({}, _.originalSettings, 3841 _.breakpointSettings[ 3842 targetBreakpoint]); 3843 if (initial === true) { 3844 _.currentSlide = _.options.initialSlide; 3845 } 3846 _.refresh(initial); 3847 }
3848 triggerBreakpoint = targetBreakpoint; 3849 } 3850 } else { 3851 _.activeBreakpoint = targetBreakpoint; 3852 if (_.breakpointSettings[targetBreakpoint] === 'unslick') { 3853 _.unslick(targetBreakpoint); 3854 } else { 3855 _.options = $.extend({}, _.originalSettings, 3856 _.breakpointSettings[ 3857 targetBreakpoint]); 3858 if (initial === true) { 3859 _.currentSlide = _.options.initialSlide; 3860 } 3861 _.refresh(initial); 3862 } 3863 triggerBreakpoint = targetBreakpoint; 3864 } 3865 } else { 3866 if (_.activeBreakpoint !== null) { 3867 _.activeBreakpoint = null; 3868 _.options = _.originalSettings; 3869 if (initial === true) { 3870 _.currentSlide = _.options.initialSlide; 3871 } 3872 _.refresh(initial); 3873 triggerBreakpoint = targetBreakpoint; 3874 } 3875 } 3876 3877 // only trigger breakpoints during an actual break. not on initialize. 3878 if( !initial && triggerBreakpoint !== false ) { 3879 _.$slider.trigger('breakpoint', [_, triggerBreakpoint]); 3880 } 3881 } 3882 3883 }; 3884 3885 Slick.prototype.changeSlide = function(event, dontAnimate) { 3886 3887 var _ = this, 3888 $target = $(event.currentTarget), 3889 indexOffset, slideOffset, unevenOffset; 3890 3891 // If target is a link, prevent default action. 3892 if($target.is('a')) { 3893 event.preventDefault(); 3894 } 3895 3896 // If target is not the <li> element (ie: a child), find the <li>. 3897 if(!$target.is('li')) { 3898 $target = $target.closest('li'); 3899 } 3900 3901 unevenOffset = (_.slideCount % _.options.slidesToScroll !== 0); 3902 indexOffset = unevenOffset ? 0 : (_.slideCount - _.currentSlide) % _.options.slidesToScroll; 3903 3904 switch (event.data.message) { 3905 3906 case 'previous': 3907 slideOffset = indexOffset === 0 ? _.options.slidesToScroll : _.options.slidesToShow - indexOffset; 3908 if (_.slideCount > _.options.slidesToShow) { 3909 _.slideHandler(_.currentSlide - slideOffset, false, dontAnimate); 3910 } 3911 break; 3912 3913 case 'next': 3914 slideOffset = indexOffset === 0 ? _.options.slidesToScroll : indexOffset; 3915 if (_.slideCount > _.options.slidesToShow) { 3916 _.slideHandler(_.currentSlide + slideOffset, false, dontAnimate); 3917 } 3918 break; 3919 3920 case 'index': 3921 var index = event.data.index === 0 ? 0 : 3922 event.data.index || $target.index() * _.options.slidesToScroll; 3923 3924 _.slideHandler(_.checkNavigable(index), false, dontAnimate); 3925 $target.children().trigger('focus'); 3926 break; 3927 3928 default: 3929 return; 3930 } 3931 3932 }; 3933 3934 Slick.prototype.checkNavigable = function(index) { 3935 3936 var _ = this, 3937 navigables, prevNavigable; 3938 3939 navigables = _.getNavigableIndexes(); 3940 prevNavigable = 0; 3941 if (index > navigables[navigables.length - 1]) { 3942 index = navigables[navigables.length - 1]; 3943 } else { 3944 for (var n in navigables) { 3945 if (index < navigables[n]) { 3946 index = prevNavigable; 3947 break; 3948 } 3949 prevNavigable = navigables[n]; 3950 } 3951 } 3952 3953 return index; 3954 }; 3955 3956 Slick.prototype.cleanUpEvents = function() { 3957 3958 var _ = this; 3959 3960 if (_.options.dots && _.$dots !== null) { 3961 3962 $('li', _.$dots) 3963 .off('click.slick', _.changeSlide) 3964 .off('mouseenter.slick', $.proxy(_.interrupt, _, true)) 3965 .off('mouseleave.slick', $.proxy(_.interrupt, _, false)); 3966 3967 if (_.options.accessibility === true) { 3968 _.$dots.off('keydown.slick', _.keyHandler); 3969 } 3970 } 3971 3972 _.$slider.off('focus.slick blur.slick'); 3973 3974 if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) { 3975 _.$prevArrow && _.$prevArrow.off('click.slick', _.changeSlide); 3976 _.$nextArrow && _.$nextArrow.off('click.slick', _.changeSlide); 3977 3978 if (_.options.accessibility === true) { 3979 _.$prevArrow && _.$prevArrow.off('keydown.slick', _.keyHandler); 3980 _.$nextArrow && _.$nextArrow.off('keydown.slick', _.keyHandler); 3981 } 3982 } 3983 3984 _.$list.off('touchstart.slick mousedown.slick', _.swipeHandler); 3985 _.$list.off('touchmove.slick mousemove.slick', _.swipeHandler); 3986 _.$list.off('touchend.slick mouseup.slick', _.swipeHandler);
3987 _.$list.off('touchcancel.slick mouseleave.slick', _.swipeHandler); 3988 3989 _.$list.off('click.slick', _.clickHandler); 3990 3991 $(document).off(_.visibilityChange, _.visibility); 3992 3993 _.cleanUpSlideEvents(); 3994 3995 if (_.options.accessibility === true) { 3996 _.$list.off('keydown.slick', _.keyHandler); 3997 } 3998 3999 if (_.options.focusOnSelect === true) { 4000 $(_.$slideTrack).children().off('click.slick', _.selectHandler); 4001 } 4002 4003 $(window).off('orientationchange.slick.slick-' + _.instanceUid, _.orientationChange); 4004 4005 $(window).off('resize.slick.slick-' + _.instanceUid, _.resize); 4006 4007 $('[draggable!=true]', _.$slideTrack).off('dragstart', _.preventDefault); 4008 4009 $(window).off('load.slick.slick-' + _.instanceUid, _.setPosition); 4010 4011 }; 4012 4013 Slick.prototype.cleanUpSlideEvents = function() { 4014 4015 var _ = this; 4016 4017 _.$list.off('mouseenter.slick', $.proxy(_.interrupt, _, true)); 4018 _.$list.off('mouseleave.slick', $.proxy(_.interrupt, _, false)); 4019 4020 }; 4021 4022 Slick.prototype.cleanUpRows = function() { 4023 4024 var _ = this, originalSlides; 4025 4026 if(_.options.rows > 0) { 4027 originalSlides = _.$slides.children().children(); 4028 originalSlides.removeAttr('style'); 4029 _.$slider.empty().append(originalSlides); 4030 } 4031 4032 }; 4033 4034 Slick.prototype.clickHandler = function(event) { 4035 4036 var _ = this; 4037 4038 if (_.shouldClick === false) { 4039 event.stopImmediatePropagation(); 4040 event.stopPropagation(); 4041 event.preventDefault(); 4042 } 4043 4044 }; 4045 4046 Slick.prototype.destroy = function(refresh) { 4047 4048 var _ = this; 4049 4050 _.autoPlayClear(); 4051 4052 _.touchObject = {}; 4053 4054 _.cleanUpEvents(); 4055 4056 $('.slick-cloned', _.$slider).detach(); 4057 4058 if (_.$dots) { 4059 _.$dots.remove(); 4060 } 4061 4062 if ( _.$prevArrow && _.$prevArrow.length ) { 4063 4064 _.$prevArrow 4065 .removeClass('slick-disabled slick-arrow slick-hidden') 4066 .removeAttr('aria-hidden aria-disabled tabindex') 4067 .css('display',''); 4068 4069 if ( _.htmlExpr.test( _.options.prevArrow )) { 4070 _.$prevArrow.remove(); 4071 } 4072 } 4073 4074 if ( _.$nextArrow && _.$nextArrow.length ) { 4075 4076 _.$nextArrow 4077 .removeClass('slick-disabled slick-arrow slick-hidden') 4078 .removeAttr('aria-hidden aria-disabled tabindex') 4079 .css('display',''); 4080 4081 if ( _.htmlExpr.test( _.options.nextArrow )) { 4082 _.$nextArrow.remove(); 4083 } 4084 } 4085 4086 4087 if (_.$slides) { 4088 4089 _.$slides 4090 .removeClass('slick-slide slick-active slick-center slick-visible slick-current') 4091 .removeAttr('aria-hidden') 4092 .removeAttr('data-slick-index') 4093 .each(function(){ 4094 $(this).attr('style', $(this).data('originalStyling')); 4095 }); 4096 4097 _.$slideTrack.children(this.options.slide).detach(); 4098 4099 _.$slideTrack.detach(); 4100 4101 _.$list.detach(); 4102 4103 _.$slider.append(_.$slides); 4104 } 4105 4106 _.cleanUpRows(); 4107 4108 _.$slider.removeClass('slick-slider'); 4109 _.$slider.removeClass('slick-initialized'); 4110 _.$slider.removeClass('slick-dotted'); 4111 4112 _.unslicked = true; 4113 4114 if(!refresh) { 4115 _.$slider.trigger('destroy', [_]); 4116 } 4117 4118 }; 4119 4120 Slick.prototype.disableTransition = function(slide) { 4121 4122 var _ = this, 4123 transition = {}; 4124 4125 transition[_.transitionType] = ''; 4126 4127 if (_.options.fade === false) { 4128 _.$slideTrack.css(transition); 4129 } else { 4130 _.$slides.eq(slide).css(transition); 4131 } 4132 4133 }; 4134 4135 Slick.prototype.fadeSlide = function(slideIndex, callback) { 4136 4137 var _ = this; 4138 4139 if (_.cssTransitions === false) { 4140 4141 _.$slides.eq(slideIndex).css({ 4142 zIndex: _.options.zIndex 4143 }); 4144 4145 _.$slides.eq(slideIndex).animate({ 4146 opacity: 1 4147 }, _.options.speed, _.options.easing, callback); 4148 4149 } else { 4150 4151 _.applyTransition(slideIndex); 4152 4153 _.$slides.eq(slideIndex).css({ 4154 opacity: 1, 4155 zIndex: _.options.zIndex 4156 }); 4157 4158 if (callback) { 4159 setTimeout(function() { 4160 4161 _.disableTransition(slideIndex); 4162 4163 callback.call(); 4164 }, _.options.speed); 4165 } 4166 4167 } 4168 4169 }; 4170 4171 Slick.prototype.fadeSlideOut = function(slideIndex) { 4172 4173 var _ = this; 4174 4175 if (_.cssTransitions === false) { 4176 4177 _.$slides.eq(slideIndex).animate({ 4178 opacity: 0, 4179 zIndex: _.options.zIndex - 2 4180 }, _.options.speed, _.options.easing); 4181 4182 } else { 4183 4184 _.applyTransition(slideIndex); 4185 4186 _.$slides.eq(slideIndex).css({ 4187 opacity: 0, 4188 zIndex: _.options.zIndex - 2 4189 }); 4190 4191 } 4192 4193 }; 4194
4195 Slick.prototype.filterSlides = Slick.prototype.slickFilter = function(filter) { 4196 4197 var _ = this; 4198 4199 if (filter !== null) { 4200 4201 _.$slidesCache = _.$slides; 4202 4203 _.unload(); 4204 4205 _.$slideTrack.children(this.options.slide).detach(); 4206 4207 _.$slidesCache.filter(filter).appendTo(_.$slideTrack); 4208 4209 _.reinit(); 4210 4211 } 4212 4213 }; 4214 4215 Slick.prototype.focusHandler = function() { 4216 4217 var _ = this; 4218 4219 _.$slider 4220 .off('focus.slick blur.slick') 4221 .on('focus.slick blur.slick', '*', function(event) { 4222 4223 event.stopImmediatePropagation(); 4224 var $sf = $(this); 4225 4226 setTimeout(function() { 4227 4228 if( _.options.pauseOnFocus ) { 4229 _.focussed = $sf.is(':focus'); 4230 _.autoPlay(); 4231 } 4232 4233 }, 0); 4234 4235 }); 4236 }; 4237 4238 Slick.prototype.getCurrent = Slick.prototype.slickCurrentSlide = function() { 4239 4240 var _ = this; 4241 return _.currentSlide; 4242 4243 }; 4244 4245 Slick.prototype.getDotCount = function() { 4246 4247 var _ = this; 4248 4249 var breakPoint = 0; 4250 var counter = 0; 4251 var pagerQty = 0; 4252 4253 if (_.options.infinite === true) { 4254 if (_.slideCount <= _.options.slidesToShow) { 4255 ++pagerQty; 4256 } else { 4257 while (breakPoint < _.slideCount) { 4258 ++pagerQty; 4259 breakPoint = counter + _.options.slidesToScroll; 4260 counter += _.options.slidesToScroll <= _.options.slidesToShow ? _.options.slidesToScroll : _.options.slidesToShow; 4261 } 4262 } 4263 } else if (_.options.centerMode === true) { 4264 pagerQty = _.slideCount; 4265 } else if(!_.options.asNavFor) { 4266 pagerQty = 1 + Math.ceil((_.slideCount - _.options.slidesToShow) / _.options.slidesToScroll); 4267 }else { 4268 while (breakPoint < _.slideCount) { 4269 ++pagerQty; 4270 breakPoint = counter + _.options.slidesToScroll; 4271 counter += _.options.slidesToScroll <= _.options.slidesToShow ? _.options.slidesToScroll : _.options.slidesToShow; 4272 } 4273 } 4274 4275 return pagerQty - 1; 4276 4277 }; 4278 4279 Slick.prototype.getLeft = function(slideIndex) { 4280 4281 var _ = this, 4282 targetLeft, 4283 verticalHeight, 4284 verticalOffset = 0, 4285 targetSlide, 4286 coef; 4287 4288 _.slideOffset = 0; 4289 verticalHeight = _.$slides.first().outerHeight(true); 4290 4291 if (_.options.infinite === true) { 4292 if (_.slideCount > _.options.slidesToShow) { 4293 _.slideOffset = (_.slideWidth * _.options.slidesToShow) * -1; 4294 coef = -1 4295 4296 if (_.options.vertical === true && _.options.centerMode === true) { 4297 if (_.options.slidesToShow === 2) { 4298 coef = -1.5; 4299 } else if (_.options.slidesToShow === 1) { 4300 coef = -2 4301 } 4302 } 4303 verticalOffset = (verticalHeight * _.options.slidesToShow) * coef; 4304 } 4305 if (_.slideCount % _.options.slidesToScroll !== 0) { 4306 if (slideIndex + _.options.slidesToScroll > _.slideCount && _.slideCount > _.options.slidesToShow) { 4307 if (slideIndex > _.slideCount) { 4308 _.slideOffset = ((_.options.slidesToShow - (sl
4308ideIndex - _.slideCount)) * _.slideWidth) * -1; 4309 verticalOffset = ((_.options.slidesToShow - (slideIndex - _.slideCount)) * verticalHeight) * -1; 4310 } else { 4311 _.slideOffset = ((_.slideCount % _.options.slidesToScroll) * _.slideWidth) * -1; 4312 verticalOffset = ((_.slideCount % _.options.slidesToScroll) * verticalHeight) * -1; 4313 } 4314 } 4315 } 4316 } else { 4317 if (slideIndex + _.options.slidesToShow > _.slideCount) { 4318 _.slideOffset = ((slideIndex + _.options.slidesToShow) - _.slideCount) * _.slideWidth; 4319 verticalOffset = ((slideIndex + _.options.slidesToShow) - _.slideCount) * verticalHeight; 4320 } 4321 } 4322 4323 if (_.slideCount <= _.options.slidesToShow) { 4324 _.slideOffset = 0; 4325 verticalOffset = 0; 4326 } 4327 4328 if (_.options.centerMode === true && _.slideCount <= _.options.slidesToShow) { 4329 _.slideOffset = ((_.slideWidth * Math.floor(_.options.slidesToShow)) / 2) - ((_.slideWidth * _.slideCount) / 2); 4330 } else if (_.options.centerMode === true && _.options.infinite === true) { 4331 _.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2) - _.slideWidth; 4332 } else if (_.options.centerMode === true) { 4333 _.slideOffset = 0; 4334 _.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2); 4335 } 4336 4337 if (_.options.vertical === false) { 4338 targetLeft = ((slideIndex * _.slideWidth) * -1) + _.slideOffset; 4339 } else { 4340 targetLeft = ((slideIndex * verticalHeight) * -1) + verticalOffset; 4341 } 4342 4343 if (_.options.variableWidth === true) { 4344
4345 if (_.slideCount <= _.options.slidesToShow || _.options.infinite === false) { 4346 targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex); 4347 } else { 4348 targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex + _.options.slidesToShow); 4349 } 4350 4351 if (_.options.rtl === true) { 4352 if (targetSlide[0]) { 4353 targetLeft = (_.$slideTrack.width() - targetSlide[0].offsetLeft - targetSlide.width()) * -1; 4354 } else { 4355 targetLeft = 0; 4356 } 4357 } else { 4358 targetLeft = targetSlide[0] ? targetSlide[0].offsetLeft * -1 : 0; 4359 } 4360 4361 if (_.options.centerMode === true) { 4362 if (_.slideCount <= _.options.slidesToShow || _.options.infinite === false) { 4363 targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex); 4364 } else { 4365 targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex + _.options.slidesToShow + 1); 4366 } 4367 4368 if (_.options.rtl === true) { 4369 if (targetSlide[0]) { 4370 targetLeft = (_.$slideTrack.width() - targetSlide[0].offsetLeft - targetSlide.width()) * -1; 4371 } else { 4372 targetLeft = 0; 4373 } 4374 } else { 4375 targetLeft = targetSlide[0] ? targetSlide[0].offsetLeft * -1 : 0; 4376 } 4377 4378 targetLeft += (_.$list.width() - targetSlide.outerWidth()) / 2; 4379 } 4380 } 4381 4382 return targetLeft; 4383 4384 }; 4385 4386 Slick.prototype.getOption = Slick.prototype.slickGetOption = function(option) { 4387 4388 var _ = this; 4389 4390 return _.options[option]; 4391 4392 }; 4393 4394 Slick.prototype.getNavigableIndexes = function() { 4395 4396 var _ = this, 4397 breakPoint = 0, 4398 counter = 0, 4399 indexes = [], 4400 max; 4401 4402 if (_.options.infinite === false) { 4403 max = _.slideCount; 4404 } else { 4405 breakPoint = _.options.slidesToScroll * -1; 4406 counter = _.options.slidesToScroll * -1; 4407 max = _.slideCount * 2; 4408 } 4409 4410 while (breakPoint < max) { 4411 indexes.push(breakPoint); 4412 breakPoint = counter + _.options.slidesToScroll; 4413 counter += _.options.slidesToScroll <= _.options.slidesToShow ? _.options.slidesToScroll : _.options.slidesToShow; 4414 } 4415 4416 return indexes; 4417 4418 }; 4419 4420 Slick.prototype.getSlick = function() { 4421 4422 return this; 4423 4424 }; 4425 4426 Slick.prototype.getSlideCount = function() { 4427 4428 var _ = this, 4429 slidesTraversed, swipedSlide, centerOffset; 4430 4431 centerOffset = _.options.centerMode === true ? _.slideWidth * Math.floor(_.options.slidesToShow / 2) : 0; 4432 4433 if (_.options.swipeToSlide === true) { 4434 _.$slideTrack.find('.slick-slide').each(function(index, slide) { 4435 if (slide.offsetLeft - centerOffset + ($(slide).outerWidth() / 2) > (_.swipeLeft * -1)) { 4436 swipedSlide = slide; 4437 return false; 4438 } 4439 }); 4440 4441 slidesTraversed = Math.abs($(swipedSlide).attr('data-slick-index') - _.currentSlide) || 1; 4442 4443 return slidesTraversed; 4444 4445 } else { 4446 return _.options.slidesToScroll; 4447 } 4448 4449 }; 4450 4451 Slick.prototype.goTo = Slick.prototype.slickGoTo = function(slide, dontAnimate) { 4452 4453 var _ = this; 4454 4455 _.changeSlide({ 4456 data: { 4457 message: 'index', 4458 index: parseInt(slide) 4459 } 4460 }, dontAnimate); 4461 4462 }; 4463 4464 Slick.prototype.init = function(creation) { 4465 4466 var _ = this; 4467 4468 if (!$(_.$slider).hasClass('slick-initialized')) { 4469 4470 $(_.$slider).addClass('slick-initialized'); 4471 4472 _.buildRows(); 4473 _.buildOut(); 4474 _.setProps(); 4475 _.startLoad(); 4476 _.loadSlider(); 4477 _.initializeEvents(); 4478 _.updateArrows(); 4479 _.updateDots(); 4480 _.checkResponsive(true); 4481 _.focusHandler(); 4482 4483 } 4484 4485 if (creation) { 4486 _.$slider.trigger('init', [_]); 4487 } 4488 4489 if (_.options.accessibility === true) { 4490 _.initADA(); 4491 } 4492 4493 if ( _.options.autoplay ) { 4494 4495 _.paused = false;
4496 _.autoPlay(); 4497 4498 } 4499 4500 }; 4501 4502 Slick.prototype.initADA = function() { 4503 var _ = this, 4504 numDotGroups = Math.ceil(_.slideCount / _.options.slidesToShow), 4505 tabControlIndexes = _.getNavigableIndexes().filter(function(val) { 4506 return (val >= 0) && (val < _.slideCount); 4507 }); 4508 4509 _.$slides.add(_.$slideTrack.find('.slick-cloned')).attr({ 4510 'aria-hidden': 'true', 4511 'tabindex': '-1' 4512 }).find('a, input, button, select').attr({ 4513 'tabindex': '-1' 4514 }); 4515 4516 if (_.$dots !== null) { 4517 _.$slides.not(_.$slideTrack.find('.slick-cloned')).each(function(i) { 4518 var slideControlIndex = tabControlIndexes.indexOf(i); 4519 4520 $(this).attr({ 4521 'role': 'tabpanel', 4522 'id': 'slick-slide' + _.instanceUid + i, 4523 'tabindex': -1 4524 }); 4525 4526 if (slideControlIndex !== -1) { 4527 var ariaButtonControl = 'slick-slide-control' + _.instanceUid + slideControlIndex 4528 if ($('#' + ariaButtonControl).length) { 4529 $(this).attr({ 4530 'aria-describedby': ariaButtonControl 4531 }); 4532 } 4533 } 4534 }); 4535 4536 _.$dots.attr('role', 'tablist').find('li').each(function(i) { 4537 var mappedSlideIndex = tabControlIndexes[i]; 4538 4539 $(this).attr({ 4540 'role': 'presentation' 4541 }); 4542 4543 $(this).find('button').first().attr({ 4544 'role': 'tab', 4545 'id': 'slick-slide-control' + _.instanceUid + i, 4546 'aria-controls': 'slick-slide' + _.instanceUid + mappedSlideIndex, 4547 'aria-label': (i + 1) + ' of ' + numDotGroups, 4548 'aria-selected': null, 4549 'tabindex': '-1' 4550 }); 4551 4552 }).eq(_.currentSlide).find('button').attr({ 4553 'aria-selected': 'true', 4554 'tabindex': '0' 4555 }).end(); 4556 } 4557 4558 for (var i=_.currentSlide, max=i+_.options.slidesToShow; i < max; i++) { 4559 if (_.options.focusOnChange) { 4560 _.$slides.eq(i).attr({'tabindex': '0'}); 4561 } else { 4562 _.$slides.eq(i).removeAttr('tabindex'); 4563 } 4564 } 4565 4566 _.activateADA(); 4567 4568 }; 4569 4570 Slick.prototype.initArrowEvents = function() { 4571 4572 var _ = this; 4573 4574 if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) { 4575 _.$prevArrow 4576 .off('click.slick') 4577 .on('click.slick', { 4578 message: 'previous' 4579 }, _.changeSlide); 4580 _.$nextArrow 4581 .off('click.slick') 4582 .on('click.slick', { 4583 message: 'next' 4584 }, _.changeSlide); 4585 4586 if (_.options.accessibility === true) { 4587 _.$prevArrow.on('keydown.slick', _.keyHandler); 4588 _.$nextArrow.on('keydown.slick', _.keyHandler); 4589 } 4590 } 4591 4592 }; 4593 4594 Slick.prototype.initDotEvents = function() { 4595 4596 var _ = this; 4597 4598 if (_.options.dots === true && _.slideCount > _.options.slidesToShow) { 4599 $('li', _.$dots).on('click.slick', { 4600 message: 'index' 4601 }, _.changeSlide); 4602 4603 if (_.options.accessibility === true) { 4604 _.$dots.on('keydown.slick', _.keyHandler); 4605 } 4606 } 4607 4608 if (_.options.dots === true && _.options.pauseOnDotsHover === true && _.slideCount > _.options.slidesToShow) { 4609 4610 $('li', _.$dots) 4611 .on('mouseenter.slick', $.proxy(_.interrupt, _, true)) 4612 .on('mouseleave.slick', $.proxy(_.interrupt, _, false)); 4613 4614 } 4615 4616 }; 4617 4618 Slick.prototype.initSlideEvents = function() { 4619 4620 var _ = this; 4621 4622 if ( _.options.pauseOnHover ) { 4623 4624 _.$list.on('mouseenter.slick', $.proxy(_.interrupt, _, true));
4625 _.$list.on('mouseleave.slick', $.proxy(_.interrupt, _, false)); 4626 4627 } 4628 4629 }; 4630 4631 Slick.prototype.initializeEvents = function() { 4632 4633 var _ = this; 4634 4635 _.initArrowEvents(); 4636 4637 _.initDotEvents(); 4638 _.initSlideEvents(); 4639 4640 _.$list.on('touchstart.slick mousedown.slick', { 4641 action: 'start' 4642 }, _.swipeHandler); 4643 _.$list.on('touchmove.slick mousemove.slick', { 4644 action: 'move' 4645 }, _.swipeHandler); 4646 _.$list.on('touchend.slick mouseup.slick', { 4647 action: 'end' 4648 }, _.swipeHandler); 4649 _.$list.on('touchcancel.slick mouseleave.slick', { 4650 action: 'end' 4651 }, _.swipeHandler); 4652 4653 _.$list.on('click.slick', _.clickHandler); 4654 4655 $(document).on(_.visibilityChange, $.proxy(_.visibility, _)); 4656 4657 if (_.options.accessibility === true) { 4658 _.$list.on('keydown.slick', _.keyHandler); 4659 } 4660 4661 if (_.options.focusOnSelect === true) { 4662 $(_.$slideTrack).children().on('click.slick', _.selectHandler); 4663 } 4664 4665 $(window).on('orientationchange.slick.slick-' + _.instanceUid, $.proxy(_.orientationChange, _)); 4666 4667 $(window).on('resize.slick.slick-' + _.instanceUid, $.proxy(_.resize, _)); 4668 4669 $('[draggable!=true]', _.$slideTrack).on('dragstart', _.preventDefault); 4670 4671 $(window).on('load.slick.slick-' + _.instanceUid, _.setPosition); 4672 $(_.setPosition); 4673 4674 }; 4675 4676 Slick.prototype.initUI = function() { 4677 4678 var _ = this; 4679 4680 if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) { 4681 4682 _.$prevArrow.show(); 4683 _.$nextArrow.show(); 4684 4685 } 4686 4687 if (_.options.dots === true && _.slideCount > _.options.slidesToShow) { 4688 4689 _.$dots.show(); 4690 4691 } 4692 4693 }; 4694 4695 Slick.prototype.keyHandler = function(event) { 4696 4697 var _ = this; 4698 //Dont slide if the cursor is inside the form fields and arrow keys are pressed 4699 if(!event.target.tagName.match('TEXTAREA|INPUT|SELECT')) { 4700 if (event.keyCode === 37 && _.options.accessibility === true) { 4701 _.changeSlide({ 4702 data: { 4703 message: _.options.rtl === true ? 'next' : 'previous' 4704 } 4705 }); 4706 } else if (event.keyCode === 39 && _.options.accessibility === true) { 4707 _.changeSlide({ 4708 data: { 4709 message: _.options.rtl === true ? 'previous' : 'next' 4710 } 4711 }); 4712 } 4713 } 4714 4715 }; 4716 4717 Slick.prototype.lazyLoad = function() { 4718 4719 var _ = this, 4720 loadRange, cloneRange, rangeStart, rangeEnd; 4721 4722 function loadImages(imagesScope) { 4723 4724 $('img[data-lazy]', imagesScope).each(function() { 4725 4726 var image = $(this), 4727 imageSource = $(this).attr('data-lazy'), 4728 imageSrcSet = $(this).attr('data-srcset'), 4729 imageSizes = $(this).attr('data-sizes') || _.$slider.attr('data-sizes'), 4730 imageToLoad = document.createElement('img'); 4731 4732 imageToLoad.onload = function() { 4733 4734 image 4735 .animate({ opacity: 0 }, 100, function() { 4736 4737 if (imageSrcSet) { 4738 image 4739 .attr('srcset', imageSrcSet ); 4740 4741 if (imageSizes) { 4742 image 4743 .attr('sizes', imageSizes ); 4744 } 4745 } 4746 4747 image 4748 .attr('src', imageSource) 4749 .animate({ opacity: 1 }, 200, function() { 4750 image 4751 .removeAttr('data-lazy data-srcset data-sizes') 4752 .removeClass('slick-loading'); 4753 }); 4754 _.$slider.trigger('lazyLoaded', [_, image, imageSource]); 4755 }); 4756 4757 }; 4758 4759 imageToLoad.onerror = function() { 4760 4761 image 4762 .removeAttr( 'data-lazy' ) 4763 .removeClass( 'slick-loading' ) 4764 .addClass( 'slick-lazyload-error' ); 4765 4766 _.$slider.trigger('lazyLoadError', [ _, image, imageSource ]); 4767 4768 }; 4769 4770 imageToLoad.src = imageSource; 4771 4772 }); 4773 4774 } 4775 4776 if (_.options.centerMode === true) { 4777 if (_.options.infinite === true) { 4778 rangeStart = _.currentSlide + (_.options.slidesToShow / 2 + 1); 4779 rangeEnd = rangeStart + _.options.slidesToShow + 2; 4780 } else { 4781 rangeStart = Math.max(0, _.currentSlide - (_.options.slidesToShow / 2 + 1)); 4782 rangeEnd = 2 + (_.options.slidesToShow / 2 + 1) + _.currentSlide; 4783 } 4784 } else {
4785 rangeStart = _.options.infinite ? _.options.slidesToShow + _.currentSlide : _.currentSlide; 4786 rangeEnd = Math.ceil(rangeStart + _.options.slidesToShow); 4787 if (_.options.fade === true) { 4788 if (rangeStart > 0) rangeStart--; 4789 if (rangeEnd <= _.slideCount) rangeEnd++; 4790 } 4791 } 4792 4793 loadRange = _.$slider.find('.slick-slide').slice(rangeStart, rangeEnd); 4794 4795 if (_.options.lazyLoad === 'anticipated') { 4796 var prevSlide = rangeStart - 1, 4797 nextSlide = rangeEnd, 4798 $slides = _.$slider.find('.slick-slide'); 4799 4800 for (var i = 0; i < _.options.slidesToScroll; i++) { 4801 if (prevSlide < 0) prevSlide = _.slideCount - 1; 4802 loadRange = loadRange.add($slides.eq(prevSlide)); 4803 loadRange = loadRange.add($slides.eq(nextSlide)); 4804 prevSlide--; 4805 nextSlide++; 4806 } 4807 } 4808 4809 loadImages(loadRange); 4810 4811 if (_.slideCount <= _.options.slidesToShow) { 4812 cloneRange = _.$slider.find('.slick-slide'); 4813 loadImages(cloneRange); 4814 } else 4815 if (_.currentSlide >= _.slideCount - _.options.slidesToShow) { 4816 cloneRange = _.$slider.find('.slick-cloned').slice(0, _.options.slidesToShow); 4817 loadImages(cloneRange); 4818 } else if (_.currentSlide === 0) { 4819 cloneRange = _.$slider.find('.slick-cloned').slice(_.options.slidesToShow * -1); 4820 loadImages(cloneRange); 4821 } 4822 4823 }; 4824 4825 Slick.prototype.loadSlider = function() { 4826 4827 var _ = this; 4828 4829 _.setPosition(); 4830 4831 _.$slideTrack.css({ 4832 opacity: 1 4833 }); 4834 4835 _.$slider.removeClass('slick-loading'); 4836 4837 _.initUI(); 4838 4839 if (_.options.lazyLoad === 'progressive') { 4840 _.progressiveLazyLoad(); 4841 } 4842 4843 }; 4844 4845 Slick.prototype.next = Slick.prototype.slickNext = function() { 4846 4847 var _ = this; 4848 4849 _.changeSlide({ 4850 data: { 4851 message: 'next' 4852 } 4853 }); 4854 4855 }; 4856 4857 Slick.prototype.orientationChange = function() { 4858 4859 var _ = this; 4860 4861 _.checkResponsive(); 4862 _.setPosition(); 4863 4864 }; 4865 4866 Slick.prototype.pause = Slick.prototype.slickPause = function() { 4867 4868 var _ = this; 4869 4870 _.autoPlayClear(); 4871 _.paused = true; 4872 4873 }; 4874 4875 Slick.prototype.play = Slick.prototype.slickPlay = function() { 4876 4877 var _ = this; 4878 4879 _.autoPlay(); 4880 _.options.autoplay = true; 4881 _.paused = false; 4882 _.focussed = false; 4883 _.interrupted = false; 4884 4885 }; 4886 4887 Slick.prototype.postSlide = function(index) { 4888 4889 var _ = this; 4890 4891 if( !_.unslicked ) { 4892 4893 _.$slider.trigger('afterChange', [_, index]); 4894 4895 _.animating = false; 4896 4897 if (_.slideCount > _.options.slidesToShow) { 4898 _.setPosition(); 4899 } 4900 4901 _.swipeLeft = null; 4902 4903 if ( _.options.autoplay ) { 4904 _.autoPlay(); 4905 } 4906 4907 if (_.options.accessibility === true) { 4908 _.initADA(); 4909 4910 if (_.options.focusOnChange) { 4911 var $currentSlide = $(_.$slides.get(_.currentSlide)); 4912 $currentSlide.attr('tabindex', 0).focus(); 4913 } 4914 } 4915 4916 } 4917 4918 }; 4919 4920 Slick.prototype.prev = Slick.prototype.slickPrev = function() { 4921 4922 var _ = this; 4923 4924 _.changeSlide({ 4925 data: { 4926 message: 'previous' 4927 } 4928 }); 4929 4930 }; 4931 4932 Slick.prototype.preventDefault = function(event) { 4933 4934 event.preventDefault(); 4935 4936 }; 4937 4938 Slick.prototype.progressiveLazyLoad = function( tryCount ) { 4939 4940 tryCount = tryCount || 1; 4941 4942 var _ = this, 4943 $imgsToLoad = $( 'img[data-lazy]', _.$slider ), 4944 image, 4945 imageSource, 4946 imageSrcSet, 4947 imageSizes, 4948 imageToLoad; 4949 4950 if ( $imgsToLoad.length ) { 4951 4952 image = $imgsToLoad.first(); 4953 imageSource = image.attr('data-lazy'); 4954 imageSrcSet = image.attr('data-srcset'); 4955 imageSizes = image.attr('data-sizes') || _.$slider.attr('data-sizes'); 4956 imageToLoad = document.createElement('img'); 4957 4958 imageToLoad.onload = function() { 4959 4960 if (imageSrcSet) { 4961 image 4962 .attr('srcset', imageSrcSet ); 4963 4964 if (imageSizes) { 4965 image 4966 .attr('sizes', imageSizes ); 4967 } 4968 } 4969 4970 image 4971 .attr( 'src', imageSource ) 4972 .removeAttr('data-lazy data-srcset data-sizes') 4973 .removeClass('slick-loading'); 4974 4975 if ( _.options.adaptiveHeight === true ) { 4976 _.setPosition(); 4977 } 4978 4979 _.$slider.trigger('lazyLoaded', [ _, image, imageSource ]); 4980 _.progressiveLazyLoad(); 4981 4982 }; 4983 4984 imageToLoad.onerror = function() { 4985 4986 if ( tryCount < 3 ) { 4987 4988 /** 4989 * try to load the image 3 times, 4990 * leave a slight delay so we don't get 4991 * servers blocking the request. 4992 */ 4993 setTimeout( function() { 4994 _.progressiveLazyLoad( tryCount + 1 ); 4995 }, 500 ); 4996 4997 } else { 4998 4999 image 5000 .removeAttr( 'data-lazy' ) 5001 .removeClass( 'slick-loading' ) 5002 .addClass( 'slick-lazyload-error' ); 5003 5004 _.$slider.trigger('lazyLoadError', [ _, image, imageSource ]); 5005 5006 _.progressiveLazyLoad(); 5007 5008 } 5009 5010 }; 5011 5012 imageToLoad.src = imageSource; 5013 5014 } else { 5015 5016 _.$slider.trigger('allImagesLoaded', [ _ ]); 5017 5018 } 5019 5020 }; 5021 5022 Slick.prototype.refresh = function( initializing ) { 5023 5024 var _ = this, currentSlide, lastVisibleIndex; 5025 5026 lastVisibleIndex = _.slideCount - _.options.slidesToShow; 5027 5028 // in non-infinite sliders, we don't want to go past the 5029 // last visible index. 5030 if( !_.options.infinite && ( _.currentSlide > lastVisibleIndex )) { 5031 _.currentSlide = lastVisibleIndex; 5032 } 5033 5034 // if less slides than to show, go to start. 5035 if ( _.slideCount <= _.options.slidesToShow ) { 5036 _.currentSlide = 0; 5037 5038 } 5039 5040 currentSlide = _.currentSlide; 5041 5042 _.destroy(true); 5043 5044 $.extend(_, _.initials, { currentSlide: currentSlide }); 5045
5046 _.init(); 5047 5048 if( !initializing ) { 5049 5050 _.changeSlide({ 5051 data: { 5052 message: 'index', 5053 index: currentSlide 5054 } 5055 }, false); 5056 5057 } 5058 5059 }; 5060 5061 Slick.prototype.registerBreakpoints = function() { 5062 5063 var _ = this, breakpoint, currentBreakpoint, l, 5064 responsiveSettings = _.options.responsive || null; 5065 5066 if ( $.type(responsiveSettings) === 'array' && responsiveSettings.length ) { 5067 5068 _.respondTo = _.options.respondTo || 'window'; 5069 5070 for ( breakpoint in responsiveSettings ) { 5071 5072 l = _.breakpoints.length-1; 5073 5074 if (responsiveSettings.hasOwnProperty(breakpoint)) { 5075 currentBreakpoint = responsiveSettings[breakpoint].breakpoint; 5076 5077 // loop through the breakpoints and cut out any existing 5078 // ones with the same breakpoint number, we don't want dupes. 5079 while( l >= 0 ) { 5080 if( _.breakpoints[l] && _.breakpoints[l] === currentBreakpoint ) { 5081 _.breakpoints.splice(l,1); 5082 } 5083 l--; 5084 } 5085 5086 _.breakpoints.push(currentBreakpoint); 5087 _.breakpointSettings[currentBreakpoint] = responsiveSettings[breakpoint].settings; 5088 5089 } 5090 5091 } 5092 5093 _.breakpoints.sort(function(a, b) { 5094 return ( _.options.mobileFirst ) ? a-b : b-a; 5095 }); 5096 5097 } 5098 5099 }; 5100 5101 Slick.prototype.reinit = function() { 5102 5103 var _ = this; 5104 5105 _.$slides = 5106 _.$slideTrack 5107 .children(_.options.slide) 5108 .addClass('slick-slide'); 5109 5110 _.slideCount = _.$slides.length; 5111 5112 if (_.currentSlide >= _.slideCount && _.currentSlide !== 0) { 5113 _.currentSlide = _.currentSlide - _.options.slidesToScroll; 5114 } 5115 5116 if (_.slideCount <= _.options.slidesToShow) { 5117 _.currentSlide = 0; 5118 } 5119 5120 _.registerBreakpoints(); 5121 5122 _.setProps(); 5123 _.setupInfinite(); 5124 _.buildArrows(); 5125 _.updateArrows(); 5126 _.initArrowEvents(); 5127 _.buildDots(); 5128 _.updateDots(); 5129 _.initDotEvents(); 5130 _.cleanUpSlideEvents(); 5131 _.initSlideEvents(); 5132 5133 _.checkResponsive(false, true); 5134 5135 if (_.options.focusOnSelect === true) { 5136 $(_.$slideTrack).children().on('click.slick', _.selectHandler); 5137 } 5138 5139 _.setSlideClasses(typeof _.currentSlide === 'number' ? _.currentSlide : 0); 5140 5141 _.setPosition(); 5142 _.focusHandler(); 5143 5144 _.paused = !_.options.autoplay; 5145 _.autoPlay(); 5146 5147 _.$slider.trigger('reInit', [_]); 5148 5149 }; 5150 5151 Slick.prototype.resize = function() { 5152 5153 var _ = this; 5154 5155 if ($(window).width() !== _.windowWidth) { 5156 clearTimeout(_.windowDelay); 5157 _.windowDelay = window.setTimeout(function() { 5158 _.windowWidth = $(window).width(); 5159 _.checkResponsive(); 5160 if( !_.unslicked ) { _.setPosition(); } 5161 }, 50); 5162 } 5163 }; 5164 5165 Slick.prototype.removeSlide = Slick.prototype.slickRemove = function(index, removeBefore, removeAll) { 5166 5167 var _ = this; 5168 5169 if (typeof(index) === 'boolean') { 5170 removeBefore = index; 5171 index = removeBefore === true ? 0 : _.slideCount - 1; 5172 } else { 5173 index = removeBefore === true ? --index : index; 5174 } 5175 5176 if (_.slideCount < 1 || index < 0 || index > _.slideCount - 1) { 5177 return false; 5178 } 5179 5180 _.unload(); 5181 5182 if (removeAll === true) { 5183 _.$slideTrack.children().remove(); 5184 } else { 5185 _.$slideTrack.children(this.options.slide).eq(index).remove(); 5186 } 5187 5188 _.$slides = _.$slideTrack.children(this.options.slide); 5189 5190 _.$slideTrack.children(this.options.slide).detach(); 5191 5192 _.$slideTrack.append(_.$slides); 5193 5194 _.$slidesCache = _.$slides; 5195 5196 _.reinit(); 5197 5198 }; 5199 5200 Slick.prototype.setCSS = function(position) { 5201 5202 var _ = this, 5203 positionProps = {}, 5204 x, y; 5205 5206 if (_.options.rtl === true) { 5207 position = -position; 5208 } 5209 x = _.positionProp == 'left' ? Math.ceil(position) + 'px' : '0px'; 5210 y = _.positionProp == 'top' ? Math.ceil(position) + 'px' : '0px'; 5211 5212 positionProps[_.positionProp] = position; 5213 5214 if (_.transformsEnabled === false) { 5215 _.$slideTrack.css(positionProps); 5216 } else { 5217 positionProps = {}; 5218 if (_.cssTransitions === false) { 5219 positionProps[_.animType] = 'translate(' + x + ', ' + y + ')'; 5220 _.$slideTrack.css(positionProps); 5221 } else { 5222 positionProps[_.animType] = 'translate3d(' + x + ', ' + y + ', 0px)'; 5223 _.$slideTrack.css(positionProps); 5224 } 5225 } 5226 5227 }; 5228 5229 Slick.prototype.setDimensions = function() { 5230 5231 var _ = this; 5232 5233 if (_.options.vertical === false) { 5234 if (_.options.centerMode === true) { 5235 _.$list.css({ 5236 padding: ('0px ' + _.options.centerPadding) 5237 }); 5238 } 5239 } else { 5240 _.$list.height(_.$slides.first().outerHeight(true) * _.options.slidesToShow); 5241 if (_.options.centerMode === true) { 5242 _.$list.css({ 5243 padding: (_.options.centerPadding + ' 0px') 5244 }); 5245 } 5246 } 5247 5248 _.listWidth = _.$list.width(); 5249 _.listHeight = _.$list.height(); 5250 5251 5252 if (_.options.vertical === false && _.options.variableWidth === false) { 5253 _.slideWidth = Math.ceil(_.listWidth / _.options.slidesToShow); 5254 _.$slideTrack.width(Math.ceil((_.slideWidth * _.$slideTrack.children('.slick-slide').length))); 5255 5256 } else if (_.options.variableWidth === true) { 5257 _.$slideTrack.width(5000 * _.slideCount); 5258 } else { 5259 _.slideWidth = Math.ceil(_.listWidth); 5260 _.$slideTrack.height(Math.ceil((_.$slides.first().outerHeight(true) * _.$slideTrack.children('.slick-slide').length))); 5261 } 5262 5263 var offset = _.$slides.first().outerWidth(true) - _.$slides.first().width(); 5264 if (_.options.variableWidth === false) _.$slideTrack.children('.slick-slide').width(_.slideWidth - offset); 5265 5266 }; 5267 5268 Slick.prototype.setFade = function() { 5269 5270 var _ = this, 5271 targetLeft; 5272 5273 _.$slides.each(function(index, element) { 5274 targetLeft = (_.slideWidth * index) * -1; 5275 if (_.options.rtl === true) { 5276 $(element).css({ 5277 position: 'relative', 5278 right: targetLeft, 5279 top: 0, 5280 zIndex: _.options.zIndex - 2, 5281 opacity: 0 5282 }); 5283 } else { 5284 $(element).css({ 5285 position: 'relative', 5286 left: targetLeft, 5287 top: 0, 5288 zIndex: _.options.zIndex - 2, 5289 opacity: 0 5290 }); 5291 } 5292 }); 5293 5294 _.$slides.eq(_.currentSlide).css({ 5295 zIndex: _.options.zIndex - 1, 5296 opacity: 1 5297 }); 5298 5299 }; 5300 5301 Slick.prototype.setHeight = function() { 5302 5303 var _ = this; 5304 5305 if (_.options.slidesToShow === 1 && _.options.adaptiveHeight === true && _.options.vertical === false) { 5306 var targetHeight = _.$slides.eq(_.currentSlide).outerHeight(true); 5307 _.$list.css('height', targetHeight); 5308 } 5309 5310 }; 5311 5312 Slick.prototype.setOption = 5313 Slick.prototype.slickSetOption = function() { 5314 5315 /** 5316 * accepts arguments in format of: 5317 * 5318 * - for changing a single option's value: 5319 * .slick("setOption", option, value, refresh ) 5320 * 5321 * - for changing a set of responsive options: 5322 * .slick("setOption", 'responsive', [{}, ...], refresh ) 5323 * 5324 * - for updating multiple values at once (not responsive) 5325 * .slick("setOption", { 'option': value, ... }, refresh ) 5326 */ 5327 5328 var _ = this, l, item, option, value, refresh = false, t
5328ype; 5329 5330 if( $.type( arguments[0] ) === 'object' ) { 5331 5332 option = arguments[0]; 5333 refresh = arguments[1]; 5334 type = 'multiple'; 5335 5336 } else if ( $.type( arguments[0] ) === 'string' ) { 5337 5338 option = arguments[0]; 5339 value = arguments[1]; 5340 refresh = arguments[2]; 5341 5342 if ( arguments[0] === 'responsive' && $.type( arguments[1] ) === 'array' ) { 5343 5344 type = 'responsive'; 5345 5346 } else if ( typeof arguments[1] !== 'undefined' ) { 5347 5348 type = 'single'; 5349 5350 } 5351 5352 } 5353 5354 if ( type === 'single' ) { 5355 5356 _.options[option] = value; 5357 5358 5359 } else if ( type === 'multiple' ) { 5360 5361 $.each( option , function( opt, val ) { 5362 5363 _.options[opt] = val; 5364 5365 }); 5366 5367 5368 } else if ( type === 'responsive' ) { 5369 5370 for ( item in value ) { 5371 5372 if( $.type( _.options.responsive ) !== 'array' ) { 5373 5374 _.options.responsive = [ value[item] ]; 5375 5376 } else { 5377 5378 l = _.options.responsive.length-1; 5379 5380 // loop through the responsive object and splice out duplicates. 5381 while( l >= 0 ) { 5382 5383 if( _.options.responsive[l].breakpoint === value[item].breakpoint ) { 5384 5385 _.options.responsive.splice(l,1); 5386 5387 } 5388 5389 l--; 5390 5391 } 5392 5393 _.options.responsive.push( value[item] ); 5394 5395 } 5396 5397 } 5398 5399 } 5400 5401 if ( refresh ) { 5402 5403 _.unload(); 5404 _.reinit(); 5405 5406 } 5407 5408 }; 5409 5410 Slick.prototype.setPosition = function() { 5411 5412 var _ = this; 5413 5414 _.setDimensions(); 5415 5416 _.setHeight(); 5417 5418 if (_.options.fade === false) { 5419 _.setCSS(_.getLeft(_.currentSlide)); 5420 } else { 5421 _.setFade(); 5422 } 5423 5424 _.$slider.trigger('setPosition', [_]); 5425 5426 }; 5427 5428 Slick.prototype.setProps = function() { 5429 5430 var _ = this, 5431 bodyStyle = document.body.style; 5432 5433 _.positionProp = _.options.vertical === true ? 'top' : 'left'; 5434 5435 if (_.positionProp === 'top') { 5436 _.$slider.addClass('slick-vertical'); 5437 } else { 5438 _.$slider.removeClass('slick-vertical'); 5439 } 5440 5441 if (bodyStyle.WebkitTransition !== undefined || 5442 bodyStyle.MozTransition !== undefined || 5443 bodyStyle.msTransition !== undefined) { 5444 if (_.options.useCSS === true) { 5445 _.cssTransitions = true; 5446 } 5447 } 5448 5449 if ( _.options.fade ) { 5450 if ( typeof _.options.zIndex === 'number' ) { 5451 if( _.options.zIndex < 3 ) { 5452 _.options.zIndex = 3; 5453 } 5454 } else { 5455 _.options.zIndex = _.defaults.zIndex; 5456 } 5457 } 5458 5459 if (bodyStyle.OTransform !== undefined) { 5460 _.animType = 'OTransform'; 5461 _.transformType = '-o-transform'; 5462 _.transitionType = 'OTransition'; 5463 if (bodyStyle.perspectiveProperty === undefined && bodyStyle.webkitPerspective === undefined) _.animType = false;
5464 } 5465 if (bodyStyle.MozTransform !== undefined) { 5466 _.animType = 'MozTransform'; 5467 _.transformType = '-moz-transform'; 5468 _.transitionType = 'MozTransition'; 5469 if (bodyStyle.perspectiveProperty === undefined && bodyStyle.MozPerspective === undefined) _.animType = false; 5470 } 5471 if (bodyStyle.webkitTransform !== undefined) { 5472 _.animType = 'webkitTransform'; 5473 _.transformType = '-webkit-transform'; 5474 _.transitionType = 'webkitTransition'; 5475 if (bodyStyle.perspectiveProperty === undefined && bodyStyle.webkitPerspective === undefined) _.animType = false; 5476 } 5477 if (bodyStyle.msTransform !== undefined) { 5478 _.animType = 'msTransform'; 5479 _.transformType = '-ms-transform'; 5480 _.transitionType = 'msTransition'; 5481 if (bodyStyle.msTransform === undefined) _.animType = false; 5482 } 5483 if (bodyStyle.transform !== undefined && _.animType !== false) { 5484 _.animType = 'transform'; 5485 _.transformType = 'transform'; 5486 _.transitionType = 'transition'; 5487 } 5488 _.transformsEnabled = _.options.useTransform && (_.animType !== null && _.animType !== false); 5489 }; 5490 5491 5492 Slick.prototype.setSlideClasses = function(index) { 5493 5494 var _ = this, 5495 centerOffset, allSlides, indexOffset, remainder; 5496 5497 allSlides = _.$slider 5498 .find('.slick-slide') 5499 .removeClass('slick-active slick-center slick-current') 5500 .attr('aria-hidden', 'true'); 5501 5502 _.$slides 5503 .eq(index) 5504 .addClass('slick-current'); 5505 5506 if (_.options.centerMode === true) { 5507 5508 var evenCoef = _.options.slidesToShow % 2 === 0 ? 1 : 0; 5509 5510 centerOffset = Math.floor(_.options.slidesToShow / 2); 5511 5512 if (_.options.infinite === true) { 5513 5514 if (index >= centerOffset && index <= (_.slideCount - 1) - centerOffset) { 5515 _.$slides 5516 .slice(index - centerOffset + evenCoef, index + centerOffset + 1) 5517 .addClass('slick-active') 5518 .attr('aria-hidden', 'false'); 5519 5520 } else { 5521 5522 indexOffset = _.options.slidesToShow + index; 5523 allSlides 5524 .slice(indexOffset - centerOffset + 1 + evenCoef, indexOffset + centerOffset + 2) 5525 .addClass('slick-active') 5526 .attr('aria-hidden', 'false'); 5527 5528 } 5529 5530 if (index === 0) { 5531 5532 allSlides 5533 .eq(allSlides.length - 1 - _.options.slidesToShow) 5534 .addClass('slick-center'); 5535 5536 } else if (index === _.slideCount - 1) { 5537 5538 allSlides 5539 .eq(_.options.slidesToShow) 5540 .addClass('slick-center'); 5541 5542 } 5543 5544 } 5545 5546 _.$slides 5547 .eq(index) 5548 .addClass('slick-center'); 5549 5550 } else { 5551 5552 if (index >= 0 && index <= (_.slideCount - _.options.slidesToShow)) { 5553 5554 _.$slides 5555 .slice(index, index + _.options.slidesToShow) 5556 .addClass('slick-active') 5557 .attr('aria-hidden', 'false'); 5558 5559 } else if (allSlides.length <= _.options.slidesToShow) { 5560 5561 allSlides 5562 .addClass('slick-active') 5563 .attr('aria-hidden', 'false'); 5564 5565 } else { 5566 5567 remainder = _.slideCount % _.options.slidesToShow; 5568 indexOffset = _.options.infinite === true ? _.options.slidesToShow + index : index; 5569 5570 if (_.options.slidesToShow == _.options.slidesToScroll && (_.slideCount - index) < _.options.slidesToShow) { 5571 5572 allSlides 5573 .slice(indexOffset - (_.options.slidesToShow - remainder), indexOffset + remainder) 5574 .addClass('slick-active') 5575 .attr('aria-hidden', 'false'); 5576 5577 } else { 5578 5579 allSlides 5580 .slice(indexOffset, indexOffset + _.options.slidesToShow) 5581 .addClass('slick-active') 5582 .attr('aria-hidden', 'false'); 5583 5584 } 5585 5586 } 5587 5588 } 5589 5590 if (_.options.lazyLoad === 'ondemand' || _.options.lazyLoad === 'anticipated') { 5591 _.lazyLoad(); 5592 } 5593 }; 5594 5595 Slick.prototype.setupInfinite = function() { 5596 5597 var _ = this, 5598 i, slideIndex, infiniteCount; 5599 5600 if (_.options.fade === true) {
5601 _.options.centerMode = false; 5602 } 5603 5604 if (_.options.infinite === true && _.options.fade === false) { 5605 5606 slideIndex = null; 5607 5608 if (_.slideCount > _.options.slidesToShow) { 5609 5610 if (_.options.centerMode === true) { 5611 infiniteCount = _.options.slidesToShow + 1; 5612 } else { 5613 infiniteCount = _.options.slidesToShow; 5614 } 5615 5616 for (i = _.slideCount; i > (_.slideCount - 5617 infiniteCount); i -= 1) { 5618 slideIndex = i - 1; 5619 $(_.$slides[slideIndex]).clone(true).attr('id', '') 5620 .attr('data-slick-index', slideIndex - _.slideCount) 5621 .prependTo(_.$slideTrack).addClass('slick-cloned'); 5622 } 5623 for (i = 0; i < infiniteCount + _.slideCount; i += 1) { 5624 slideIndex = i; 5625 $(_.$slides[slideIndex]).clone(true).attr('id', '') 5626 .attr('data-slick-index', slideIndex + _.slideCount) 5627 .appendTo(_.$slideTrack).addClass('slick-cloned'); 5628 } 5629 _.$slideTrack.find('.slick-cloned').find('[id]').each(function() { 5630 $(this).attr('id', ''); 5631 }); 5632 5633 } 5634 5635 } 5636 5637 }; 5638 5639 Slick.prototype.interrupt = function( toggle ) { 5640 5641 var _ = this; 5642 5643 if( !toggle ) { 5644 _.autoPlay(); 5645 } 5646 _.interrupted = toggle; 5647 5648 }; 5649 5650 Slick.prototype.selectHandler = function(event) { 5651 5652 var _ = this; 5653 5654 var targetElement = 5655 $(event.target).is('.slick-slide') ? 5656 $(event.target) : 5657 $(event.target).parents('.slick-slide'); 5658 5659 var index = parseInt(targetElement.attr('data-slick-index')); 5660 5661 if (!index) index = 0; 5662 5663 if (_.slideCount <= _.options.slidesToShow) { 5664 5665 _.slideHandler(index, false, true); 5666 return; 5667 5668 } 5669 5670 _.slideHandler(index); 5671 5672 }; 5673 5674 Slick.prototype.slideHandler = function(index, sync, dontAnimate) { 5675 5676 var targetSlide, animSlide, oldSlide, slideLeft, targetLeft = null, 5677 _ = this, navTarget; 5678 5679 sync = sync || false; 5680 5681 if (_.animating === true && _.options.waitForAnimate === true) { 5682 return; 5683 } 5684 5685 if (_.options.fade === true && _.currentSlide === index) { 5686 return; 5687 } 5688 5689 if (sync === false) { 5690 _.asNavFor(index); 5691 } 5692 5693 targetSlide = index; 5694 targetLeft = _.getLeft(targetSlide); 5695 slideLeft = _.getLeft(_.currentSlide); 5696 5697 _.currentLeft = _.swipeLeft === null ? slideLeft : _.swipeLeft; 5698 5699 if (_.options.infinite === false && _.options.centerMode === false && (index < 0 || index > _.getDotCount() * _.options.slidesToScroll)) { 5700 if (_.options.fade === false) { 5701 targetSlide = _.currentSlide; 5702 if (dontAnimate !== true && _.slideCount > _.options.slidesToShow) { 5703 _.animateSlide(slideLeft, function() { 5704 _.postSlide(targetSlide); 5705 }); 5706 } else { 5707 _.postSlide(targetSlide); 5708 } 5709 } 5710 return; 5711 } else if (_.options.infinite === false && _.options.centerMode === true && (index < 0 || index > (_.slideCount - _.options.slidesToScroll))) { 5712 if (_.options.fade === false) { 5713 targetSlide = _.currentSlide; 5714 if (dontAnimate !== true && _.slideCount > _.options.slidesToShow) { 5715 _.animateSlide(slideLeft, function() { 5716 _.postSlide(targetSlide); 5717 }); 5718 } else { 5719 _.postSlide(targetSlide); 5720 } 5721 } 5722 return; 5723 } 5724 5725 if ( _.options.autoplay ) { 5726 clearInterval(_.autoPlayTimer); 5727 } 5728 5729 if (targetSlide < 0) { 5730 if (_.slideCount % _.options.slidesToScroll !== 0) { 5731 animSlide = _.slideCount - (_.slideCount % _.options.slidesToScroll); 5732 } else { 5733 animSlide = _.slideCount + targetSlide; 5734 } 5735 }
5735 else if (targetSlide >= _.slideCount) { 5736 if (_.slideCount % _.options.slidesToScroll !== 0) { 5737 animSlide = 0; 5738 } else { 5739 animSlide = targetSlide - _.slideCount; 5740 } 5741 } else { 5742 animSlide = targetSlide; 5743 } 5744 5745 _.animating = true; 5746 5747 _.$slider.trigger('beforeChange', [_, _.currentSlide, animSlide]); 5748 5749 oldSlide = _.currentSlide; 5750 _.currentSlide = animSlide; 5751 5752 _.setSlideClasses(_.currentSlide); 5753 5754 if ( _.options.asNavFor ) { 5755 5756 navTarget = _.getNavTarget(); 5757 navTarget = navTarget.slick('getSlick'); 5758 5759 if ( navTarget.slideCount <= navTarget.options.slidesToShow ) { 5760 navTarget.setSlideClasses(_.currentSlide); 5761 } 5762 5763 } 5764 5765 _.updateDots(); 5766 _.updateArrows(); 5767 5768 if (_.options.fade === true) { 5769 if (dontAnimate !== true) { 5770 5771 _.fadeSlideOut(oldSlide); 5772 5773 _.fadeSlide(animSlide, function() { 5774 _.postSlide(animSlide); 5775 }); 5776 5777 } else { 5778 _.postSlide(animSlide); 5779 } 5780 _.animateHeight(); 5781 return; 5782 } 5783 5784 if (dontAnimate !== true && _.slideCount > _.options.slidesToShow) { 5785 _.animateSlide(targetLeft, function() { 5786 _.postSlide(animSlide); 5787 }); 5788 } else { 5789 _.postSlide(animSlide); 5790 } 5791 5792 }; 5793 5794 Slick.prototype.startLoad = function() { 5795 5796 var _ = this; 5797 5798 if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) { 5799 5800 _.$prevArrow.hide(); 5801 _.$nextArrow.hide(); 5802 5803 } 5804 5805 if (_.options.dots === true && _.slideCount > _.options.slidesToShow) { 5806 5807 _.$dots.hide(); 5808 5809 } 5810 5811 _.$slider.addClass('slick-loading'); 5812 5813 }; 5814 5815 Slick.prototype.swipeDirection = function() { 5816 5817 var xDist, yDist, r, swipeAngle, _ = this; 5818 5819 xDist = _.touchObject.startX - _.touchObject.curX; 5820 yDist = _.touchObject.startY - _.touchObject.curY; 5821 r = Math.atan2(yDist, xDist); 5822 5823 swipeAngle = Math.round(r * 180 / Math.PI); 5824 if (swipeAngle < 0) { 5825 swipeAngle = 360 - Math.abs(swipeAngle); 5826 } 5827 5828 if ((swipeAngle <= 45) && (swipeAngle >= 0)) { 5829 return (_.options.rtl === false ? 'left' : 'right'); 5830 } 5831 if ((swipeAngle <= 360) && (swipeAngle >= 315)) { 5832 return (_.options.rtl === false ? 'left' : 'right'); 5833 } 5834 if ((swipeAngle >= 135) && (swipeAngle <= 225)) { 5835 return (_.options.rtl === false ? 'right' : 'left'); 5836 } 5837 if (_.options.verticalSwiping === true) { 5838 if ((swipeAngle >= 35) && (swipeAngle <= 135)) { 5839 return 'down'; 5840 } else { 5841 return 'up'; 5842 } 5843 } 5844 5845 return 'vertical'; 5846 5847 }; 5848 5849 Slick.prototype.swipeEnd = function(event) { 5850 5851 var _ = this, 5852 slideCount, 5853 direction; 5854 5855 _.dragging = false; 5856 _.swiping = false; 5857 5858 if (_.scrolling) { 5859 _.scrolling = false; 5860 return false; 5861 } 5862 5863 _.interrupted = false; 5864 _.shouldClick = ( _.touchObject.swipeLength > 10 ) ? false : true; 5865 5866 if ( _.touchObject.curX === undefined ) { 5867 return false; 5868 } 5869 5870 if ( _.touchObject.edgeHit === true ) { 5871 _.$slider.trigger('edge', [_, _.swipeDirection() ]); 5872 } 5873 5874 if ( _.touchObject.swipeLength >= _.touchObject.minSwipe ) { 5875 5876 direction = _.swipeDirection(); 5877 5878 switch ( direction ) { 5879 5880 case 'left': 5881 case 'down': 5882 5883 slideCount = 5884 _.options.swipeToSlide ? 5885 _.checkNavigable( _.currentSlide + _.getSlideCount() ) : 5886 _.currentSlide + _.getSlideCount(); 5887 5888 _.currentDirection = 0; 5889 5890 break; 5891 5892 case 'right': 5893 case 'up': 5894 5895 slideCount =
5896 _.options.swipeToSlide ? 5897 _.checkNavigable( _.currentSlide - _.getSlideCount() ) : 5898 _.currentSlide - _.getSlideCount(); 5899 5900 _.currentDirection = 1; 5901 5902 break; 5903 5904 default: 5905 5906 5907 } 5908 5909 if( direction != 'vertical' ) { 5910 5911 _.slideHandler( slideCount ); 5912 _.touchObject = {}; 5913 _.$slider.trigger('swipe', [_, direction ]); 5914 5915 } 5916 5917 } else { 5918 5919 if ( _.touchObject.startX !== _.touchObject.curX ) { 5920 5921 _.slideHandler( _.currentSlide ); 5922 _.touchObject = {}; 5923 5924 } 5925 5926 } 5927 5928 }; 5929 5930 Slick.prototype.swipeHandler = function(event) { 5931 5932 var _ = this; 5933 5934 if ((_.options.swipe === false) || ('ontouchend' in document && _.options.swipe === false)) { 5935 return; 5936 } else if (_.options.draggable === false && event.type.indexOf('mouse') !== -1) { 5937 return; 5938 } 5939 5940 _.touchObject.fingerCount = event.originalEvent && event.originalEvent.touches !== undefined ? 5941 event.originalEvent.touches.length : 1; 5942 5943 _.touchObject.minSwipe = _.listWidth / _.options 5944 .touchThreshold; 5945 5946 if (_.options.verticalSwiping === true) { 5947 _.touchObject.minSwipe = _.listHeight / _.options 5948 .touchThreshold; 5949 } 5950 5951 switch (event.data.action) { 5952 5953 case 'start': 5954 _.swipeStart(event); 5955 break; 5956 5957 case 'move': 5958 _.swipeMove(event); 5959 break; 5960 5961 case 'end': 5962 _.swipeEnd(event); 5963 break; 5964 5965 } 5966 5967 }; 5968 5969 Slick.prototype.swipeMove = function(event) { 5970 5971 var _ = this, 5972 edgeWasHit = false, 5973 curLeft, swipeDirection, swipeLength, positionOffset, touches, verticalSwipeLength; 5974 5975 touches = event.originalEvent !== undefined ? event.originalEvent.touches : null; 5976 5977 if (!_.dragging || _.scrolling || touches && touches.length !== 1) { 5978 return false; 5979 } 5980 5981 curLeft = _.getLeft(_.currentSlide); 5982 5983 _.touchObject.curX = touches !== undefined ? touches[0].pageX : event.clientX; 5984 _.touchObject.curY = touches !== undefined ? touches[0].pageY : event.clientY; 5985 5986 _.touchObject.swipeLength = Math.round(Math.sqrt( 5987 Math.pow(_.touchObject.curX - _.touchObject.startX, 2))); 5988 5989 verticalSwipeLength = Math.round(Math.sqrt( 5990 Math.pow(_.touchObject.curY - _.touchObject.startY, 2))); 5991 5992 if (!_.options.verticalSwiping && !_.swiping && verticalSwipeLength > 4) { 5993 _.scrolling = true; 5994 return false; 5995 } 5996 5997 if (_.options.verticalSwiping === true) { 5998 _.touchObject.swipeLength = verticalSwipeLength; 5999 } 6000 6001 swipeDirection = _.swipeDirection(); 6002 6003 if (event.originalEvent !== undefined && _.touchObject.swipeLength > 4) { 6004 _.swiping = true; 6005 event.preventDefault(); 6006 } 6007 6008 positionOffset = (_.options.rtl === false ? 1 : -1) * (_.touchObject.curX > _.touchObject.startX ? 1 : -1); 6009 if (_.options.verticalSwiping === true) { 6010 positionOffset = _.touchObject.curY > _.touchObject.startY ? 1 : -1; 6011 } 6012 6013 6014 swipeLength = _.touchObject.swipeLength; 6015 6016 _.touchObject.edgeHit = false; 6017 6018 if (_.options.infinite === false) { 6019 if ((_.currentSlide === 0 && swipeDirection === 'right') || (_.currentSlide >= _.getDotCount() && swipeDirection === 'left')) { 6020 swipeLength = _.touchObject.swipeLength * _.options.edgeFriction; 6021 _.touchObject.edgeHit = true; 6022 } 6023 } 6024 6025 if (_.options.vertical === false) { 6026 _.swipeLeft = curLeft + swipeLength * positionOffset; 6027 } else { 6028 _.swipeLeft = curLeft + (swipeLength * (_.$list.height() / _.listWidth)) * positionOffset; 6029 } 6030 if (_.options.verticalSwiping === true) { 6031 _.swipeLeft = curLeft + swipeLength * positionOffset; 6032 } 6033 6034 if (_.options.fade === true || _.options.touchMove === false) { 6035 return false;
6036 } 6037 6038 if (_.animating === true) { 6039 _.swipeLeft = null; 6040 return false; 6041 } 6042 6043 _.setCSS(_.swipeLeft); 6044 6045 }; 6046 6047 Slick.prototype.swipeStart = function(event) { 6048 6049 var _ = this, 6050 touches; 6051 6052 _.interrupted = true; 6053 6054 if (_.touchObject.fingerCount !== 1 || _.slideCount <= _.options.slidesToShow) { 6055 _.touchObject = {}; 6056 return false; 6057 } 6058 6059 if (event.originalEvent !== undefined && event.originalEvent.touches !== undefined) { 6060 touches = event.originalEvent.touches[0]; 6061 } 6062 6063 _.touchObject.startX = _.touchObject.curX = touches !== undefined ? touches.pageX : event.clientX; 6064 _.touchObject.startY = _.touchObject.curY = touches !== undefined ? touches.pageY : event.clientY; 6065 6066 _.dragging = true; 6067 6068 }; 6069 6070 Slick.prototype.unfilterSlides = Slick.prototype.slickUnfilter = function() { 6071 6072 var _ = this; 6073 6074 if (_.$slidesCache !== null) { 6075 6076 _.unload(); 6077 6078 _.$slideTrack.children(this.options.slide).detach(); 6079 6080 _.$slidesCache.appendTo(_.$slideTrack); 6081 6082 _.reinit(); 6083 6084 } 6085 6086 }; 6087 6088 Slick.prototype.unload = function() { 6089 6090 var _ = this; 6091 6092 $('.slick-cloned', _.$slider).remove(); 6093 6094 if (_.$dots) { 6095 _.$dots.remove(); 6096 } 6097 6098 if (_.$prevArrow && _.htmlExpr.test(_.options.prevArrow)) { 6099 _.$prevArrow.remove(); 6100 } 6101 6102 if (_.$nextArrow && _.htmlExpr.test(_.options.nextArrow)) { 6103 _.$nextArrow.remove(); 6104 } 6105 6106 _.$slides 6107 .removeClass('slick-slide slick-active slick-visible slick-current') 6108 .attr('aria-hidden', 'true') 6109 .css('width', ''); 6110 6111 }; 6112 6113 Slick.prototype.unslick = function(fromBreakpoint) { 6114 6115 var _ = this; 6116 _.$slider.trigger('unslick', [_, fromBreakpoint]); 6117 _.destroy(); 6118 6119 }; 6120 6121 Slick.prototype.updateArrows = function() { 6122 6123 var _ = this, 6124 centerOffset; 6125 6126 centerOffset = Math.floor(_.options.slidesToShow / 2); 6127 6128 if ( _.options.arrows === true && 6129 _.slideCount > _.options.slidesToShow && 6130 !_.options.infinite ) { 6131 6132 _.$prevArrow.removeClass('slick-disabled').attr('aria-disabled', 'false'); 6133 _.$nextArrow.removeClass('slick-disabled').attr('aria-disabled', 'false'); 6134 6135 if (_.currentSlide === 0) { 6136 6137 _.$prevArrow.addClass('slick-disabled').attr('aria-disabled', 'true'); 6138 _.$nextArrow.removeClass('slick-disabled').attr('aria-disabled', 'false'); 6139 6140 } else if (_.currentSlide >= _.slideCount - _.options.slidesToShow && _.options.centerMode === false) { 6141 6142 _.$nextArrow.addClass('slick-disabled').attr('aria-disabled', 'true'); 6143 _.$prevArrow.removeClass('slick-disabled').attr('aria-disabled', 'false'); 6144 6145 } else if (_.currentSlide >= _.slideCount - 1 && _.options.centerMode === true) { 6146 6147 _.$nextArrow.addClass('slick-disabled').attr('aria-disabled', 'true'); 6148 _.$prevArrow.removeClass('slick-disabled').attr('aria-disabled', 'false'); 6149 6150 } 6151 6152 } 6153 6154 }; 6155 6156 Slick.prototype.updateDots = function() { 6157 6158 var _ = this; 6159 6160 if (_.$dots !== null) { 6161 6162 _.$dots 6163 .find('li') 6164 .removeClass('slick-active') 6165 .end(); 6166 6167 _.$dots 6168 .find('li') 6169 .eq(Math.floor(_.currentSlide / _.options.slidesToScroll)) 6170 .addClass('slick-active'); 6171 6172 } 6173 6174 }; 6175 6176 Slick.prototype.visibility = function() { 6177 6178 var _ = this; 6179 6180 if ( _.options.autoplay ) { 6181 6182 if ( document[_.hidden] ) { 6183 6184 _.interrupted = true; 6185 6186 } else { 6187 6188 _.interrupted = false; 6189 6190 } 6191 6192 } 6193 6194 }; 6195 6196 $.fn.slick = function() { 6197 var _ = this, 6198 opt = arguments[0], 6199 args = Array.prototype.slice.call(arguments, 1), 6200 l = _.length, 6201 i, 6202 ret; 6203 for (i = 0; i < l; i++) { 6204 if (typeof opt == 'object' || typeof opt == 'undefined') 6205 _[i].slick = new Slick(_[i], opt); 6206 else 6207 ret = _[i].slick[opt].apply(_[i].slick, args); 6208 if (typeof ret != 'undefined') return ret; 6209 } 6210 return _; 6211 }; 6212 6213}));
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.