1( function() { 2 'use strict'; 3 // Compatibility with YITH WISHLIST PRO 4 if ( typeof yith_wcwl_l10n != 'undefined' ) { 5 yith_wcwl_l10n.enable_tooltip = false; 6 } 7 // Theme Functions 8 function portoCalcSliderButtonsPosition( $parent, padding ) { 9 var $buttons = $parent.find( '.show-nav-title .owl-nav' ); 10 if ( $buttons.length ) { 11 if ( window.theme.rtl ) { 12 $buttons.css( 'left', padding ); 13 } else { 14 $buttons.css( 'right', padding ); 15 } 16 if ( $buttons.closest( '.porto-products' ).length && $buttons.closest( '.porto-products' ).parent().children( '.products-slider-title' ).length ) { 17 var $title = $buttons.closest( '.porto-products' ).parent().children( '.products-slider-title' ), newMT = $title.offset().top - $parent.offset().top - parseInt( $title.css( 'padding-top' ), 10 ) - parseInt( $title.css( 'line-height' ), 10 ) / 2 + $buttons.children().outerHeight() - parseInt( $buttons.children().css( 'margin-top' ), 10 ); 18 $buttons.css( 'margin-top', newMT ); 19 } 20 } 21 } 22 23 // Woocommerce Products Slider 24 if ( typeof jQuery.fn.owlCarousel == 'function' ) { 25 ( function( theme, $ ) { 26 27 theme = theme || {}; 28 29 var instanceName = '__wooProductsSlider'; 30 31 var WooProductsSlider = function( $el, opts ) { 32 return this.initialize( $el, opts ); 33 }; 34 35 WooProductsSlider.defaults = { 36 rtl: theme.rtl, 37 autoplay: theme.slider_autoplay == '1' ? true : false, 38 autoplayTimeout: theme.slider_speed ? theme.slider_speed : 5000, 39 loop: theme.slider_loop, 40 nav: false, 41 navText: ["", ""], 42 dots: false, 43 autoplayHoverPause: true, 44 items: 1, 45 responsive: {}, 46 autoHeight: true, 47 lazyLoad: true 48 }; 49 50 WooProductsSlider.prototype = { 51 initialize: function( $el, opts ) { 52 if ( $el.data( instanceName ) ) { 53 return this; 54 } 55 56 this.$el = $el; 57 58 this 59 .setData() 60 .setOptions( opts ) 61 .build(); 62 63 return this; 64 }, 65 66 setData: function() { 67 this.$el.data( instanceName, true ); 68 69 return this; 70 }, 71 72 setOptions: function( opts ) { 73 this.options = $.extend( true, {}, WooProductsSlider.defaults, opts, { 74 wrapper: this.$el 75 } ); 76 77 return this; 78 }, 79 80 calcOwlHeight: function( $el ) { 81 var h = 0; 82 $el.find( '.owl-item.active' ).each( function() { 83 if ( h < $( this ).height() ) 84 h = $( this ).height(); 85 } ); 86 $el.find( '.owl-stage-outer' ).height( h ); 87 }, 88 89 build: function() { 90 var self = this, 91 $el = this.options.wrapper, 92 lg = this.options.lg, 93 md = this.options.md, 94 xs = this.options.xs, 95 ls = this.options.ls, 96 $slider_wrapper = $el.closest( '.slider-wrapper' ), 97 single = this.options.single, 98 dots = this.options.dots, 99 nav = this.options.nav, 100 responsive = {}, 101 items, 102 // scrollwidth = 0 not using getscrollbarwidth 103 scrollWidth = 0, 104 count = $el.find( '> *' ).length, 105 w_xs = 576 - scrollWidth, 106 w_md = 768 - scrollWidth, 107 w_xl = theme.screen_xl - scrollWidth, 108 w_sl = theme.screen_xxl - scrollWidth; 109 110 if ( $el.find( '.product-col' ).get( 0 ) ) { 111 portoCalcSliderButtonsPosition( $slider_wrapper, $el.find( '.product-col' ).css( 'padding-left' ) ); 112 } 113 114 if ( single ) { 115 items = 1; 116 } else { 117 items = lg ? lg : 1; 118 if ( this.options.xl ) { 119 responsive[w_sl] = { items: this.options.xl, loop: ( this.options.loop && count > this.options.xl ) ? true : false }; 120 } 121 responsive[w_xl] = { items: items, loop: ( this.options.loop && count > items ) ? true : false }; 122 if ( md ) responsive[w_md] = { items: md, loop: ( this.options.loop && count > md ) ? true : false }; 123 if ( xs ) responsive[w_xs] = { items: xs, loop: ( this.options.loop && count > xs ) ? true : false }; 124 if ( ls ) responsive[0] = { items: ls, loop: ( this.options.loop && count > ls ) ? true : false }; 125 } 126 127 this.options = $.extend( true, {}, this.options, { 128 loop: ( this.options.loop && count > items ) ? true : false, 129 items: items, 130 responsive: responsive, 131 onRefresh: function() { 132 if ( $el.find( '.product-col' ).get( 0 ) ) { 133 portoCalcSliderButtonsPosition( $slider_wrapper, $el.find( '.product-col' ).css( 'padding-left' ) ); 134 } 135 }, 136 onInitialized: function() { 137 if ( $el.find( '.product-col' ).get( 0 ) ) { 138 portoCalcSliderButtonsPosition( $slider_wrapper, $el.find( '.product-col' ).css( 'padding-left' ) ); 139 } 140 //$el.find('.cloned .porto-lazyload:not(.lazy-load-loaded)').themePluginLazyLoad(); 141 142 if ( $el.find( '.owl-item.cloned' ).length ) { 143 setTimeout( function() { 144 var ins = $el.find( '.owl-item.cloned .porto-lazyload:not(.lazy-load-loaded)' ).themePluginLazyLoad( { effect: 'fadeIn', effect_speed: 400 } ); 145 if ( ins && ins.loadAndDestroy ) { 146 ins.loadAndDestroy(); 147 } 148 }, 100 ); 149 } 150 }, 151 touchDrag: ( count == 1 ) ? false : true, 152 mouseDrag: ( count == 1 ) ? false : true 153 } ); 154 155 // Auto Height Fixes 156 if ( this.options.autoHeight ) { 157 var thisobj = this; 158 $( window ).on( 'resize', function() { 159 thisobj.calcOwlHeight( $el ); 160 } ); 161 162 if ( theme.isLoaded ) { 163 setTimeout( function() { 164 thisobj.calcOwlHeight( $el ); 165 }, 100 ); 166 } else { 167 $( window ).on( 'load', function() { 168 thisobj.calcOwlHeight( $el ); 169 } ); 170 } 171 } 172 173 $el.owlCarousel( this.options ); 174 175 return this; 176 } 177 }; 178 179 // expose to scope 180 $.extend( theme, { 181 WooProductsSlider: WooProductsSlider 182 } ); 183 184 // jquery plugin 185 $.fn.themeWooProductsSlider = function( opts ) { 186 return this.map( function() { 187 var $this = $( this ); 188 189 if ( $this.data( instanceName ) ) { 190 return $this; 191 } else { 192 return new theme.WooProductsSlider( $this, opts ); 193 } 194 195 } ); 196 } 197 198 } ).apply( this, [window.theme, jQuery] ); 199 } 200 201 // Woocommerce Add to Cart, View Cart Events 202 ( function( theme, $ ) { 203 204 var $supports_html5_storage; 205 try { 206 $supports_html5_storage = ( 'sessionStorage' in window && window.sessionStorage !== null ); 207 208 window.sessionStorage.setItem( 'wc', 'test' ); 209 window.sessionStorage.removeItem( 'wc' ); 210 } catch ( err ) { 211 $supports_html5_storage = false; 212 } 213 214 var setCartCreationTimestamp = function() {
215 if ( $supports_html5_storage ) { 216 sessionStorage.setItem( 'wc_cart_created', ( new Date() ).getTime() ); 217 } 218 }; 219 220 var setCartHash = function( cart_hash ) { 221 if ( $supports_html5_storage && wc_cart_fragments_params ) { 222 localStorage.setItem( wc_cart_fragments_params.cart_hash_key, cart_hash ); 223 sessionStorage.setItem( wc_cart_fragments_params.cart_hash_key, cart_hash ); 224 } 225 }; 226 227 var initAjaxRemoveCartItem = function() { 228 $( document ).off( 'click', '.widget_shopping_cart .remove-product, .shop_table.cart .remove-product, .shop_table.review-order .remove-product' ).on( 'click', '.widget_shopping_cart .remove-product, .shop_table.cart .remove-product, .shop_table.review-order .remove-product', function( e ) { 229 e.preventDefault(); 230 var $this = $( this ); 231 var cart_id = $this.data( "cart_id" ); 232 var product_id = $this.data( "product_id" ); 233 var is_checkout = false; 234 $this.closest( 'li' ).find( '.ajax-loading' ).show(); 235 236 if ( 'undefined' == typeof cart_id ) { 237 is_checkout = true; 238 cart_id = $this.closest( '.cart_item' ).data( 'key' ); 239 } 240 $.ajax( { 241 type: 'POST', 242 dataType: 'json', 243 url: theme.ajax_url, 244 data: { 245 action: "porto_cart_item_remove", 246 nonce: js_porto_vars.porto_nonce, 247 cart_id: cart_id 248 }, 249 success: function( response ) { 250 updateCartFragment( response ); 251 $( document.body ).trigger( 'wc_fragments_refreshed' ); 252 var this_page = window.location.toString(), 253 item_count = $( response.fragments['div.widget_shopping_cart_content'] ).find( '.mini_cart_item' ).length; 254 255 this_page = this_page.replace( 'add-to-cart', 'added-to-cart' ); 256 $( '.viewcart-' + product_id ).removeClass( 'added' ); 257 $( '.porto_cart_item_' + cart_id ).remove(); 258 259 // Block widgets and fragments 260 if ( item_count == 0 && ( $( 'body' ).hasClass( 'woocommerce-cart' ) || $( 'body' ).hasClass( 'woocommerce-checkout' ) ) ) { 261 $( '.page-content' ).fadeTo( 400, 0.8 ).block( { 262 message: null, 263 overlayCSS: { 264 opacity: 0.2 265 } 266 } ); 267 } else { 268 $( 'form.woocommerce-cart-form, #order_review, .updating, .cart_totals' ).fadeTo( 400, 0.8 ).block( { 269 message: null, 270 overlayCSS: { 271 opacity: 0.2 272 } 273 } ); 274 } 275 276 // Unblock 277 $( '.widget_shopping_cart, .updating' ).stop( true ).css( 'opacity', '1' ).unblock(); 278 279 // Cart page elements 280 if ( item_count == 0 && ( $( 'body' ).hasClass( 'woocommerce-cart' ) || $( 'body' ).hasClass( 'woocommerce-checkout' ) ) ) { 281 $( '.page-content' ).load( this_page + ' .page-content:eq(0) > *', function() { 282 $( '.page-content' ).stop( true ).css( 'opacity', '1' ).unblock(); 283 } ); 284 } else { 285 $( 'form.woocommerce-cart-form' ).load( this_page + ' form.woocommerce-cart-form:eq(0) > *', function() { 286 $( 'form.woocommerce-cart-form' ).stop( true ).css( 'opacity', '1' ).unblock(); 287 } ); 288 289 $( '.cart_totals' ).load( this_page + ' .cart_totals:eq(0) > *', function() { 290 $( '.cart_totals' ).stop( true ).css( 'opacity', '1' ).unblock(); 291 } ); 292 293 // Checkout page elements 294 $( '#order_review' ).load( this_page + ' #order_review:eq(0) > *', function() { 295 $( '#order_review' ).stop( true ).css( 'opacity', '1' ).unblock(); 296 } ); 297 } 298 } 299 } ); 300 301 return false; 302 } ); 303 }; 304 305 var refreshCartFragment = function() { 306 initAjaxRemoveCartItem(); 307 if ( $.cookie( 'woocommerce_items_in_cart' ) > 0 ) { 308 $( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).show(); 309 } else { 310 $( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).hide(); 311 } 312 }; 313 314 var updateCartFragment = function( data ) { 315 if ( data && data.fragments ) { 316 var fragments = data.fragments, 317 cart_hash = data.cart_hash; 318 319 $.each( fragments, function( key, value ) { 320 $( key ).replaceWith( value ); 321 } ); 322 if ( typeof wc_cart_fragments_params === 'undefined' ) { 323 return; 324 } 325 /* Storage Handling */
326 if ( $supports_html5_storage ) { 327 var prev_cart_hash = sessionStorage.getItem( 'wc_cart_hash' ); 328 329 if ( prev_cart_hash === null || prev_cart_hash === undefined || prev_cart_hash === '' ) { 330 setCartCreationTimestamp(); 331 } 332 sessionStorage.setItem( wc_cart_fragments_params.fragment_name, JSON.stringify( fragments ) ); 333 setCartHash( cart_hash ); 334 } 335 } 336 }; 337 338 $( function() { 339 340 refreshCartFragment(); 341 342 // add ajax cart loading 343 $( document ).on( 'click', '.add_to_cart_button', function( e ) { 344 var $this = $( this ); 345 if ( $this.is( '.product_type_simple' ) ) { 346 if ( $this.attr( 'data-product_id' ) ) { 347 $this.addClass( 'product-adding' ); 348 } 349 // add to cart notifaction style 2, 3 350 if ( $this.hasClass( 'viewcart-style-2' ) || $this.hasClass( 'viewcart-style-3' ) ) { 351 $( 'body' ).append( '<div id="loading-mask"><div class="background-overlay"></div></div>' ); 352 if ( !$( this ).closest( '.product' ).find( '.loader-container' ).length ) { 353 $( this ).closest( '.product' ).find( '.product-image' ).append( '<div class="loader-container"><div class="loader"><i class="porto-ajax-loader"></i></div></div>' ); 354 } 355 $( this ).closest( '.product' ).find( '.loader-container' ).show(); 356 } 357 } 358 } ); 359 360 // add to cart action 361 $( document ).on( 'click', 'span.add_to_cart_button', function( e ) { 362 var $this = $( this ); 363 if ( $this.is( '.product_type_simple' ) ) { 364 if ( typeof theme.noAjaxCart == 'undefined' ) { 365 theme.noAjaxCart = ! $( '#wc-add-to-cart-js' ).length; 366 } 367 if ( !$this.attr( 'data-product_id' ) || theme.noAjaxCart ) { 368 window.location.href = $this.attr( 'href' ); 369 } 370 } else { 371 window.location.href = $this.attr( 'href' ); 372 } 373 } ); 374 375 $( document.body ).on( 'added_to_cart', function() { 376 $( 'ul.products li.product .added_to_cart, .porto-tb-item .added_to_cart' ).remove(); 377 initAjaxRemoveCartItem(); 378 } ); 379 380 $( document.body ).on( 'wc_cart_button_updated', function() { 381 $( 'ul.products li.product .added_to_cart, .porto-tb-item .added_to_cart' ).remove(); 382 } ); 383 384 $( document.body ).on( 'wc_fragments_refreshed wc_fragments_loaded', function() { 385 refreshCartFragment(); 386 } ); 387 388 $( document ).on( 'click', '.product-image .viewcart, .after-loading-success-message .viewcart', function( e ) { 389 if ( wc_add_to_cart_params.cart_url ) { 390 window.location.href = wc_add_to_cart_params.cart_url; 391 } 392 e.preventDefault(); 393 } ); 394 var porto_product_add_cart_timer = null; 395 $( document ).on( 'added_to_cart', 'body', function( event ) { 396 var $mc_item = $( '#mini-cart .cart-items' ); 397 if ( $mc_item.length ) { 398 $mc_item.addClass( 'count-updating' ); 399 setTimeout( function() { 400 $mc_item.removeClass( 'count-updating' ); 401 }, 1000 ); 402 } 403 404 //add to cart notifaction style 2,3 405 $( 'body #loading-mask' ).remove(); 406 407 $( '.add_to_cart_button.product-adding' ).each( function() { 408 var $link = $( this ); 409 $link.removeClass( 'product-adding' ); 410 if ( $link.hasClass( 'viewcart-style-1' ) ) { 411 $link.closest( '.product' ).find( '.viewcart' ).addClass( 'added' ); 412 $( '.minicart-offcanvas' ).addClass( 'minicart-opened' ); 413 } else { 414 $link.closest( '.product' ).find( '.loader-container' ).hide(); 415 if ( $link.closest( 'li.outofstock' ).length ) { 416 return; 417 } 418 var $msg; 419 if ( $link.hasClass( 'viewcart-style-2' ) ) { 420 $msg = $( '.after-loading-success-message .success-message-container' ).eq( 0 ); 421 $msg.find( '.product-name' ).text( $link.closest( '.product' ).find( '.woocommerce-loop-product__title' ).text() ); 422 } else { 423 $msg = $( '.after-loading-success-message .success-message-container' ).last().clone().removeClass( 'd-none' ); 424 $msg.find( '.product-name' ).empty().append( $link.closest( '.product' ).find( '.product-loop-title, .post-title a' ).clone() ); 425 } 426 $msg.find( '.msg-box img' ).remove(); 427 if ( $link.closest( '.product' ).find( '.product-image img' ).length ) { 428 var $img = $link.closest( '.product' ).find( '.product-image img' ).eq( 0 ); 429 $( '<img />' ).attr( 'src', $img.data( 'oi' ) ? $img.data( 'oi' ) : $img.attr( 'src' ) ).appendTo( $msg.find( '.msg-box' ) ); 430 } 431 $( '.after-loading-success-message' ).eq( 0 ).stop().show(); 432 433 if ( $link.hasClass( 'viewcart-style-2' ) ) { 434 if ( porto_product_add_cart_timer ) { 435 clearTimeout( porto_product_add_cart_timer ); 436 } 437 porto_product_add_cart_timer = setTimeout( function() { $( '.after-loading-success-message' ).eq( 0 ).hide(); }, 4000 ); 438 } else {
439 $msg.prependTo( '.after-loading-success-message' ); 440 theme.requestFrame( function() { 441 $msg.addClass( 'active' ); 442 } ); 443 setTimeout( function() { $msg.find( '.mfp-close' ).trigger( 'click' ); }, 5000 ); 444 } 445 } 446 } ); 447 } ); 448 449 $( '.after-loading-success-message .continue_shopping' ).on( 'click', function() { 450 $( '.after-loading-success-message' ).eq( 0 ).fadeOut( 200 ); 451 } ); 452 $( '.after-loading-success-message' ).on( 'click', '.mfp-close', function() { 453 var $obj = $( this ).closest( '.success-message-container' ); 454 $obj.removeClass( 'active' ); 455 theme.requestTimeout( function() { 456 $obj.slideUp( 300, function() { 457 $obj.remove(); 458 } ); 459 }, 350 ); 460 } ); 461 462 $( document.body ).on( 'click', '.variations_form .variations .filter-item-list .filter-color, .variations_form .variations .filter-item-list .filter-item', function( e ) { 463 e.preventDefault(); 464 var $this = $( this ), 465 $selector = $this.closest( 'ul' ).siblings( 'select' ); 466 if ( !$selector.length || $this.hasClass( 'disabled' ) ) { 467 return; 468 } 469 var $li_obj = $this.closest( 'li' ); 470 if ( $li_obj.hasClass( 'active' ) ) { 471 $li_obj.removeClass( 'active' ); 472 $selector.val( '' ); 473 } else { 474 $li_obj.addClass( 'active' ).siblings().removeClass( 'active' ); 475 $selector.val( $this.data( 'value' ) ); 476 } 477 $selector.trigger( 'change.wc-variation-form' ); 478 } ); 479 $( document ).on( 'wc_variation_form', '.variations_form', function() { 480 $( this ).addClass( 'vf_init' ); 481 if ( $( this ).find( '.filter-item-list' ).length < 1 ) { 482 return; 483 } 484 $( this ).find( '.variations select' ).trigger( 'focusin' ); 485 } ); 486 $( document ).on( 'updated_wc_div', function() { 487 $( '.woocommerce-cart-form .porto-lazyload' ).themePluginLazyLoad(); 488 } ); 489 $( document ).on( 'found_variation reset_data', '.variations_form', function( e, args ) { 490 // attribute description 491 var $this = $( this ); 492 if ( $this.find( '.product-attr-description' ).length ) { 493 if ( typeof args == 'undefined' ) { 494 $this.find( '.product-attr-description' ).removeClass( 'active' ); 495 } else { 496 $this.find( '.product-attr-description' ).addClass( 'active' ); 497 $this.find( '.product-attr-description .attr-desc' ).removeClass( 'active' ); 498 $this.find( '.variations select' ).each( function() { 499 var $obj = $( this ); 500 $this.find( '.product-attr-description .attr-desc[data-attrid="' + $obj.val() + '"]' ).addClass( 'active' ); 501 } ); 502 } 503 } 504 505 if ( $this.find( ".filter-item-list" ).length < 1 ) { 506 return; 507 } 508 $this.find( ".filter-item-list" ).each( function() { 509 if ( $( this ).next( "select" ).length < 1 ) { 510 return; 511 } 512 var selector = $( this ).next( "select" ), 513 //html = '', 514 $list = $( this ); 515 $list.find( 'li.active' ).removeClass( 'active' ); 516 $list.find( '.filter-color, .filter-item' ).removeClass( 'enabled' ).removeClass( 'disabled' ); 517 selector.children( "option" ).each( function() { 518 /*var isColor = typeof $(this).data('color') != 'undefined' ? true : false, 519 isImage = typeof $(this).data('image') != 'undefined' ? true : false, 520 spanClass = isColor ? "filter-color" : ( isImage ? "filter-item filter-image" : "filter-item" );*/ 521 if ( !$( this ).val() ) { 522 return; 523 } 524 $list.find( '[data-value="' + $( this ).val().replace(/"/g, '\\\"') + '"]' ).addClass( 'enabled' ); 525 if ( $( this ).val() == selector.val() ) { 526 $list.find( '[data-value="' + $( this ).val().replace(/"/g, '\\\"') + '"]' ).parent().addClass( 'active' ); 527 } 528 /*html += '<li'; 529 if ($(this).val() == selector.val()) { 530 html += ' class="active"'; 531 } 532 html += '><a href="#" data-value="'+ escape( $(this).val() ) +'" class="' + spanClass + '"'; 533 if (isColor) { 534 html += ' style="background-color: #' + escape( $(this).data('color').replace('#','') ) + '"'; 535 } 536 if (isImage) { 537 html += ' style="background-image:url(' + $(this).data('image') + ')"'; 538 } 539 html += '>'; 540 if (!isColor) { 541 html += $(this).text(); 542 } 543 html += '</a></li>';*/ 544 } ); 545 $list.find( '.filter-color:not(.enabled), .filter-item:not(.enabled)' ).addClass( 'disabled' ); 546 //$(this).html(html); 547 } ); 548 } ); 549 550 // daily sale 551 $( document ).on( 'found_variation reset_data', '.variations_form', function( e, obj ) { 552 var $wrapper = $( this ).closest( '.product' ), 553 $timer = $wrapper.find( '.sale-product-daily-deal.for-some-variations' ); 554 if ( !$timer.length ) { 555 $timer = $wrapper.find( '.porto-product-sale-timer' ).eq( 0 ); 556 if ( !$timer.length ) { 557 return; 558 } 559 } 560 if ( obj && obj.is_purchasable && typeof obj.porto_date_on_sale_to != 'undefined' && obj.porto_date_on_sale_to ) {
561 var saleTimer = $timer.find( '.porto_countdown-dateAndTime' ); 562 if ( saleTimer.data( 'terminal-date' ) != obj.porto_date_on_sale_to ) { 563 var newDate = new Date( obj.porto_date_on_sale_to ); 564 saleTimer.porto_countdown( 'option', { until: newDate } ); 565 saleTimer.data( 'terminal-date', obj.porto_date_on_sale_to ); 566 } 567 $timer.slideDown(); 568 } else { 569 if ( $timer.is( ':hidden' ) ) { 570 $timer.hide(); 571 } else { 572 $timer.slideUp(); 573 } 574 } 575 } ); 576 577 $( 'body' ).on( 'click', '.product-attr-description > a', function( e ) { 578 e.preventDefault(); 579 $( this ).next().stop().slideToggle( 400 ); 580 } ); 581 582 // if product was already added to cart, show check icon in add to cart button and view cart button in single product page 583 if ( $( document.body ).hasClass( 'single-product' ) ) { 584 $( document ).on( 'woocommerce_variation_has_changed', '.variations_form', function( e, variation ) { 585 $( document.body ).removeClass( 'single-add-to-cart' ); 586 } ); 587 $( document ).on( 'found_variation', '.variations_form', function( e, variation ) { 588 try { 589 var cart_items = JSON.parse( sessionStorage.getItem( wc_cart_fragments_params.fragment_name ) ); 590 if ( cart_items['div.widget_shopping_cart_content'] ) { 591 var cart_item = $( cart_items['div.widget_shopping_cart_content'] ).find( '.porto-variation-' + variation.variation_id ); 592 if ( cart_item.length ) { 593 theme.requestFrame( function() { 594 $( document.body ).addClass( 'single-add-to-cart' ); 595 } ); 596 } 597 } 598 } catch ( e ) { 599 } 600 } ); 601 } 602 603 // Mini Cart Quantity on Cart Popup or Offcanvas 604 var timeout; 605 606 $( document ).on( 'change input', '.cart_list .quantity .qty, .woocommerce-checkout-review-order-table .quantity .qty', function() { 607 var input = $(this); 608 var itemID = ''; 609 var qtyVal = input.val(); 610 var maxValue = input.attr( 'max' ); 611 var is_checkout = false; 612 613 clearTimeout( timeout ); 614 615 if ( parseInt( qtyVal ) > parseInt( maxValue ) ) { 616 qtyVal = maxValue; 617 } 618 if ( input.closest( '.cart_list' ).length ) { 619 itemID = input.parents( '.woocommerce-mini-cart-item' ).data( 'key' ); 620 } else { 621 is_checkout = true; 622 itemID = input.closest( '.cart_item' ).data( 'key' ); 623 } 624 timeout = setTimeout( function() { 625 if ( ! is_checkout ) { 626 input.parents( '.mini_cart_item' ).find( '.ajax-loading' ).show(); 627 } 628 $.ajax( { 629 url : theme.ajax_url, 630 data : { 631 action : 'porto_update_cart_item', 632 item_id: itemID, 633 qty : qtyVal 634 }, 635 success : function( data ) { 636 if ( data && data.fragments ) { 637 updateCartFragment( data ); 638 $( document.body ).trigger( 'wc_fragments_refreshed' ); 639 } 640 if ( is_checkout ) { 641 input.closest( 'form.checkout' ).trigger( 'update' ); 642 } else { 643 input.parents( '.mini_cart_item' ).find( '.ajax-loading' ).hide(); 644 } 645 }, 646 dataType: 'json', 647 method : 'GET' 648 } ); 649 }, 500 ); 650 } ); 651 } ); 652 653 } ).apply( this, [window.theme, jQuery] ); 654 655 656 // Woocommerce Product Image Slider 657 ( function( theme, $ ) { 658 659 theme = theme || {}; 660 661 var duration = 300, 662 flag = false; 663 664 $.extend( theme, { 665 666 WooProductImageSlider: { 667 668 defaults: { 669 elements: '.product-image-slider' 670 }, 671 672 initialize: function( $elements ) { 673 this.$elements = ( $elements || $( this.defaults.elements ) ); 674 if ( !this.$elements.length && !$( '.product-images-block' ).length ) { 675 return this; 676 } 677 678 this.build(); 679 680 return this; 681 }, 682 683 build: function() { 684 var self = this, 685 thumbs_count = theme.product_thumbs_count; 686 687 if ( theme.product_zoom && ( !( 'ontouchstart' in document ) || ( ( 'ontouchstart' in document ) && theme.product_zoom_mobile ) ) ) { 688 var zoomConfig = { 689 responsive: true, 690 zoomWindowFadeIn: 200, 691 zoomWindowFadeOut: 100, 692 zoomType: js_porto_vars.zoom_type, 693 cursor: 'grab' 694 }; 695 696 if ( js_porto_vars.zoom_type == 'lens' ) { 697 zoomConfig.scrollZoom = js_porto_vars.zoom_scroll; 698 zoomConfig.lensSize = js_porto_vars.zoom_lens_size; 699 zoomConfig.lensShape = js_porto_vars.zoom_lens_shape; 700 zoomConfig.containLensZoom = js_porto_vars.zoom_contain_lens; 701 zoomConfig.lensBorderSize = js_porto_vars.zoom_lens_border; 702 zoomConfig.borderColour = js_porto_vars.zoom_border_color; 703 } 704 705 if ( js_porto_vars.zoom_type == 'inner' ) { 706 zoomConfig.borderSize = 0; 707 } else { 708 zoomConfig.borderSize = js_porto_vars.zoom_border; 709 } 710 zoomConfig.zoomActivation = 'dbltouch'; 711 712 if ( !self.$elements.length ) { 713 var $images_grid = $( '.product-images-block' ); 714 if ( $images_grid.length ) { 715 self.initZoom( $images_grid, zoomConfig ); 716 } 717 } 718 } 719 720 self.$elements.each( function() { 721 var $this = $( this ), 722 $product = $this.closest( '.product' ); 723 if ( !$product.length ) { 724 $product = $this.closest( '.product_layout, .product-layout-image' ).eq( 0 ); 725 } 726 var $thumbs_slider = $product.find( '.product-thumbs-slider' ), 727 $thumbs = $product.find( '.product-thumbnails-inner' ), 728 $thumbs_vertical_slider = $product.find( '.product-thumbs-vertical-slider' ), 729 currentSlide = 0, 730 count = $this.find( '> *' ).length; 731 732 $this.find( '> *:first-child' ).imagesLoaded( function() { 733 734 var links = []; 735 if ( theme.product_image_popup ) { 736 var i = 0; 737 $this.find( 'img' ).each( function() { 738 var slide = {}; 739 740 slide.src = $( this ).attr( 'href' ); 741 slide.title = $( this ).attr( 'alt' ); 742 743 links[i] = slide; 744 i++; 745 } ); 746 } 747 748 if ( $.fn.owlCarousel ) { 749 $thumbs_slider.owlCarousel( { 750 rtl: theme.rtl, 751 loop: false, 752 autoplay: false, 753 items: thumbs_count, 754 nav: false, 755 navText: ["", ""], 756 dots: false, 757 rewind: true, 758 margin: 8, 759 stagePadding: 1, 760 lazyLoad: true, 761 onInitialized: function() { 762 self.selectThumb( null, $thumbs_slider, 0 ); 763 if ( $thumbs_slider.find( '.owl-item' ).length >= thumbs_count ) 764 $thumbs_slider.append( '<div class="thumb-nav"><div class="thumb-prev"></div><div class="thumb-next"></div></div>' ); 765 } 766 } ).on( 'click', '.owl-item', function() { 767 self.selectThumb( $this, $thumbs_slider, $( this ).index() ); 768 } ); 769 if ( $thumbs_vertical_slider.length > 0 && typeof $.fn.slick == 'function' ) { 770 var slickOptions = { 771 dots: false, 772 vertical: true, 773 slidesToShow: thumbs_count, 774 slidesToScroll: 1, 775 infinite: false, 776 } 777 if ( thumbs_count >= 5 ) { 778 slickOptions['responsive'] = [ 779 { 780 breakpoint: 992, 781 settings: { 782 slidesToShow: 4, 783 } 784 }, 785 { 786 breakpoint: 768, 787 settings: { 788 slidesToShow: 3, 789 } 790 } 791 ] 792 } 793 $thumbs_vertical_slider.slick( slickOptions ).on( 'click', '.img-thumbnail', function() { 794 self.selectVerticalSliderThumb( $this, $thumbs_vertical_slider, $( this ).data( 'slick-index' ) ); 795 } ); 796 self.selectVerticalSliderThumb( null, $thumbs_vertical_slider, 0 ); 797 if ( $thumbs_vertical_slider.find( '.porto-lazyload' ).length ) { 798 theme.requestTimeout( function() { 799 $thumbs_vertical_slider.find( '.slick-cloned .porto-lazyload:not(.lazy-load-loaded)' ).each( function() { 800 $( this ).attr( 'src', $( this ).data( 'oi' ) ).removeAttr( 'data-oi' ).addClass( 'lazy-load-loaded' ); 801 } ); 802 }, 100 ); 803 } 804 } 805 806 self.selectVerticalThumb( null, $thumbs, 0 ); 807 $thumbs.off( 'click', '.img-thumbnail' ).on( 'click', '.img-thumbnail', function() { 808 self.selectVerticalThumb( $this, $thumbs, $( this ).index() ); 809 } ); 810 811 $thumbs_slider.off( 'click', '.thumb-prev' ).on( 'click', '.thumb-prev', function( e ) { 812 var currentThumb = $thumbs_slider.data( 'currentThumb' ); 813 self.selectThumb( $this, $thumbs_slider, --currentThumb ); 814 } ); 815 $thumbs_slider.off( 'click', '.thumb-next' ).on( 'click', '.thumb-next', function( e ) { 816 var currentThumb = $thumbs_slider.data( 'currentThumb' ); 817 self.selectThumb( $this, $thumbs_slider, ++currentThumb ); 818 } ); 819 820 var itemsCount = typeof $this.data( 'items' ) != 'undefined' ? $this.data( 'items' ) : 1, 821 itemsResponsive = typeof $this.data( 'responsive' ) != 'undefined' ? $this.data( 'responsive' ) : {}, 822 centerItem = typeof $this.data( 'centeritem' ) != 'undefined' ? true : false, 823 margin = typeof $this.data( 'margin' ) != 'undefined' ? $this.data( 'margin' ) : 0, 824 loop = ( count > 1 ) ? ( typeof $this.data( 'loop' ) != 'undefined' ? $this.data( 'loop' ) : true ) : false; 825 for ( var itemCount in itemsResponsive ) { 826 itemsResponsive[itemCount] = { items: itemsResponsive[itemCount] }; 827 } 828 $this.owlCarousel( { 829 rtl: theme.rtl, 830 loop: loop, 831 autoplay: false, 832 items: itemsCount, 833 margin: margin, 834 responsive: itemsResponsive, 835 autoHeight: true, 836 nav: true, 837 navText: ["", ""], 838 dots: false, 839 rewind: true, 840 lazyLoad: true, 841 center: centerItem, 842 onInitialized: function() { 843 if ( $this.find( '.owl-item.cloned' ).length ) { 844 setTimeout( function() { 845 var ins = $this.find( '.owl-item.cloned .porto-lazyload:not(.lazy-load-loaded)' ).themePluginLazyLoad( { effect: 'fadeIn', effect_speed: 400 } ); 846 if ( ins && ins.loadAndDestroy ) { 847 ins.loadAndDestroy(); 848 } 849 }, 100 ); 850 } 851 //$this.find('.cloned .porto-lazyload:not(.lazy-load-loaded)').themePluginLazyLoad(); 852 self.initZoom( $this, zoomConfig ); 853 }, 854 onTranslate: function( event ) { 855 currentSlide = event.item.index - $this.find( '.cloned' ).length / 2; 856 currentSlide = ( currentSlide + event.item.count ) % event.item.count; 857 self.selectThumb( null, $thumbs_slider, currentSlide ); 858 self.selectVerticalThumb( null, $thumbs, currentSlide ); 859 self.selectVerticalSliderThumb( null, $thumbs_vertical_slider, currentSlide ); 860 861 /*var $obj = event.relatedTarget.items(currentSlide).find('img.owl-lazy:not(.owl-lazy-loaded)'); 862 if ($obj.length) { 863 var src = $obj.attr('href'), 864 elevateZoom = $obj.data('elevateZoom'), 865 smallImage = $obj.data('src') ? $obj.data('src') : $obj.attr('src'); 866 if (typeof elevateZoom != 'undefined') { 867 elevateZoom.swaptheimage(smallImage, src); 868 } 869 }*/ 870 }, 871 onRefreshed: function() { 872 if ( theme.product_zoom && ( !( 'ontouchstart' in document ) || ( ( 'ontouchstart' in document ) && theme.product_zoom_mobile ) ) ) { 873 $this.find( 'img' ).each( function() { 874 var $this = $( this ), 875 src = typeof $this.attr( 'href' ) != 'undefined' ? $this.attr( 'href' ) : ( $this.data( 'oi' ) ? $this.data( 'oi' ) : $this.attr( 'src' ) ), 876 elevateZoom = $this.data( 'elevateZoom' ), 877 smallImage = $this.data( 'src' ) ? $this.data( 'src' ) : ( $this.data( 'oi' ) ? $this.data( 'oi' ) : $this.attr( 'src' ) ); 878 if ( typeof elevateZoom != 'undefined' ) { 879 elevateZoom.startZoom(); 880 elevateZoom.swaptheimage( smallImage, src ); 881 } else if ( $.fn.elevateZoom ) { 882 zoomConfig.zoomContainer = $this.parent(); 883 $this.elevateZoom( zoomConfig ); 884 } 885 } ); 886 } 887 } 888 } ); 889 } else { 890 self.initZoom( $this, zoomConfig ); 891 } 892 893 $this.data( 'links', links ); 894 895 if ( theme.product_image_popup ) { 896 var $zoom_buttons = $this.siblings( '.zoom' ); 897 $zoom_buttons.off( 'click' ).on( 'click', function( e ) { 898 e.preventDefault(); 899 if ( $.fn.magnificPopup ) { 900 $.magnificPopup.close(); 901 $.magnificPopup.open( $.extend( true, {}, theme.mfpConfig, { 902 items: $this.data( 'links' ), 903 gallery: { 904 enabled: true 905 }, 906 type: 'image' 907 } ), currentSlide ); 908 } 909 } ); 910 } 911 912 } ); 913 } ); 914 915 return self; 916 }, 917 918 selectThumb: function( $image_slider, $thumbs_slider, index ) { 919 if ( flag || !$thumbs_slider.length ) return; 920 921 flag = true; 922 var len = $thumbs_slider.find( '.owl-item' ).length, 923 actives = [], 924 i = 0; 925 926 index = ( index + len ) % len; 927 if ( $image_slider ) { 928 $image_slider.trigger( 'to.owl.carousel', [index, duration, true] ); 929 } 930 $thumbs_slider.find( '.owl-item' ).removeClass( 'selected' ); 931 $thumbs_slider.find( '.owl-item:eq(' + index + ')' ).addClass( 'selected' ); 932 $thumbs_slider.data( 'currentThumb', index ); 933 $thumbs_slider.find( '.owl-item.active' ).each( function() { 934 actives[i++] = $( this ).index(); 935 } ); 936 if ( $.inArray( index, actives ) == -1 ) { 937 if ( Math.abs( index - actives[0] ) > Math.abs( index - actives[actives.length - 1] ) ) { 938 $thumbs_slider.trigger( 'to.owl.carousel', [( index - actives.length + 1 ) % len, duration, true] ); 939 } else { 940 $thumbs_slider.trigger( 'to.owl.carousel', [index % len, duration, true] ); 941 } 942 } 943 flag = false; 944 }, 945 946 selectVerticalSliderThumb: function( $image_slider, $thumbs_vertical_slider, index ) { 947 if ( flag || !$thumbs_vertical_slider.length ) return; 948 flag = true; 949 if ( 'undefined' == typeof $thumbs_vertical_slider[0].slick ) { 950 return; 951 } 952 var len = $thumbs_vertical_slider[0].slick.slideCount, 953 actives = [], 954 i = 0; 955 index = ( index + len ) % len; 956 if ( $image_slider ) { 957 $image_slider.trigger( 'to.owl.carousel', [index, duration, true] ); 958 } 959 $thumbs_vertical_slider.find( '.img-thumbnail' ).removeClass( 'selected' ); 960 $thumbs_vertical_slider.find( '.img-thumbnail:eq(' + index + ')' ).addClass( 'selected' ); 961 $thumbs_vertical_slider.data( 'currentThumb', index ); 962 $thumbs_vertical_slider.find( '.img-thumbnail.slick-active' ).each( function() { 963 actives[i++] = $( this ).index(); 964 } ); 965 if ( $.inArray( index, actives ) == -1 ) { 966 if ( Math.abs( index - actives[0] ) > Math.abs( index - actives[actives.length - 1] ) ) { 967 $thumbs_vertical_slider.get( 0 ).slick.goTo( ( index - actives.length + 1 ) % len, false ); 968 } else { 969 $thumbs_vertical_slider.get( 0 ).slick.goTo( index % len, false ); 970 } 971 } 972 flag = false; 973 }, 974 975 selectVerticalThumb: function( $image_slider, $thumbs, index ) { 976 if ( flag || !$thumbs.length ) return; 977 flag = true; 978 var len = $thumbs.find( '.img-thumbnail' ).length, 979 i = 0; 980 981 index = ( index + len ) % len; 982 if ( $image_slider ) { 983 $image_slider.trigger( 'to.owl.carousel', [index, duration, true] ); 984 } 985 $thumbs.find( '.img-thumbnail' ).removeClass( 'selected' ); 986 $thumbs.find( '.img-thumbnail:eq(' + index + ')' ).addClass( 'selected' ); 987 $thumbs.data( 'currentThumb', index ); 988 flag = false; 989 }, 990 991 initZoom: function( $this, zoomConfig ) { 992 if ( theme.product_zoom && ( !( 'ontouchstart' in document ) || ( ( 'ontouchstart' in document ) && theme.product_zoom_mobile ) ) ) { 993 $this.find( 'img' ).each( function() { 994 var $this = $( this ); 995 zoomC
995onfig.zoomContainer = $this.parent(); 996 if ( $.fn.elevateZoom ) { 997 $this.elevateZoom( zoomConfig ); 998 } else { 999 setTimeout( function() { 1000 if ( $.fn.elevateZoom ) { 1001 $this.elevateZoom( zoomConfig ); 1002 } 1003 }, 1000 ); 1004 } 1005 } ); 1006 } 1007 } 1008 } 1009 1010 } ); 1011 1012 } ).apply( this, [window.theme, jQuery] ); 1013 1014 1015 // Woocommerce Quick View 1016 ( function( theme, $ ) { 1017 1018 theme = theme || {}; 1019 1020 $.extend( theme, { 1021 1022 WooQuickView: { 1023 1024 initialize: function() { 1025 1026 this.events(); 1027 1028 return this; 1029 }, 1030 1031 events: function() { 1032 var self = this; 1033 1034 $( document ).on( 'click', '.quickview', function( e ) { 1035 e.preventDefault(); 1036 1037 if ( !$.fn.elevateZoom && !$( '#porto-script-jquery-elevatezoom' ).length ) { 1038 var js = document.createElement( 'script' ); 1039 js.id = 'porto-script-jquery-elevatezoom'; 1040 $( js ).appendTo( 'body' ).attr( 'src', js_porto_vars.ajax_loader_url.replace( '/images/[email protected]', '/js/libs/jquery.elevatezoom.min.js' ) ); 1041 } 1042 1043 var $this = $( this ), 1044 pid = $this.attr( 'data-id' ); 1045 1046 function init_quick_view_window() { 1047 1048 var args = { 1049 href: theme.ajax_url, 1050 ajax: { 1051 data: { 1052 action: 'porto_product_quickview', 1053 variation_flag: typeof wc_add_to_cart_variation_params !== 'undefined', 1054 pid: pid, 1055 nonce: js_porto_vars.porto_nonce 1056 } 1057 }, 1058 type: 'ajax', 1059 helpers: { 1060 overlay: { 1061 locked: true, 1062 fixed: true 1063 } 1064 }, 1065 tpl: { 1066 error: '<p class="fancybox-error">' + theme.request_error + '</p>', 1067 closeBtn: '<a title="' + js_porto_vars.popup_close + '" class="fancybox-item fancybox-close" href="javascript:;"></a>', 1068 next: '<a title="' + js_porto_vars.popup_next + '" class="fancybox-nav fancybox-next" href="javascript:;"><span></span></a>', 1069 prev: '<a title="' + js_porto_vars.popup_prev + '" class="fancybox-nav fancybox-prev" href="javascript:;"><span></span></a>' 1070 }, 1071 autoSize: true, 1072 autoWidth: true, 1073 afterShow: function( flag ) { 1074 theme.requestTimeout( function() { 1075 if ( typeof flag == 'undefined' || flag ) { 1076 porto_woocommerce_init(); 1077 } 1078 theme.WooProductImageSlider.initialize( $( '.quickview-wrap-' + pid ).find( '.product-image-slider' ) ); 1079 1080 // compatibility issue with Yith WooCommerce Booking form 1081 if ( $( document.body ).hasClass( 'yith-booking' ) ) { 1082 $( document ).trigger( 'yith-wcbk-init-booking-form' ); 1083 } 1084 1085 // Variation Form 1086 var form_variation = $( '.quickview-wrap-' + pid ).find( 'form.variations_form' ); 1087 if ( form_variation.length > 0 ) { 1088 form_variation.wc_variation_form(); 1089 } 1090 $( document.body ).trigger( 'porto_init_countdown', [$( '.quickview-wrap-' + pid )] ); 1091 1092 // Ajax load at the first by Yith Wishlist Plugin 1093 if ( ( 'undefined' !== typeof yith_wcwl_l10n ) && yith_wcwl_l10n.enable_ajax_loading ) { 1094 if ( $( '.fancybox-opened .wishlist-fragment' ).length ) { 1095 var options = {}, 1096 $product = $( '.fancybox-opened .wishlist-fragment' ), 1097 id = $product.attr( 'class' ).split( ' ' ).filter( ( val ) => { 1098 return val.length && val !== 'exists'; 1099 } ).join( yith_wcwl_l10n.fragments_index_glue ); 1100 options[id] = $product.data( 'fragment-options' ); 1101 1102 if ( !options ) { 1103 return; 1104 } 1105 1106 var ajaxData = { 1107 action: yith_wcwl_l10n.actions.load_fragments, 1108 context: 'frontend', 1109 fragments: options 1110 }; 1111 1112 if ( typeof yith_wcwl_l10n.nonce != 'undefined' ) { 1113 ajaxData.nonce = yith_wcwl_l10n.nonce.load_fragments_nonce; 1114 } 1115 1116 $.ajax( { 1117 ajaxData, 1118 method: 'post', 1119 success: function( data ) { 1120 if ( typeof data.fragments !== 'undefined' ) { 1121 $.each( data.fragments, function( i, v ) { 1122 var itemSelector = '.' + i.split( yith_wcwl_l10n.fragments_index_glue ).filter( ( val ) => { return val.length && val !== 'exists' && val !== 'with-count'; } ).join( '.' ), 1123 toReplace = $( itemSelector ); 1124 1125 // find replace tempalte 1126 var replaceWith = $( v ).filter( itemSelector ); 1127 1128 if ( !replaceWith.length ) { 1129 replaceWith = $( v ).find( itemSelector ); 1130 } 1131 1132 if ( toReplace.length && replaceWith.length ) { 1133 toReplace.replaceWith( replaceWith ); 1134 } 1135 } ); 1136 } 1137 }, 1138 url: yith_wcwl_l10n.ajax_url 1139 } ); 1140 } 1141 } 1142 }, 200 ); 1143 }, 1144 onUpdate: function() { 1145 theme.requestTimeout( function() { 1146 if ( js_porto_vars.use_skeleton_screen.indexOf( 'quickview' ) == -1 || !js_porto_vars.quickview_skeleton ) { 1147 porto_woocommerce_init(); 1148 } 1149 var $slider = $( '.quickview-wrap-' + pid ).find( '.product-image-slider' ); 1150 if ( typeof $slider.data( 'owl.carousel' ) != 'undefined' && typeof $slider.data( 'owl.carousel' )._invalidated != 'undefined' ) 1151 $slider.data( 'owl.carousel' )._invalidated.width = true; 1152 $slider.trigger( 'refresh.owl.carousel' ); 1153 $( document.body ).trigger( 'porto_init_countdown', [$( '.quickview-wrap-' + pid )] ); 1154 }, 300 ); 1155 } 1156 }; 1157 if ( js_porto_vars.use_skeleton_screen.indexOf( 'quickview' ) != -1 && js_porto_vars.quickview_skeleton ) { 1158 delete args['href']; 1159 delete args['ajax']; 1160 args['type'] = 'inline'; 1161 $.fancybox.open( 1162 js_porto_vars.quickview_skeleton, 1163 args 1164 ); 1165 $.ajax( { 1166 url: theme.ajax_url, 1167 type: 'post', 1168 dataType: 'html', 1169 data: { 1170 action: 'porto_product_quickview', 1171 variation_flag: typeof wc_add_to_cart_variation_params !== 'undefined', 1172 pid: pid, 1173 nonce: js_porto_vars.porto_nonce 1174 }, 1175 success: function( res ) { 1176 var $res = $( res ); 1177 $res.imagesLoaded( function() { 1178 $( '.skeleton-body.product' ).replaceWith( $res ); 1179 theme.WooQtyField.initialize(); 1180 $( window ).trigger( 'resize' ); 1181 args['afterShow'].call( false ); 1182 } ); 1183 } 1184 } ); 1185 } else { 1186 if ( typeof $.fancybox == 'function' ) { 1187 $.fancybox( args ); 1188 } else if ( typeof $.fancybox == 'object' && $.fancybox.version && 0 === $.fancybox.version.indexOf( '3' ) ) { 1189 args['src'] = args['href']; 1190 args['ajax']['settings'] = { 1191 data: args['ajax']['data'] 1192 }; 1193 $.fancybox.open( args ); 1194 } 1195 } 1196 } 1197 1198 if ( $.fn.fancybox ) { 1199 init_quick_view_window(); 1200 } else if ( !$( '#porto-script-jquery-fancybox' ).length ) { 1201 var js1 = document.createElement( 'script' ); 1202 js1.id = 'porto-script-jquery-fancybox'; 1203 $( js1 ).appendTo( 'body' ).on( 'load', function() { 1204 init_quick_view_window(); 1205 } ).attr( 'src', js_porto_vars.ajax_loader_url.replace( '/images/[email protected]', '/js/libs/jquery.fancybox.min.js' ) ); 1206 } 1207 1208 return false; 1209 } ); 1210 1211 // ajax add to cart on quickview 1212 if ( typeof wc_add_to_cart_params != 'undefined' ) { 1213 $( document.body ).on( 'click', '.single-product .single_add_to_cart_button:not(.disabled)', function( e ) { 1214 if ( $( this ).closest( '.single-product' ).hasClass( 'product-type-external' ) || $( this ).closest( '.single-product' ).hasClass( 'product-type-grouped' ) ) { 1215 return true; 1216 } 1217 e.preventDefault(); 1218 1219 var $button = $( this ), 1220 product_id = $button.val(), 1221 variation_id = $button.closest( 'form' ).find( 'input[name="variation_id"]' ).val(), 1222 quantity = $button.closest( 'form' ).find( 'input[name="quantity"]' ).val(); 1223 if ( $button.hasClass( 'loading' ) ) { 1224 return false; 1225 } 1226 $button.removeClass( 'added' ); 1227 $button.addClass( 'loading' ); 1228 $button.parent().addClass( 'porto-ajax-loading' ); 1229 if ( !$button.siblings( '.porto-loading-icon' ).length ) { 1230 let $last = $button.siblings( 'button:last-of-type' ); 1231 $( '<span class="porto-loading-icon"></span>' ).insertAfter( $last.length ? $last : $button ); 1232 } 1233 1234 var data = { 1235 action: 'porto_add_to_cart', 1236 product_id: variation_id ? variation_id : product_id, 1237 quantity: quantity 1238 }; 1239 if ( variation_id ) { 1240 var $variations = $button.closest( 'form' ).find( '.variations select' ); 1241 if ( $variations.length ) { 1242 $variations.each( function() { 1243 var name = $( this ).data( 'attribute_name' ), 1244 val = $( this ).val();
1245 if ( name && val ) { 1246 data[name] = val; 1247 } 1248 } ); 1249 } 1250 } 1251 1252 // Trigger event. 1253 $( document.body ).trigger( 'adding_to_cart', [$button, data] ); 1254 1255 $.ajax( { 1256 type: 'POST', 1257 url: theme.ajax_url, 1258 data: data, 1259 dataType: 'json', 1260 success: function( response ) { 1261 $button.parent().removeClass( 'porto-ajax-loading' ); 1262 if ( !response ) { 1263 return; 1264 } 1265 if ( response.error && response.product_url ) { 1266 window.location = response.product_url; 1267 return; 1268 } 1269 // Redirect to cart option 1270 if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) { 1271 window.location = wc_add_to_cart_params.cart_url; 1272 return; 1273 } 1274 1275 // Trigger event. 1276 $( document.body ).trigger( 'added_to_cart', [response.fragments, response.cart_hash, $button] ); 1277 } 1278 } ); 1279 } ); 1280 } 1281 1282 return self; 1283 } 1284 } 1285 1286 } ); 1287 1288 } ).apply( this, [window.theme, jQuery] ); 1289 1290 1291 // Woocommerce Qty Field 1292 ( function( theme, $ ) { 1293 1294 theme = theme || {}; 1295 1296 $.extend( theme, { 1297 1298 WooQtyField: { 1299 1300 initialize: function() { 1301 1302 this.build() 1303 .events(); 1304 1305 return this; 1306 }, 1307 1308 qty_handler: function() { 1309 var $obj = $( this ); 1310 if ( $obj.closest( '.quantity' ).next( '.add_to_cart_button[data-quantity]' ).length ) { 1311 var count = $obj.val(); 1312 if ( count ) { 1313 $obj.closest( '.quantity' ).next( '.add_to_cart_button[data-quantity]' ).attr( 'data-quantity', count ); 1314 } 1315 } 1316 }, 1317 1318 build: function() { 1319 var self = this; 1320 1321 // Quantity buttons 1322 $( 'div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)' ).addClass( 'buttons_added' ).append( '<button type="button" value="+" class="plus">+</button>' ).prepend( '<button type="button" value="-" class="minus">-</button>' ); 1323 1324 // Target quantity inputs on product pages 1325 $( 'input.qty:not(.product-quantity input.qty)' ).each( function() { 1326 var min = parseFloat( $( this ).attr( 'min' ) ); 1327 1328 if ( min && min > 0 && parseFloat( $( this ).val() ) < min ) { 1329 $( this ).val( min ); 1330 } 1331 } ); 1332 1333 $( 'input.qty:not(.product-quantity input.qty)' ).off( 'change', self.qty_handler ).on( 'change', self.qty_handler ); 1334 1335 $( document ).off( 'click', '.quantity .plus, .quantity .minus' ).on( 'click', '.quantity .plus, .quantity .minus', function() { 1336 1337 // Get values 1338 var $qty = $( this ).closest( '.quantity' ).find( '.qty' ), 1339 currentVal = parseFloat( $qty.val() ), 1340 max = parseFloat( $qty.attr( 'max' ) ), 1341 min = parseFloat( $qty.attr( 'min' ) ), 1342 step = $qty.attr( 'step' ); 1343 1344 // Format values 1345 if ( !currentVal || currentVal === '' || currentVal === 'NaN' ) currentVal = 0; 1346 if ( max === '' || max === 'NaN' ) max = ''; 1347 if ( min === '' || min === 'NaN' ) min = 0; 1348 if ( step === 'any' || step === '' || step === undefined || parseFloat( step ) === 'NaN' ) step = 1; 1349 1350 // Change the value 1351 if ( $( this ).is( '.plus' ) ) { 1352 1353 if ( max && ( max == currentVal || currentVal > max ) ) { 1354 $qty.val( max ); 1355 } else { 1356 $qty.val( currentVal + parseFloat( step ) ); 1357 } 1358 1359 } else { 1360 1361 if ( min && ( min == currentVal || currentVal < min ) ) { 1362 $qty.val( min ); 1363 } else if ( currentVal > 0 ) { 1364 $qty.val( currentVal - parseFloat( step ) ); 1365 } 1366 1367 } 1368 1369 // Trigger change event 1370 $qty.trigger( 'change' ); 1371 } ); 1372 1373 return self; 1374 }, 1375 1376 events: function() { 1377 var self = this; 1378 1379 $( document ).ajaxComplete( function( event, xhr, options ) { 1380 self.build(); 1381 } ); 1382 1383 return self; 1384 } 1385 } 1386 1387 } ); 1388 1389 } ).apply( this, [window.theme, jQuery] ); 1390 1391 1392 // Woocommerce Variation Form 1393 ( function( theme, $ ) { 1394 1395 theme = theme || {}; 1396 1397 var duration = 300; 1398 1399 $.extend( theme, { 1400 1401 WooVariationForm: { 1402 1403 initialize: function() { 1404 1405 this.init().events(); 1406 1407 return this; 1408 }, 1409 1410 init: function() { 1411 $( '.variations_form' ).each( function() { 1412 var $variation_form = $( this ), 1413 $reset_variations = $variation_form.find( '.reset_variations' ); 1414 1415 if ( $reset_variations.css( 'visibility' ) == 'hidden' ) 1416 $reset_variations.hide(); 1417 } ); 1418 return this; 1419 }, 1420 1421 events: function() { 1422 var self = this; 1423 1424 $( document ).on( 'check_variations', '.variations_form', function( event, exclude, focus ) { 1425 var $variation_form = $( this ), 1426 $reset_variations = $variation_form.find( '.reset_variations' ); 1427 1428 if ( $reset_variations.css( 'visibility' ) == 'hidden' ) 1429 $reset_variations.hide(); 1430 } ); 1431 1432 $( document ).on( 'reset_image', '.variations_form', function( event ) { 1433 var $product = $( this ).closest( '.product, .product-col' ), 1434 $product_img = $product.find( 'div.product-images .woocommerce-main-image' ); 1435 if ( $product.hasClass( 'porto-tb-item' ) ) { // in type builder 1436 $product_img = $product.find( '.porto-tb-featured-image img' ).eq( 0 ); 1437 } else if ( $product.hasClass( 'product-col' ) ) { // shop pages 1438 $product_img = $product.find( 'div.product-image .inner img:first-child' ); 1439 } 1440 var o_src = $product_img.attr( 'data-o_src' ), 1441 o_title = $product_img.attr( 'data-o_title' ), 1442 o_href = $product_img.attr( 'data-o_href' ), 1443 $thumb_img = $product.find( '.woocommerce-main-thumb' ), 1444 o_thumb_src = $thumb_img.attr( 'data-o_src' ); 1445 1446 var $image_slider = $product.find( '.product-image-slider' ), 1447 $thumbs_slider = $product.find( '.product-thumbs-slider' ), 1448 links; 1449 1450 if ( $image_slider.length ) { 1451 $image_slider.trigger( 'to.owl.carousel', [0, duration, true] ); 1452 links = $image_slider.data( 'links' ); 1453 } 1454 if ( $thumbs_slider.length ) { 1455 $thumbs_slider.trigger( 'to.owl.carousel', [0, duration, true] ); 1456 $thumbs_slider.find( '.owl-item:eq(0)' ).trigger( 'click' ); 1457 } 1458 1459 if ( o_src ) { 1460 $product_img 1461 .attr( 'src', o_src ) 1462 .attr( 'srcset', '' ) 1463 .attr( 'alt', o_title ) 1464 .attr( 'href', o_href ); 1465 1466 $product_img.each( function() { 1467 var elevateZoom = $( this ).data( 'elevateZoom' ); 1468 if ( typeof elevateZoom != 'undefined' ) { 1469 elevateZoom.swaptheimage( $( this ).attr( 'src' ), $( this ).attr( 'src' ) ); 1470 } 1471 } ); 1472 1473 if ( theme.product_image_popup && typeof links != 'undefined' ) { 1474 links[0].src = o_href; 1475 links[0].title = o_title; 1476 } 1477 } 1478 if ( o_thumb_src ) { 1479 $thumb_img.attr( 'src', o_thumb_src ); 1480 } 1481 } ); 1482 1483 $( document ).on( 'found_variation', '.variations_form', function( event, variation ) { 1484 1485 if ( typeof variation == 'undefined' ) { 1486 return; 1487 } 1488 1489 var $product = $( this ).closest( '.product, .product-col' ), 1490 $image_slider = $product.find( '.product-image-slider' ), 1491 $thumbs_slider = $product.find( '.product-thumbs-slider' ), 1492 links; 1493 1494 if ( $image_slider.length ) { 1495 $image_slider.trigger( 'to.owl.carousel', [0, duration, true] ); 1496 links = $image_slider.data( 'links' ); 1497 } 1498 if ( $thumbs_slider.length ) { 1499 $thumbs_slider.trigger( 'to.owl.carousel', [0, duration, true] ); 1500 $thumbs_slider.find( '.owl-item:eq(0)' ).trigger( 'click' ); 1501 } 1502 1503 var $shop_single_image = $product.find( 'div.product-images .woocommerce-main-image' ).length ? $product.find( 'div.product-images .woocommerce-main-image' ) : $( '.single-product div.product-images .woocommerce-main-image' ), 1504 productimage = $shop_single_image.attr( 'data-o_src' ), 1505 imagetitle = $shop_single_image.attr( 'data-o_title' ), 1506 imagehref = $shop_single_image.attr( 'data-o_href' ), 1507 $shop_thumb_image = $product.find( '.woocommerce-main-thumb' ), 1508 thumbimage = $shop_thumb_image.attr( 'data-o_src' ), 1509 variation_image = variation.image_src, 1510 variation_link = variation.image_link, 1511 variation_title = variation.image_title, 1512 variation_thumb = variation.image_thumb; 1513 1514 if ( $product.hasClass( 'porto-tb-item' ) ) { // in type builder 1515 $shop_single_image = $product.find( '.porto-tb-featured-image img' ).eq( 0 ); 1516 productimage = $shop_single_image.attr( 'data-o_src' ); 1517 variation_image = variation.image.thumb_src; 1518 } else if ( $product.hasClass( 'product-col' ) ) { // shop pages 1519 $shop_single_image = $product.find( 'div.product-image .inner img:first-child' ); 1520 productimage = $shop_single_image.attr( 'data-o_src' ); 1521 variation_image = variation.image.thumb_src; 1522 } 1523 1524 if ( !productimage ) { 1525 productimage = $shop_single_image.attr( 'data-oi' ) ? $shop_single_image.attr( 'data-oi' ) : ( ( !$shop_single_image.attr( 'src' ) ) ? '' : $shop_single_image.attr( 'src' ) ); 1526 $shop_single_image.attr( 'data-o_src', productimage ); 1527 } 1528 1529 if ( !imagehref ) { 1530 imagehref = ( !$shop_single_image.attr( 'href' ) ) ? '' : $shop_single_image.attr( 'href' ); 1531 $shop_single_image.attr( 'data-o_href', imagehref ); 1532 } 1533 1534 if ( !imagetitle ) { 1535 imagetitle = ( !$shop_single_image.attr( 'alt' ) ) ? '' : $shop_single_image.attr( 'alt' ); 1536 $shop_single_image.attr( 'data-o_title', imagetitle ); 1537 } 1538 1539 if ( !thumbimage ) { 1540 thumbimage = $shop_thumb_image.attr( 'data-oi' ) ? $shop_thumb_image.attr( 'data-oi' ) : ( ( !$shop_thumb_image.attr( 'src' ) ) ? '' : $shop_thumb_image.attr( 'src' ) ); 1541 $shop_thumb_image.attr( 'data-o_src', thumbimage ); 1542 } 1543 1544 if ( variation_image ) { 1545 $shop_single_image.attr( 'src', variation_image ); 1546 $shop_single_image.attr( 'srcset', '' ); 1547 $shop_single_image.attr( 'alt', variation_title ); 1548 $shop_single_image.attr( 'href', variation_link ); 1549 $shop_thumb_image.attr( 'src', variation_thumb ); 1550 if ( theme.product_image_popup && typeof links != 'undefined' ) { 1551 links[0].src = variation_link; 1552 links[0].title = variation_title; 1553 } 1554 } else { 1555 $shop_single_image.attr( 'src', productimage ); 1556 $shop_single_image.attr( 'srcset', '' ); 1557 $shop_single_image.attr( 'alt', imagetitle ); 1558 $shop_single_image.attr( 'href', imagehref ); 1559 $shop_thumb_image.attr( 'src', thumbimage ); 1560 if ( theme.product_image_popup && typeof links != 'undefined' ) { 1561 links[0].src = imagehref; 1562 links[0].title = imagetitle; 1563 } 1564 } 1565 $shop_single_image.each( function() { 1566 var elevateZoom = $( this ).data( 'elevateZoom' ); 1567 if ( typeof elevateZoom != 'undefined' ) { 1568 elevateZoom.swaptheimage( $( this ).attr( 'src' ), $( this ).attr( 'src' ) ); 1569 } 1570 } ); 1571 } ); 1572 1573 // fix scrolling to top issue on fancybox quickview whenever updating variation 1574 var porto_fb_update_trigger = null; 1575 $( document ).on( 'found_variation reset_image', '.variations_form', function( event, variation ) { 1576 if ( $( this ).closest( '.fancybox-inner' ).length && $.fancybox ) { 1577 $( window ).off( 'resize.fb', $.fancybox.update ); 1578 if ( porto_fb_update_trigger ) { 1579 theme.deleteTimeout( porto_fb_update_trigger ); 1580 } 1581 porto_fb_update_trigger = theme.requestTimeout( function() { 1582 $( window ).on( 'resize.fb', $.fancybox.update ); 1583 porto_fb_update_trigger = false; 1584 }, 160 ); 1585 } 1586 } ); 1587 1588 return self; 1589 } 1590 } 1591 1592 } ); 1593 1594 } ).apply( this, [window.theme, jQuery] ); 1595 1596 1597 // Woocommerce Events 1598 ( function( theme, $ ) { 1599 1600 theme = theme || {}; 1601 1602 $.extend( theme, { 1603 1604 WooEvents: { 1605 1606 initialize: function() { 1607 1608 this.events(); 1609 1610 return this; 1611 }, 1612 1613 events: function() { 1614 var self = this; 1615 1616 // wcml currency switcher 1617 $( document ).on( 'click', '.wcml-switcher li', function() { 1618 if ( $( this ).parent().attr( 'disabled' ) == 'disabled' ) 1619 return; 1620 var currency = $( this ).attr( 'rel' ); 1621 self.loadCurrency( currency ); 1622 } ); 1623 1624 // woocommerce currency switcher 1625 $( document ).on( 'click', '.woocs-switcher li', function() { 1626 if ( $( this ).parent().attr( 'disabled' ) == 'disabled' ) 1627 return; 1628 var currency = $( this ).attr( 'rel' ); 1629 self.loadWoocsCurrency( currency ); 1630 } ); 1631 1632 return self; 1633 }, 1634 1635 loadCurrency: function( currency ) { 1636 $( '.wcml-switcher' ).attr( 'disabled', 'disabled' ); 1637 $( '.wcml-switcher' ).append( '<li class="loading"></li>' ); 1638 var data = { action: 'wcml_switch_currency', currency: currency }; 1639 $.ajax( { 1640 type: 'post', 1641 url: theme.ajax_url, 1642 data: { 1643 action: 'wcml_switch_currency', 1644 currency: currency 1645 }, 1646 success: function( response ) { 1647 $( '.wcml-switcher' ).removeAttr( 'disabled' ); 1648 $( '.wcml-switcher' ).find( '.loading' ).remove(); 1649 window.location = window.location.href; 1650 } 1651 } ); 1652 }, 1653 1654 loadWoocsCurrency: function( currency ) { 1655 $( '.woocs-switcher' ).attr( 'disabled', 'disabled' ); 1656 $( '.woocs-switcher' ).append( '<li class="loading"></li>' ); 1657 var l = window.location.href; 1658 l = l.split( '?' ); 1659 l = l[0];
1660 var string_of_get = '?'; 1661 woocs_array_of_get.currency = currency; 1662 1663 if ( Object.keys( woocs_array_of_get ).length > 0 ) { 1664 jQuery.each( woocs_array_of_get, function( index, value ) { 1665 string_of_get = string_of_get + "&" + index + "=" + value; 1666 } ); 1667 } 1668 window.location = l + string_of_get; 1669 }, 1670 1671 removeParameterFromUrl: function( url, parameter ) { 1672 return url 1673 .replace( new RegExp( '[?&]' + parameter + '=[^&#]*(#.*)?$' ), '$1' ) 1674 .replace( new RegExp( '([?&])' + parameter + '=[^&]*&' ), '$1' ); 1675 } 1676 } 1677 1678 } ); 1679 1680 } ).apply( this, [window.theme, jQuery] ); 1681 1682 ( function( theme, $ ) { 1683 1684 $( document ).ready( function() { 1685 // Woocommerce Qty Field 1686 if ( typeof theme.WooQtyField !== 'undefined' ) { 1687 theme.WooQtyField.initialize(); 1688 } 1689 1690 // Woocommerce Quick View 1691 if ( typeof theme.WooQuickView !== 'undefined' ) { 1692 theme.WooQuickView.initialize(); 1693 } 1694 1695 // Woocommerce Events 1696 if ( typeof theme.WooEvents !== 'undefined' ) { 1697 theme.WooEvents.initialize(); 1698 } 1699 1700 // disable drop down 1701 if ( !( 'ontouchstart' in document ) ) { 1702 $( '.mini-cart' ).on( 'hide.bs.dropdown', function() { 1703 return false; 1704 } ); 1705 } else { 1706 $( '#mini-cart .cart-head' ).on( 'click', function( e ) { 1707 $( this ).parent().toggleClass( 'open' ); 1708 } ); 1709 $( 'html,body' ).on( 'click', function( e ) { 1710 if ( $( '#mini-cart' ).hasClass( 'open' ) && !$( e.target ).closest( '#mini-cart' ).length ) { 1711 $( '#mini-cart' ).removeClass( 'open' ); 1712 } 1713 } ); 1714 } 1715 1716 $( document ).on( 'tabactivate', '.woocommerce-tabs', function( e, ui ) { 1717 var label = $( ui ).attr( 'aria-controls' ); 1718 var panel = $( '[aria-labelledby="' + label + '"' ); 1719 theme.refreshVCContent( panel ); 1720 } ); 1721 1722 // Perfect WooCommerce Brand Plugin 1723 $( document ).find( '.pwb-columns a[href="' + window.location.href + '"' ).each( function(){ 1724 $( this ).addClass( 'active' ); 1725 } ) 1726 } ); 1727 } ).apply( this, [window.theme, jQuery] ); 1728 1729 1730 ( function( theme, $, undefined ) { 1731 1732 $( document ).ready( function() { 1733 1734 /*===================================================================================*/ 1735 /* TOOLTIP FOR YITH WISHLIST, COMPARE, ADD TO CART, QUICK VIEW 1736 /*===================================================================================*/ 1737 if ( ! theme.isMobile() ) { 1738 $( document ).on( 'yith_wcwl_init_after_ajax', function() { 1739 $( '.product-col .add_to_wishlist:not([data-bs-original-title]), .product-col .yith-wcwl-wishlistaddedbrowse > a:not([data-bs-original-title]), .product-col .yith-wcwl-wishlistexistsbrowse > a:not([data-bs-original-title])' ).each( function() { 1740 let _this = $( this ); 1741 if ( ! _this.attr( 'title' ) ) { 1742 _this.attr( 'title', _this.text().trim() ); 1743 } 1744 _this.tooltip(); 1745 } ); 1746 } ); 1747 } 1748 // Woocommerce Variation Form 1749 theme.WooVariationForm.initialize(); 1750 1751 // Woocommerce Product Image Slider 1752 if ( typeof theme.initAsync == 'function' ) { 1753 theme.WooProductImageSlider.initialize(); 1754 porto_woocommerce_init(); 1755 } else { 1756 $.when( theme.asyncDeferred ).done( function() { 1757 theme.WooProductImageSlider.initialize(); 1758 porto_woocommerce_init(); 1759 } ); 1760 } 1761 1762 $( window ).on( 'vc_reload', function() { 1763 porto_woocommerce_init(); 1764 $( '.type-product' ).addClass( 'product' ); 1765 } ); 1766 1767 // Add wishlist popup 1768 /*if ( !$( '#yith-wcwl-popup-message' ).length ) { 1769 $( 'body' ).prepend( $( '<div>' ).attr( 'id', 'yith-wcwl-popup-message' ).html( '<div id="yith-wcwl-message"></div>' ).hide() ); 1770 }*/ 1771 1772 // shop horizontal filter 1773 $( document ).on( 'click', '.porto-product-filters-toggle a', function( e ) { 1774 e.preventDefault(); 1775 $( this ).closest( '.porto-product-filters-toggle' ).toggleClass( 'opened' ); 1776 var $products_wrapper = $( this ).closest( '#main' ).find( '.main-content' ).find( 'ul.products' ), offset, $main = $( this ).closest( '#main' ).find( '.main-content-wrap' ); 1777 $main.toggleClass( 'opened' ); 1778 if ( $main.hasClass( 'opened' ) ) { 1779 offset = -1; 1780 } else { 1781 offset = 1; 1782 } 1783 if ( $products_wrapper.hasClass( 'grid' ) ) { 1784 var cols_lg_index = 0, cols_md_index = 0, width_lg_index = 0, width_md_index = 0; 1785 for ( var i = 1; i <= 8; i++ ) { 1786 if ( !cols_lg_index && $products_wrapper.hasClass( 'pcols-lg-' + i ) ) { 1787 cols_lg_index = i; 1788 if ( i + offset >= 1 ) { 1789 $products_wrapper.removeClass( 'pcols-lg-' + i ); 1790 $products_wrapper.addClass( 'pcols-lg-' + ( i + offset ) ); 1791 } 1792 } 1793 if ( !cols_md_index && $products_wrapper.hasClass( 'pcols-md-' + i ) ) { 1794 cols_md_index = i; 1795 if ( i + offset >= 1 ) { 1796 $products_wrapper.removeClass( 'pcols-md-' + i ); 1797 if ( offset === -1 ) { 1798 $products_wrapper.addClass( 'pcols-sm-' + i ); 1799 } 1800 $products_wrapper.addClass( 'pcols-md-' + ( i + offset ) ); 1801 } 1802 } 1803 if ( !width_lg_index && $products_wrapper.hasClass( 'pwidth-lg-' + i ) ) { 1804 width_lg_index = i; 1805 if ( i + offset >= 1 ) { 1806 $products_wrapper.removeClass( 'pwidth-lg-' + i ); 1807 $products_wrapper.addClass( 'pwidth-lg-' + ( i + offset ) ); 1808 } 1809 } 1810 if ( !width_md_index && $products_wrapper.hasClass( 'pwidth-md-' + i ) ) { 1811 width_md_index = i; 1812 if ( i + offset >= 1 ) { 1813 $products_wrapper.removeClass( 'pwidth-md-' + i ); 1814 $products_wrapper.addClass( 'pwidth-md-' + ( i + offset ) ); 1815 } 1816 } 1817 } 1818 } 1819 theme.requestTimeout( function() { 1820 $( window ).trigger( 'scroll' ); 1821 // Update Carousel 1822 $( document ).find( '.owl-carousel' ).each( function( e ) { 1823 var $this = $( this ); 1824 if ( $this.data( 'owl.carousel' ) ) { 1825 $this.trigger( 'refresh.owl.carousel' ); 1826 } 1827 } ); 1828 // Update Swiper 1829 $( document ).find( '.swiper-container' ).each( function( e ) { 1830 var $this = $( this ), 1831 $instance = $this.data( 'swiper' ); 1832 if ( $instance ) {
1833 $instance.update(); 1834 } 1835 } ); 1836 }, 300 ); 1837 1838 if ( $main.hasClass( 'opened' ) ) { 1839 $.cookie( 'porto_horizontal_filter', 'opened' ); 1840 } else { 1841 $.cookie( 'porto_horizontal_filter', 'closed' ); 1842 } 1843 theme.refreshStickySidebar( true ); 1844 1845 return false; 1846 } ); 1847 if ( $.cookie && 'opened' == $.cookie( 'porto_horizontal_filter' ) && $( '#main .porto-products-filter-body' ).length && !theme.isTablet() ) { 1848 $( '.porto-product-filters-toggle a' ).trigger( 'click' ); 1849 $( '#main .porto-products-filter-body [data-plugin-sticky]:not(.manual)' ).addClass( 'manual' ); 1850 setTimeout( function() { 1851 var $obj = $( '#main .porto-products-filter-body [data-plugin-sticky].manual' ), 1852 pluginOptions = $obj.data( 'plugin-options' ); 1853 $obj.removeClass( 'manual' ).themeSticky( pluginOptions ); 1854 theme.requestTimeout( function() { 1855 $( window ).trigger( 'scroll' ); 1856 }, 100 ); 1857 }, 500 ); 1858 } 1859 1860 $( document ).on( 'click', '.porto-product-filters.style2 .widget-title', function( e ) { 1861 e.preventDefault(); 1862 if ( $( this ).next().is( ':hidden' ) ) { 1863 $( '.porto-product-filters.style2 .widget-title' ).next().hide(); 1864 $( '.porto-product-filters.style2 .widget' ).removeClass( 'opened' ); 1865 $( this ).next().show(); 1866 $( this ).next().find( 'input[type="text"]:first-child' ).focus(); 1867 } else { 1868 $( this ).next().hide(); 1869 } 1870 $( this ).parent().toggleClass( 'opened' ); 1871 return false; 1872 } ); 1873 $( 'body' ).on( 'click', function( e ) { 1874 if ( !$( e.target ).is( '.porto-product-filters' ) && !$( e.target ).is( '.porto-product-filters *' ) ) { 1875 $( '.porto-product-filters.style2 .widget-title' ).next().hide(); 1876 $( '.porto-product-filters.style2 .widget' ).removeClass( 'opened' ); 1877 } 1878 } ); 1879 1880 // Perform AJAX login on form submit 1881 $( 'body' ).on( 'click', '#login-form-popup form .woocommerce-Button', function( e ) { 1882 var $this = $( this ), 1883 $form = $this.closest( 'form' ), 1884 isLogin = $this.hasClass( 'login-btn' ); 1885 if ( !isLogin && !$this.hasClass( 'register-btn' ) ) { 1886 isLogin = $form.hasClass( 'login' ); 1887 } 1888 $form.find( '#email' ).val( $form.find( '#username' ).val() ); 1889 $form.find( 'p.status' ).show().text( 'Please wait...' ).addClass( 'loading' ); 1890 $form.find( 'button[type=submit]' ).attr( 'disabled', 'disabled' ); 1891 $.ajax( { 1892 type: 'POST', 1893 dataType: 'json', 1894 url: theme.ajax_url, 1895 data: $form.serialize() + '&action=porto_account_login_popup_' + ( isLogin ? 'login' : 'register' ), 1896 success: function( data ) { 1897 $form.find( 'p.status' ).html( data.message.replace( '/<script.*?\/script>/s', '' ) ).removeClass( 'loading' ); 1898 $form.find( 'button[type=submit]' ).removeAttr( 'disabled' ); 1899 if ( data.loggedin === true ) { 1900 window.location.reload(); 1901 } 1902 } 1903 } ); 1904 e.preventDefault(); 1905 } ); 1906 1907 // shortcodes 1908 var $ajax_tab_cache = {}; 1909 $( document ).on( 'click', '.porto-products.show-category .product-categories a', function( e ) { 1910 e.preventDefault(); 1911 var $this = $( this ), $form = $this.closest( '.porto-products' ).find( '.pagination-form' ), id = $this.closest( '.porto-products' ).attr( 'id' ), group = []; 1912 $( this ).parent().siblings().removeClass( 'current' ); 1913 $( this ).parent().addClass( 'current' ); 1914 if ( typeof $this.data( 'sort_id' ) != 'undefined' ) {
1915 $form.find( 'input[name="orderby"]' ).val( $this.data( 'sort_id' ) ); 1916 group = $this.data( 'sort_id' ); 1917 $form.find( 'input[name="category"]' ).val( '' ); 1918 } 1919 if ( typeof $this.data( 'cat_id' ) != 'undefined' ) { 1920 if ( typeof $this.data( 'sort_id' ) == 'undefined' ) { 1921 $form.find( 'input[name="orderby"]' ).val( $form.find( 'input[name="original_orderby"]' ).val() ); 1922 group = $form.find( 'input[name="original_orderby"]' ).val(); 1923 } 1924 if ( typeof $form.data( 'original_cat_id' ) == 'undefined' ) { 1925 $form.data( 'original_cat_id', $form.find( 'input[name="category"]' ).val() ); 1926 group = $form.find( 'input[name="category"]' ).val(); 1927 } 1928 if ( $this.data( 'cat_id' ) ) { 1929 $form.find( 'input[name="category"]' ).val( $this.data( 'cat_id' ) ); 1930 group = $this.data( 'cat_id' ); 1931 } else { 1932 if ( $form.data( 'original_cat_id' ) ) { 1933 $form.find( 'input[name="category"]' ).val( $form.data( 'original_cat_id' ) ); 1934 group = $form.data( 'original_cat_id' ); 1935 } else {
1936 $form.find( 'input[name="category"]' ).val( '' ); 1937 group = ''; 1938 } 1939 } 1940 } 1941 var data = $form.serialize() + '&product-page=1&action=porto_woocommerce_shortcodes_products&nonce=' + js_porto_vars.porto_nonce; 1942 $this.closest( '.porto-products' ).find( 'ul.products' ).trigger( 'porto_update_products', [data, '', $this, id, group] ); 1943 } ); 1944 $( document ).on( 'click', '.porto-products .page-numbers a', function( e ) { 1945 var $this = $( this ), pagination_style, 1946 $shop_container = $this.closest( '.porto-products' ).find( 'ul.products' ), 1947 cur_page = $shop_container.data( 'cur_page' ), 1948 max_page = $shop_container.data( 'max_page' ), 1949 $form = $this.closest( '.porto-products' ).find( '.pagination-form' ); 1950 e.preventDefault(); 1951 if ( $this.closest( '.pagination' ).hasClass( 'load-more' ) ) { 1952 if ( !cur_page || !max_page || ++cur_page > max_page ) { 1953 return; 1954 } 1955 pagination_style = 'load_more'; 1956 $this.data( 'text', $this.text() ); 1957 $this.text( js_porto_vars.loader_text ); 1958 } else { 1959 var url = new RegExp( "product-page(=|/)([^(&|/)]*)", "i" ).exec( this.href ); 1960 cur_page = url && unescape( url[2] ) || ""; 1961 pagination_style = 'default'; 1962 } 1963 var page_var = cur_page ? '&product-page=' + escape( cur_page ) : '', data = $form.serialize() + page_var + '&action=porto_woocommerce_shortcodes_products&nonce=' + js_porto_vars.porto_nonce; 1964 $shop_container.trigger( 'porto_update_products', [data, pagination_style, $this] ); 1965 if ( 'default' == pagination_style ) { 1966 theme.scrolltoContainer( $shop_container ); 1967 } 1968 } ); 1969 $( document ).on( 'porto_update_products', 'ul.products', function( e, data, pagination_style, $obj, id, group ) { 1970 var $this = $( this ); 1971 // ajax tab 1972 if ( undefined == $ajax_tab_cache[id] || -1 == Object.keys( $ajax_tab_cache[id] ).indexOf( group ) ) { 1973 porto_ajax_load_products( $this, data, pagination_style, $ajax_tab_cache, id, group ); 1974 } else { 1975 var response = $ajax_tab_cache[id][group]; 1976 //animation 1977 $this.css( 'opacity', 0 ); 1978 $this.animate( 1979 { 1980 'opacity': 1, 1981 }, 1982 400, 1983 function() { 1984 $this.css( 'opacity', '' ); 1985 } 1986 ); 1987 1988 porto_ajax_load_products_success( $this, response, pagination_style ); 1989 } 1990 } ); 1991 1992 // initialize woocommerce actions after skeleton loading 1993 var skeletonLoadingTrigger; 1994 $( '.skeleton-loading' ).on( 'skeleton-loaded', function() { 1995 var $this = $( this ); 1996 if ( skeletonLoadingTrigger ) { 1997 theme.deleteTimeout( skeletonLoadingTrigger ); 1998 } 1999 porto_woocommerce_variations_init( $this ); 2000 2001 // yith wishlist pro compatibility 2002 if ( $this.hasClass( 'products' ) || $this.hasClass( 'product' ) ) { 2003 $( document ).trigger( 'yith_infs_added_elem' ); 2004 } 2005 2006 skeletonLoadingTrigger = theme.requestTimeout( function() { 2007 porto_woocommerce_init(); 2008 if ( $( 'body' ).hasClass( 'single-product' ) ) { 2009 theme.WooVariationForm.init(); 2010 var $image_slider = $( '.product-image-slider' ); 2011 if ( $image_slider.length && $image_slider.data( 'owl.carousel' ) ) { 2012 $image_slider.trigger( 'refresh.owl.carousel' ); 2013 } else { 2014 theme.WooProductImageSlider.initialize(); 2015 } 2016 $( '.wc-tabs-wrapper, .woocommerce-tabs, #rating' ).trigger( 'init' ); 2017 2018 // compatibility issue with Yith WooCommerce Booking form 2019 if ( $( document.body ).hasClass( 'yith-booking' ) ) { 2020 $( document ).trigger( 'yith-wcbk-init-booking-form' ); 2021 } 2022 } 2023 2024 // refresh cart content 2025 if ( $this.find( '.widget_shopping_cart_content' ).length ) { 2026 $( document.body ).trigger( 'wc_fragment_refresh' ); 2027 } 2028 }, 100 ); 2029 } ); 2030 } ); 2031 2032 $( document ).on( 'porto_theme_init', function() { 2033 2034 // sticky add to cart 2035 var $sticky_product_obj = $( '.single-product .sticky-product' ), 2036 is_elementor_editor = $( document.body ).hasClass( 'elementor-editor-active' ), 2037 $sticky_product_form; 2038 2039 var init_sticky_add_to_cart_fn = function( $sticky_product_obj, is_elementor_editor ) { 2040 if ( is_elementor_editor && elementorFrontend && elementorFrontend.hooks ) { 2041 elementorFrontend.hooks.addAction( 'frontend/element_ready/porto_cp_addcart_sticky.default', function( $obj ) { 2042 $sticky_product_obj = $( '.single-product .sticky-product' ); 2043 window.dispatchEvent( new Event( 'scroll' ) ); 2044 } ); 2045 } 2046 2047 $sticky_product_form = $( 'form.cart:visible' ).eq(0); 2048 2049 window.addEventListener( 'scroll', function() { 2050 var scrollTop = $( window ).scrollTop(), 2051 offset = theme.adminBarHeight() + theme.StickyHeader.sticky_height, 2052 prevScrollPos = $sticky_product_obj.data('prev-pos') ? $sticky_product_obj.data('prev-pos') : 0; 2053 if ( $sticky_product_form.length && $sticky_product_form.offset().top + $sticky_product_form.height() / 2 <= scrollTop + offset ) { 2054 if ( $( '.page-wrapper' ).hasClass( 'sticky-scroll-up' ) && ! $( 'html' ).hasClass( 'porto-search-opened' ) && $sticky_product_obj.hasClass( 'pos-top' ) ) { 2055 if ( scrollTop >= prevScrollPos ) { 2056 $sticky_product_obj.addClass('scroll-down'); 2057 } else { 2058 $sticky_product_obj.removeClass('scroll-down'); 2059 } 2060 2061 var scrollUpOffset = - theme.StickyHeader.sticky_height; 2062 if ( 'undefined' == typeof ( theme.StickyHeader.sticky_height ) ) { 2063 $sticky_product_obj.data( 'prev-pos', 0 ); 2064 } else { 2065 // The transition of Sticky isn't working in this area 2066 var $transitionOffset = ( offset > 100 ) ? offset : 100; 2067 if ( $sticky_product_form.offset().top + $sticky_product_obj.outerHeight() + $transitionOffset < scrollTop + offset + scrollUpOffset ) { 2068 $sticky_product_obj.addClass( 'sticky-ready' ); 2069 } else { 2070 $sticky_product_obj.removeClass( 'sticky-ready' ); 2071 } 2072 $sticky_product_obj.data( 'prev-pos', scrollTop ); 2073 } 2074 } 2075 2076 var porto_progress_obj = $( '.porto-scroll-progress.fixed-top.fixed-under-header' ); 2077 if ( porto_progress_obj.length ) { 2078 offset += porto_progress_obj.height(); 2079 } 2080 2081 $sticky_product_obj.removeClass( 'hide' ); 2082 if ( !$sticky_product_obj.hasClass( 'pos-bottom' ) ) {
2083 $sticky_product_obj.css( 'top', offset ); 2084 } 2085 } else { 2086 $sticky_product_obj.addClass( 'hide' ); 2087 } 2088 }, { passive: true } ); 2089 $sticky_product_obj.find( '.add-to-cart .button' ).on( 'click', function( e ) { 2090 e.preventDefault(); 2091 if ( $sticky_product_obj.find( '.add-to-cart .qty' ).length ) { 2092 $( '.single-product form .quantity .qty' ).filter(function() { 2093 if ( $( this ).closest( '.product-col' ).length ) { 2094 return false; 2095 } 2096 return true; 2097 }).val( $sticky_product_obj.find( '.add-to-cart .qty' ).val() ); 2098 } 2099 $( '.single-product form .single_add_to_cart_button' ).filter(function() { 2100 if ( $( this ).closest( '.product-col' ).length ) { 2101 return false; 2102 } 2103 return true; 2104 }).eq(0).trigger( 'click' ); 2105 } ); 2106 $( '.single-product .entry-summary .quantity' ).clone().prependTo( '.single-product .sticky-product .add-to-cart' ); 2107 2108 var origin_img = $sticky_product_obj.find( '.sticky-image img' ).data( 'oi' ) ? $sticky_product_obj.find( '.sticky-image img' ).data( 'oi' ) : $sticky_product_obj.find( '.sticky-image img' ).attr( 'src' ), 2109 origin_price = $sticky_product_obj.find( '.price' ).html(), 2110 origin_stock = $sticky_product_obj.find( '.availability' ).html(), 2111 is_variation = false; 2112 $( document ).on( 'found_variation reset_data', '.variations_form', function( e, obj ) { 2113 if ( obj ) { 2114 is_variation = true; 2115 $sticky_product_obj.find( '.sticky-image img' ).attr( 'src', obj.image_thumb ? obj.image_thumb : origin_img ); 2116 $sticky_product_obj.find( '.price' ).replaceWith( obj.price_html ); 2117 $sticky_product_obj.find( '.availability' ).html( obj.availability_html ? obj.availability_html : origin_stock ); 2118 } else if ( is_variation ) { 2119 is_variation = false; 2120 $sticky_product_obj.find( '.sticky-image img' ).attr( 'src', origin_img ); 2121 $sticky_product_obj.find( '.price' ).html( origin_price ); 2122 $sticky_product_obj.find( '.availability' ).html( origin_stock ); 2123 } 2124 } ); 2125 }; 2126 if ( $sticky_product_obj.length || is_elementor_editor ) { 2127 init_sticky_add_to_cart_fn( $sticky_product_obj, is_elementor_editor ); 2128 } else { 2129 $( document.body ).on( 'porto_elementor_editor_init', function() { 2130 var $sticky_product_obj = $( '.single-product .sticky-product' ), 2131 is_elementor_editor = $( document.body ).hasClass( 'elementor-editor-active' ); 2132 if ( $sticky_product_obj.length || is_elementor_editor ) { 2133 init_sticky_add_to_cart_fn( $sticky_product_obj, is_elementor_editor ); 2134 } 2135 } ); 2136 } 2137 2138 // sticky filter on mobile 2139 if ( 1 === $( '.shop-loop-before' ).length && $( '.mobile-sidebar' ).length ) { 2140 var porto_progress_obj = $( '.porto-scroll-progress.fixed-top.fixed-under-header' ), 2141 porto_progress_height = 0; 2142 if ( porto_progress_obj.length ) { 2143 var flag = false; 2144 if ( porto_progress_obj.is( ':hidden' ) ) { 2145 porto_progress_obj.show(); 2146 flag = true; 2147 } 2148 porto_progress_height = porto_progress_obj.height(); 2149 if ( flag ) { 2150 porto_progress_obj.hide(); 2151 } 2152 } else { 2153 porto_progress_height = 0; 2154 } 2155 2156 var init_filter_sticky = function() { 2157 var $obj = $( '.shop-loop-before' ), 2158 prevScrollPos = $obj.data('prev-pos') ? $obj.data('prev-pos') : 0, 2159 scrollUpOffset = 0, 2160 $pageWrapper = $( '.page-wrapper' ); 2161 if ( !$obj.prev( '.filter-placeholder' ).length ) { 2162 $( '<div class="filter-placeholder m-0"></div>' ).insertBefore( $obj ); 2163 } 2164 var $ph = $obj.prev( '.filter-placeholder' ), 2165 scrollTop = $( window ).scrollTop(), 2166 offset = theme.adminBarHeight() + theme.StickyHeader.sticky_height + porto_progress_height - 1, 2167 objHeight = $obj.outerHeight() + parseInt( $obj.css( 'margin-bottom' ) ); 2168 if ( $( '.page-wrapper' ).hasClass( 'sticky-scroll-up' ) ) { 2169 if ( scrollTop >= prevScrollPos ) { 2170 $obj.addClass('scroll-down'); 2171 } else { 2172 $obj.removeClass('scroll-down'); 2173 } 2174 // Header is scroll-up Sticky Type 2175 scrollUpOffset = - theme.StickyHeader.sticky_height; 2176 if ( 'undefined' == typeof ( theme.StickyHeader.sticky_height ) ) { 2177 $obj.data( 'prev-pos', 0 ); 2178 } else { 2179 // The transition of Sticky isn't working in this area 2180 var $transitionOffset = ( offset > 100 ) ? offset : 100; 2181 if ( $ph.offset().top + objHeight + $transitionOffset < scrollTop + offset + scrollUpOffset ) { 2182 $obj.addClass( 'sticky-ready' ); 2183 } else { 2184 $obj.removeClass( 'sticky-ready' ); 2185 } 2186 $obj.data( 'prev-pos', scrollTop ); 2187 } 2188 } 2189 // if ( $( 'html.filter-sidebar-opened' ).length ) { 2190 // $ph.css( 'height', '' ); 2191 // return; 2192 // } 2193 if ( ( $ph.offset().top + objHeight < scrollTop + offset + scrollUpOffset ) ) { 2194 if ( ! $pageWrapper.hasClass( 'sticky-scroll-up' ) || ( $pageWrapper.hasClass( 'sticky-scroll-up' ) && 0 !== prevScrollPos ) ) { 2195 $ph.css( 'height', objHeight );
2196 $obj.css( 'top', offset ); 2197 $obj.addClass( 'sticky' ); 2198 } 2199 } else { 2200 $ph.css( 'height', '' ); 2201 $obj.removeClass( 'sticky' ).css( 'top', '' ); 2202 } 2203 }; 2204 if ( window.innerWidth < 992 ) { 2205 window.removeEventListener( 'scroll', init_filter_sticky ); 2206 window.addEventListener( 'scroll', init_filter_sticky, { passive: true } ); 2207 init_filter_sticky(); 2208 } 2209 var request_timer = null, 2210 old_win_width = window.innerWidth; 2211 $( window ).on( 'resize', function() { 2212 if ( old_win_width != window.innerWidth ) { 2213 if ( request_timer ) { 2214 theme.deleteTimeout( request_timer ); 2215 request_timer = false; 2216 } 2217 if ( window.innerWidth < 992 ) { 2218 request_timer = theme.requestTimeout( function() { 2219 window.removeEventListener( 'scroll', init_filter_sticky ); 2220 window.addEventListener( 'scroll', init_filter_sticky, { passive: true } ); 2221 $( window ).trigger( 'scroll' ); 2222 }, 100 ); 2223 } else { 2224 window.removeEventListener( 'scroll', init_filter_sticky ); 2225 $( '.shop-loop-before' ).removeClass( 'sticky' ).css( 'top', '' ).prev( '.filter-placeholder' ).css( 'height', '' ); 2226 } 2227 2228 if ( $sticky_product_obj.length ) { 2229 $sticky_product_form = $( 'form.cart:visible' ).eq(0); 2230 } 2231 old_win_width = window.innerWidth; 2232 } 2233 } ); 2234 } 2235 } ); 2236 2237 // cart page accordion 2238 $( '.cart-v2 .cart_totals .accordion-toggle.out' ).removeClass( 'out' ); 2239 $( document ).ajaxComplete( function( event, xhr, options ) { 2240 $( '.cart-v2 .cart_totals .accordion-toggle.out' ).each( function() { 2241 if ( $( $( this ).attr( 'href' ) ).length && $( $( this ).attr( 'href' ) ).is( ':hidden' ) ) { 2242 $( this ).removeClass( 'collapsed' ); 2243 $( $( this ).attr( 'href' ) ).addClass( 'show' ); 2244 } 2245 } ); 2246 } ); 2247 2248 // porto products filter element 2249 $( '.porto_products_filter_form .btn-submit' ).on( 'click', function( e ) { 2250 e.preventDefault(); 2251 var data = $( this ).closest( 'form' ).serializeArray(), 2252 submit_data = ''; 2253 for ( var i in data ) { 2254 var param = data[i]; 2255 if ( param.value ) { 2256 if ( submit_data ) { 2257 submit_data += '&'; 2258 } 2259 submit_data += param.name + '=' + param.value; 2260 if ( 'min_price' == param.name ) { 2261 var max_price = $( this ).closest( 'form' ).find( '.porto_dropdown_price_range option:selected' ).data( 'maxprice' ); 2262 if ( max_price ) { 2263 submit_data += '&max_price=' + max_price; 2264 } 2265 } 2266 } 2267 } 2268 location.href = $( this ).closest( 'form' ).attr( 'action' ) + '?' + submit_data; 2269 } ); 2270 2271 // yith wishlist 2272 if ( $( '.wishlist_table.responsive' ).length ) { 2273 $( window ).on( 'resize', function() { 2274 var media = window.matchMedia( '(max-width: 768px)' ), 2275 $wishlist_table = $( '.wishlist_table.responsive' ); 2276 if ( $wishlist_table.hasClass( 'traditional' ) ) { 2277 if ( media.matches ) { 2278 $wishlist_table.addClass( 'mobile' ); 2279 } else { 2280 $wishlist_table.removeClass( 'mobile' ); 2281 } 2282 } 2283 } ); 2284 } 2285 2286 // pre-order 2287 if ( js_porto_vars.pre_order ) { 2288 var porto_pre_order = { 2289 init: function() { 2290 this.$add_to_cart_btn = $( '.product-summary-wrap .single_add_to_cart_button:not(.wpcbn-btn)' ); 2291 this.add_to_cart_label = this.$add_to_cart_btn.html(); 2292 $( '.product-summary-wrap form.variations_form' ).on( 'show_variation', function( e, v, p ) { 2293 if ( v.porto_pre_order ) { 2294 porto_pre_order.$add_to_cart_btn.html( v.porto_pre_order_label ); 2295 if ( v.porto_pre_order_date ) { 2296 $( this ).find( '.woocommerce-variation-description' ).append( v.porto_pre_order_date ); 2297 } 2298 } else { 2299 porto_pre_order.$add_to_cart_btn.html( porto_pre_order.add_to_cart_label ); 2300 } 2301 } ).on( 'hide_variation', function() { 2302 porto_pre_order.$add_to_cart_btn.html( porto_pre_order.add_to_cart_label ); 2303 } ); 2304 } 2305 }; 2306 if ( $( 'div.product.skeleton-loading' ).length ) { 2307 $( 'div.product.skeleton-loading' ).on( 'skeleton-loaded', function() { 2308 porto_pre_order.init(); 2309 } ); 2310 } else { 2311 porto_pre_order.init(); 2312 } 2313 } 2314 2315 // refresh yith wishlist 2316 if ( $( '#header .my-wishlist .wishlist-count' ).length ) { 2317 $( document.body ).on( 'added_to_wishlist removed_from_wishlist added_to_cart', function( e ) { 2318 var $obj = $( '#header .my-wishlist .wishlist-count' ); 2319 if ( $obj.text() ) { 2320 $.ajax( { 2321 type: 'POST', 2322 dataType: 'json', 2323 url: theme.ajax_url, 2324 data: { 2325 action: 'porto_refresh_wishlist_count', 2326 nonce: js_porto_vars.porto_nonce, 2327 }, 2328 success: function( response ) { 2329 if ( response || 0 === response ) { 2330 $obj.addClass( 'count-updating' ).text( Number( response ) ); 2331 setTimeout( function() { 2332 $obj.removeClass( 'count-updating' ); 2333 }, 1000 ); 2334 } 2335 } 2336 } ); 2337 } 2338 } ); 2339 } 2340
2341 // fix contact form 7 role="alert" issue in cart page 2342 if ( $( document.body ).hasClass( 'woocommerce-cart' ) && $( '.wpcf7 .screen-reader-response' ).length ) { 2343 $( '.wpcf7 .screen-reader-response' ).attr( 'role', '' ); 2344 } 2345 2346 // fix dokan search vendor 2347 $( '#dokan-store-listing-filter-form-wrap .store-search-input' ).on( 'keydown', function( e ) { 2348 if ( e.which && event.which == 13 ) { 2349 $( this ).closest( 'form' ).find( '#apply-filter-btn' ).trigger( 'click' ); 2350 e.preventDefault(); 2351 } 2352 } ); 2353 2354 // add spinner to block 2355 if ( $.fn.block ) { 2356 var funcBlock = $.fn.block; 2357 $.fn.block = function( opts ) { 2358 if ( this.hasClass( 'yith-wcwl-add-to-wishlist' ) ) { 2359 this.children().addClass( 'pe-none opacity-6' ); 2360 return this; 2361 } 2362 if ( this.is( '.woocommerce-checkout' ) ) { 2363 this.append( '<div class="loader-container d-block"><div class="loader"><i class="porto-ajax-loader"></i></div></div>' ); 2364 } 2365 return funcBlock.call( this, opts ); 2366 } 2367 2368 var funcUnblock = $.fn.unblock; 2369 $.fn.unblock = function( opts ) { 2370 if ( this.hasClass( 'yith-wcwl-add-to-wishlist' ) ) { 2371 this.children().removeClass( 'pe-none opacity-6' ); 2372 return this; 2373 } 2374 funcUnblock.call( this, opts ); 2375 this.is( '.processing' ) || ( this.is( '.woocommerce-checkout' ) && this.children( '.loader-container' ).remove() ); 2376 return this; 2377 } 2378 } 2379 } )( window.theme, jQuery ); 2380 2381 // Compare 2382 ( function( theme, $ ) { 2383 // remove margin-right 2384 $( 'body' ).on( 'click', '.yith_woocompare_colorbox #cboxClose, #cboxOverlay', function() { 2385 $( 'html' ).css( { 'overflow': '', 'margin-right': '' } ); 2386 } ); 2387 } )( window.theme, window.jQuery ); 2388 2389} )(); 2390 2391function porto_woocommerce_init( $wrap ) { 2392 'use strict'; 2393 2394 if ( !$wrap ) { 2395 $wrap = jQuery( document.body ); 2396 } 2397 // Woo Widget Toggle 2398 ( function( $ ) { 2399 2400 if ( $.fn.themeWooWidgetToggle ) { 2401 2402 $( function() { 2403 $wrap.find( '.widget_filter_by_brand, .widget_product_categories, .widget_price_filter, .widget_layered_nav, .widget_layered_nav_filters, .widget_rating_filter, .widget-woof, .porto_widget_price_filter, #wcfmmp-store .widget.sidebar-box, #wcfmmp-store-lists-sidebar .sidebar-box' ).find( '.widget-title' ).each( function() { 2404 var $this = $( this ), 2405 opts; 2406 2407 var pluginOptions = $this.data( 'plugin-options' ); 2408 if ( pluginOptions ) 2409 opts = pluginOptions; 2410 2411 $this.themeWooWidgetToggle( opts ); 2412 } ); 2413 } ); 2414 2415 } 2416 2417 // Woo Widget Accordion 2418 if ( $.fn.themeWooWidgetAccordion ) { 2419 2420 $( function() { 2421 $wrap.find( '.widget_filter_by_brand, .widget_product_categories, .widget_price_filter, .widget_layered_nav, .widget_layered_nav_filters, .widget_rating_filter, .widget-woof, #wcfmmp-store .widget.sidebar-box, #wcfmmp-store-lists-sidebar .sidebar-box' ).each( function() { 2422 var $this = $( this ), 2423 opts; 2424 2425 var pluginOptions = $this.data( 'plugin-options' ); 2426 if ( pluginOptions ) 2427 opts = pluginOptions; 2428 2429 $this.themeWooWidgetAccordion( opts ); 2430 } ); 2431 } ); 2432 2433 } 2434 2435 // Woo Products Slider 2436 if ( $.fn.themeWooProductsSlider ) { 2437 2438 $( function() { 2439 var $direct_carousels = $wrap.find( '.products-slider:not(.manual)' ).filter( function() { 2440 if ( $( this ).closest( '.porto-carousel:not(.owl-loaded)' ).length ) { 2441 return false; 2442 } 2443 return true; 2444 } ); 2445 var $parent_carousel = $wrap.find( '.porto-carousel:not(.owl-loaded)' ).filter( function() { 2446 if ( $( this ).find( '.products-slider:not(.manual)' ).length ) { 2447 return true; 2448 } 2449 return false; 2450 } ); 2451 if ( $parent_carousel.length ) { 2452 $parent_carousel.one( 'initialized.owl.carousel', function() { 2453 $( this ).find( '.products-slider:not(.manual)' ).each( function() { 2454 var $this = $( this ); 2455 $this.themeWooProductsSlider( $this.data( 'plugin-options' ) ); 2456 } ); 2457 } ); 2458 } 2459 2460 $direct_carousels.each( function() { 2461 var $this = $( this ), 2462 opts; 2463 2464 var pluginOptions = $this.data( 'plugin-options' ); 2465 if ( pluginOptions ) 2466 opts = pluginOptions; 2467 2468 setTimeout( function() { 2469 $this.themeWooProductsSlider( opts ); 2470 }, 0 ); 2471 } ); 2472 } ); 2473 } 2474 2475 /*===================================================================================*/ 2476 /* TOOLTIP FOR YITH WISHLIST, COMPARE, ADD TO CART, QUICK VIEW 2477 /*===================================================================================*/ 2478 if ( ! theme.isMobile() ) { 2479 $wrap.find( '.product-col .quickview, .product-col .add_to_cart_read_more, .product-col .add_to_cart_button, .product-col a.compare, .product-col .add_to_wishlist, .product-col .yith-wcwl-wishlistaddedbrowse > a, .product-col .yith-wcwl-wishlistexistsbrowse > a' ).each( function() { 2480 let _this = $( this ); 2481 // Exclude
2482 let $productCol = _this.closest( '.product-col' ); 2483 if ( _this.closest( '.porto-tb-woo-link' ).hasClass( 'no-tooltip' ) ) { 2484 return; 2485 } 2486 if ( _this.hasClass( 'add_to_cart_read_more' ) || _this.hasClass( 'add_to_cart_button' ) ) { 2487 if ( $productCol.hasClass( 'product-wq_onimage' ) || $productCol.hasClass( 'product-onimage' ) || $productCol.hasClass( 'product-outimage' ) || $productCol.hasClass( 'product-default' ) ) { 2488 return; 2489 } 2490 if ( _this.closest( 'ul.products' ).hasClass( 'list' ) ) { 2491 return; 2492 } 2493 } 2494 if ( _this.hasClass( 'quickview' ) ) { 2495 if ( $productCol.hasClass( 'product-wq_onimage' ) || $productCol.hasClass( 'product-onimage3' ) || $productCol.hasClass( 'product-onimage2' ) || $productCol.hasClass( 'product-onimage' ) || $productCol.hasClass( 'product-outimage_aq_onimage' ) ) { 2496 return; 2497 } 2498 } 2499 if ( ! _this.attr( 'title' ) ) { 2500 _this.attr( 'title', _this.text().trim() ); 2501 } 2502 _this.tooltip(); 2503 } ); 2504 } 2505 2506 } )( jQuery ); 2507} 2508 2509function porto_woocommerce_variations_init( $parent_obj ) { 2510 'use strict'; 2511 2512 theme.requestTimeout( function() { 2513 var form_variation = $parent_obj.find( 'form.variations_form:not(.vf_init)' ); 2514 if ( form_variation.length && jQuery.fn.wc_variation_form ) { 2515 form_variation.each( function() { 2516 var data_a = jQuery._data( this, 'events' ); 2517 if ( !data_a || !data_a['show_variation'] ) { 2518 jQuery( this ).wc_variation_form(); 2519 } 2520 } ); 2521 } 2522 }, 100 ); 2523} 2524function porto_ajax_load_products( $obj, data, pagination_style, $ajax_tab_cache, id, group ) { 2525 'use strict'; 2526 ( function( $ ) { 2527 if ( $obj.hasClass( 'loading' ) ) { 2528 return; 2529 } 2530 $obj.addClass( 'loading' ); 2531 if ( 'load_more' != pagination_style ) { 2532 $obj.addClass( 'yith-wcan-loading' ); 2533 if ( !$obj.children( '.porto-loading-icon' ).length ) { 2534 $obj.append( '<i class="porto-loading-icon"></i>' ); 2535 } 2536 } 2537 if ( $ajax_tab_cache[id] == undefined ) { 2538 $ajax_tab_cache[id] = {}; 2539 } 2540 $.ajax( { 2541 url: theme.ajax_url, 2542 data: data, 2543 type: 'post', 2544 success: function( response ) { 2545 //cache 2546 if ( $( response ).length ) { 2547 $ajax_tab_cache[id][group] = $( response ).html(); 2548 } else { 2549 $ajax_tab_cache[id][group] = ''; 2550 } 2551 porto_ajax_load_products_success( $obj, response, pagination_style ); 2552 }, 2553 complete: function() { 2554 $obj.removeClass( 'loading' ); 2555 } 2556 } ); 2557 } )( jQuery ); 2558} 2559 2560function porto_ajax_load_products_success( $obj, success, pagination_style ) { 2561 'use strict'; 2562 2563 ( function( $ ) { 2564 let _successProducts = $( success ).find( 'ul.products' ); 2565 if ( $obj.data( 'cur_page' ) && _successProducts.data( 'cur_page' ) ) { 2566 $obj.data( 'cur_page', _successProducts.data( 'cur_page' ) ); 2567 } 2568 if ( ! ( $obj.hasClass( 'grid-creative' ) && typeof $obj.attr( 'data-plugin-masonry' ) != 'undefined' ) ) { 2569 _successProducts.children( ':not(.grid-col-sizer)' ).addClass( 'fadeInUp animated' ); 2570 } 2571 if ( 'load_more' == pagination_style ) { 2572 $obj.append( _successProducts.html() ); 2573 } else { 2574 if ( $obj.hasClass( 'owl-carousel' ) ) { 2575 $obj.parent().css( 'min-height', $obj.parent().height() ); 2576 } 2577 if ( $obj.hasClass( 'grid-creative' ) && typeof $obj.attr( 'data-plugin-masonry' ) != 'undefined' ) { 2578 $obj.isotope( 'remove', $obj.children() ); 2579 $obj.find( '.grid-col-sizer' ).remove(); 2580 var newItems = _successProducts.children(); 2581 $obj.append( newItems ); 2582 $obj.isotope( 'appended', newItems ); 2583 $obj.imagesLoaded( function() { 2584 $obj.isotope( 'layout' ); 2585 } ); 2586 } else { 2587 if ( $( success ).length ) { 2588 $obj.html( _successProducts.html() ); 2589 } else { 2590 $obj.html( '' ); 2591 } 2592 } 2593 } 2594 2595 if ( $obj.hasClass( 'owl-carousel' ) && $.fn.themeWooProductsSlider ) { 2596 $obj.trigger( 'destroy.owl.carousel' ); 2597 theme.requestTimeout( function() { 2598 var pluginOptions = $obj.data( 'plugin-options' ), opts; 2599 if ( pluginOptions ) 2600 opts = pluginOptions; 2601 $obj.data( '__wooProductsSlider', '' ).themeWooProductsSlider( opts ); 2602 $obj.parent().css( 'min-height', '' ); 2603 }, 100 ); 2604 } 2605 if ( $obj.closest( '.porto-products' ).find( '.shop-loop-after' ).length ) { 2606 if ( $( success ).find( '.shop-loop-after' ).length ) { 2607 $obj.closest( '.porto-products' ).find( '.shop-loop-after' ).replaceWith( $( success ).find( '.shop-loop-after' ) ); 2608 } else { 2609 $obj.closest( '.porto-products' ).find( '.shop-loop-after' ).remove(); 2610 } 2611 } 2612 if ( typeof $obj.data( 'infinitescroll' ) != 'undefined' ) { 2613 var infinitescrollData = $obj.data( 'infinitescroll' ); 2614 infinitescrollData.options.state.currPage = 1; 2615 $obj.data( 'infinitescroll', infinitescrollData ); 2616 } 2617 $obj.removeClass( 'yith-wcan-loading' ); 2618 if ( 'load_more' == pagination_style && typeof $obj != 'undefined' && typeof $obj.data( 'text' ) != 'undefined' ) { 2619 $obj.text( $obj.data( 'text' ) ); 2620 } 2621 $( document ).trigger( "yith-wcan-ajax-filtered" ); 2622 } )( jQuery ); 2623}
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.