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