1jQuery(function($){ 2 // if website rtl 3 4 var rtl = $('body').hasClass('rtl'); 5 6 7 8 9 // TO DO , get this variable through localize 10 // var colorTax = 'pa_color'; 11 // var sizeTax = 'pa_size'; 12 var colorTax = ocThemeSettings.color_attribute ? ocThemeSettings.color_attribute : ''; 13 var sizeTax = ocThemeSettings.button_attribute ? ocThemeSettings.button_attribute : ''; 14 var mobileWidth = 782; 15 // helpfull function 16 // var isMobile = function(){ 17 // var check = $(window).width() >= mobileWidth; 18 // console.log( check, 'check' ); 19 // return check; 20 // } 21 22 function isMobile(){ 23 var check = $(window).width() <= mobileWidth; 24 // console.log( check, 'check' ); 25 return check; 26 } 27 28 // console.log( $('.top-header-slider'), 'top slder ' ); 29 // alert( 'top slider ' ) 30 if ( $('.top-header-slider').length ){ 31 $('.top-header-slider').slick(); 32 } 33 34 // add class for body for sticky header 35 function sticky_header(){ 36 // var header = $('header.site-header').height(); 37 var docViewTop = $(document).scrollTop(); 38 39 if ( docViewTop > 1 ){ 40 $('body').addClass('sticky-header'); 41 } else { 42 $('body').removeClass('sticky-header'); 43 // if ( $(window).width() > mobileWidth ){ 44 if ( !isMobile() ){ 45 $('body').removeClass('mobile-menu'); 46 } 47 } 48 } 49 50 // announcement bar timer with settings from admin panel 51 function announcement_bar_timer(){ 52 if ( typeof ocThemeSettings === 'undefined' || ocThemeSettings.anBarTimerEnd == '' ){ 53 return; 54 } 55 56 // Set the date we're counting down to, get timer start date from localize variable admin panel! 57 var countDownDate = new Date( ocThemeSettings.anBarTimerEnd ).getTime(); 58 // moved outside timer function 59 var timer = document.querySelector("#timer"); 60 // console.log( timer, 'timer' ); 61 if ( typeof timer === undefined || timer === null ){ 62 return; 63 } 64 // Update the count down every 1 second 65 var timerFunction = setInterval(function() { 66 67 // Get today's date and time 68 var now = new Date().getTime(); 69 // Find the distance between now and the count down date 70 var distance = countDownDate - now; 71 72 const secondsInMinute = 1000 * 60; 73 const minutesInHour = secondsInMinute * 60; 74 const hoursInDay = minutesInHour * 24; 75 // Time calculations for days, hours, minutes and seconds 76 var days = Math.floor(distance / ( hoursInDay )); 77 var hours = Math.floor((distance % ( hoursInDay )) / (minutesInHour)); 78 var minutes = Math.floor((distance % ( minutesInHour )) / (secondsInMinute)); 79 var seconds = Math.floor((distance % ( secondsInMinute )) / 1000); 80 81 timer.querySelector('.days .val').innerHTML = days; 82 timer.querySelector('.hours .val').innerHTML = hours; 83 timer.querySelector('.minutes .val').innerHTML = minutes; 84 timer.querySelector('.seconds .val').innerHTML = seconds; 85 86 // If the count down is finished, write some text 87 if ( distance < 0 ) { 88 clearInterval(timerFunction); 89 timer.innerHTML = "EXPIRED"; 90 } 91 }, 1000 ); 92 } 93 94 announcement_bar_timer(); 95 96 // open panel on search btn click 97 $(document).on( 'click', 'button.search-icon', function(e){ 98 // console.log( 'search icon' ); 99 $('.search-form--dropdown-panel').toggleClass( 'active' ); 100 if ( $('.oc-woo-search--wrap').hasClass('active') ){ 101 $('.page-overlay').addClass('is-visible'); 102 } else { 103 $('.page-overlay').removeClass('is-visible'); 104 } 105 106 e.preventDefault(); 107 }); 108 109 // close panel on icon click 110 $(document).on( 'click', 'button.search__close', function(e){ 111 $('.search-form--dropdown-panel').removeClass( 'active' ); 112 $('.page-overlay').removeClass('is-visible'); 113 }); 114 115 // temp submenu show for hamburger menu 116 // $(document).on( 'click', '.hamburger-panel .panel-menu-navigation .nav-menu li.menu-item-has-children', function(e){ 117 // // console.log( e, 'e event' ); 118 // console.log( 'click menu has children' ) 119 // // e.stopPropagation(); 120 // $(this).toggleClass( 'active-submenu' ); 121 // e.preventDefault(); 122 // }); 123 124 $(document).on( 'click', '.hamburger-panel .panel-menu-navigation .nav-menu li.menu-item-has-children span.open-submenu', function(e){ 125 let target = $(this).closest('li'); 126 target.toggleClass( 'active-submenu' ); 127 128 if ( !$(this).closest('li').hasClass( 'active-submenu' ) ){ 129 target.find('.sub-menu').slideUp(); 130 } else { 131 target.find('.sub-menu').slideDown(); 132 } 133 134 e.stopPropagation(); 135 }); $(document).on( 'click', '.panel-menu-navigation .mega-menu-item-has-children>a', function(e){ e.preventDefault(); let target = $(this).closest('li'); target.toggleClass( 'active-submenu' ); if ( !$(this).closest('li').hasClass( 'active-submenu' ) ){ target.find('.mega-sub-menu').slideUp(); } else { target.find('.mega-sub-menu').slideDown(); } e.stopPropagation(); }); 136 137 138 // e.stopPropagation(); 139 // }); 140 141 // close hamburger menu, remove attribute, remove active class 142 $(document).on( 'click', 'button.hamburger__close', function(){ 143 $('#hamburger-panel').attr( 'aria-hidden', true ); 144 $('button.hamburger-menu').removeClass('active'); 145 $('body').removeClass('no-scroll'); 146 $('.oc-woo-search--wrap').removeClass('active'); 147 }); 148 149 // toggle aria-hidden attribute, based on this class 150 function toggle_hidden_attribute( $this, target ){ 151 $this.toggleClass('active'); 152 153 if ( $this.hasClass('active') ){ 154 $(target).attr( 'aria-hidden', false ); 155 } else { 156 $(target).attr( 'aria-hidden', true ); 157 } 158 } 159 160 // open hamburger panel 161 $(document).on( 'click', 'button.hamburger-menu', function(){
162 let $this = $(this); 163 toggle_hidden_attribute( $this, '#hamburger-panel' ); 164 $('.page-overlay').addClass('is-visible top'); 165 $('body').toggleClass('no-scroll'); 166 $('.oc-woo-search--wrap').removeClass('active'); 167 }); 168 169 // open minicart panel 170 $(document).on( 'click', '.mini-cart-icon', function(e){ 171 let $this = $(this); 172 toggle_hidden_attribute( $this, '#cart-panel' ); 173 $('.page-overlay').addClass('is-visible top'); 174 $('body').toggleClass('no-scroll'); 175 e.preventDefault(); 176 177 $('.recently-viewed-products-container ul.products').slick({ 178 slidesToShow: 2, 179 slidesToScroll:1, 180 rtl: rtl, 181 infinite: true, 182 }); 183 184 return false; 185 }); 186 187 // on page overlay click: close overlay, close menu, close minicart, remove active class from clicked button 188 $(document).on( 'click', 'div.page-overlay, button.mini-close, button.hamburger__close', function(e){ 189 $('.page-overlay').removeClass('is-visible top'); 190 $('.mini-cart-icon').removeClass('active'); 191 $('button.hamburger-menu').removeClass('active'); 192 $('a.my-account-link').removeClass('active'); 193 $('button.wishlist-icon').removeClass('active'); 194 // $('#cart-panel,.hamburger-panel,.auth-panel, .help-panel').attr( 'aria-hidden', true ); 195 // close minicart 196 $('.drawer-panel').attr( 'aria-hidden', true ); 197 $('body').removeClass('no-scroll'); 198 // close quickview 199 $('.oc-woo-product-quickview-container').removeClass('active'); 200 // close need help 201 $('.need_help a').removeClass('active'); 202 // close search panel 203 $('.oc-woo-search--wrap').removeClass('active'); 204 // close mobile filter 205 $('.oc-woo-products-filter--container.mobile-panel').removeClass('active'); 206 // upsells variable product 207 $('.oc-variable-product-upsells-popup--container').removeClass('active'); 208 $('.drawer-panel.cart-panel').removeClass('panel-under'); 209 $('.drawer-panel.cart-panel').removeClass('active-upsells-products'); 210 }); 211 212 // Minicart toggle 213 $(document).on( 'click', '.minicart-coupon-title', function(){ 214 $(this).parent().toggleClass('active'); 215 }); 216 217 // Check add to cart notice method 218 function minicart_notice_method(){ 219 if ( typeof ocThemeSettings === 'undefined' ){ 220 return; 221 } 222 // console.clear(); 223 if ( ocThemeSettings.noticeMethod == '' || ocThemeSettings.noticeMethod == 'notice' ){ 224 // Display meesage notice on add to cart 225 $( document.body ).on( 'adding_to_cart', oc_add_to_cart_minicart_notice ); 226 } else { 227 // open minicart on product add to cart 228 // if works on ajax ( cat|shop page ) 229 $( document.body ).on( 'added_to_cart', function( fragments, cart_hash, $thisbutton ){ 230 toggle_hidden_attribute( $('.mini-cart-icon'), '#cart-panel' ); 231 $('.page-overlay').addClass('is-visible top'); 232 $('body').addClass('no-scroll'); 233 }); 234 235 // open cart on page reload 236 $( document ).on( 'ajaxSuccess', function( event, xhr, settings ) { 237 // if ajax request refreshed fragments -> some product added to cart 238 if ( settings.url == '/?wc-ajax=get_refreshed_fragments' ){ 239 // open cart ??? 240 toggle_hidden_attribute( $('.mini-cart-icon'), '#cart-panel' ); 241 $('.page-overlay').addClass('is-visible top'); 242 $('body').addClass('no-scroll'); 243 } 244 245 }); 246 } 247 } 248 249 minicart_notice_method(); 250 251 // console.clear(); 252 function oc_add_to_cart_minicart_notice( data, $thisbutton ){ 253 let target = $('.mini-cart-icon'); 254 let template = $('#oc-add-to-cart-notice'); 255 let message = template.clone(true); 256 let image, title, price; 257 let arSelectedVariation = false; 258 let parent = $thisbutton.closest('.item_wrap'); 259 260 message = $(message.html()); 261 262 // console.clear(); 263 // console.group('adding_to_cart'); 264 // console.log( $thisbutton, '$thisbutton' ); 265 // // // console.log( template, 'template' ); 266 // // // console.log( message.find('.add-to-cart-notice--container'), 'message fidn' ); 267 // // // console.log( message, 'message' ); 268 // // // console.log( $(message), '$.message' ); 269 // // // console.log( data, 'data' ); 270 // // console.log( $thisbutton.closest('.item').length , 'length' ) 271 // console.log( $thisbutton , 'button' ) 272 // console.log( $thisbutton.closest('.oc-variable-product-upsells-container'), '.oc-variable-product-upsells-container' ); 273 // console.groupEnd('adding_to_cart'); 274 275 // on adding product to cart , me must show notice ! But it can be from many places 276 277 // added from upsells 278 if ( $thisbutton.closest('.oc-variable-product-upsells-container').length ){ 279 let upsellsContainer = $thisbutton.closest('.oc-variable-product-upsells-container'); 280 let upsellsContainerMobile = $thisbutton.closest('.oc-product-quick-add-to-cart-panel-1'); 281 // 282 if ( upsellsContainer.length > 0 ){ 283 title = upsellsContainer.find('.product-name a'); 284 price = upsellsContainer.find( '.product-price' ); 285 image = upsellsContainer.find( '.image-src img' ); 286 } 287 // else if ( upsellsContainerMobile.length > 0 ) { 288 // title = upsellsContainerMobile.find('.product-name a'); 289 // price = upsellsContainerMobile.find( '.product-price' ); 290 // image = upsellsContainerMobile.clsoest().find( '.image-src img' ); 291 // } 292 // console.log( price, 'price' ); 293 // console.log( image, 'image' ); 294 // console.log( upsellsContainerMobile, 'upsellsContainerMobile' ); 295 296 // add from home page 297 } else if ( $('body').hasClass('single-product') ){ 298 299 // main product 300 if ( $thisbutton.hasClass('single_add_to_cart_button') ){ 301 // it might be upsells product 302 303 // console.log( $('.woocommerce-product-gallery__wrapper').hasClass('slick-slider') , 'hasClass slider' ); 304 if ( $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').hasClass('slick-slider') ){ 305 image = $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__image:not(.slick-cloned)').first().find('img'); 306 } else { 307 image = $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__image:first-child img'); 308 } 309 title = $('.product_title'); 310 price = $( 'p.price' ); 311 if ( image.length == 0 ){ 312 var firstSlide = $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__image:not(.slick-cloned)'); 313 if ( firstSlide.length > 0 ){ 314 image = firstSlide.first().find('img') 315 } 316 } 317 318 // new type of products ?? 319 } else if ( $thisbutton.hasClass('add-to-cart') && $thisbutton.closest('.item').length ){ 320 let parent = $thisbutton.closest('.item'); 321 image = parent.find('.img img'); 322 title = parent.find('.name'); 323 price = parent.find( '.price' ); 324 325 // related products from single page 326 } else if ( ( $thisbutton.hasClass('add-to-cart') || $thisbutton.hasClass('add-to-cart-icon') || $thisbutton.hasClass('attribute-button') ) && $thisbutton.closest('.item_wrap').length ) { 327 328 title = parent.find('.woocommerce-loop-product__title'); 329 price = parent.find( '.price' ); 330 // image = parent.find('.wrap-for-top-part a img'); 331 let sliders = parent.find( '.product-images-slider--container' ); 332 // console.log( sliders, 'sliders' ); 333 334 if ( sliders.length > 0 ){ 335 let slider; 336 if ( sliders.length > 1 ){ 337 slider = parent.find( '.product-images-slider--container:not(.hidden-gallery)' ); 338 // console.log( slider , 'islider' ); 339 } else { 340 slider = sliders.first(); 341 } 342 image = slider.children().first().find('img'); 343 // console.log( image , 'image' ); 344 } else { 345 image = parent.find('.wrap-for-top-part a img'); 346 // console.log( image.first() , 'image first()' ); 347 if ( image.length > 1 ){ 348 image.first(); 349 } 350 } 351 // console.log( slider, 'slider' ); 352 } 353 354 // console.log( image , 'image after' ); 355 // console.log( $thisbutton , '$thisbutton' ); 356 // console.log( $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__image:first-child img') , '.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__image:first-child img SELECTOR' ); 357 } else if ( $('body').hasClass('archive') ){ 358 let parent = $thisbutton.closest('.item_wrap'); 359 title = parent.find('.woocommerce-loop-product__title'); 360 price = parent.find( '.price' ); 361 362 if ( $thisbutton.hasClass('add-to-cart-mobile') ){ 363 image = parent.find('.wrap-for-top-part a img'); 364 productSlider = parent.find('.wrap-for-top-part .product-images-slider--container.slick-slider'); 365 366 if ( productSlider.length > 0 ){ 367 image = productSlider.find('.slick-slide:not(.slick-cloned)').first().find('img'); 368 } 369 // img 370 // if ( image = parent.find('.wrap-for-top-part .product-images-slider--container img') ) 371 console.log( image , 'image image add to cart mobile ' ); 372 } else { 373 let sliders = parent.find( '.product-images-slider--container' ); 374 if ( sliders.length > 0 ){ 375 let slider; 376 if ( sliders.length > 1 ){ 377 slider = parent.find( '.product-images-slider--container:not(.hidden-gallery)' ); 378 } else { 379 slider = sliders.first(); 380 } 381 image = slider.find('.slick-slide:not(.slick-cloned) img'); 382 } 383 // Fallback to single product image if no slider is found 384 if (!image || image.length === 0) { 385 image = parent.find('.wrap-for-top-part a img'); 386 } 387 } 388 console.log( image , 'image archive ' ); 389 // console.log( slider , 'slider ' ); 390 } else if ( $('body').hasClass('home') ){ 391 let parent = $thisbutton.closest('.item_wrap'); 392 title = parent.find('.woocommerce-loop-product__title'); 393 price = parent.find( '.price' ); 394 // image = parent.find('.wrap-for-top-part a img'); 395 let sliders = parent.find( '.product-images-slider--container' ); 396 // console.log( sliders, 'sliders' ); 397 398 if ( sliders.length > 0 ){ 399 let slider; 400 if ( sliders.length > 1 ){ 401 slider = parent.find( '.product-images-slider--container:not(.hidden-gallery)' ); 402 // console.log( slider , 'islider' ); 403 } else { 404 slider = sliders.first(); 405 } 406 image = slider.children().first().find('img'); 407 // console.log( image , 'image' ); 408 } else { 409 image = parent.find('.wrap-for-top-part a img'); 410 // console.log( image.first() , 'image first()' ); 411 if ( image.length > 1 ){ 412 image.first(); 413 } 414 } 415 } else if ( $('body').hasClass('single-recipes') ){ 416 let parent = $thisbutton.closest('.item_wrap'); 417 title = parent.find('.woocommerce-loop-product__title'); 418 price = parent.find( '.price' ); 419 image = parent.find('.wrap-for-top-part a img'); 420 } 421 // console.log( image , 'image' ); 422 // console.log( parent , 'parent' ); 423 // console.log( $thisbutton , '$thisbutton' ); 424 // console.log( $thisbutton.closest('.item_wrap') , 'closest ITEM WRAP' ); 425 426 427 let attributePannel; 428 // check if added from panel 429 if ( $thisbutton.hasClass('add-to-cart-mobile') ){ 430 attributePannel = parent.find('.oc-product-quick-add-to-cart-panel-1 .oc-product-variable-panel'); 431 } else { 432 attributePannel = parent.find('.oc-product-quick-add-to-cart-panel .oc-product-variable-panel'); 433 } 434 let variationsForm = $thisbutton.closest('form.variations_form'); 435 arSelectedVariation = {}; 436 // because slug doesn`t even to attribute name 437 arSelectedAttrs = {}; 438 439 if ( attributePannel.length > 0 ){ 440 console.log( attributePannel, 'attributePannel' ); 441 442 attributePannel.each( function( index, panelToShow ){ 443 let activeBtn = $(panelToShow).find( 'button.attribute-button.active' ); 444 let activeColor = $(panelToShow).find( '.color-attribute.active' ); 445 446 // console.log( panelToShow, 'panel To Show' ); 447 if ( activeBtn.length > 0 ){ 448 let attributeName = $(panelToShow).find('.attribute-header .attr-label') 449 // console.log( activeBtn, 'activeBtn' ); 450 // console.log( attributeName.html(), 'html' ); 451 // console.log( activeBtn.data('slug'), 'slug' ); 452 // console.log( activeBtn.attr('name'), 'name' ); 453 454 var attributeLabel = attributeName.html(); 455 attributeLabel = attributeLabel.replace( ':', '' ); 456 457 arSelectedVariation[ attributeLabel ] = activeBtn.data('slug'); 458 // arSelectedAttrs[ attributeName.html() ] = activeBtn.html(); 459 let btnText = activeBtn.html(); 460 arSelectedAttrs[ attributeLabel ] = btnText; 461 462 } else if ( activeColor.length > 0 ){ 463 let attributeName = 'צ××¢'; 464 // console.log( activeColor, 'aria activeColor' ) 465 // console.log( activeColor.attr('aria-label'), 'aria label' ) 466 arSelectedVariation[ attributeName ] = activeColor.attr('aria-label'); 467 let btnText = activeBtn.html(); 468 // btnText = btnText.replace( ':', '' ); 469 // arSelectedAttrs[ attributeName ] = btnText; 470 arSelectedAttrs[ attributeName ] = activeColor.attr('aria-label');; 471 472 } 473 }); 474 475 // console.log( arSelectedVariation, 'arSelectedVariation' ) 476 // console.log( arSelectedAttrs, 'arSelectedAttrs' ) 477 // 478 } else if ( variationsForm.length > 0 ){ 479 480 console.log( variationsForm, 'variationsForm' ); 481 482 var variationAttributePanel = variationsForm.find('.buttons-attrs-panel--wrapper'); 483 if ( variationAttributePanel.length > 0 ){ 484 variationAttributePanel.each( function( index, panel ){ 485 let activeBtn = $(panel).find('button.active'); 486 let attributeName = $(panel).find('.attribute-title').clone(); 487 attributeName.find('.selected-value').remove(); 488 // console.log( attributeName, 'attributeName clone' ); 489 // console.log( attributeName, 'attributeName' ); 490 // console.log( attributeName.html(), 'attributeName.html()' ); 491 // console.log( activeBtn.attr( 'data-val' ), 'activeBtn' ); 492 // arSelectedVariation[ attributeName.html() ] = ':' + activeBtn.attr( 'data-val' ); 493 494 var attributeLabel = attributeName.html(); 495 attributeLabel = attributeLabel.replace( ':', '' ); 496 arSelectedVariation[ attributeLabel ] = activeBtn.attr( 'aria-label' ); 497 498 let btnText = activeBtn.html(); 499 // 500 if ( $(panel).hasClass( 'color-attributes-container' ) ){ 501 arSelectedAttrs[ attributeLabel ] = decodeURI( activeBtn.attr( 'aria-label' ) ); 502 } else { 503 arSelectedAttrs[ attributeLabel ] = btnText; 504 } 505 506 }); 507 } 508 // console.log( variationAttributePanel, 'variationAttributePanel' ); 509 // console.log( arSelectedAttrs, 'arSelectedAttrs here !!!!' ); 510 // console.log( arSelectedVariation, 'arSelectedVariation here !!!!' ); 511 } 512 513 514 // Image insert 515 if ( image ){ 516 console.log('test'); 517 console.log(image.attr('src')); 518 $(message).find('.product-image img').attr( 'src', image.attr('src') ); 519 } 520 if ( title ){ 521 $(message).find('.product-title .title').html( title.html() ); 522 } 523 524 if ( price ){ 525 // $(message).find('.product-price').html( price.html() ); 526 } 527 528 // console.log( arSelectedAttrs, 'arSelectedAttrs' ); 529 530 // add variation attribute to notice 531 532 // add attributes 533 if ( arSelectedAttrs ){ 534 let html = ''; 535 // for (const property in arSelectedVariation) { 536 // html += '<div><span class="attr-name">'+property+'</span><span class="attr-prop">'+arSelectedVariation[property]+'</span></div>'; 537 // } 538 for ( const property in arSelectedAttrs ) { 539 html += '<div><span class="attr-name">'+property+'</span><span class="attr-prop">'+arSelectedAttrs[property]+'</span></div>'; 540 } 541 if ( html != '' ){ 542 $(message).find('.variation').html( html ); 543 } 544 } 545 546 $(message).addClass( 'active' ); 547 $(message).appendTo( target ); 548 $('body').removeClass('no-scroll'); 549 setTimeout( function(){ 550 // target.find( '.add-to-cart-notice--container' ).remove(); 551 target.find( '.add-to-cart-notice--container' ).addClass('hidden'); 552 }, 3000 ); 553 } 554 555 // return; 556 557 $( document ).on( 'ajaxSuccess', function( event, xhr, settings ) { 558 if ( settings.data ){ 559 let isOcFilter = 'action=oc_woo_fiter_ajax'; 560 let ajaxData = settings.data; 561 562 if ( ajaxData.indexOf( isOcFilter ) != -1 ){ 563 // reinit slick 564 init_product_slider_slick(); 565 // console.log( settings.data, 'settings data' ); 566 } 567 } 568 // console.group('ajaxSuccess'); 569 // console.log( settings, 'settings ' ); 570 571 // console.log( settings.contents, 'settings.contents' ); 572 // // console.log( settings.data, 'settings.data' ); 573 // // console.log( settings.responseFields, 'settings.responseFields' ); 574 // console.log(xhr.responseText, 'xhr.responseText' ); 575 // console.log(event, 'event' ); 576 // console.groupEnd(); 577 578 579 // if ( $('.single-product-wishlist-button').length > 0 ){ 580 // if ( xhr.responseText != '' ){ 581 // let parsed = JSON.parse( xhr.responseText ); 582 583 // if (
583parsed['fragments'] ){ 584 // // console.log( parsed['fragments'], 'parsed.fragments' ); 585 // // console.log( $(parsed['fragments']), '$ parsed.fragments' ); 586 587 // for ( const property in parsed['fragments'] ) { 588 // if ( property == 'woocommerce.yith-wcwl-form.wishlist-fragment' ){ 589 // // $('.single-product-wishlist-button').html( parsed['fragments'][property] ) 590 // // console.log( property, 'property' ); 591 // // console.log( parsed['fragments'], 'fragments ' ); 592 // console.log( parsed['fragments'][property], 'fragments[property]' ); 593 // } 594 595 // } 596 // } 597 // } 598 // } 599 600 }); 601 602 // update minicart circle count 603 $( document.body ).on( 'added_to_cart', function( fragments, cart_hash, $thisbutton ){ 604 $('span.minicart-circle').html( cart_hash['count'] ); 605 $('.minicart-count').html( cart_hash['count'] ); 606 if ( cart_hash['count'] > 0 ){ 607 $('span.minicart-circle').removeClass('hidden'); 608 } else { 609 $('span.minicart-circle').addClass('hidden'); 610 } 611 }); 612 613 // on remove product from cart , display updated cart items quantity in minicart circle 614 $( document.body ).on( 'removed_from_cart', function( fragments, cart_hash, thisButton ){ 615 $('span.minicart-circle').html( cart_hash['count'] ); 616 $('.minicart-count').html( cart_hash['count'] ); 617 if ( cart_hash['count'] > 0 ){ 618 $('span.minicart-circle').removeClass('hidden'); 619 } else { 620 $('span.minicart-circle').addClass('hidden'); 621 } 622 // $('.recently-viewed-products-container ul.products').slick({ 623 // slidesToShow: 2, 624 // slidesToScroll:1, 625 // rtl: rtl, 626 // infinite: false, 627 // }); 628 }); 629 630 // Footer accordion basic 631 $(document).on( 'click', '.footer-accordion-title' , function(){ 632 let target = $(this).next('div'); 633 634 if ( $(window).width() > 1024 ){ 635 return; 636 } 637 638 console.log( target, 'target' ); 639 640 $(this).toggleClass('active'); 641 642 // target.toggleClass('active'); 643 target.toggleClass( 'active-submenu' ); 644 645 if ( !target.hasClass( 'active-submenu' ) ){ 646 target.slideUp(); 647 } else { 648 target.slideDown(); 649 } 650 }); 651 652 653 654 // remove from mini-cart ajax 655 // $(document).on( 'click', '.cart-list a.remove', function(e){ 656 $(document).on( 'click', '.woocommerce-mini-cart-item a.remove', function(e){ 657 e.preventDefault(); 658 659 var product_id = $(this).attr("data-product_id"); 660 var cart_item_key = $(this).attr("data-cart_item_key"); 661 var li = $(this).closest( '.woocommerce-mini-cart-item'); 662 663 li.addClass('blocked'); 664 li.append( '<span class="loader-css"></span>' ); 665 $(this).closest('.mini-cart-panel--container').addClass('blocked') 666 667 // console.log( product_id, 'product_id :: REMOVE fron minicart' ); 668 oc_ajax_minicart_remove_product( product_id, cart_item_key, li ) 669 }); 670 671 // function oc_click_first_var(){ 672 // $('.item_wrap').each(function() { 673 // // Find the first li of color in the current product's item_wrap 674 // var firstColorLi = $(this).find('.product-colors-container li.color-attribute').first(); 675 // 676 // // Trigger a click on this element if it exists 677 // if (firstColorLi.length) { 678 // firstColorLi.click(); 679 // } 680 // }) 681 // } 682 // $(document).ready(function() { 683 // oc_click_first_var(); 684 // }); 685 686 // remove product from minicart ! 687 function oc_ajax_minicart_remove_product( product_id, cart_item_key, li = '' ){ 688 // console.log( 'oc_ajax_minicart_remove_product' ); 689 // var miniCartPreloader = $('.mini-cart-preloader'); 690 // miniCartPreloader.addClass( 'active' ); 691 $.ajax({ 692 type: 'POST', 693 dataType: 'json', 694 url: woocommerce_params.ajax_url, 695 data: { 696 action: "minicart_product_remove", 697 product_id: product_id, 698 cart_item_key: cart_item_key 699 }, 700 success: function(response) { 701 if ( ! response || response.error ){ 702 li.removeClass('block'); 703 li.find('.loader-css').remove(); 704 705 console.log( response.error, 'response.error' ); 706 return; 707 } 708 // console.log( 'WITHOUT REMOVE' ); 709 // return; 710 var fragments = response.fragments; 711 var minicart_sidebar = response.fragments['minicart_sidebar']; 712 713 console.log( minicart_sidebar, 'minicart_sidebar' ); 714 console.log( fragments, 'fragments' ); 715 console.log( $(fragments['.mini-cart-widget--container']), 'recently-viewed-products-container ul.products' ); 716 717 // Replace fragments 718 if ( fragments ) { 719 $.each( fragments, function( key, value ) { 720 $( key ).replaceWith( value ); 721 }); 722 if ( minicart_sidebar ){ 723 $('.minicart-sidebar--container').html( minicart_sidebar ); 724 } 725 } 726 li.removeClass('block'); 727 // li.find('.loader-css').remove(); 728 729 730 // miniCartPreloader.removeClass( 'active' ); 731 $(document.body).trigger('removed_from_cart', [response.fragments, response.cart_hash]); 732 733 734 735 $(document.body).trigger( 'cart_page_refreshed' ); 736 $(document.body).trigger( 'update_checkout' ); 737 738 // if ( $(fragments['.mini-cart-widget--container']).find('.recently-viewed-products-container ul.products').length > 0 ) { 739 // $(fragments['.mini-cart-widget--container']).find('.recently-viewed-products-container ul.products').slick({ 740 // slidesToShow: 2, 741 // slidesToScroll:1, 742 // rtl: rtl, 743 // infinite: false, 744 // }); 745 // } 746 747 setTimeout( function(){ 748 // $('.recently-viewed-products-container .preloader-wrapper').show(); 749 // $('.recently-viewed-products-container .preloader-wrapper').addClass('center-loader'); 750 $('.recently-viewed-products-container ul.products').slick({ 751 slidesToShow: 2, 752 slidesToScroll:1, 753 rtl: rtl, 754 infinite: false, 755 }); 756 // $('.recently-viewed-products-container ul.products').show(); 757 // $('.recently-viewed-products-container .preloader-wrapper').hide(); 758 759 }, 50 ) 760 $('.recently-viewed-products-container').show(); 761 $('.recently-viewed-products-container .preloader-wrapper').hide(); 762 } 763 }); 764 } 765 766 // apply coupon code in minicart 767 $(document).on('click', 'button.minicart-coupon-btn', function() { 768 var coupon = $( 'input#minicart_coupon_code' ).val(); 769 var button = ( this ); 770 var data = { 771 action: 'minicart_apply_coupon_code', 772 coupon_code: coupon, 773 coupon_apply: true, 774 }; 775 oc_ajax_minicart_apply_coupon( data ); 776 }); 777 778 // callback function for apply coupon event 779 function oc_ajax_minicart_apply_coupon( data ){ 780 $.ajax({ 781 type: 'POST', 782 dataType: 'json', 783 url: woocommerce_params.ajax_url, 784 data: data, 785 success: function (response) { 786 // console.log(response); 787 if ( response.success ){ 788 // $('.mini-cart-widget--container').html(response.data); 789 console.log( response.data, 'response.data' ); 790 $('.minicart-bottom--container .minicart-bottom-subtotal').html( response.data ); 791 } 792 }, 793 error: function (errorThrown) { 794 console.log(errorThrown, 'errorThrown'); 795 } 796 }); 797 } 798 799 800 // Change quantity on button click
801 $(document).on( 'click', '.mini-cart-product-quantity button.btn-qty', function(){ 802 let parent = $(this).closest('.mini-cart-product-quantity'); 803 let input = parent.find('input.qty'); 804 let isPlus = $(this).hasClass('plus'); 805 let cart_item_key = ''; 806 807 if ( input.length ){ 808 let attrMax = ( input.attr('max') != '' ) ? input.attr('max') : 999; 809 let max = parseInt( attrMax ); 810 let min = parseInt( input.attr('min') ); 811 812 if ( max == '' ){ 813 max = 999; 814 } 815 if ( min == '' ){ 816 min = 1; 817 } 818 819 let quantity = input.val(); 820 if ( isPlus ){ 821 if ( quantity < max ){ 822 quantity++; 823 } 824 } else { 825 if ( quantity != 1 ){ 826 if ( quantity > min ){ 827 quantity--; 828 } 829 } 830 } 831 832 if ( input.val() == quantity ){ 833 // console.log( 'nothing change' ); 834 // return; 835 } 836 837 let id = input.attr('id'); 838 cart_item_key = id.replace('quantity_', ''); 839 input.val( quantity ); 840 oc_ajax_set_minicart_quantity( cart_item_key, quantity ); 841 } 842 }); 843 844 // new select on minicart 845 $(document).on( 'change', '.mini-cart-product-quantity select.quantity-select', function(){ 846 let parent = $(this).closest('.mini-cart-product-quantity'); 847 var quantity = $(this).val(); 848 var cart_item_key = $(this).attr( 'data-cart-item-key' ); 849 oc_ajax_set_minicart_quantity( cart_item_key, quantity ); 850 }); 851 852 // Ajax callback function: set quantity at minicart 853 function oc_ajax_set_minicart_quantity( cart_item_key, quantity ){ 854 $.ajax({ 855 type: 'POST', 856 dataType: 'json', 857 url: woocommerce_params.ajax_url, 858 data: { 859 action: "minicart_product_set_quantity", 860 cart_item_key: cart_item_key, 861 quantity: quantity, 862 }, 863 success: function(response) { 864 if ( ! response || response.error ){ 865 console.log( response.error, 'response.error' ); 866 return; 867 } 868 // console.log( response, 'response ajax increase' ); 869 var totals = response.data.totals; 870 var freeShippingBar = response.data.free_shipping_bar; 871 var sidebarMinicartTotals = response.data.sidebar_minicart_totals; 872 var count = response.data.count ; 873 var cartContent = response.data.mini_cart ; 874 875 $('.mini-cart-panel--container .minicart-bottom-subtotal').html( totals ); 876 $('.mini-cart-panel--container .shipping-bar--wrap').html( freeShippingBar ); 877 $('.minicart-circle').html( count ); 878 $('.minicart-count').html( count ); 879 880 // update sidebar minicart 881 $('.sidebar-minicart-subtotal').html( sidebarMinicartTotals ); 882 $('.sidebar-minicart-subtotal .cart-count' ).html(count); 883 884 // 885 let updatedCartItem = $(cartContent).find( 'ul.woocommerce-mini-cart .woocommerce-mini-cart-item' ); 886 if ( $('ul.woocommerce-mini-cart .woocommerce-mini-cart-item').length > 0 && updatedCartItem.length > 0 ){ 887 $('ul.woocommerce-mini-cart .woocommerce-mini-cart-item').each( function( index, el ){ 888 if ( updatedCartItem[index] ){ 889 let price = $(updatedCartItem[index]).find('.mini-cart-product-price'); 890 $(el).find('.mini-cart-product-price').html( price.html() ); 891 // console.log( price.html(), 'price' ); 892 // console.log( $(el).find('.mini-cart-product-price').html(), 'el .mini-cart-product-price' ); 893 } 894 }); 895 } 896 897 // update total sum on checkout btn 898 let checkoutBtnTotal = $('.minicart-checkout-proceed-container a.checkout .cart-total'); 899 if ( checkoutBtnTotal.length > 0 ){ 900 let newTotal = $(totals).find('tr.order-total td strong').html(); 901 checkoutBtnTotal.html( newTotal ) 902 } 903 904 // console.log( checkoutBtnTotal, 'checkoutBtnTotal' ); 905 // console.log( totals, 'totals' ); 906 // $('.mini-cart-panel--container .minicart--container').html( cartContent ); 907 // console.log( $(cartContent), '$cartContent' ); 908 // console.log( cart_item_key, 'cart_item_key' ); 909 910 // let aLink = $('.mini-cart-panel--container a[data-cart_item_key='+cart_item_key+']'); 911 // if ( aLink.length > 0 ){ 912 // let li = aLink.closest('.mini_cart_item'); 913 // if ( li.find( '.price-per-item bdi' ).length > 0 ){4 914 // let priceItem = li.find( '.price-per-item bdi' ).html(); 915 // let currency = '<span class="woocommerce-Price-currencySymbol">âª</span>'; 916 // let itemPrice = priceItem.replace( currency, '' ); 917 918 // if ( itemPrice.indexOf(',') != -1 ){ 919 // itemPrice = itemPrice.replace(',' , '') ; 920 // } 921 922 // if ( itemPrice.indexOf('.00') != -1 ){ 923 // itemPrice = itemPrice.replace('.00' , '') ; 924 // } 925 926 // if ( itemPrice.indexOf('.0') != -1 ){ 927 // itemPrice = itemPrice.replace('.0' , '') ; 928 // } 929 930 // console.log( quantity, 'quantity' ); 931 // // console.log( priceItem.html(), 'priceItem' ); 932 // console.log( itemPrice, 'itemPrice' ); 933 // console.log( itemPrice * quantity , 'itemPrice * quantity ' ); 934 // } 935 936 // } 937 // console.log( aLink, 'aLink' ); 938 939 // $(document.body).trigger( 'updated_shipping_method' ); 940 $( document.body ).trigger( 'update_checkout', { update_shipping_method: true } ); 941 } 942 }); 943 } 944 945 // On minicart input quantity field change 946 $(document).on( 'change', '.mini-cart-product-quantity input.qty', function(){ 947 let input = $(this); 948 let quantity = input.val(); 949 let id = input.attr('id'); 950 cart_item_key = id.replace('quantity_', ''); 951 oc_ajax_set_minicart_quantity( cart_item_key, quantity ); 952 }); 953 954 // On quantity plus|minus button click, single product 955 $(document).on( 'click', '.product .summary .quantity button.btn-qty', function(){ 956 let parent = $(this).closest('.quantity'); 957 let input = parent.find('input.qty'); 958 let isPlus = $(this).hasClass('plus'); 959 let quantity; 960 if ( input.length ){ 961 let max = ( input.attr('max') ) ? parseInt( input.attr('max') ) : 999; 962 let min = ( input.attr('min') ) ? parseInt( input.attr('min') ) : 1 ; 963 964 quantity = input.val(); 965 if ( isPlus ){ 966 if ( quantity < max ){ 967 quantity++; 968 } 969 } else { 970 if ( quantity != 1 ){ 971 if ( quantity > min ){ 972 quantity--; 973 } 974 } 975 } 976 input.val( quantity ); 977 } 978 }); 979 980
981 // Remove coupon from minicart 982 $(document).on( 'click', '.minicart-bottom-subtotal a.woocommerce-remove-coupon', function(e){ 983 var coupon = $(this).data('coupon'); 984 var data = { 985 action: 'minicart_apply_coupon_code', 986 coupon_code: coupon, 987 coupon_apply: false, 988 }; 989 oc_ajax_minicart_apply_coupon( data ); 990 e.preventDefault(); 991 }); 992 993 // Change shipping method select at minicart 994 $(document).on( 'change', '.minicart-bottom--container select#mini-cart-shipping-method', function(){ 995 let shippingMethod = $(this).val(); 996 // let radioTarget = $('.minicart-bottom-subtotal #shipping_method input[value="'+ val +'"]'); 997 // console.log( radioTarget, 'radio btn from wc totals' ); 998 if ( shippingMethod ){ 999 // $( document.body ).trigger( 'update_checkout' ); 1000 $.ajax({ 1001 type: 'POST', 1002 dataType: 'json', 1003 url: woocommerce_params.ajax_url, 1004 data: { 1005 action: "oc_woo_shipping_set_method", 1006 shipping_method: shippingMethod, 1007 }, 1008 success: function(response) { 1009 if ( ! response || response.error ){ 1010 console.log( response.error, 'response.error' ); 1011 return; 1012 } 1013 var totals = response.data.totals; 1014 $('.mini-cart-panel--container .minicart-bottom-subtotal').html( totals ); 1015 console.log( response, 'Response AJAX, last' ); 1016 }, 1017 error: function(error){ 1018 console.log( error, 'error' ); 1019 } 1020 }); 1021 } 1022 }); 1023 1024 // Change register to login form ( transform animation ) 1025 $(document).on( 'click', 'button.auth-btn', function(e){ 1026 let val = $(this).val(); 1027 let parent = $(this).closest( '#customer_login' ); 1028 let target; 1029 // console.log( val, 'val' ); 1030 // console.log( parent, 'parent' ); 1031 1032 if ( val == 'register' ){ 1033 parent.addClass( 'register-show' ); 1034 target = $('.authorization-panel--container .col-2'); 1035 } else { 1036 target = $('.authorization-panel--container .col-1'); 1037 parent.removeClass( 'register-show' ); 1038 } 1039 }); 1040 1041 // Open my account drawer 1042 $(document).on( 'click', 'a.my-account-link.login-panel', function(e){ 1043 let $this = $(this); 1044 toggle_hidden_attribute( $this, '#auth-panel' ); 1045 $('.page-overlay').addClass('is-visible top'); 1046 e.preventDefault(); 1047 return false; 1048 }); 1049 1050 // Close authorization panel 1051 $(document).on( 'click', 'button.auth__close', function(){ 1052 $('.page-overlay').removeClass('is-visible top'); 1053 $('#auth-panel').attr( 'aria-hidden', true ); 1054 $('.site-header a.my-account-link').removeClass('active'); 1055 $('.oc-woo-search--wrap').removeClass('active'); 1056 }); 1057 1058 // On lost password click - show lost-password form 1059 $(document).on( 'click', '.authorization-panel--container .woocommerce-form-login p a.lost_password', function(e){ 1060 $('.authorization-panel--container .my-account-lost-password-form--container').toggleClass('show') 1061 e.preventDefault(); 1062 }); 1063 1064 // return to login from from lost password form 1065 $(document).on( 'click', 'button.return-to-login-form', function(){ 1066 $('.my-account-lost-password-form--container').removeClass('show'); 1067 }); 1068 1069 $(document).on( 'click', '.open-registration', function(){ 1070 // $('a.login-panel').trigger( 'click' ) 1071 // $( '#customer_login' ).addClass( 'register-show' ); 1072 } ) 1073 1074 //Single Product! 1075 //**************************************************************************/ 1076 // Single product tabs use as accordion 1077 if ( $('body').hasClass('single-product-tab-style-accordion') ){ 1078 $('.wc-tabs-accordion-wrapper').accordion({ 1079 collapsible:true, 1080 heightStyle: "content", 1081 active :false 1082 }); 1083 } 1084 1085 // 1086 // console.log( 'found_variation +++' ) 1087 1088 $( document.body ).on( "found_variation", function ( event, variation ) { 1089 console.log(variation.display_price, 'variation found_variation' ); 1090 if ( $('body').hasClass('admin-bar') ){ 1091 console.group( 'found_variation ' ); 1092 console.log( variation, 'variation found_variation' ); 1093 console.groupEnd(); 1094 } 1095 1096 }); 1097 1098 1099 // jQuery(document).ready(function($) { 1100 // $('.single-product .variations_form').on('found_variation', function(event, variation) { 1101 // var $productContainer = $(this).closest('.product'); 1102 // 1103 // // Check if the variation has a price 1104 // if (variation.display_price) { 1105 // var formattedPrice = $('<span>').addClass('woocommerce-Price-currencySymbol').text('âª').get(0).outerHTML + variation.display_price.toLocaleStr
1105ing(); 1106 // $productContainer.find('.woocommerce-Price-amount bdi').html(formattedPrice); 1107 // // Remove the "××× ×-" prefix 1108 // $productContainer.find('.price').contents().filter(function() { 1109 // return this.nodeType === 3; // Node type 3 is a text node 1110 // }).remove(); 1111 // } 1112 // }); 1113 // 1114 // $('.single-product .variations_form').on('reset_data', function() { 1115 // var $productContainer = $(this).closest('.product'); 1116 // var initialPrice = $productContainer.find('.woocommerce-Price-amount bdi').data('initial-price'); 1117 // if (initialPrice) { 1118 // $productContainer.find('.woocommerce-Price-amount bdi').html(initialPrice); 1119 // $productContainer.find('.price').prepend('××× ×: '); 1120 // } 1121 // }); 1122 // }); 1123// ; 1124 1125 jQuery(document).ready(function($) { 1126 $('.single-product .variations_form').on('found_variation', function(event, variation) { 1127 var $productContainer = $(this).closest('.product'); 1128 1129 // Check if the variation has a price 1130 if (variation.display_price) { 1131 if(variation.display_price != variation.display_regular_price){ 1132 var formattedPrice = '<del aria-hidden="true"><span class="woocommerce-Price-amount amount"><bdi role="label" aria-label="Regular price" tabindex="0"><span class="woocommerce-Price-currencySymbol">âª</span>'+variation.display_regular_price+'</bdi></span></del><ins><span class="woocommerce-Price-amount amount"><bdi role="label" aria-label="Regular price" tabindex="0"><span class="woocommerce-Price-currencySymbol">âª</span>'+variation.display_price+'</bdi></span></ins>'; 1133 $productContainer.find('.entry-summary p.price').html(formattedPrice); 1134 }else{ 1135 //var formattedPrice = $('<span>').addClass('woocommerce-Price-currencySymbol').text('âª').get(0).outerHTML + variation.display_price.toLocaleString(); 1136 var formattedPrice = '<span class="woocommerce-Price-amount amount"><bdi role="label" aria-label="Regular price" tabindex="0"><span class="woocommerce-Price-currencySymbol">âª</span>'+variation.display_price+'</bdi></span>'; 1137 $productContainer.find('.entry-summary p.price').html(formattedPrice); 1138 } 1139 // Remove the "××× ×-" prefix 1140 $productContainer.find('.price').contents().filter(function() { 1141 return this.nodeType === 3; // Node type 3 is a text node 1142 }).remove(); 1143 } 1144 }); 1145 1146 $('.single-product .variations_form').on('reset_data', function() { 1147 var $productContainer = $(this).closest('.product'); 1148 var initialPrice = $productContainer.find('.woocommerce-Price-amount bdi').data('initial-price'); 1149 if (initialPrice) { 1150 $productContainer.find('.woocommerce-Price-amount bdi').html(initialPrice); 1151 $productContainer.find('.price').prepend('××× ×: '); 1152 } 1153 }); 1154 }); 1155 1156 1157 1158 var firstLoad = true; 1159 // Change buy now link for variable product on variation change. Fired when the user selects all the required dropdowns / attributes 1160 $( ".single_variation_wrap" ).on( "show_variation", function ( event, variation, purchasable ) { 1161 1162 if ( $('body').hasClass('admin-bar') ){ 1163 1164 let metalAttr = variation.attributes['attribute_pa_metal']; 1165 1166 console.group( 'single_variation_wrap ON show_variation ' ); 1167 // console.log( purchasable, 'purchasable ' ); 1168 console.log( metalAttr, 'metalAttr' ); 1169 console.log( decodeURI( metalAttr ), 'metalAttr decoded' ); 1170 console.log( variation.is_in_stock, 'variation.is_in_stock' ); 1171 console.log( variation, 'variation ' ); 1172 // console.log( event, 'event' ); 1173 console.groupEnd(); 1174 } 1175 1176 let buyNowBtn = $('a.buy-now-btn') 1177 if ( buyNowBtn.length ){ 1178 if ( variation.is_in_stock ){ 1179 let query = '?add-to-cart=' + variation.variation_id 1180 let link = buyNowBtn.data('original-link'); 1181 let addToCartLink = link + query + '&quantity=1'; 1182 buyNowBtn.attr( 'href', addToCartLink ); 1183 buyNowBtn.removeClass('disabled') 1184 } 1185 } 1186 1187 if ( !variation.is_in_stock ){ 1188 // console.log( $('.buttons-attrs-panel--wrapper.color-attributes-container .attribute-btn.active'), 'ATTRIBUTE BTN active' ); 1189 // add class to outofstock attribute buttons ! 1190 if ( $('.buttons-attrs-panel--wrapper.color-attributes-container .attribute-btn.active').length > 0 ){ 1191 $('.buttons-attrs-panel--wrapper.color-attributes-container .attribute-btn.active').addClass('outofstock'); 1192 } 1193 } 1194 1195 // to do move to child theme 1196 // variationIsInstock = false;
1197 // if ( variation.is_in_stock && variation.availability_html != '' ){ 1198 // let avaiabilityHtml = variation.availability_html; 1199 // if ( avaiabilityHtml.indexOf('in-stock') != -1 ){ 1200 // variationIsInstock = true; 1201 // } 1202 // } 1203 1204 // // console.log( variationIsInstock, 'variationIsInstock' ); 1205 // if ( !variationIsInstock ){ 1206 // event.stopPropagation(); 1207 // } 1208 1209 // if ( firstLoad && variation && variation.is_in_stock ){ 1210 if ( variation && variation.is_in_stock ){ 1211 1212 // console.log( variation.attributes, 'attributes from default variation' ); 1213 1214 if ( $('.buttons-attrs-panel--wrapper').length > 0 ){ 1215 $('.buttons-attrs-panel--wrapper').each( function( index, el ){ 1216 let panel = $(el); 1217 let taxonomy = 'attribute_' + panel.data( 'tax' ); 1218 // console.log(taxonomy, 'taxonomy ' ); 1219 1220 if ( variation.attributes[taxonomy] ){ 1221 let taxValue = variation.attributes[taxonomy]; 1222 1223 let btn = $(el).find( '.attribute-btn[data-val="'+taxValue+'"]') 1224 1225 // console.log( taxonomy, 'taxonomy isset here ! ' ); 1226 // console.log( variation.attributes[taxonomy], 'taxonomy isset here ! ' ); 1227 // console.log( btn, 'btn' ); 1228 btn.addClass('active') 1229 1230 } 1231 }); 1232 firstLoad = false; 1233 } 1234 } 1235 1236 }); 1237 1238 // make buynow button disabled if user didn`t choose variation 1239 $(document).on( 'change', 'input.variation_id', function(){ 1240 let buyNowBtn = $('a.buy-now-btn'); 1241 if ( !$(this).val() || $(this).val() == '' ){ 1242 buyNowBtn.addClass('disabled') 1243 } 1244 }) 1245 1246 // Single product 1247 var windowMobileResolution = 768; 1248 let singleProductGallerySlick = false; 1249 let singleProductMobileGallerySlick = false; 1250 var spMobileGalleryUseDots = false; 1251 var spMobileGalleryUseArrows = false; 1252 // var centerPadding = ocThemeSettings.galleryThumbsPadding + 'px'; 1253 var centerPadding = '50px'; 1254 1255 var singleProductGalleryArrows = false; 1256 var singleProductGalleryDots = false; 1257 if ( ocThemeSettings && ocThemeSettings.product_gallery_desktop_use_arrows ){ 1258 if ( ocThemeSettings.product_gallery_desktop_use_arrows == 'true' ){ 1259 singleProductGalleryArrows = true ; 1260 } else { 1261 singleProductGalleryArrows = false; 1262 } 1263 } 1264 1265 if ( ocThemeSettings && ocThemeSettings.product_gallery_desktop_use_dots ){ 1266 if ( ocThemeSettings.product_gallery_desktop_use_dots == 'true' ){ 1267 singleProductGalleryDots = true; 1268 } else { 1269 singleProductGalleryDots = false; 1270 } 1271 } 1272 1273 // console.log( ocThemeSettings.product_gallery_desktop_use_arrows , 'product_gallery_desktop_use_arrows' ); 1274 // console.log( ocThemeSettings , 'ocThemeSettings' ); 1275 1276 if ( $('.woocommerce-product-gallery').hasClass('mobile-use-dots') ){ 1277 spMobileGalleryUseDots = true; 1278 } 1279 1280 if ( $('.woocommerce-product-gallery').hasClass('mobile-use-arrows') ){ 1281 spMobileGalleryUseArrows = true; 1282 } 1283 1284 // Main slick object for init lib 1285 var singleProductMainSlider = { 1286 rtl: rtl, 1287 speed: 250, 1288 infinite: true, 1289 arrows: singleProductGalleryArrows, 1290 dots: singleProductGalleryDots, 1291 // useTransform: false, 1292 responsive: [ 1293 { 1294 breakpoint: windowMobileResolution, 1295 settings: { 1296 dots: spMobileGalleryUseDots 1297 } 1298 } 1299 ] 1300 } 1301 1302 // console.log( spMobileGalleryUseDots, 'spMobileGalleryUseDots ~' ); 1303 // // console.log( spMobileGalleryUseDots, 'spMobileGalleryUseDots ~' ); 1304 // console.log( centerPadding, 'centerPadding from settings 01-Jan-1970 ~' ); 1305 1306 // init slick on desktop 1307 if ( $('body').hasClass('product-gallery-vertical-thumbs') || $('body').hasClass('product-gallery-vertical-thumbs-column') || $('body').hasClass('product-gallery-regular-slider') ){ 1308 singleProductGallerySlick = true 1309 } 1310 1311 // Mobile classes for slick init + slick settings 1312 if ( $('body').hasClass('product-gallery-mobile-center-mode') ){ 1313 singleProductMainSlider.responsive = [ 1314 { 1315 breakpoint: windowMobileResolution, 1316 settings: { 1317 dots: spMobileGalleryUseDots, 1318 arrows: spMobileGalleryUseArrows, 1319 centerMode: true, 1320 centerPadding: centerPadding, 1321 slidesToShow: 1, 1322 speed: 1300, 1323 } 1324 } 1325 ]; 1326 singleProductMobileGallerySlick = true; 1327 1328 } else if ( $('body').hasClass('product-gallery-mobile-side-mode') ){ 1329 // centerPadding = '30px'; 1330 1331 singleProductMainSlider.responsive = [ 1332 { 1333 breakpoint: windowMobileResolution, 1334 settings: { 1335 dots: spMobileGalleryUseDots, 1336 arrows: spMobileGalleryUseArrows, 1337 1338 centerMode: true, 1339 centerPadding: centerPadding, 1340 slidesToShow: 1, 1341 infinite:true, 1342 speed: 1300, 1343 1344 } 1345 } 1346 ]; 1347 // $('.woocommerce-product-gallery__wrapper').addClass( 'side-mode' ); 1348 $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').addClass( 'side-mode' ); 1349 1350 singleProductMobileGallerySlick = true; 1351 } else if ( $('body').hasClass( 'product-gallery-mobile-regular-slider' ) || $('body').hasClass( 'product-gallery-two-per-row' ) || $('body').hasClass( 'product-gallery-one-per-row' ) ) { 1352 // add_class_if_odd(); 1353 1354 singleProductMainSlider.responsive = [ 1355 { 1356 breakpoint: windowMobileResolution, 1357 settings: { 1358 dots: spMobileGalleryUseDots, 1359 arrows: spMobileGalleryUseArrows, 1360 infinite:true 1361 } 1362 } 1363 ]; 1364 singleProductMobileGallerySlick = true; 1365 } 1366 1367 // console.log( singleProductGallerySlick, 'singleProductGallerySlick'); 1368 1369 // SP gallery init slick, desktop 1370 function single_product_gallery_slick(){ 1371 // if ( $(window).width() >= windowMobileResolution ){ 1372 // return; 1373 // } 1374 // console.log( 'single_product_gallery_slick' ); 1375 if ( $('body').hasClass('product-gallery-vertical-thumbs') || $('body').hasClass('product-gallery-vertical-thumbs-column') || $('body').hasClass('product-gallery-regular-slider') || ( $('body').hasClass('product-gallery-two-per-row') && $('.woocommerce-product-gallery__inner .woocommerce-product-gallery__image').length<=3) ){ 1376 // console.log( 'inside' ); 1377 // if ( !$('.woocommerce-product-gallery__wrapper').hasClass( 'slick-initialized' ) ){ 1378 if ( !$('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').hasClass( 'slick-initialized' ) ){ 1379 1380 // console.log( singleProductMainSlider, 'init singleProductMainSlider obj' ); 1381 1382 1383 // singleProductMainSlider.infinite = false;
1384 // singleProductMainSlider.asNavfor = '.vertical-thumbnails--container'; 1385 1386 // change vertical slider on change main slider 1387 // $('.woocommerce-product-gallery__wrapper').on('beforeChange', function(event, slick, currentSlide, nextSlide){ 1388 $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').on('beforeChange', function(event, slick, currentSlide, nextSlide){ 1389 // $('.vertical-thumbnails--container .slide.active').removeClass('active'); 1390 // $('.vertical-thumbnails--container .slide.slide-' + nextSlide).addClass('active'); 1391 $('.vertical-thumbnails--container:not(.hidden-gallery) .slide.slick-current').removeClass('slick-current'); 1392 if ( nextSlide == 0 ){ 1393 setTimeout( function(){ 1394 $('.vertical-thumbnails--container:not(.hidden-gallery) .slide.slide-0:not(.slick-cloned)').addClass('slick-current') 1395 }, 100 ); 1396 1397 // $('.vertical-thumbnails--container:not(.hidden-gallery) .slide.slide-0:not(.slick-cloned)').trigger('click'); 1398 1399 } else { 1400 $('.vertical-thumbnails--container:not(.hidden-gallery) .slide.slide-' + nextSlide).addClass('slick-current'); 1401 } 1402 let t = $('.vertical-thumbnails--container:not(.hidden-gallery) .slide.slide-' + nextSlide); 1403 // if ( t.length > 1 ){ 1404 // t.first().addClass('slick-current'); 1405 // } 1406 // console.log( nextSlide, 'nextSlide !!!!!!' ) 1407 // console.log( t, 't' ) 1408 // console.log( t.first(), 't.first()' ) 1409 1410 1411 if ( ocThemeSettings.thumbs_max_quantity < $('.vertical-thumbnails--container:not(.hidden-gallery) .slide').length ){ 1412 $('.vertical-thumbnails--container:not(.hidden-gallery)').slick('slickGoTo', nextSlide ) 1413 } else { 1414 // console.log('this is else condition' ); 1415 } 1416 // console.log( nextSlide, 'nextSlide' ); 1417 // console.log( currentSlide, 'currentSlide' ); 1418 }); 1419 1420 // $('.woocommerce-product-gallery__wrapper').slick( singleProductMainSlider ); 1421 $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').slick( singleProductMainSlider ); 1422 1423 if ( $('.vertical-thumbnails--container').hasClass('slick-slider') ){ 1424 $('.vertical-thumbnails--container').slick('unslick'); 1425 } 1426 1427 // console.log( $('.vertical-thumbnails--container .slide').length , 'length ' ); 1428 // console.log( ocThemeSettings.thumbs_max_quantity , ' ocThemeSettings.thumbs_max_quantity ' ); 1429 1430 if ( ocThemeSettings.thumbs_max_quantity <= $('.vertical-thumbnails--container:not(.hidden-gallery) .slide').length ){ 1431 var verticalSeliderSettings = oc_vertical_slider_slick_settings(); 1432 if ( ocThemeSettings.thumbs_max_quantity == $('.vertical-thumbnails--container:not(.hidden-gallery) .slide').length ){ 1433 verticalSeliderSettings.infinite = false; 1434 } 1435 1436 $('.vertical-thumbnails--container').slick( verticalSeliderSettings ); 1437 1438 if ( ocThemeSettings.thumbs_max_quantity < $('.vertical-thumbnails--container:not(.hidden-gallery) .slide').length ){ 1439 $('.vertical-thumbnails--container:not(.hidden-gallery)').on( 'beforeChange', function(event, aslick, currentSlide, nextSlide){ 1440 // $('.vertical-thumbnails--container').on( 'afterChange', function(slick, currentSlide ){ 1441 1442 // console.group('CURRNT SLIDE change ') 1443 // // console.log(slick, 'slick'); 1444 // // // console.log(nextSlide, 'nextSlide'); 1445 // // console.log(currentSlide, 'currentSlide'); 1446 // // console.log(nextSlide, 'nextSlide'); 1447 // console.groupEnd() 1448 1449 $('.vertical-thumbnails--container').slick('slickGoTo', nextSlide ) 1450 $('.vertical-thumbnails--container').find('.slide.slick-current').removeClass('slick-current'); 1451 $('.vertical-thumbnails--container').find('.slide[data-slick-index='+nextSlide+']').addClass('slick-current'); 1452 if ( ocThemeSettings.thumbs_max_quantity < $('.vertical-thumbnails--container:not(.hidden-gallery) .slide').length ){ 1453 $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').slick( 'slickGoTo', nextSlide ); 1454 } 1455 }); 1456 } 1457 } 1458 1459 $('.vertical-thumbnails--container').on( 'afterChange', function(slick, currentSlide ){ 1460 // console.log( currentSlide, 'currentSlide' ); 1461 // console.log( currentSlide.currentSlide, 'currentSlide.currentSlide' ); 1462 // $('.vertical-thumbnails--container').find('.slide').removeClass('active'); 1463 // $('.vertical-thumbnails--container').find('.slide[data-slick-index='+currentSlide.currentSlide+']').addClass('active'); 1464 }); 1465 } else { 1466 // $(window).trigger('resize'); 1467 // console.log( 'ELSE resize' ); 1468 // $('.vertical-thumbnails--container').slick({ 1469 // slidesToShow:ocThemeSettings.thumbs_max_quantity, 1470 // slidesToScroll: 1, 1471 // arrows: true, 1472 // dots: false, 1473 // vertical: true, 1474 // infinite: true, 1475 // asNavfor: '.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner', 1476 // }); 1477 } 1478 } 1479 } 1480 1481 // 1482 function oc_vertical_slider_slick_settings(){ 1483 var settings = { 1484 slidesToShow:ocThemeSettings.thumbs_max_quantity, 1485 slidesToScroll: 1, 1486 arrows: true, 1487 dots: false, 1488 vertical: true, 1489 infinite: true, 1490 asNavfor: '.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner', 1491 } 1492 1493 return settings; 1494 } 1495 1496 // SP gallery init slick, mobile 1497 function single_product_gallery_mobile_slick(){ 1498 // console.log( singleProductMobileGallerySlick, 'singleProductMobileGallerySlick' ); 1499 // console.log( 'singleProductMobileGallerySlick' ); 1500 1501 if ( singleProductMobileGallerySlick ){ 1502 // console.group( 'Single_product_gallery_mobile_slick start:' ); 1503 1504 // $('.woocommerce-product-gallery__wrapper').flickity({ 1505 // // options 1506 // // cellAlign: 'left', 1507 // contain: true, 1508 // freeScroll: true, 1509 // freeScrollFriction: 0.03, 1510 // cellSelector: '.woocommerce-product-gallery__image', 1511 // rightToLeft: true, 1512 // }); 1513 // return; 1514 1515 if ( $(window).width() <= windowMobileResolution ){ 1516 1517 // if ( !$('.woocommerce-product-gallery__wrapper').hasClass( 'slick-initialized' ) ){ 1518 if ( !$('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').hasClass( 'slick-initialized' ) ){ 1519 1520 console.log( 'NOT .slick-initialized' ); 1521 oc_reasign_photoswipe(); 1522 } else { 1523 $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').on('beforeChange', function(event, slick, currentSlide, nextSlide){ 1524 // console.log( nextSlide, 'nextSlide' ) 1525 // $('.minislider-thumbnails--container').flickity( 'select', nextSlide, false, false ) 1526 let slideToActivate = $('.minislider-thumbnails--container .slide-' + nextSlide); 1527 slideToActivate.siblings().removeClass('slick-current'); 1528 slideToActivate.addClass('slick-current') 1529 }); 1530 } 1531 1532 // console.log( spMobileGalleryUseDots, 'spMobileGalleryUseDots' ); 1533 // useDotsMobile = false;
1534 1535 if ( !spMobileGalleryUseDots ){ 1536 // console.log( $('.minislider-thumbnails--container .slide'), 'SLIDE' ); 1537 1538 if ( $('.minislider-thumbnails--container .slide').length > 1 ){ 1539 1540 $('.minislider-thumbnails--container').each( function(i, el){ 1541 if( !$(el).hasClass('slick-initialized') ){ 1542 var useArrow = ( $(el).find( '.slide' ).length > ocThemeSettings.thumbnail_mobile_max_quantity ) ? true : false; 1543 // $(el).slick({ 1544 // rtl: rtl, 1545 // speed: 1300, 1546 // slidesToShow: ocThemeSettings.thumbnail_mobile_max_quantity, 1547 // adaptiveHeight: true, 1548 // centerMode: false, 1549 // arrows: useArrow, 1550 // dots: false, 1551 // infinite: true, 1552 // asNavFor: '.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner', 1553 // useTransform: false, 1554 // }); 1555 // singleProductMainSlider.asNavFor = '.minislider-thumbnails--container.slick-slider'; 1556 } 1557 if ( $(el).find( '.slide' ).length > ocThemeSettings.thumbnail_mobile_max_quantity ){ 1558 // use flickity 1559 $(el).flickity({ 1560 // options 1561 cellAlign: 'right', 1562 contain: true, 1563 freeScroll: true, 1564 rightToLeft: rtl, 1565 prevNextButtons: false, 1566 pageDots: false, 1567 wrapAround: true 1568 }); 1569 } 1570 1571 }); 1572 1573 // 1574 $('.minislider-thumbnails--container .slide').on( 'click', function(){ 1575 let id = $(this).attr( 'id' ); 1576 let thumbIndex = id.replace( 'mobile-thumb-', '' ); 1577 // add active class 1578 // $(this).siblings().removeClass('active'); 1579 // $(this).addClass('active'); 1580 1581 $(this).siblings().removeClass('slick-current'); 1582 $(this).addClass('slick-current'); 1583 1584 // console.log( $(this).siblings(), 'SIBLINGS' ); 1585 // $('.woocommerce-product-gallery__wrapper').slick( 'slickGoTo', thumbIndex ); 1586 $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner.slick-slider').slick( 'slickGoTo', thumbIndex ); 1587 }); 1588 } 1589 } 1590 1591 // console.log( singleProductMainSlider, 'singleProductMainSlider' ); 1592 // $('.woocommerce-product-gallery__wrapper').slick( singleProductMainSlider ); 1593 1594 // init mobile slider 1595 if ( !$('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').hasClass('slick-slider') ){ 1596 // alert('singleProductMainSlider mobile init ' ); 1597 singleProductMainSlider.infinite = false; 1598 // console.log(singleProductMainSlider, 'singleProductMainSlider' ); 1599 // console.log( $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').children(), 'childre' ) 1600 if ( $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').length > 1 ){ 1601 1602 $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').each(function() { 1603 if (!$(this).hasClass('slick-initialized')) { 1604 $(this).slick(singleProductMainSlider); 1605 } }); 1606 } else { 1607 // console.log( $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').children(), 'SLIDER .woocommerce-product-gallery__inner children' ); 1608 $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').slick( singleProductMainSlider ); 1609 } 1610 } 1611 1612 } else { 1613 // if ( !singleProductGallerySlick && $('.woocommerce-product-gallery__wrapper').hasClass( 'slick-initialized' ) ){ 1614 if ( !singleProductGallerySlick && $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').hasClass( 'slick-initialized' ) ){ 1615 // $('.woocommerce-product-gallery__wrapper').slick('unslick'); 1616 // $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').slick('unslick'); 1617 1618 // console.log( 'REMOVE UNSLICK' ) 1619 } 1620 } 1621 1622 // console.groupEnd(); 1623 } 1624 } 1625 1626 // on load 1627 single_product_gallery_mobile_slick(); 1628 single_product_gallery_slick(); 1629 1630 // For vertical thumbs, synchronize 2 sliders 1631 $(document).on('click', '.vertical-thumbnails--container .slide', function(e){ 1632 let index = $(this).attr('data-slick-index'); 1633 if ( index === undefined ){ 1634 index = $(this).attr('tabindex'); 1635 } 1636 // console.log(index, 'index!!!'); 1637 // $('.woocommerce-product-gallery__wrapper').slick( 'slickGoTo', index ); 1638 $('.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__inner').slick( 'slickGoTo', index ); 1639 if ( $('.vertical-thumbnails--container').hasClass('slick-slider') ){ 1640 1641 if ( $('.vertical-thumbnails--container:not(.hidden-gallery) .slide').length >= ocThemeSettings.thumbs_max_quantity ){ 1642 $('.vertical-thumbnails--container').slick('slickGoTo', index ); 1643 } 1644 // console.log( 'HERE go to X slide' ) 1645 // alert( 'do no go vertical1' ) 1646 } 1647 // $(this).siblings().removeClass('active'); 1648 // $(this).addClass('active'); 1649 $(this).siblings().removeClass('slick-current'); 1650 $(this).addClass('slick-current'); 1651 }); 1652 1653 // get offset top for summary block 1654 function single_product_content_sticky(){ 1655 if ( $('body').hasClass('product-content-summary-sticky') ){ 1656 var headerHeight = 0; 1657 // if ( $('body').hasClass('sticky-header') ){
1658 headerHeight += $('.site-header').height(); 1659 // } 1660 if ( $('body').hasClass('admin-bar') ){ 1661 headerHeight += $('#wpadminbar').height(); 1662 } 1663 1664 // console.log( headerHeight, 'headerHeight' ); 1665 1666 $('.single-product.product-content-summary-sticky .product .summary').css( { top: headerHeight} ) 1667 1668 // let blockHeight = $('.single-product.product-content-summary-sticky .product .summary').height() * -1; 1669 // $('.single-product.product-content-summary-sticky .product .summary').css( { top: blockHeight} ) 1670 } 1671 } 1672 1673 // single_product_content_sticky(); 1674 1675 $(window).on( 'scroll', function(){ 1676 if ( $('body').hasClass('single-product') ){ 1677 // console.log( 'scroll SP ' ) 1678 1679 var docViewTop = $(document).scrollTop(); 1680 var stikySummary = $('.single-product.product-content-summary-sticky .product .summary'); 1681 1682 var headerHeight = 0; 1683 headerHeight += $('.site-header').height(); 1684 1685 if ( $('body').hasClass('admin-bar') ){ 1686 headerHeight += $('#wpadminbar').height(); 1687 } 1688 1689 // console.log( docViewTop, 'docViewTop' ); 1690 // console.log( stikySummary.height(), 'stikySummary.heigth ' ); 1691 // let newTop = headerHeight ; 1692 1693 let diff = stikySummary.height() - $(window).height(); 1694 let newTop = diff* -1; 1695 if ( stikySummary.height() >= $(window).height() ){ 1696 // let diff = stikySummary.height() - $(window).height() - headerHeight; 1697 // console.group( '1 case ' ); 1698 // console.log( $(window).height(), 'window.height' ); 1699 // console.log( stikySummary.height(), 'stikySummary.height()' ); 1700 // console.log( diff, 'diff' ); 1701 // console.log( docViewTop, 'docViewTop scrolled from top !' ); 1702 // console.groupEnd(); 1703 1704 if ( docViewTop >= diff ){ 1705 var summaryCss = { 1706 top: newTop, 1707 bottom: '0', 1708 marginTop: '0', 1709 } 1710 } else { 1711 var summaryCss = { 1712 top: newTop, 1713 bottom: '0', 1714 marginTop: '0', 1715 } 1716 } 1717 // $('.single-product.product-content-summary-sticky .product .summary').css( summaryCss ) 1718 } else { 1719 // console.group( '2 case ' ); 1720 // console.groupEnd(); 1721 // var summaryCss = { 1722 // top: newTop, 1723 // bottom: 'auto', 1724 // marginBottom: '0', 1725 // } 1726 newTop = headerHeight; 1727 if ( $(window).width() > windowMobileResolution ){ 1728 // newTop += 50; 1729 // newTop += 10; 1730 } 1731 var summaryCss = { 1732 top: newTop, 1733 bottom: 'auto', 1734 } 1735 } 1736 1737 $('.single-product.product-content-summary-sticky .product .summary').css( summaryCss ) 1738 1739 // if ( docViewTop >= stikySummary.height() ){ 1740 // // let newTop = stikySummary.height() - $(window).height() - headerHeight; 1741 // // let newTop = $(window).height() - stikySummary.height(); 1742 // var marginTop = stikySummary.height() / 2 ; 1743 // console.group("STICKY"); 1744 // // console.log( headerHeight, 'headerHeight' ); 1745 // console.log( stikySummary.height(), 'stikySummary.height()' ); 1746 // console.log( $(window).height() , 'Window height' ); 1747 // console.log( newTop, 'newTop on scroll ' ); 1748 // console.groupEnd(); 1749 // var summaryCss = { 1750 // bottom: newTop, 1751 // // marginTop: marginTop 1752 // } 1753 // $('.single-product.product-content-summary-sticky .product .summary').css( summaryCss ) 1754 // } else { 1755 // // single_product_content_sticky(); 1756 // var summaryCss = { 1757 // bottom: 'auto', 1758 // marginTop: '0' 1759 // } 1760 // $('.single-product.product-content-summary-sticky .product .summary').css( summaryCss ) 1761 // } 1762 } 1763 }); 1764 1765 /* ajax add to cart + quantity increase 1766 **************************************************************************/ 1767 // increase | decrease quantity 1768 $(document).on( 'click', '.quantity--wrapper .quantity .btn-qty, .woo-add-to-cart-variable-loop--container .quantity .btn-qty', function(){ 1769 let input = $(this).closest( '.quantity' ).find( 'input.qty' ); 1770 let productQ = input.val(); 1771 let quantity = productQ 1772 1773 if ( $(this).hasClass('minus') ){ 1774 if ( productQ > 1 ){ 1775 quantity--; 1776 } 1777 } else { 1778 quantity++ 1779 } 1780 input.val( quantity ); 1781 }); 1782 1783 // var useAddToCartAnimation = false; 1784 var useAddToCartAnimation = parseInt( ocThemeSettings.minicart_add_to_cart_animation ); 1785 1786 // add to cart button ! FOR SIMPLE PRODUCTS! 1787 $(document).on( 'click', '.quantity--wrapper .add-to-cart', function(){ 1788 let $thisbutton = $(this); 1789 // let quantity = $(this).closest( '.quantity' ).find( 'input.qty' ); 1790 // changed to class, for select 1791 let quantity = $(this).closest( '.quantity--wrapper' ).find( '.qty' ); 1792 var product_id = $(this).val(); 1793 let data = { 1794 product_id: product_id, 1795 quantity: quantity.val(), 1796 } 1797 if ( useAddToCartAnimation ){ 1798 addToCartAnimation( $thisbutton ); 1799 } 1800 addToCartAjax( product_id, false, quantity.val(), $(this) ); 1801 }); 1802 1803 // remove classes , remove slide from slick ! 1804 function upsellsVariableProductAddToCartCallback( product_id ){ 1805 console.log( product_id, 'upsellsVariableProductAddToCartCallback + product_id ' ); 1806 console.log( $('.oc-variable-product-upsells-popup--container'), 'oc-variable-product-upsells-popup--container' ); 1807 1808 $('.oc-variable-product-upsells-popup--container').removeClass('active'); 1809 $('.drawer-panel.cart-panel').removeClass('panel-under'); 1810 1811 // if slick init 1812 let upsellProduct = $('.product-upsell-list').find( '#product-' + product_id ); 1813 if ( $('.product-upsell-list').hasClass('slick-initialized') ){ 1814 1815 // console.log( upsellProduct, 'upsellProduct' ); 1816 1817 if ( upsellProduct.length > 0 ){ 1818 // console.log( 'REMOVE ' ); 1819 let indexRemove = upsellProduct.data( 'slick-index' ); 1820 $('.product-upsell-list').slick('slickRemove', indexRemove ); 1821 } 1822 1823 let product = $('.product-upsell-list').find( '.product' ); 1824 if ( product.length == 0 ){ 1825 1826 $('.product-upsell-list').slick('unslick'); 1827 $('.upsells-products-sidebar-close').addClass('active'); 1828 // $('.upsells-products-sidebar').addClass('hidden'); 1829 $('.upsells-products-sidebar').css( { display: 'none' } ) 1830 } 1831 1832 if ( $('.upsells-products-sidebar--inner.init-slider .product-upsell-list .product').length <= 4 ){ 1833 $('.upsells-products-sidebar--inner.init-slider .bottom-arrow.slick-next').hide(); 1834 $('.upsells-products-sidebar--inner.init-slider .top-arrow.slick-prev').hide(); 1835 } 1836 } else { 1837 if ( upsellProduct.length > 0 ){ 1838 1839 // console.log( 'remove from DOM' ); 1840 1841 upsellProduct.remove(); 1842 let product = $('.product-upsell-list').find( '.product' ); 1843 if ( product.length == 0 ){ 1844 $('.upsells-products-sidebar').css( { display: 'none' } ); 1845 } 1846 1847 } 1848 } 1849 } 1850 1851 // add to cart variable product ????????????????? 1852 $(document).on( 'click', '.woo-add-to-cart-variable-loop--container .single_add_to_cart_button, .summary .single_add_to_cart_button', function(e){ 1853 // alert('ADD RI CART '); 1854 e.preventDefault(); 1855 let $thisbutton = $(this); 1856 let form = $(this).closest( 'form' ); 1857 let productId, variationId, quantity, product_id, variation_id; 1858 1859 let attributes = form.find('.attributes-panel-container'); 1860 let singleVariation = form.find('.woocommerce-variation.single_variation'); 1861 1862 1863 let isFirst = true ; 1864 let prefix = '××ר '; 1865 1866 console.log( attributes, 'attributes' ); 1867 // variation unavailable, is variation form 1868 if ( form.hasClass('variations_form') && $thisbutton.hasClass('wc-variation-selection-needed') ){ 1869 if ( attributes.length > 0 ){ 1870 // 1871 attributes.find('.buttons-attrs-panel--wrapper').each( function(i, el){ 1872 let title = $(el).find('.attribute-title'); 1873 1874 let selectedValue = title.find('.attribute-name.selected-value') 1875 // console.log( title, 'title' ); 1876 // console.log( selectedValue.length , 'selectedValuex ' ); 1877 // console.log( isFirst , 'isFirst ' ); 1878 1879 1880 if ( selectedValue.length == 0 && isFirst ){ 1881 1882 let message = prefix + title.html(); 1883 let warningMessage = '<span class="variation-unavailbale warning-message">' + message + '</span>'; 1884 // console.log( attributes.find('.variation-unavailbale'), 'VARIATION UNVAILBALE' ) 1885 // console.log( $('.single_variation_wrap').find('.variation-unavailbale'), 'VARIATION UNVAILBALE' ) 1886 console.log( message, 'message to append ' ) 1887 // append only 1 time 1888 if ( $('.single_variation_wrap').find('.variation-unavailbale').length == 0 ){ 1889 singleVariation.after( warningMessage ); 1890 } else { 1891 1892 $('.variation-unavailbale.warning-message').html( message ); 1893 } 1894 isFirst = false;
1895 } 1896 1897 }); 1898 } 1899 // return; 1900 } 1901 1902 // check if user can add to acart 1903 if ( $thisbutton.hasClass('wc-variation-selection-needed') || $thisbutton.hasClass('wc-variation-is-unavailable') ){ 1904 // 1905 return; 1906 } 1907 1908 if ( $('body').hasClass( 'single-product' ) ){ 1909 // quantity = form.find( 'input.qty' ); 1910 quantity = form.find( '.qty' ); 1911 1912 if ( !form.hasClass('variations_form') ){ 1913 productId = $thisbutton; 1914 variationId = ''; 1915 } else { 1916 productId = form.find( 'input[name=product_id]' ); 1917 variationId = form.find( 'input[name=variation_id]' ); 1918 } 1919 1920 product_id = productId.length ? productId.val() : false; 1921 variation_id = variationId.length ? variationId.val() : false; 1922 1923 // if ( form.closest( '.product' ).hasClass( 'multiple_add_to_cart_button' ) ){ 1924 // console.log( 'adding miultiple poructs' ) 1925 // } 1926 // console.log( 'SINGLE PRIODCT' ) 1927 1928 1929 // console.log( attributes, 'attributes' ); 1930 // console.log( singleVariation, 'singleVariation' ); 1931 1932 } else { 1933 1934 // quantity = $(this).closest( 'form' ).find( 'input.qty' ); 1935 quantity = $(this).closest( 'form' ).find( '.qty' ); 1936 variationId = $(this).closest( 'form' ).find( 'input[name=variation_id]' ); 1937 1938 if ( $('.oc-woo-product-quickview-container.active').length ){ 1939 productId = $(this); 1940 } else { 1941 // if product page 1942 productId = $(this).closest( 'form' ).find( 'input[name=product_id]' ); 1943 } 1944 1945 product_id = productId.length ? productId.val() : false; 1946 variation_id = variationId.length ? variationId.val() : false; 1947 1948 let upsellsContainer = $(this ).closest( '.oc-variable-product-upsells-popup--container' ); 1949 1950 // let first = $(this).closest( 'form' ); 1951 // console.group( form, 'forM !' ); 1952 // console.log( upsellsContainer, 'upsellsContainer' ); 1953 // console.log( quantity, 'quantity' ); 1954 // console.log( productId, 'productId' ); 1955 // console.log( variationId, 'variationId' ); 1956 // console.groupEnd(); 1957 1958 } 1959 1960 if ( useAddToCartAnimation ){ 1961 addToCartAnimation( $thisbutton ); 1962 } 1963 1964 // message 1965 if ( singleVariation.find( '.variation-unavailbale' ).length ){ 1966 singleVariation.find( '.variation-unavailbale' ).remove(); 1967 } 1968 1969 // ????????? 1970 // let addToCartCallback = upsellsVariableProductAddToCartCallback( productId ); 1971 1972 // console.log( upsellsVariableProductAddToCartCallback, 'upsellsVariableProductAddToCartCallback'); 1973 addToCartAjax( product_id, variation_id, quantity.val(), $thisbutton, true ); 1974 // addToCartAjax( product_id, variation_id, quantity.val(), $thisbutton, addToCartCallback ); 1975 1976 }); 1977 1978 1979 function init_product_slider_slick(){ 1980 $('.archive_wrap .product-images-slider--container').each( function( index, el ){ 1981 // console.log( el, 'el' ); 1982 if ( !$(el).hasClass('slick-slider') && $(el).find('.slide').length > 1 ){ 1983 $(el).slick({ 1984 slidesToShow: 1, 1985 adaptiveHeight: true, 1986 rtl: rtl, 1987 speed: 200, 1988 touchThreshold: 50, 1989 // new 1990 }); 1991 } 1992 }); 1993 } 1994 1995 // after infinitte scrolling init slick 1996 function product_slick_slider_after_append_items( items ){ 1997 // console.log( 'product_slick_slider_after_append_items ' ); 1998 // console.log( items, 'items' ); 1999 // console.log( $(items), '$items' ); 2000 // console.log( $(items).find('.product-images-slider--container'), 'items .product-images-slider--container' ); 2001 2002 if ( items.length ){ 2003 $(items).find('.product-images-slider--container').each( function( index, el ){ 2004 // console.log( el, 'el' ); 2005 let images = $(el).find( 'img' ); 2006 // console.log( images, 'images, founded' ); 2007 if ( images.length ){ 2008 // console.log( images, 'images' ); 2009 images.removeAttr( 'loading' ); 2010 images.removeAttr( 'decoding' ); 2011 } 2012 2013 if ( $(el).find('.slide').length > 1 ){ 2014 $(el).slick({ 2015 slidesToShow: 1, 2016 adaptiveHeight: true, 2017 rtl: rtl, 2018 speed: 200, 2019 touchThreshold: 50, 2020 // new 2021 }); 2022 2023 } 2024 }); 2025 } 2026 } 2027 2028 /* ARCHIVE | CATEGORY | TAGS PAGES 2029 **************************************************************************/ 2030 // Archive page 2031 if ( $('body').hasClass('archive') ){ 2032 2033 init_product_slider_slick(); 2034 2035 // Async get vimeo script 2036 $.getScript( "https://player.vimeo.com/api/player.js" ).done( function( script, textStatus ){ 2037 // autoplay_video(); 2038 }); 2039 2040 // infinite-scrolling 2041 if ( $('body').hasClass('product-archive-infinitescrolling') && $('body').hasClass('archive') ){ 2042 let scrollThreshold 2043 if ( isMobile() ){ 2044 scrollThreshold = 2000; 2045 } else { 2046 scrollThreshold = 800 2047 } 2048 2049 let pagination; 2050 let path; 2051 2052 if ( $('body').hasClass('search-results') ){ 2053 path = '.nav-links a.next'; 2054 pagination = '.navigation.pagination'; 2055 } else { 2056 path = 'ul.page-numbers li a.next'; 2057 pagination = '.woocommerce-pagination'; 2058 } 2059 // console.log( scrollThreshold, 'scrollThreshold' ); 2060 if ( $(path).length > 0 ){ 2061 $('ul.products').infiniteScroll({ 2062 // options 2063 path: path, 2064 append: 'li.product', 2065 history: false, 2066 hideNav: pagination , 2067 status: '.page-load-status', 2068 scrollThreshold: scrollThreshold, 2069 }).on( 'request.infiniteScroll', function( event, path, fetchPromise) { 2070 // alert('REQUEST !!!'); 2071 $('.infinitescrolling-page-load-status').show(); 2072 }).on( 'append.infiniteScroll', function( event, body, path, items, response ) { 2073 2074 console.group( 'append.infiniteScroll ++ slider init after' ); 2075 console.log( items, 'items' ); 2076 // console.log( response, 'response' ); 2077 // console.log( body, 'body' ); 2078 console.groupEnd(); 2079 2080 // init_product_slider_slick(); 2081// Loop through each video element and attempt to play it 2082 const videos = document.querySelectorAll('video'); 2083 2084 videos.forEach(video => { 2085 video.play() 2086 2087 }); 2088 2089 product_slick_slider_after_append_items( items ); 2090 2091 }).on( 'last.infiniteScroll', function( event, body, path ) { 2092 // console.log( 'last.infiniteScroll' ); 2093 $('.infinitescrolling-page-load-status').hide(); 2094 }); 2095 } 2096 } 2097 } 2098 2099 // 2100 if ( $('body').hasClass('home') ){ 2101 // init_product_slider_slick(); 2102 } 2103 2104 function autoplay_video(){ 2105 var iframe = $('.vimeo-wrapper iframe.vimeo'); 2106 var vimeoPlayer = new Vimeo.Player( iframe ); 2107 vimeoPlayer.ready().then(function() { 2108 vimeoPlayer.setVolume(1); 2109 vimeoPlayer.play(); 2110 }); 2111 } 2112 2113 // NEED TO CHECK THIS !!! 2114 // place single product thumbnail in header logo 2115 function single_product_thumb_in_logo(){ 2116 if ( $('body').hasClass( 'single-product' ) ){ 2117 let headerLogo = $( '.header-logo--container img' ); 2118 let img = $( '.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__image:first img' ); 2119 let headerMobileLogo = $('.header-logo-mobile--container img'); 2120 2121 if ( headerLogo.length ){ 2122 // console.log( headerLogo.attr( 'data-original-src' ), 'data-original-src' ); 2123 if ( headerLogo.attr( 'data-original-src') === undefined ){ 2124 headerLogo.attr( 'data-original-src', headerLogo.attr('src') ); 2125 } 2126 // set logo 2127 headerLogo.attr( 'src', img.attr('src') ); 2128 } 2129 2130 if ( headerMobileLogo.length ){ 2131 if ( headerMobileLogo.attr( 'data-original-src') === undefined ){ 2132 headerMobileLogo.attr( 'data-original-src', headerMobileLogo.attr('src') ); 2133 } 2134 headerMobileLogo.attr( 'src', img.attr('src') ); 2135 } 2136 // console.log( img, 'img SINGLE PRODUCT' ); 2137 } 2138 } 2139 2140 // on color swatches hover - change image 2141 $(document).on( 'mouseover, click', 'ul.product-colors-container li', function(){ 2142 let button = $(this); 2143 let productLink = $(this).data('product-link'); 2144 let parent = $(this).closest('.product'); 2145 let imgSrc = $(this).data('img'); 2146 let imgId = $(this).attr('id');
2147 let img = parent.find( 'img.attachment-woocommerce_thumbnail' ); 2148 if ( img.length == 0 ){ 2149 img = parent.find('.item_wrap img:first-child'); 2150 } 2151 let topPart = parent.find('.wrap-for-top-part'); 2152 let galleries = parent.find('.wrap-for-top-part .product-images-slider--container'); 2153 let isArchiveWrap = parent.closest( '.archive_wrap' ); 2154 let imageHeight = topPart.height(); 2155 let imagesHover = parent.find('.wrap-for-top-part .product-images-loop-on-hover--container'); 2156 // clicked on quick add panel no need change image 2157 let variablePanel = button.closest( '.oc-product-quick-add-to-cart-panel-1' ); 2158 2159 2160 // variablePanel 2161 // on color change 2162 let addToCartBtn = parent.find('.add-to-cart-icon') 2163 if ( addToCartBtn.length ){ 2164 let productId = $(this).data('product-id'); 2165 // set new ID for add to cart 2166 addToCartBtn.val( productId ); 2167 } 2168 2169 $(this).siblings().removeClass('active'); 2170 $(this).addClass('active'); 2171 2172 // change slider color 2173 if ( galleries.length > 0 ){ 2174 2175 // if is mobile skip change color functionalitty 2176 if ( variablePanel.length > 0 && isMobile() ){ 2177 console.log( variablePanel, 'variablePanel' ); 2178 // return; 2179 } else { 2180 2181 let outOfStockLabel = parent.find('.stock.out-of-stock'); 2182 // console.log( outOfStockLabel, 'outOfStockLabel' ); 2183 // console.log( $(this).hasClass('outofstock'), 'this is outofstock' ); 2184 2185 if ( $(this).hasClass('outofstock') ){ 2186 outOfStockLabel.show(); 2187 } else { 2188 outOfStockLabel.hide(); 2189 } 2190 // change link for product 2191 if ( productLink != undefined && typeof productLink !== undefined ){ 2192 let productA = topPart.find( 'a' ); 2193 let selectedColorAttr = '#'+ colorTax +'=' + imgId; 2194 // change product link 2195 productA.attr('href', productLink + selectedColorAttr ); 2196 // change title link 2197 parent.find( '.woocommerce-loop-product__title a' ).attr('href', productLink ); 2198 // console.log( productA, 'dat productA' ); 2199 } 2200 console.log(imgId); 2201 let colorGalleryToShow = parent.find("#attr-color-"+imgId); 2202 // console.log(colorGalleryToShow, 'colorGalleryToShow'); 2203 if ( colorGalleryToShow.length > 0 ){ 2204 galleries.addClass('hidden-gallery'); 2205 if ( isArchiveWrap.length > 0 ){ 2206 // remove jump after color change 2207 topPart.height( imageHeight ); 2208 2209 if ( colorGalleryToShow.hasClass('slick-slider') ){ 2210 colorGalleryToShow.slick('unslick'); 2211 } 2212 2213 colorGalleryToShow.slick({ 2214 slidesToShow: 1, 2215 adaptiveHeight: true, 2216 rtl: rtl, 2217 }); 2218 2219 setTimeout( function(){ 2220 topPart.height('auto'); 2221 // console.log( 'height auto' ); 2222 }, 400 ); 2223 } 2224 colorGalleryToShow.removeClass('hidden-gallery'); 2225 } 2226 } 2227 } 2228 2229 // images on hover 2230 if ( imagesHover.length > 0 ){ 2231 let productLink = $(this).data('product-link'); 2232 if ( productLink != undefined && typeof productLink !== undefined ){ 2233 let productA = topPart.find( 'a' ); 2234 let selectedColorAttr = '#' + colorTax + '=' + imgId; 2235 // change product link 2236 productA.attr('href', productLink + selectedColorAttr ); 2237 // change title link 2238 parent.find( '.woocommerce-loop-product__title a' ).attr('href', productLink ); 2239 // console.log( productA, 'dat productA' ); 2240 } 2241 let colorGalleryToShow = parent.find("#attr-color-"+imgId); 2242 if ( colorGalleryToShow.length > 0 ){ 2243 imagesHover.addClass('hidden-gallery'); 2244 imagesHover.siblings().addClass('hidden-gallery'); 2245 colorGalleryToShow.removeClass('hidden-gallery'); 2246 } 2247 } 2248 // console.group( parent, 'paremt' ); 2249 // console.log( 'hover on !' ); 2250 // console.log( imgSrc, 'imgSrc' ); 2251 // console.log( imgId, 'imgId' ); 2252 // console.log( img, 'img' ); 2253 // console.log( 'SHOW | HIDE: label' ); 2254 // console.log( galleries, 'galleries' ); 2255 // console.log( slug, "slug !!!!!!!!!!!!! " ) 2256 // console.groupEnd(); 2257 2258 // moved to function 2259 oc_quick_add_to_cart_panel( button ); 2260 }); 2261 2262 // change panel quick add to cart 2263 2264 function oc_quick_add_to_cart_panel(button) { 2265 console.log('oc_quick_add_to_cart_panel called', button); 2266 2267 // closest product 2268 let parent = button.closest('.product');
2269 console.log('Parent product:', parent); 2270 2271 // slug of variation (used for attribute value) 2272 let slug = button.data('slug'); 2273 console.log('Slug:', slug); 2274 2275 // for quick add set slug 2276 let closestPanel = button.closest('.oc-product-variable-panel'); 2277 console.log('Closest panel:', closestPanel); 2278 2279 // set slug to panel 2280 if (closestPanel.length) { 2281 console.log('Setting slug to panel:', slug); 2282 closestPanel.attr('data-value', slug); 2283 } 2284 2285 // Choose panel mobile panel or desktop! 2286 let allVariableProductPanels; 2287 if (isMobile()) { 2288 allVariableProductPanels = parent.find('.oc-product-quick-add-to-cart-panel-1 .oc-product-variable-panel'); 2289 console.log('Mobile panels selected:', allVariableProductPanels); 2290 } else { 2291 allVariableProductPanels = parent.find('.oc-product-quick-add-to-cart-panel .oc-product-variable-panel'); 2292 console.log('Desktop panels selected:', allVariableProductPanels); 2293 } 2294 2295 let mobileAddToCart = parent.find('.mobile .add-to-cart-mobile'); 2296 let addToCartBtn = parent.find('.add-to-cart-icon'); 2297 console.group('change panel quick add to cart, global allVariableProductPanels OBJECT!'); 2298 2299 // set new product ID 2300 let newProductId = button.data('product-id'); 2301 console.log('New product ID:', newProductId); 2302 2303 if (newProductId) { 2304 let variationObject = parent.find('.product-available-variations-object'); 2305 if (variationObject.length) { 2306 console.log('Setting product ID to variation object:', newProductId); 2307 variationObject.data('product_id', newProductId); 2308 } 2309 } 2310 2311 let attributeName = ''; 2312 let attrId; 2313 if (button.hasClass('color-attribute')) { 2314 attributeName = button.attr('aria-label'); 2315 attrId = button.attr('id'); 2316 console.log('Color attribute selected:', attributeName, attrId); 2317 } else { 2318 attributeName = button.html(); 2319 attrId = button.val(); 2320 console.log('Other attribute selected:', attributeName, attrId); 2321 } 2322 2323 // which panel is changed 2324 let currentPanelAttribute = closestPanel.data('attribute_name'); 2325 console.log('Current panel attribute:', currentPanelAttribute); 2326 2327 console.groupEnd(); 2328 2329 // loop through only if more than one panel 2330 let variationObject = parent.find('.product-available-variations-object'); 2331 let arVariations = []; 2332 console.log('Variation object found:', variationObject); 2333 2334 if (variationObject.length > 0 && allVariableProductPanels.length > 1) { 2335 let chosenAttributes = getChosenAttributes(parent); 2336 console.log('Chosen attributes:', chosenAttributes); 2337 2338 if (chosenAttributes) { 2339 let variations = variationObject.data('variations'); 2340 console.log('Variations:', variations); 2341 2342 if (variations) { 2343 variations.forEach(variation => { 2344 if (variation.attributes) { 2345 for (let property in variation.attributes) { 2346 let chosenAttribute = chosenAttributes.data[property]; 2347 if (chosenAttribute != '' && chosenAttribute == variation.attributes[property]) { 2348 arVariations.push(variation); 2349 console.log('Matching variation added:', variation); 2350 } 2351 } 2352 } 2353 }); 2354 } 2355 2356 if (arVariations.length > 0) { 2357 for (let i = 0; i < allVariableProductPanels.length; i++) { 2358 let panel = $(allVariableProductPanels[i]); 2359 let panelAttribute = panel.data('attribute_name'); 2360 console.log('Updating panel:', panel, 'with attribute:', panelAttribute); 2361 2362 // Update the attribute buttons in each panel 2363 if (panelAttribute != currentPanelAttribute) { 2364 let container = panel.find('.attribute-container'); 2365 if (container.length > 0) { 2366 console.log('Updating attribute buttons in container:', container); 2367 2368 container.find('.attribute-button').each(function(index, element) { 2369 let variationIndex = index % arVariations.length; 2370 let variation = arVariations[variationIndex]; 2371 console.log('Applying variation to button:', variation, element); 2372 2373 if (variation.is_in_stock) { 2374 // $(element).removeClass('outofstock'); 2375 } else { 2376 // $(element).addClass('outofstock'); 2377 } 2378 }); 2379 } 2380 2381 // set attribute name in attribute title 2382 if (panel.find('.attr-title .selected-attribute').length > 0) { 2383 panel.find('.attr-title .selected-attribute').html(attributeName); 2384 console.log('Set attribute name in title:', attributeName); 2385 } 2386 } 2387 } 2388 2389 // Block add to cart button if the current button is out of stock 2390 if (button.hasClass('outofstock')) { 2391 addToCartBtn.addClass('disabled'); 2392 mobileAddToCart.addClass('disabled'); 2393 console.log('Button is out of stock. Disabling add to cart buttons.'); 2394 } else { 2395 addToCartBtn.removeClass('disabled'); 2396 mobileAddToCart.removeClass('disabled'); 2397 console.log('Button is in stock. Enabling add to cart buttons.'); 2398 } 2399 } 2400 } 2401 } else if (allVariableProductPanels.length == 1 && allVariableProductPanels.hasClass('image')) { 2402 if (button.hasClass('outofstock')) { 2403 addToCartBtn.addClass('disabled'); 2404 } else { 2405 addToCartBtn.removeClass('disabled'); 2406 } 2407 } 2408 2409 // Mobile specific behavior 2410 if (isMobile() && button.hasClass('color-attribute')) { 2411 let temp = parent.find('.oc-product-quick-add-to-cart-panel-1 .oc-product-variable-panel.image'); 2412 if (attrId) { 2413 console.log(attrId, 'found attrId'); 2414 let foundColor = temp.find('li#' + attrId); 2415 2416 if (foundColor.length > 0) { 2417 foundColor.siblings().removeClass('active'); 2418 foundColor.addClass('active'); 2419 temp.attr('data-value', foundColor.data('slug')); 2420 2421 if (foundColor.hasClass('outofstock')) { 2422 mobileAddToCart.addClass('disabled'); 2423 addToCartBtn.addClass('disabled'); 2424 } else { 2425 mobileAddToCart.removeClass('disabled'); 2426 addToCartBtn.removeClass('disabled'); 2427 } 2428 } 2429 } 2430 } 2431 console.log('oc_quick_add_to_cart_panel function completed'); 2432 } 2433 2434 2435 2436 $('.wp-block-custom-slider-block-slider .oc-slider--container').slick().on('beforeChange', function(event, slick, currentSlide, nextSlide){ 2437 if ( $('.wp-block-custom-slider-block-slider .progressbar').length ){ 2438 let btn = $('.wp-block-custom-slider-block-slider .progressbar #btn-' + nextSlide );
2439 btn.siblings().removeAttr('aria-current'); 2440 btn.attr( 'aria-current', true ); 2441 } 2442 }); 2443 2444 // progressbar for main slider ( Oc-custom-slider ) 2445 $(document).on( 'click', '.progressbar .progressbar-btn', function(){ 2446 let index = $(this).val(); 2447 $('.wp-block-custom-slider-block-slider .oc-slider--container').slick( 'slickGoTo', index ) 2448 }); 2449 2450 $('.oc-product-categories--container').slick(); 2451 2452 if ( $('.oc-wc-slider__products--wrapper .oc-wc-slider__products').length > 0 ){ 2453 console.log( 'HERE INIT!' ) 2454 $('.oc-wc-slider__products').each( function( i, el ){ 2455 if ( !$(el).hasClass( 'slick-initialized' ) ){ 2456 $(el).slick() 2457 } 2458 }) 2459 } 2460 2461 2462 2463 // slider for product list 2464 // $('.wp-block-oc-product-slider-product-slider .wc-block-grid__products-grid').slick({ 2465 // rtl:rtl, 2466 // arrow:false, 2467 // slidesToShow: 3, 2468 // }); 2469 // console.clear(); 2470 var itemsOwl = $('.wp-block-oc-product-slider-product-slider .wc-block-grid__products-grid .product-grid').length; 2471 2472 // $('.wp-block-oc-product-slider-product-slider .wc-block-grid__products-grid').owlCarousel({ 2473 // items: 1, 2474 // rtl: rtl, 2475 // loop: true, 2476 // dots: false, 2477 // pagination: false, 2478 // navigation: false, 2479 // // slideTransition: "linear", 2480 // responsive: { 2481 // 768: { 2482 // items: 4, 2483 // slideTransition: "linear", 2484 // } 2485 // } 2486 // }); 2487 2488 $('.wp-block-oc-product-slider-product-slider .wc-block-grid__products-grid').slick(); 2489 2490 var isDragging = false; 2491 var dragStartX = 0; 2492 var scrollLeftStart = 0; 2493 var $draggableZone = $('.slider-rolling-dice--l'); 2494 2495 $draggableZone.mousedown(function(e) { 2496 isDragging = true; 2497 dragStartX = e.pageX; 2498 scrollLeftStart = $draggableZone.scrollLeft(); 2499 $draggableZone.css('cursor', 'grabbing'); 2500 }); 2501 2502 $(document).mouseup(function() { 2503 isDragging = false; 2504 $draggableZone.css('cursor', 'grab'); 2505 }); 2506 2507 $(document).mousemove(function(e) { 2508 if (isDragging) { 2509 var dragOffset = e.pageX - dragStartX; 2510 $draggableZone.scrollLeft(scrollLeftStart - dragOffset); 2511 } 2512 }); 2513 2514 function draggableSlider(){ 2515 // console.log( 'function draggableSlider(){' ); 2516 } 2517 2518 draggableSlider(); 2519 2520 // product slider add to cart || quick add to cart 2521 $(document).on( 'click', '.quick-add-to-cart--inner button.add-to-cart', function(e){ 2522 var productId = $(this).val(); 2523 var inner = $(this).closest('.quick-add-to-cart--inner'); 2524 let quantityBlock = inner.find( '.product-quantity' ); 2525 var quantity = quantityBlock.val(); 2526 e.preventDefault(); 2527 2528 console.log( inner, 'inner add to cart ' ); 2529 2530 if ( useAddToCartAnimation ){ 2531 addToCartAnimation( $(this) ); 2532 } 2533 addToCartAjax( productId, false, quantity, $(this) ); 2534 2535 }); 2536 2537 // product slider plus | minus 2538 $(document).on( 'click', '.quick-add-to-cart--inner .add-to-cart-buttons button', function(e){ 2539 var inner = $(this).closest('.quick-add-to-cart--inner'); 2540 let quantityBlock = inner.find( '.product-quantity' ); 2541 var quantity = parseInt( quantityBlock.val() ); 2542 let newQuantity = quantity; 2543 2544 if ( $(this).hasClass( 'plus' ) ){ 2545 newQuantity = quantity + 1; 2546 2547 } else if ( $(this).hasClass( 'minus' ) ){ 2548 if ( quantity > 1 ){ 2549 newQuantity = quantity - 1; 2550 } 2551 } 2552 quantityBlock.val( newQuantity ); 2553 }); 2554 2555 function addToCartAjax( productId, variationId, quantity, button, callbackFunction ){ 2556 // $('body').addClass('no-scroll'); 2557 // $('.page-overlay').addClass( 'is-visible top' ); 2558 2559 var data = { 2560 action: 'oc_woo_add_to_cart' , 2561 product_id: productId, 2562 quantity: quantity, 2563 variation_id: variationId, 2564 // wc_cart_fragments_params: wc_add_to_cart_params.ajax_url 2565 }; 2566 2567 $(document.body).trigger('adding_to_cart', [ $(button), data ] ); 2568 // console.log( productId, 'productId add to cart ' ); 2569 // console.log( quantity, 'quantity add to cart ' ); 2570 // console.log( data, 'data addToCartAjax' ); 2571 // console.log( button, 'button' ); 2572 2573 // console.log( callbackFunction, 'callbackFunction' ); 2574 2575 $.ajax({ 2576 type: 'POST', 2577 dataType: 'json', 2578 url: woocommerce_params.ajax_url, 2579 data: data, 2580 success: function (response) { 2581 console.log( response, 'response' ); 2582 2583 if ( response.cart_hash ){
2584 let cartFragments = response.fragments['div.widget_shopping_cart_content']; 2585 // update minicart 2586 let cartFragmentsSidebar = response.fragments['minicart_sidebar']; 2587 2588 // console.group('CART fragments sidebar'); 2589 // console.log( response.fragments, 'response.fragments' ); 2590 // console.log( cartFragmentsSidebar, 'cartFragmentsSidebar' ); 2591 // console.log( cartFragments, 'cartFragments' ); 2592 // console.log( response.fragments, ' response.fragments' ); 2593 // console.groupEnd(); 2594 2595 // $( document.body ).trigger( 'wc_fragment_refresh' ); 2596 $(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash]); 2597 // minicart panel ! 2598 $('.mini-cart-widget--container').html(cartFragments); 2599 if ( $('.minicart-sidebar--container').length ){ 2600 $('.minicart-sidebar--container').html(cartFragmentsSidebar); 2601 } 2602 // $('.minicart-bottom--container .minicart-bottom-subtotal').html( response.data ); 2603 } else if ( response.error ) { 2604 // console.log( 'response.error' ); 2605 2606 if ( !response.passed_validation ) { 2607 $( document.body ).trigger( { 2608 type: 'wc_add_to_cart_error', 2609 product: productId 2610 }); 2611 } 2612 else if ( !response.is_in_stock ){ 2613 alert( '××צר ××× ××××××' ); 2614 // for quick add 2615 if ( !button.hasClass( 'attribute-button' ) ){ 2616 button.addClass('disabled') 2617 } 2618 } else { 2619 // button.removeClass('outofstock'); 2620 alert( 'Something gone wrong!' ); 2621 } 2622 } 2623 2624 // $('body').removeClass('no-scroll'); 2625 // $('.page-overlay').removeClass( 'is-visible top' ); 2626 // new callback function as parametr 2627 // console.log( callbackFunction, 'callbackFunction' ) ; 2628 console.log( typeof callbackFunction, 'typeof ' ) ; 2629 2630 if ( typeof callbackFunction == 'function' ){ 2631 // console.log( 'callbackFunction !!!!!!!!' ) 2632 callbackFunction( productId ); 2633 2634 } else if ( typeof callbackFunction == 'boolean' ){ 2635 // get callback 2636 console.log( 'here !' ); 2637 upsellsVariableProductAddToCartCallback( productId ); 2638 } 2639 }, 2640 error: function (errorThrown) { 2641 console.log(errorThrown, 'errorThrown'); 2642 // $('body').removeClass('no-scroll'); 2643 // $('.page-overlay').removeClass( 'is-visible top' ); 2644 } 2645 }); 2646 } 2647 // console.log( 'REMOVE FROM SIDEBAR CCART ' ) 2648 2649 // remove product from sidebar cart 2650 $(document).on( 'click', '.woo-sidebar-minicart a.remove', function(e){ 2651 e.preventDefault(); 2652 2653 var product_id = $(this).attr("data-product_id"); 2654 var cart_item_key = $(this).attr("data-cart_item_key"); 2655 // product_container = $(this).parents('.mini_cart_item'); 2656 2657 let li = $(this).closest('li.woo-sidebar-mini-cart-item'); 2658 // li.block(); 2659 li.addClass('block') 2660 li.append( '<span class="loader"></span>' ); 2661 // return; 2662 // console.log( product_id, 'product_id :: removed from sidebar miniart ' ); 2663 oc_ajax_minicart_remove_product( product_id, cart_item_key, li ) 2664 }); 2665 2666 // add to cart animation 2667 function addToCartAnimation( button ) { 2668 let productImg; 2669 var target = $('.site-header .mini-cart-icon').first(); 2670 // sidebar minicart | ristretto 2671 if ( $('.minicart-sidebar--container').length ){ 2672 target = $('.minicart-sidebar--container'); 2673 } 2674 2675 if ( $('body').hasClass('single-post') || $('body').hasClass('home') ){ 2676 2677 if ( button.closest('.oc-woo-product-quickview--inner').length ){ 2678 productImg = button.closest('.oc-woo-product-quickview--inner').find('.product-image-wrap img').first(); 2679 // console.log( productImg, 'productImg HOME PAGE' ); 2680 } else { 2681 productImg = button.closest('.product').find('.product-image img'); 2682 } 2683 // console.log( productImg, 'productImg start' ); 2684 // console.log( button.closest( '.product' ).find('.wrap-for-top-part img'), 'IMG +++' ) 2685 } else if ( $('body').hasClass('archive') ) { 2686 // woo loop , cat page 2687 productImg = button.closest('.product').find('.wrap-for-top-part img:first-child'); 2688 } else if ( $('body').hasClass('single-product') ){ 2689 if ( button.closest('.p_upgrade_items').length ){ 2690 productImg = button.closest('.item').find('.img img'); 2691 } else { 2692 productImg = button.closest('.product').find('.woocommerce-product-gallery__image:first-child img'); 2693 } 2694 } else { 2695 productImg = button.closest('.product').find('.woocommerce-product-gallery__image:first-child img'); 2696 } 2697 2698 // search add to cart 2699 if ( button.hasClass('search-add-to-cart') ){ 2700 productImg = button.closest('.product-row-wrap').find('.search-result__image-wrap img'); 2701 } 2702 2703 if ( productImg.length == 0 ){ 2704 productImg = button.closest( '.product' ).find('.wrap-for-top-part img').first() 2705 } 2706 2707 // console.log( productImg, 'productImg' ); 2708 2709 if ( productImg ){
2710 productBackground = productImg.attr('src'); 2711 } else { 2712 productBackground = ''; 2713 } 2714 2715 var target_offset = target.offset(); 2716 var target_x = target_offset.left; 2717 var target_y = target_offset.top; 2718 var obj_id = 1 + Math.floor( Math.random() * 100000 ); 2719 var obj_class = 'cart-animation-helper'; 2720 var obj_class_id = obj_class + '_' + obj_id; 2721 var obj_offset; 2722 2723 var obj = $("<div>", { 2724 'class': obj_class + ' ' + obj_class_id 2725 }); 2726 var image = '<img src="'+productBackground+'" class="flying-img" / >'; 2727 obj.append( image ); 2728 2729 // var appendTo = button.parent().parent(); 2730 // appendTo.append(obj); 2731 // var obj_offset = obj.offset(); 2732 if ( $('body').hasClass( 'home' ) ){ 2733 if ( button.closest('.oc-woo-product-quickview--inner').length ){ 2734 obj_offset = button.closest('.oc-woo-product-quickview--inner').find('.product-image-wrap').offset(); 2735 $('.oc-woo-product-quickview-container').removeClass('active'); 2736 // $('body').removeClass('no-scroll'); 2737 // $('.page-overlay').removeClass( 'is-visible top' ); 2738 } else { 2739 2740 let productInner = button.closest('div.product-inner'); 2741 if ( productInner.length ){ 2742 obj_offset = productInner.find('.product-image').offset(); 2743 } else { 2744 obj_offset = button.closest( '.product' ).find('.wrap-for-top-part img').first().offset(); 2745 } 2746 2747 // console.log( productImg, 'productImg' ); 2748 } 2749 } else { 2750 // var obj_offset = button.closest('.product').find('.wrap-for-top-part a').offset(); 2751 obj_offset = button.offset(); 2752 } 2753 2754 // search add to cart 2755 if ( button.hasClass('search-add-to-cart') ){ 2756 obj_offset = button.closest('.product-row-wrap').find('.search-result__image-wrap img').offset(); 2757 } 2758 2759 // console.log( obj_offset, 'obj_offset afr' ); 2760 2761 if ( obj_offset != undefined ){ 2762 obj.css({ 2763 'top' : obj_offset.top, 2764 'left': obj_offset.left, 2765 }); 2766 } else { 2767 obj.css({ 2768 'top' : '0', 2769 'left': '0', 2770 }); 2771 } 2772 obj.appendTo('body'); 2773 2774 var delay = 0.8; // seconds 2775 var dist_x = target_x ; 2776 var dist_y = target_y; 2777 var transition_css = delay.toString() + 's'; 2778 var transition = delay * 1000; 2779 2780 // console.group('addToCartAnimation | new '); 2781 // console.log( obj, 'obj' ); 2782 // console.log( obj.find('span'), 'obj.find span' ); 2783 // console.log( button, 'button' ); 2784 // console.log( productImg ,'productImg' ); 2785 // console.log( button ,'button' ); 2786 // console.log( target ,'target' ); 2787 // console.log( button.parent().parent(), 'button.parent().parent()' ); 2788 // console.groupEnd('addToCartAnimation'); 2789 2790 setTimeout(function() { 2791 let imageContainer = $('.cart-animation-helper_' + obj_class_id ); 2792 let top = target_offset.top ; 2793 let left = target_offset.left ; 2794 2795 obj.css({ 2796 'top': top + 'px', 2797 'left': left + 'px', 2798 'transition': transition_css 2799 }); 2800 setTimeout(function() { 2801 obj.css({ 2802 'width': '0px', 2803 'height': '0px' 2804 }); 2805 setTimeout(function() { 2806 obj.remove(); 2807 }, 100 + (transition * 2)) 2808 }, 100 + transition) 2809 }, 100); 2810 } 2811 2812 2813 // Auth panel focus | blur 2814 $(document).on( 'focus' , 'form.woocommerce-form.woocommerce-form-login.login input', function(){ 2815 let label = $(this).prev('label'); 2816 label.addClass( 'active' ); 2817 }); 2818 2819 $(document).on( 'blur', 'form.woocommerce-form.woocommerce-form-login.login input', function(){ 2820 if ( $(this).val() == '' ){ 2821 let label = $(this).prev('label'); 2822 label.removeClass( 'active' ); 2823 } 2824 }); 2825 2826 // console.log( $('.oc-woo-filter-open'), 'open filter' ); 2827 $(document).on( 'click', 'button.products-as-row', function(){ 2828 $('body').toggleClass( 'product-row' ); 2829 $(this).toggleClass( 'quick' ); 2830 if ( $('body').hasClass( 'product-row' ) ){ 2831 setCookie( 'oc_woo_theme_archive_product_row', 1 , 1 ); 2832 } else { 2833 // console.log( 'deleteCookie' ) 2834 // deleteCookie( 'oc_woo_theme_archive_product_row' ); 2835 setCookie( 'oc_woo_theme_archive_product_row', 0 , 1 ); 2836 } 2837 }); 2838 2839 // set cookie value 2840 function setCookie( cname, cvalue, exdays ) { 2841 var d = new Date(); 2842 let minute = 60*1000; 2843 let hour = 60*minute; 2844 let day = 24*minute; 2845 2846 d.setTime( d.getTime() + ( exdays*24*60*60*1000 ) ); 2847 var expires = "expires="+ d.toUTCString(); 2848 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; 2849 } 2850 2851 // get cookie value 2852 function getCookie( cname ) { 2853 var name = cname + "="; 2854 var decodedCookie = decodeURIComponent( document.cookie ); 2855 var ca = decodedCookie.split( ';' ); 2856 for(var i = 0; i <ca.length; i++) { 2857 var c = ca[i]; 2858 while ( c.charAt(0) == ' ' ) { 2859 c = c.substring( 1 ); 2860 } 2861 if ( c.indexOf( name ) == 0 ) { 2862 return c.substring( name.length, c.length ); 2863 } 2864 } 2865 return ""; 2866 } 2867 2868 // Set cookie for object 2869 function deleteCookie(name) { 2870 document.cookie = [name, '=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.', window.location.host.toString()].join(''); 2871 } 2872 2873 function set_shipping_to_other_address(){ 2874 if ( $('body').hasClass( 'woocommerce-checkout' ) ){ 2875 var oc_shipping_to_other_address = getCookie( 'oc_shipping_to_other_address' ); 2876 // console.log( 'set_shipping_to_other_address' ) 2877 // console.log( oc_shipping_to_other_address, 'oc_shipping_to_other_address' ) 2878 2879 if ( oc_shipping_to_other_address == 1 ){ 2880 $('.woocommerce-billing-fields__field-wrapper.billing-fields-shipping-data').hide(); 2881 $( 'div.shipping_address' ).show(); 2882 } else if ( oc_shipping_to_other_address == 0 ) { 2883 $( 'div.shipping_address' ).hide(); 2884 let shippingMethod = $('#shipping_method input:checked'); 2885 2886 let checkedMethod; 2887 if ( shippingMethod.length ){ 2888 checkedMethod = shippingMethod.val(); 2889 } else { 2890 checkedMethod = $('#shipping_method input').val(); 2891 } 2892 if ( checkedMethod.indexOf( 'local_pickup' ) == -1 ){ 2893 $('.woocommerce-billing-fields__field-wrapper.billing-fields-shipping-data').show(); 2894 } 2895 } 2896 } 2897 } 2898 2899 set_shipping_to_other_address(); 2900 2901 // 2902 $(document).on( 'change', '#customer_details .col-1 input#ship-to-different-address-checkbox', function(){ 2903 let checked = $(this).prop('checked'); 2904 let hiddenField = $('input.shipping-to-other-address'); 2905 // console.log( hiddenField, 'hiddenField' ); 2906 2907 if ( checked ){ 2908 hiddenField.val('yes'); 2909 setCookie( 'oc_shipping_to_other_address', 1 , 1 ); 2910 2911 $('.woocommerce-billing-fields__field-wrapper.billing-fields-shipping-data').slide
2911Up(); 2912 $('.woocommerce-shipping-fields .shipping_address').slideDown(); 2913 } else { 2914 hiddenField.val('no'); 2915 setCookie( 'oc_shipping_to_other_address', 0 , 1 ); 2916 2917 $('.woocommerce-billing-fields__field-wrapper.billing-fields-shipping-data').slideDown(); 2918 $('.woocommerce-shipping-fields .shipping_address').slideUp(); 2919 } 2920 }); 2921 2922 // Accordion for FAQ page 2923 $('.schema-faq.wp-block-yoast-faq-block .schema-faq-question').on('click', function(e){ 2924 let parent = $(this).closest('div.schema-faq-section'); 2925 let siblings = parent.siblings(); 2926 // siblings.removeClass('active'); 2927 // parent.addClass( 'active' ); 2928 parent.toggleClass( 'active' ); 2929 2930 if ( parent.hasClass('active') ){ 2931 parent.find('.schema-faq-answer').slideDown(); 2932 } else { 2933 parent.find('.schema-faq-answer').slideUp(); 2934 } 2935 2936 }); 2937 2938 // input 2939 $( document.body ).on('change', '#shipping_method input', function(event) { 2940 let method = $(this).val(); 2941 2942 if ( method.indexOf( 'local_pickup' ) != -1 ){ 2943 $('.diff-address-shipping, .billing-fields-shipping-data, .woocommerce-shipping-fields').addClass('hidden'); 2944 } else { 2945 $('.diff-address-shipping, .billing-fields-shipping-data, .woocommerce-shipping-fields').removeClass('hidden'); 2946 } 2947 // set_shipping_to_other_address(); 2948 }); 2949 2950 $( document.body ).on('focus', 'form.woocommerce-form-register input, form.lost_reset_password input', function(event) { 2951 let parent = $(this).closest('p'); 2952 parent.addClass('label-off'); 2953 }); 2954 2955 $( document.body ).on('blur', 'form.woocommerce-form-register input, form.lost_reset_password input', function(event) { 2956 let parent = $(this).closest('p'); 2957 // console.log( $(this).val(), 'this val blur' ); 2958 if ( $(this).val() == '' ){ 2959 parent.removeClass('label-off'); 2960 } 2961 }); 2962 2963 // quickview 2964 // console.clear(); 2965 // if ( $('button.product-quickview').length ){ 2966 // setTimeout( function(){ 2967 // $('button.product-quickview').last().trigger('click'); 2968 // }, 100 ) 2969 // } 2970 2971 2972 // open popup 2973 $(document.body).on( 'click', 'button.product-quickview', function(){ 2974 var product_id = $(this).val(); 2975 var product = $(this).closest('li.product'); 2976 var target = $('.oc-woo-product-quickview-container'); 2977 2978 target.addClass('active'); 2979 $('.page-overlay').addClass( 'is-visible top' ); 2980 $('body').addClass('no-scroll'); 2981 2982 $.ajax({ 2983 type: 'POST', 2984 dataType: 'json', 2985 url: woocommerce_params.ajax_url, 2986 data: { 2987 action: 'oc_get_quickview_product', 2988 product_id: product_id, 2989 }, 2990 success: function(response) { 2991 // console.log( response, 'response' ); 2992 let responseHtml = $(response.data); 2993 // responseHtml.find('.woocommerce-product-gallery').css({'opacity': 1}) 2994 2995 // responseHtml 2996 // console.log( responseHtml, 'responseHtml' ); 2997 2998 target.find(' .oc-woo-product-quickview--inner').html( responseHtml ); 2999 3000 target.find('.quickview-product-slider').slick({ 3001 slidesToShow: 1, 3002 rtl:rtl, 3003 arrows:false, 3004 dots: true, 3005 }); 3006 3007 }, 3008 }); 3009 }); 3010 3011 // 3012 $(document).on( 'click', '.oc-woo-product-quickview-container button.oc-woo-product-quickview-close', function(){ 3013 $(this).closest('.oc-woo-product-quickview-container').removeClass('active'); 3014 $('.page-overlay').removeClass('is-visible top'); 3015 $('body').removeClass('no-scroll'); 3016 }); 3017 3018 3019 // from category page 3020// $(document).on( 'click', 'li.product.click-for-quickview a.woocommerce-loop-product__link', function(e){ 3021// var target = $('.oc-woo-product-quickview-container'); 3022// let parent = $(this).closest('li.product'); 3023// var product_id = parent.find( 'button.add-to-cart' ).val(); 3024 3025 3026 3027 // from category page 3028 $(document).on( 'click', 'li.product.click-for-quickview a.woocommerce-loop-product__link', function(e){ 3029 var target = $('.oc-woo-product-quickview-container'); 3030 let parent = $(this).closest('li.product'); 3031 var product_id = parent.find( 'button.add-to-cart' ).val(); 3032 3033 var windowWidth = $(window).width(); 3034 // console.log( windowWidth, 'windowWidth' ); 3035 // console.log( windowMobileResolution, 'windowMobileResolution' ); 3036 if ( parent.hasClass( 'desktop-and-mobile' ) ){ 3037 oc_woo_quickview_window( product_id, target ); 3038 e.preventDefault(); 3039 } else if ( parent.hasClass( 'desktop' ) && windowWidth > windowMobileResolution ){ 3040 oc_woo_quickview_window( product_id, target ); 3041 e.preventDefault(); 3042 } else if ( parent.hasClass( 'mobile' ) && windowWidth < windowMobileResolution ){ 3043 oc_woo_quickview_window( product_id, target ); 3044 e.preventDefault(); 3045 } 3046 // oc_woo_quickview_window( product_id, target ); 3047 }); 3048 3049 // front page 3050 $(document).on( 'click', '.product-grid.click-for-quickview a.link', function(e){ 3051 var target = $('.oc-woo-product-quickview-container'); 3052 let parent = $(this).closest('.product-grid'); 3053 var product_id = parent.find( 'button.add-to-cart' ).val(); 3054 // console.log( 'CLICK!' ); 3055 var windowWidth = $(window).width(); 3056 3057 if ( parent.hasClass( 'desktop-and-mobile' ) ){ 3058 oc_woo_quickview_window( product_id, target ); 3059 e.preventDefault(); 3060 } else if ( parent.hasClass( 'desktop' ) && windowWidth > windowMobileResolution ){ 3061 oc_woo_quickview_window( product_id, target ); 3062 e.preventDefault(); 3063 } else if ( parent.hasClass( 'mobile' ) && windowWidth < windowMobileResolution ){ 3064 oc_woo_quickview_window( product_id, target ); 3065 e.preventDefault(); 3066 } 3067 }); 3068 3069 function resize_quickview_window(){ 3070 var target = $('.oc-woo-product-quickview-container'); 3071 if ( target.hasClass( 'active' ) ){ 3072 windowHeight = $(window).height(); 3073 let newBlockHeight = target.find(' .oc-woo-product-quickview--inner').height(); 3074 3075 if ( newBlockHeight > windowHeight ){ 3076 target.addClass('big') 3077 } else { 3078 target.removeClass('big') 3079 } 3080 } 3081 } 3082 3083 // get quickview window via ajax 3084 function oc_woo_quickview_window( product_id, target ){ 3085 $.ajax({ 3086 type: 'POST', 3087 dataType: 'json', 3088 url: woocommerce_params.ajax_url, 3089 data: { 3090 action: 'oc_get_quickview_product', 3091 product_id: product_id, 3092 }, 3093 success: function(response) { 3094 // console.log( response, 'response' ); 3095 target.find('.quickview-product-slider').slick('unslick'); 3096 target.find('.up-sells ul.products').slick('unslick'); 3097 3098 let responseHtml = $(response.data); 3099 target.find(' .oc-woo-product-quickview--inner').html( responseHtml ); 3100 3101 let newBlockHeight = target.find(' .oc-woo-product-quickview--inner').height(); 3102 3103 if ( newBlockHeight > $(window).height() ){ 3104 target.addClass('big') 3105 } else { 3106 target.removeClass('big') 3107 } 3108 3109 target.find('.quickview-product-slider').slick({ 3110 slidesToShow: 1, 3111 rtl:rtl, 3112 arrows:false, 3113 dots: true, 3114 }); 3115 3116 target.find('.up-sells ul.products').slick({ 3117 dots: false, 3118 infinite: false, 3119 slidesToShow: 4, 3120 slidesToScroll: 4, 3121 rtl:rtl, 3122 arrows : false, 3123 responsive: [ 3124 { 3125 breakpoint: 992, 3126 settings: { 3127 slidesToShow: 3, 3128 slidesToScroll: 3, 3129 arrows : false, 3130 } 3131 }, 3132 { 3133 breakpoint: 600, 3134 settings: { 3135 slidesToShow: 2, 3136 slidesToScroll: 2, 3137 arrows : false, 3138 } 3139 }, 3140 { 3141 breakpoint: 480, 3142 settings: { 3143 slidesToShow: 1, 3144 slidesToScroll: 1, 3145 centerMode: true, 3146 infinite: false, 3147 // arrows : false, 3148 } 3149 } 3150 ] 3151 }); 3152 3153 3154 let description = target.find('.woocommerce-product-details__short-description'); 3155 if ( description.length ){ 3156 if ( description.height() > 100 ){ 3157 description.addClass('scrollable'); 3158 } 3159 } 3160 // console.log( description.height(), 'description height' ) ; 3161 // console.log($(description).scrollHeight, 'description.scrollHeight' ) ; 3162 // console.log($(description).clientHeight, 'description.clientHeight' ) ; 3163 3164 target.removeClass( 'preloader' ); 3165 }, 3166 beforeSend: function(){ 3167 target.find(' .oc-woo-product-quickview--inner').html(''); 3168 3169 target.addClass('active'); 3170 $('.page-overlay').addClass( 'is-visible top' ); 3171 $('body').addClass('no-scroll'); 3172 target.addClass( 'preloader' ); 3173 // alert('prelaoder!'); 3174 } 3175 }); 3176 } 3177 3178 function animateCounter(element, duration, end) { 3179 var start = 0; 3180 var range = end - start; 3181 var increment = end > start ? 1 : -1; 3182 var stepTime = Math.abs(Math.floor(duration / range)); 3183 3184 function step() { 3185 start += increment; 3186 // element.innerText = '<div class="number">' + start + '</div>'; 3187 element.html( start ); 3188 3189 3190 if (start !== end) { 3191 setTimeout(step, stepTime); 3192 } 3193 } 3194 setTimeout(step, stepTime); 3195 } 3196 3197// animateCounter('.number-wrap .number', 2000) 3198 $.fn.isInViewport = function() { 3199 var elementTop = $(this).offset().top; 3200 var elementBottom = elementTop + $(this).outerHeight(); 3201 // console.log( $(this).css('marginTop'), 'marginTop' ) 3202 3203 var viewportTop = $(window).scrollTop(); 3204 var viewportBottom = viewportTop + $(window).height(); 3205 return elementBottom > viewportTop && elementTop < viewportBottom; 3206 }; 3207 3208 timer_widget(); 3209 3210 // timer widget ( number + text ) 3211 function timer_widget(){ 3212 if ( $('.number-wrap').length > 0 ){ 3213 if ( $('.number-wrap').isInViewport() && !$('.number-wrap').hasClass('done') ){ 3214 console.log('isInViewport' ); 3215 $('.number-wrap').each( function(index, el){ 3216 let target = $(this).find('.number'); 3217 var end = parseInt( $(this).find('.number').data('number') ); 3218 animateCounter( $(target), 2000, end ) 3219 }); 3220 $('.number-wrap').addClass('done') 3221 } 3222 } 3223 } 3224 3225 function icon_repeater_gutenberg(){ 3226 if ( $(window).width() <= windowMobileResolution ){ 3227 if ( $('.oc-icon-text-repeater').length ){ 3228 3229 if ( !$('.oc-icon-text-repeater').hasClass('slick-slider') ){ 3230 $('.oc-icon-text-repeater').slick({ 3231 rtl: rtl, 3232 slidesToShow:1, 3233 dots: true,
3234 arrows: false, 3235 // prevArrow:'<button type="button" class="slick-prev">Prev</button>', 3236 // nextArrow:'<button type="button" class="slick-next">Next</button>', 3237 }); 3238 } 3239 } 3240 } else { 3241 if ( $('.oc-icon-text-repeater').hasClass( 'slick-slider' ) ){ 3242 $('.oc-icon-text-repeater').slick('unslick') 3243 } 3244 } 3245 } 3246 3247 icon_repeater_gutenberg(); 3248 3249 $('.home-rec.preset-1').slick({ 3250 dots: false, 3251 infinite: true, 3252 slidesToShow: 4, 3253 slidesToScroll: 4, 3254 rtl: true, 3255 // responsive: [ 3256 // { 3257 // breakpoint: 1400, 3258 // settings: { 3259 // slidesToShow: 3, 3260 // slidesToScroll: 3, 3261 // } 3262 // }, 3263 // { 3264 // breakpoint: 786, 3265 // settings: { 3266 // slidesToShow: 2, 3267 // slidesToScroll: 2 3268 // } 3269 // }, 3270 // { 3271 // breakpoint: 480, 3272 // settings: { 3273 // slidesToShow: 1, 3274 // slidesToScroll: 1, 3275 // centerMode: true 3276 // } 3277 // } 3278 // ] 3279 }); 3280 3281 // 3282 $('.home-rec.preset-2').slick({ 3283 dots: false, 3284 infinite: false, 3285 slidesToShow: 1, 3286 slidesToScroll: 1, 3287 rtl: $('body').hasClass('rtl'), 3288 infinite: false, 3289 centerMode:true , 3290 centerPadding:'0', 3291 }); 3292 3293 // Eran code , add animation for input labels 3294 3295 /*checkout labels 3296 **************************************************************************/ 3297 $( ".woocommerce-billing-fields__field-wrapper p,.woocommerce-shipping-fields__field-wrapper p" ).each(function( index ) { 3298 var field = $(this).find('input.input-text'); 3299 if( field.val() ) { 3300 $(field).parent().parent().addClass('label-on'); 3301 }else{ 3302 $(field).parent().parent().addClass('label-off'); 3303 } 3304 }); 3305 $( document ).on( "focus", ".woocommerce-billing-fields__field-wrapper p input.input-text,.woocommerce-shipping-fields__field-wrapper p input.input-text", function() { 3306 $(this).parent().parent().addClass('label-on'); 3307 }); 3308 $( document ).on( "focusout", ".woocommerce-billing-fields__field-wrapper p input.input-text,.woocommerce-shipping-fields__field-wrapper p input.input-text", function() { 3309 if( !$(this).val() ) { 3310 $(this).parent().parent().removeClass('label-on'); 3311 $(this).parent().parent().addClass('label-off'); 3312 } 3313 }); 3314 $( document ).on( 'ajaxSuccess', function( event, xhr, settings ) { 3315 $( ".woocommerce-billing-fields__field-wrapper p" ).each(function( index ) { 3316 // console.log( this,'this' ); 3317 var field = $(this).find('input.input-text'); 3318 if( field.val() ) { 3319 $(field).parent().parent().addClass('label-on'); 3320 }else{ 3321 $(field).parent().parent().addClass('label-off'); 3322 } 3323 }); 3324 }); 3325 $('.woocommerce form .form-row input.input-text#shipping_address_1').attr('placeholder',''); 3326 /*checkout labels 3327 **************************************************************************/ 3328 3329 /* SP 3330 **************************************************************************/ 3331 $objRelatedProductSlick = get_related_product_object(); 3332 3333 $('.up-sells ul.products, .related ul.products').slick( $objRelatedProductSlick ); 3334 3335 // get related product 3336 function get_related_product_object( initialSlide ){ 3337 if ( typeof initialSlide == undefined ){ 3338 initialSlide = 0 3339 } 3340 3341 return { 3342 initialSlide: initialSlide, 3343 dots: false, 3344 infinite: true, 3345 slidesToShow: 4, 3346 slidesToScroll: 4, 3347 rtl: true, 3348 slide: 'li', 3349 responsive: [ 3350 { 3351 breakpoint: 1300, 3352 settings: { 3353 slidesToShow: 4, 3354 slidesToScroll: 4, 3355 } 3356 }, 3357 { 3358 breakpoint: 992, 3359 settings: { 3360 slidesToShow: 2, 3361 slidesToScroll: 2 3362 } 3363 }, 3364 { 3365 breakpoint: 480, 3366 settings: { 3367 slidesToShow: 1, 3368 slidesToScroll: 1, 3369 centerMode: true, 3370 arrows : false, 3371 infinite: false, 3372 } 3373 } 3374 ] 3375 } 3376 } 3377 3378 /* Open need help link 3379 **************************************************************************/ 3380 $(document).on( 'click', '.need_help a', function(e){ 3381 var target = $('#help-panel'); 3382 $(this).toggleClass('active'); 3383 3384 if ( $(this).hasClass('active') ){ 3385 target.attr( 'aria-hidden', false ); 3386 } else { 3387 target.attr( 'aria-hidden', true ); 3388 } 3389 3390 $('.page-overlay').addClass('top is-visible'); 3391 // $('body').toggleClass('no-scroll'); 3392 e.preventDefault(); 3393 }); 3394 3395 var checkoutButtons = $('.woocommerce-checkout-payment'); 3396 var reviewOrder = $('.woocommerce-checkout-review-order-table'); 3397 var checkoutForm = $('.woocommerce-checkout form.checkout.woocommerce-checkout'); 3398 3399 function oc_add_preloader(target){ 3400 target.append( '<span class="loader-css"></span>' ); 3401 target.addClass('blocked'); 3402 } 3403 3404 function oc_remove_preloader(target){ 3405 target.removeClass('blocked'); 3406 target.find( '.loader-css' ).remove(); 3407 } 3408 3409 /* Global Window event, on window load , widndow resize, doc scroll e.t.c. 3410 **************************************************************************/ 3411 $(window).on('scroll', function() { 3412 // make header sticky 3413 sticky_header(); 3414 // single_product_thumb_in_logo(); 3415 timer_widget(); 3416 }); 3417 3418 $(window).on('resize', function() { 3419 // $('.cart-panel .mini-cart-panel--container').css({'height':(($(window).height()))+'px'}); 3420 resize_quickview_window(); 3421 // reinit slick if it necessary 3422 // console.log( 'removed reinit mobile gallery, resize' ); 3423 3424 // console.log( 'Reinit mobile gallery, on resize' ); 3425 3426 single_product_gallery_mobile_slick(); 3427 single_product_gallery_slick(); 3428 // console.log( 'window resize' ); 3429 icon_repeater_gutenberg(); 3430 // console.group( 'RESIZE , reinit event' ) 3431 setTimeout( function(){ 3432 // console.log( 'window resize slick init ' ); 3433 if ( $('.archive_wrap .product-images-slider--container.slick-slider').length > 0 ){ 3434 $('.archive_wrap .product-images-slider--container.slick-slider img').removeAttr('loading') 3435 // $('.archive_wrap .product-images-slider--container.slick-slider img').removeAttr('decoding') 3436 } 3437 3438 return; 3439 // if ( $('.archive_wrap .product-images-slider--container.slick-slider').length > 0 ){ 3440 // $('.archive_wrap .product-images-slider--container.slick-slider').each( function( index, el ){ 3441 // // console.log( el, 'el' ); 3442 // if ( $(el).hasClass('slick-slider') && $(el).find('.slide').length > 1 ){} 3443 // // console.log( $(el), 'element of slic k' ); 3444 // // destroy ! 3445 // if ( $(el).hasClass('slick-slider') ){ 3446 // $(el).slick('unslick'); 3447 // } 3448 // $(el).slick({ 3449 // slidesToShow: 1, 3450 // adaptiveHeight: true, 3451 // rtl: rtl, 3452 // speed: 200, 3453 // touchThreshold: 50, 3454 // // new 3455 // }); 3456 3457 // }); 3458 // } 3459 }, 300 ) 3460 // console.groupEnd(); 3461 }); 3462 3463 // Set mini cart height on doc load 3464 $(window).on( 'load', function(){ 3465 // $('.cart-panel .mini-cart-panel--container').css({'height':(($(window).height()))+'px'}); 3466 }); 3467 3468 $( document ).on( 'ajaxSend', function( event, xhr, settings ) { 3469 if ( $('body').hasClass( 'woocommerce-checkout')){ 3470 // if ajax request refreshed fragments -> some product added to cart 3471 if ( settings.url == "/?wc-ajax=update_order_review" ){ 3472 oc_add_preloader( reviewOrder ); 3473 oc_add_preloader( checkoutButtons ); 3474 } 3475 if ( settings.url == '/?wc-ajax=checkout' ){ 3476 oc_add_preloader( checkoutForm ); 3477 } 3478 } 3479 }); 3480 3481 // on ajax success 3482 $( document ).on( 'ajaxSuccess', function( event, xhr, settings ) { 3483 if ( settings.url == '/?wc-ajax=update_order_review' ){ 3484 if ( xhr.responseJSON ){ 3485 if ( typeof xhr.responseJSON.fragments['.woocommerce-checkout-review-order-table'] != undefined ){ 3486 let $html = $(xhr.responseJSON.fragments['.woocommerce-checkout-review-order-table']); 3487 let shipping_method = $html.find( '#shipping_method' ); 3488 $('.ship-method .woocommerce-shipping-methods').html( shipping_method.html() ); 3489 } 3490 } 3491 } 3492 3493 // if ajax request refreshed fragments -> some product added to cart 3494 if ( $('body').hasClass( 'woocommerce-checkout') ){ 3495 if ( settings.url == "/?wc-ajax=update_order_review" ){ 3496 // var target = $('.woocommerce-checkout-review-order-table'); 3497 oc_remove_preloader($('.woocommerce-checkout-review-order-table')); 3498 oc_remove_preloader($('.woocommerce-checkout-payment')); 3499 } 3500 3501 if ( settings.url == '/?wc-ajax=checkout' ){ 3502 oc_remove_preloader( checkoutForm ); 3503 } 3504 } 3505 }); 3506 3507
3508 // $(document).on( 'click', '.oc-under-checkout-button', function(e){ 3509 // e.preventDefault(); 3510 // var target = $('li.mini_cart_item'); 3511 // target.append( '<span class="loader-css"></span>' ); 3512 // target.block({ 3513 // message: null, 3514 // overlayCSS: { 3515 // opacity: 0.6 3516 // } 3517 // }); 3518 // target.addClass('blocked'); 3519 // // $('.').addClass('blocked'); 3520 // }); 3521 3522 function external_product_image_height(){ 3523 if ( $('body').hasClass('woocommerce') ){ 3524 let externalProducts = $('li.product-type-external'); 3525 let maxProductHeight = 0; 3526 if ( externalProducts.length ){ 3527 let firstImg = externalProducts.find( '.wrap-for-top-part img:first-child' ); 3528 let normalProductImg = $('li.product:not(.product-type-external)'); 3529 3530 normalProductImg.each( function( i, el){ 3531 if ( $(el).height() > maxProductHeight ){ 3532 maxProductHeight = $(el).height(); 3533 } 3534 }); 3535 if ( firstImg.height() > maxProductHeight ){ 3536 firstImg.height( maxProductHeight ); 3537 } 3538 // console.log( firstImg, 'firstImg' ); 3539 // console.log( maxProductHeight, 'maxProductHeight' ); 3540 // console.log( normalProductImg.height(), 'normalProductImg height' ); 3541 // console.log( firstImg.height(), 'firstImg height' ); 3542 } 3543 } 3544 } 3545 external_product_image_height(); 3546 3547 3548 // trick for iPhone 3549 function iOS() { 3550 return [ 3551 'iPad Simulator', 3552 'iPhone Simulator', 3553 'iPod Simulator', 3554 'iPad', 3555 'iPhone', 3556 'iPod' 3557 ].includes(navigator.platform) 3558 // iPad on iOS 13 detection 3559 || (navigator.userAgent.includes("Mac") && "ontouchend" in document) 3560 } 3561 3562 // iframe 3563 function oc_ios_iframe_size_mobile(){ 3564 if ( iOS() ){ 3565 let wrap = $('.iframe-wrap.mobile-video'); 3566 wrap.css( { height: '80vh' } ); 3567 var vimeoPlayer = new Vimeo.Player( wrap.find('iframe') ); 3568 vimeoPlayer.play(); 3569 3570 // vimeoPlayer.ready().then(function() {c 3571 // // vimeoPlayer.setVolume(0); 3572 // vimeoPlayer.play(); 3573 // }); 3574 } 3575 } 3576 3577 if ( $('.iframe-wrap.mobile-video').length ){ 3578 $.getScript( "https://player.vimeo.com/api/player.js" ).done( function( textStatus ){ 3579 oc_ios_iframe_size_mobile(); 3580 }); 3581 } 3582 3583 // Upsells products 3584 // ############################## 3585 var upsellsProductMobileBrealpoint = 650; 3586 3587 // on button click on ,mobile open form 3588 $(document).on('click', '.mini-cart-panel--container a.checkout', function(e){ 3589 let upsells = $('.upsells-products-sidebar .product-upsell-list'); 3590 if ( $(window).width() < upsellsProductMobileBrealpoint && upsells.length ){ 3591 // $('.upsells-products-sidebar').toggleClass('active'); 3592 $('#cart-panel').toggleClass('active-upsells-products'); 3593 $('.upsells-products-sidebar-close').removeClass('active'); 3594 e.preventDefault(); 3595 } 3596 3597 }); 3598 3599 // close sidebar and save to cookie 3600 $(document).on( 'click', '.upsells-products-sidebar-close', function(e){ 3601 3602 let upsells = $('.upsells-products-sidebar .product-upsell-list'); 3603 3604 $('.upsells-products-sidebar').toggleClass('hidden'); 3605 $(this).toggleClass('active'); 3606 3607 if ( $(this).hasClass('active') ){ 3608 setCookie( 'oc_woo_minicart_upsells_hide', 1 , 1 ); 3609 } else { 3610 setCookie( 'oc_woo_minicart_upsells_hide', 0 , 1 ); 3611 } 3612 3613 if ( $(window).width() < upsellsProductMobileBrealpoint && upsells.length ){ 3614 $('#cart-panel').removeClass('active-upsells-products'); 3615 $('.upsells-products-sidebar-close').removeClass('active'); 3616 } 3617 }); 3618 3619 // close upsells list 3620 $(document).on( 'click', '.upsells-products-block-close', function(e){ 3621 let upsells = $('.upsells-product--container .product-upsell-list'); 3622 3623 $('.upsells-product--container').toggleClass('hidden'); 3624 $(this).toggleClass('active'); 3625 3626 if ( $(this).hasClass('active') ){ 3627 setCookie( 'oc_woo_minicart_upsells_hide', 1 , 1 ); 3628 } else { 3629 setCookie( 'oc_woo_minicart_upsells_hide', 0 , 1 ); 3630 oc_upsells_products_init_slider(); 3631 } 3632 3633 if ( $(window).width() < upsellsProductMobileBrealpoint && upsells.length ){ 3634 $('#cart-panel').removeClass('active-upsells-products') 3635 } 3636 3637 }); 3638 3639 // console.clear(); 3640 // console.log( 'ADD TO CART ' ); 3641 3642 // add to cart UPSELLS ! FOR SIMPLE PRODUCTS! 3643 $(document).on( 'click', '.product-upsell-list .quick-add', function(e){ 3644 let $thisbutton = $(this); 3645 let quantity = 1; 3646 let product = $thisbutton.closest('.product'); 3647 let productId = $(this).val(); 3648 3649 console.group( 'quick add click' ); 3650 e.preventDefault(); 3651 // additional popup for 3652 if ( $(this).hasClass('variable-product') ){
3653 var productContainer = $('.oc-variable-product-upsells-popup--container'); 3654 console.log( productContainer, 'productContainer' ); 3655 console.log( productId, 'productId' ); 3656 3657 oc_connected_color_for_upsells( productContainer, productId ); 3658 productContainer.addClass('active'); 3659 return; 3660 } 3661 3662 // addToCartAnimation( $thisbutton ); 3663 addToCartAjax( productId, false, quantity, $(this) ); 3664 setTimeout( function(){ 3665 if ( $('.upsells-products-sidebar--inner.init-slider .product-upsell-list').hasClass('slick-slider') ){ 3666 var slideIndex = product.data( 'slick-index' ); 3667 $('.upsells-products-sidebar--inner.init-slider .product-upsell-list').slick('slickRemove',slideIndex - 1); 3668 // console.log( 'I am here !' ) ; 3669 3670 if ( $('.upsells-products-sidebar--inner.init-slider .product-upsell-list .product').length <= 4 ){ 3671 $('.upsells-products-sidebar--inner.init-slider .bottom-arrow.slick-next').hide(); 3672 $('.upsells-products-sidebar--inner.init-slider .top-arrow.slick-prev').hide(); 3673 $('.upsells-products-sidebar--inner.init-slider .product-upsell-list').slick('unslick'); 3674 } 3675 } else { 3676 product.addClass('removed'); 3677 } 3678 }, 200 ); 3679 3680 console.groupEnd( 'quick add click' ); 3681 }); 3682 3683 // ####################################################### Upsells products 3684 // $('.upsells-products-sidebar--inner.init-slider .product-upsell-list').on( 'init', oc_upsells_product_vertical_slider ); 3685 // $('.upsells-products-sidebar--inner.init-slider .product-upsell-list').on( 'afterChange', oc_upsells_product_vertical_slider ); 3686 3687 3688 3689 // custom arrow click 3690 // $('.upsells-products-sidebar button.top-arrow.slick-prev').on( 'click', function(){ 3691 $('.upsells-products-sidebar button.top-arrow').on( 'click', function(){ 3692 $('.upsells-products-sidebar--inner.init-slider .product-upsell-list').slick('slickNext'); 3693 // $('.upsells-products-sidebar--inner.init-slider .product-upsell-list').slick('slickPrev'); 3694 }); 3695 3696 // custom arrow click 3697 // $('.upsells-products-sidebar button.bottom-arrow.slick-next').on( 'click', function(){ 3698 $('.upsells-products-sidebar button.bottom-arrow').on( 'click', function(){ 3699 $('.upsells-products-sidebar--inner.init-slider .product-upsell-list').slick('slickPrev'); 3700 // $('.upsells-products-sidebar--inner.init-slider .product-upsell-list').slick('slickNext'); 3701 }); 3702 3703// console.log($('.upsells-products-sidebar--inner.init-slider .product-upsell-list'), 'UPSELL SLITS' ); 3704 3705 let upsellsProducts = $('.upsells-products-sidebar--inner.init-slider .product-upsell-list .product'); 3706 let upsellsProductsUnderList = $('ul.woocommerce-mini-cart .upsells-product--container .product'); 3707 3708 // console.log( upsellsProductsUnderList, 'upsellsProductsUnderList ' ); 3709 3710 if ( upsellsProducts.length > 0 ){ 3711 3712 // var useArrow = upsellsProducts.length >= 4 ? true : false; 3713 var useArrow = false ; 3714 // console.log( upsellsProducts, 'upsellsProducts' ); 3715 // console.log( useArrow, 'useArrow' ); 3716 3717 // init upsell slick , sidebar 3718 if ( upsellsProducts.length > 4 ){ 3719 slideQ = 4; 3720 let widnowHeight = $(window).height(); 3721 3722 let productH = upsellsProducts.first(); 3723 if ( productH.length ){ 3724 let upsellsHeader = $('.upsells-products-sidebar--header .title').outerHeight(true); 3725 slideQ = Math.floor( ( widnowHeight - upsellsHeader ) / productH.outerHeight(true) ); 3726 if ( slideQ > 4 ){ 3727 slideQ = 4; 3728 } 3729 // console.log( slideQ, 'slideQ' ); 3730 // console.log( productH, 'productH ' ); 3731 // console.log( productH.outerHeight(true), 'productH .outerHeight()' ); 3732 // console.log( upsellsHeader, 'upsellsHeader outerHeight ++ ' ); 3733 // console.log( widnowHeight, 'widnowHeight' ); 3734 } 3735 3736 if ( $('.upsells-products-sidebar--inner.init-slider .product-upsell-list').length ){ 3737 $('.upsells-products-sidebar--inner.init-slider .product-upsell-list').slick({ 3738 slidesToShow:slideQ, 3739 slidesToScroll: 1, 3740 arrows: useArrow, 3741 dots: false, 3742 vertical: true, 3743 centerMode:false, 3744 infinite:true, 3745 responsive: [ 3746 { 3747 breakpoint: 650, 3748 settings: "unslick" 3749 } 3750 ] 3751 }); 3752 } 3753 3754 // $('.upsells-products-sidebar--inner.init-slider .product-upsell-list').flickity({ 3755 // // options 3756 // verticalCells: true, 3757 // cellAlign: 'right', 3758 // contain: true, 3759 // freeScroll: true, 3760 // rightToLeft: rtl, 3761 // prevNextButtons: true, 3762 // pageDots: false, 3763 // wrapAround: true 3764 // }); 3765 // console.log("FLICKITY !" ) 3766 3767 } else { 3768 $('.upsells-products-sidebar--inner.init-slider .top-arrow').hide(); 3769 $('.upsells-products-sidebar--inner.init-slider .bottom-arrow').hide(); 3770 } 3771 3772 } else if ( upsellsProductsUnderList.length > 0 ){
3773 // console.log( $('ul.woocommerce-mini-cart .upsells-product--container .product-upsell-list'), 'UPSELLS LIST ' ); 3774 oc_upsells_products_bottom_minicart_init_slider(); 3775 } 3776 3777 function oc_upsells_products_init_slider(){ 3778 if ( !$('.upsells-product--container.sticky .product-upsell-list').hasClass('slick-slider') ){ 3779 $('.upsells-product--container.sticky .product-upsell-list').slick({ 3780 slidesToShow:1, 3781 slidesToScroll: 1, 3782 arrows: true, 3783 dots: false, 3784 rtl: rtl, 3785 // centerMode:true, 3786 infinite: true, 3787 responsive: [ 3788 { 3789 breakpoint: 768, 3790 settings: { 3791 slidesToShow:1, 3792 slidesToScroll: 1, 3793 centerMode:false, 3794 } 3795 }, 3796 { 3797 breakpoint: 480, 3798 settings: { 3799 slidesToShow:1, 3800 slidesToScroll: 1, 3801 centerMode:false, 3802 } 3803 } 3804 ] 3805 }); 3806 // moved IN 3807 $(window).trigger('resize'); 3808 } 3809 } 3810 3811 // init slick 3812 function oc_upsells_products_bottom_minicart_init_slider(){ 3813 if ( !$('ul.woocommerce-mini-cart .upsells-product--container .product-upsell-list').hasClass('slick-slider') ){ 3814 $('ul.woocommerce-mini-cart .upsells-product--container .product-upsell-list').slick({ 3815 slidesToShow: 2, 3816 slidesToScroll: 1, 3817 arrows: useArrow, 3818 dots: false, 3819 centerMode:false, 3820 infinite:true, 3821 rtl: rtl, 3822 }); 3823 $(window).trigger('resize'); 3824 } 3825 } 3826 3827 oc_upsells_products_init_slider() 3828 3829 $( document.body ).on( 'added_to_cart', function( fragments, cart_hash, $thisbutton ){ 3830 setTimeout( function(){ 3831 oc_upsells_products_init_slider(); 3832 // reinit 3833 oc_upsells_products_bottom_minicart_init_slider(); 3834 }, 10 ) 3835 }); 3836 3837 $( document.body ).on( 'removed_from_cart', function( fragments, cart_hash, $thisbutton ){ 3838 setTimeout( function(){ 3839 oc_upsells_products_init_slider(); 3840 // reitni 3841 oc_upsells_products_bottom_minicart_init_slider() 3842 }, 10 ) 3843 }); 3844 3845 3846 //########################################### Coupon code 3847 $(document).on( 'keyup', 'table.woocommerce-checkout-review-order-table .coupon-form input.input-text', function(e){ 3848 let code = $(this).val(); 3849 console.log( code, 'code' ); 3850 $('form.checkout_coupon input.input-text').val( code ); 3851 }); 3852 3853 $(document).on( 'click', 'table.woocommerce-checkout-review-order-table .apply-coupon-copy', function(e){ 3854 $('form.checkout_coupon .button').trigger( 'click' ) 3855 e.preventDefault(); 3856 }); 3857 3858 //########################################### Coupon end 3859 3860 ////########################################### Wishlist 3861 $(document).on( 'click', '.wishlist-icon--container button.wishlist-icon', function(){ 3862 // $('#wishlist-panel'); 3863 let $this = $(this); 3864 toggle_hidden_attribute( $this, '#wishlist-panel' ); 3865 $('.page-overlay').addClass('top is-visible'); 3866 $('body').toggleClass('no-scroll'); 3867 }); 3868 3869 // close panel on icon click 3870 $(document).on( 'click', 'button.wishlist__close', function(e){ 3871 // $('.search-form--dropdown-panel').removeClass( 'active' ); 3872 $('#wishlist-panel').attr( 'aria-hidden', true ); 3873 $('.page-overlay').removeClass('is-visible top'); 3874 $('.oc-woo-search--wrap').removeClass('active'); 3875 $('body').removeClass('no-scroll'); 3876 }); 3877 3878 ////########################################### Wishlist 3879 3880 3881 // OC timer 3882 // 3883 $('button.close-header-timer').on( 'click', function(){ 3884 $('.oc-header-timer-container').slideUp(); 3885 setCookie( 'oc_header_timer_closed', 1, 1 ); 3886 var newHeight = bumper.height() - $('.oc-timer-bar--container').height(); 3887 bumper.height( newHeight ); 3888 }); 3889 3890 function check_bumper_height(){ 3891 if ( $('.oc-timer-bar--container').length ){ 3892 3893 let bckgrnd = $('.main-header--container').css('backgroundColor'); 3894 // console.log( bckgrnd, 'bckgrnd' ); 3895 3896 let bumper = $('.header-bumper'); 3897 let headerHeight = $('#main-header'); 3898 3899 // trarnsparent 3900 if ( bckgrnd == 'rgba(0, 0, 0, 0)' ){ 3901 var newHeight = bumper.height() + $('.oc-timer-bar--container').height(); 3902 bumper.height( newHeight ); 3903 3904 } 3905 // let timerHeight = $('.oc-timer-bar--container').height(); 3906 if ( headerHeight.height() > bumper.height() ){ 3907 // bumper.height( headerHeight.height() ); 3908 } 3909 } 3910 } 3911 3912 check_bumper_height(); 3913 //########################################### Recommended products 3914 3915 // Add to cart upsells on product page | miximum 3916 $(document).on( 'click', '.p_upgrade_items .add-to-cart', function(){ 3917 let $thisbutton = $(this); 3918 let quantity = 1; 3919 let data = { 3920 product_id : $(this).val(), 3921 quantity: quantity, 3922 } 3923 3924 if ( useAddToCartAnimation ){ 3925 addToCartAnimation( $thisbutton ); 3926 } 3927 addToCartAjax( $(this).val(), false, quantity, $(this) ); 3928 }); 3929 3930 3931 // nextend social plugin : move block 3932 if ( $('#nsl-custom-login-form-1').length ){ 3933 // console.log( $('#nsl-custom-login-form-1') , 'nsl ' ); 3934 $('.login-buttons--container').append( $('#nsl-custom-login-form-1') ); 3935 } 3936 3937 3938 // Add to cart for search product 3939 $(document).on( 'click', '.oc-woo-search--container .add-to-cart', function(){ 3940 let $thisbutton = $(this); 3941 let quantity = 1; 3942 3943 if ( useAddToCartAnimation ){ 3944 addToCartAnimation( $thisbutton ); 3945 } 3946 addToCartAjax( $(this).val(), false, quantity, $(this) ); 3947 let product = $thisbutton.closest('.product-row-wrap'); 3948 setTimeout( function(){ 3949 product.addClass('removed'); 3950 }, 200 ); 3951 }); 3952 3953 $(document).on( 'click', 'a.open-auth-panel.checkout', function(e){ 3954 $('a.my-account-link.login-panel').trigger( 'click' ); 3955 }); 3956 3957 3958 $(document.body).on( 'change', 'input.shipping_method', function() { 3959 let requiredLabel = '<abbr class="required" title="× ×רש">*</abbr>'; 3960 let optional = '<span class="optional">(××פצ××× ××)</span>'; 3961 var value = $('input.shipping_method:checked').val(); 3962 3963 if ( value.indexOf( 'local_pickup' ) != -1 ){ 3964 // $('#billing_city_field .optional').html( optional ); 3965 // $('#billing_address_1_field .optional').html( optional ); 3966 } else { 3967 // $('#billing_city_field .optional').html( requiredLabel ); 3968 // $('#billing_address_1_field .optional').html( requiredLabel ); 3969 } 3970 }); 3971 3972 // orderby submit 3973 $( ".woocommerce-ordering .select-list-checkbox label" ).on( "click", function() { 3974 $('form.woocommerce-ordering').submit(); 3975 }); 3976 3977 // temporary for megamenu ! 3978 if ( $('ul.mega-menu').length ){ 3979 $('ul.mega-menu').addClass('nav-menu'); 3980 } 3981 3982 function hide_external_product_on_sort(){ 3983 var search = window.location.search; 3984 if ( search.indexOf('orderby') != -1 ){ 3985 $('.products li.product-type-external').hide(); 3986 } 3987 } 3988 3989 // if search is active hide external products 3990 hide_external_product_on_sort(); 3991 3992 //################################################################### OC color swatch 3993 3994 // on color select, remove unactive class from sizes 3995 if ( colorTax ){ 3996 $(document).on('change', '.variations #' + colorTax, function(e){ 3997 if ( sizeTax ){ 3998 let sizeSelect = $( 'select#' + sizeTax ); 3999 if ( sizeSelect.length > 0 && sizeSelect.val() == false && $(this).val() == false && $('input.variation_id') ) { 4000 let inactive = $('.attribute-btn.inactive') 4001 if ( inactive.length > 0 ){ 4002 inactive.removeClass('inactive') 4003 } 4004 } 4005 } 4006 }); 4007 } 4008 4009 // console.clear(); 4010 // console.log( singleProductMainSlider, 'singleProductMainSlider START ' ); 4011 4012 // attributes swatches clcik 4013 $(document).on( 'click', '.attributes-panel-container .buttons-attrs-panel--wrapper .attribute-btn', function(e){ 4014 let $t = $(this); 4015 // var variationForm = $('form.variations_form'); 4016 var variationForm = $t.closest('.product').find('form.variations_form'); 4017 4018 var variations = false;
4019 var productVariableFlag = false; 4020 4021 e.preventDefault(); 4022 4023 // this is for quickview 4024 if ( variationForm.length == 0 ){ 4025 variationForm = $t.closest('.product-info.summary').find('form.variations_form.cart'); 4026 } 4027 if ( variationForm ){ 4028 variations = JSON.parse( variationForm.attr('data-product_variations') ); 4029 var productVariableFlag = variations && variations.length > 0; 4030 } 4031 4032 // 4033 let product = $t.closest('div.product'); 4034 var attr = $t.data('val'); 4035 let tax = $t.closest('.buttons-attrs-panel--wrapper').data('tax'); 4036 4037 console.group( 'CHECK' ); 4038 console.log( tax, 'tax name ORIGINAL' ); 4039 // decode attribute tax 4040 tax = encodeURI(tax); 4041 tax = tax.toLowerCase() 4042 4043 // console.log( tax, 'tax toLowerCase ' ); 4044 4045 // let selectToChange = $( 'select#'+ tax ); 4046 // let selectorV = "tr." + tax + ' td.value select'; 4047 // let selectToChange = $( selectorV ); 4048 let selectToChange = variationForm.find('select[id="' + tax + '"]'); 4049 console.log(product, 'product'); 4050 console.log($('select[id="' + tax + '"]')); 4051 console.log('select[id="' + tax + '"]'); 4052 let colorSelect = ( colorTax != '' ) ? product.find( 'select#'+ colorTax ) : false; 4053 let sizeSelect = ( sizeTax != '' ) ? product.find( 'select#'+ sizeTax ) : false ; 4054 let variantId = variationForm.find( 'input.variation_id' ); 4055 4056 // console.log( selectToChange, 'selectToChange' ); 4057 // // console.log( selectorV, 'selectorV' ); 4058 // // console.log( colorTax, 'colorTax' ); 4059 // console.groupEnd(); 4060 // console.log( sizeSelect.val(), 'sizeSelect val' ); 4061 // console.log( colorSelect.val(), ' colorSelect val' ); 4062 // on color attribute change 4063 if ( colorTax && tax == colorTax && !$t.hasClass('active') ){ 4064 4065 selectToChange.trigger('change'); 4066 4067 // get color id 4068 let colorId = $t.val() 4069 let mainGalleryColor = product.find('.main-gallery#attr-color-' + colorId ); 4070 let miniSliderGallery = product.find('.minislider-thumbnails--container#attr-color-' + colorId ); 4071 4072 // console.log( mainGalleryColor, 'mainGalleryColor!' ) ; 4073 // console.log( $(window).width() <= 768, '$(window).width() <= 768!' ) ; 4074 // show additional gallery 4075 if ( mainGalleryColor.length > 0 ){ 4076 // show new galerry and hide old 4077 mainGalleryColor.siblings().addClass('hidden-gallery'); 4078 4079 // console.log( mainGalleryColor, 'mainGalleryColor' ); 4080 // reinit slick if already initiated 4081 if ( $('body').hasClass('product-gallery-vertical-thumbs') || $('body').hasClass('product-gallery-vertical-thumbs-column') || $('body').hasClass('product-gallery-regular-slider') ){ 4082 if ( mainGalleryColor.hasClass('slick-slider') ){ 4083 mainGalleryColor.slick('unslick'); 4084 } 4085 } 4086 4087 mainGalleryColor.addClass('preloader'); 4088 // mainGalleryColor.trigger('change'); 4089 if ( $('body').hasClass('product-gallery-vertical-thumbs') || $('body').hasClass('product-gallery-vertical-thumbs-column') || $('body').hasClass('product-gallery-regular-slider') ){ 4090 // singleProductMainSlider.asNavfor = '.vertical-thumbnails--container'; 4091 console.log( singleProductMainSlider, 'singleProductMainSlider SETTINGS ' ); 4092 mainGalleryColor.slick( singleProductMainSlider ); 4093 if ( $('.vertical-thumbnails--container').hasClass('slick-slider') ){ 4094 $('.vertical-thumbnails--container').slick( 'unslick' ); 4095 } 4096 var verticalSeliderSettings = oc_vertical_slider_slick_settings(); 4097 $('.vertical-thumbnails--container').slick( verticalSeliderSettings ); 4098 // console.log( "RESIZE !" ) 4099 } 4100 mainGalleryColor.removeClass('hidden-gallery'); 4101 4102 // add animation to gallery 4103 setTimeout(function(){ 4104 mainGalleryColor.removeClass('preloader'); 4105 }, 250 ); 4106 } else { 4107 // console.log( "SHOW gallery__inner not main" ); 4108 // show original images 4109 let mainGallery = $('.woocommerce-product-gallery__inner:not(.main-gallery)'); 4110 mainGallery.siblings().addClass('hidden-gallery'); 4111 mainGallery.removeClass('hidden-gallery'); 4112 } 4113 4114 // Reinit slider on mobile 4115 if ( $(window).width() <= 768 ){ 4116 // console.log( miniSliderGallery, 'miniSliderGallery' ); 4117 4118 if ( miniSliderGallery.length > 0 ){ 4119 miniSliderGallery.siblings().addClass('hidden-gallery'); 4120 4121 console.log( 'destroy slick on mobile !!!' ); 4122 4123 if ( miniSliderGallery.hasClass('slick-slider') ){ 4124 miniSliderGallery.slick('unslick'); 4125 } 4126 4127 // console.log( miniSliderGallery, 'console.log( miniSliderGallery' ); 4128 // console.log( miniSliderGallery.find('.slide').length, 'miniSliderGallery .slide.length ' ); 4129 4130 miniSliderGallery.flickity('destroy'); 4131 miniSliderGallery.removeClass('hidden-gallery'); 4132 4133 if ( miniSliderGallery.find('.slide').length > ocThemeSettings.thumbnail_mobile_max_quantity ) { 4134 miniSliderGallery.flickity({ 4135 // options 4136 cellAlign: 'right', 4137 contain: true, 4138 freeScroll: true, 4139 rightToLeft: rtl,
4140 prevNextButtons: false, 4141 pageDots: false, 4142 wrapAround: true 4143 }); 4144 } 4145 4146 // miniSliderGallery.slick({ 4147 // rtl: rtl, 4148 // speed: 250, 4149 // slidesToShow: miniSliderGallery.find('.slide').length, 4150 // adaptiveHeight: true, 4151 // centerMode: false, 4152 // arrows: false, 4153 // dots: false, 4154 // }); 4155 4156 // miniSliderGallery.addClass('preloader'); 4157 // miniSliderGallery.removeClass('hidden-gallery'); 4158 // setTimeout(function(){ 4159 // // miniSliderGallery.removeClass('preloader'); 4160 // }, 250 ); 4161 } else { 4162 if ( $('.woocommerce-product-gallery__inner.slick-initialized').length ){ 4163 $('.woocommerce-product-gallery__inner.slick-initialized').slick('unslick'); 4164 } 4165 } 4166 // 4167 } else { 4168 var thumbsGalleryColor = $('.vertical-thumbnails--container.additional-colors-gallery#attr-color-' + colorId ); 4169 // console.log( thumbsGalleryColor, 'thumbsGalleryColor ELSE condition ' ); 4170 // console.log( thumbsGalleryColor.siblings(), 'thumbsGalleryColor.siblings()' ); 4171 // show addiional gallery 4172 if ( thumbsGalleryColor.length > 0 ){ 4173 4174 thumbsGalleryColor.siblings().addClass('hidden-gallery'); 4175 thumbsGalleryColor.addClass('preloader'); 4176 thumbsGalleryColor.removeClass('hidden-gallery'); 4177 4178 setTimeout(function(){ 4179 thumbsGalleryColor.removeClass('preloader'); 4180 }, 250 ); 4181 } else { 4182 let thumbsGallery = $('.vertical-thumbnails--container:not(.additional-colors-gallery)'); 4183 thumbsGallery.siblings().addClass('hidden-gallery'); 4184 thumbsGallery.removeClass('hidden-gallery'); 4185 } 4186 } 4187 } 4188 4189 if ( $t.hasClass('outstock') ){ 4190 // console.log( "OUTOF STOCK !!!!!!!!!!!!!" ) 4191 // return; 4192 } 4193 4194 4195 // on size change add to href size value 4196 // console.group('Attribue clicked '); 4197 // console.log( variationForm, 'variationForm' ); 4198 // // console.log( $t, '$t' ); 4199 // // console.log( variantId, 'variantId' ); 4200 // console.log( sizeTax, 'sizeTax' ); 4201 // console.log( attr, 'attr' ); 4202 // // console.log( decodeURI( attr ), 'DECODE URI' ) 4203 // console.log( selectToChange, 'selectToChange' ) 4204 // console.log( productVariableFlag, 'productVariableFlag' ) 4205 // console.groupEnd(); 4206 4207 /* 4208 if ( sizeTax && tax == sizeTax ){ 4209 // set color attribute value 4210 if ( $('a.connected-product-color').length > 0 ){ 4211 $('a.connected-product-color').each(function(i, el){ 4212 let href = $(el).attr( 'data-original-link' ); 4213 var sizeValue = href + '&' + sizeTax + '=' + attr; 4214 $(el).attr( 'href', sizeValue ); 4215 }); 4216 } 4217 } 4218 */ 4219 4220 $t.siblings().removeClass('active'); 4221 $t.addClass('active'); 4222 4223 // remove_attribute_that_out_of_stock( attr, tax, this ); 4224 remove_product_out_of_stock_from_data( attr, tax, this ); 4225 4226 if ( productVariableFlag ){ 4227 4228 // if ( variantId.val() == '' || variantId.val() == 0 ){ 4229 // variantId.val(variations[0].variation_id); 4230 // variantId.trigger( 'change' ); 4231 // } 4232 4233 let options = selectToChange.find('option').removeAttr( 'selected' ); 4234 selectToChange.val(attr); 4235 4236 selectToChange.trigger('change'); 4237 4238 // if ( tax == colorTax ){ 4239 // if ( !selectToChange.hasClass('changed') ){ 4240 // $( ".variations_form" ).trigger( "woocommerce_variation_select_change" ); 4241 // variantId.trigger('change'); 4242 // selectToChange.addClass('changed') 4243 // } 4244 // } else { 4245 // variantId.trigger('change'); 4246 // selectToChange.trigger('change'); 4247 // } 4248 } 4249 }); 4250 4251 4252 // / 4253 // $('.variations_form').on('check_variations', function( event, chosenAttributes){ 4254 // console.log( event, 'event check_variations' ); 4255 // console.log( event.data, 'data' ); 4256 // // console.log( chosenAttributes, 'chosenAttributes' ); 4257 // }); 4258 4259 // add class to attribute outofstock 4260 function remove_attribute_that_out_of_stock( attribute, tax, btn ){ 4261 var variationForm = $('form.variations_form.cart'); 4262 if ( variationForm.length == 0 ){ 4263 return; 4264 } 4265 4266 // return 4267 4268 // clean 4269 $('.attribute-btn').removeClass('outofstock'); 4270 4271 var arOutOfStock = []; 4272 var parent = $('div.product .summary'); 4273 var variations = JSON.parse( variationForm.attr('data-product_variations') ); 4274 var variationsLength = variations.length - 1; 4275 4276 console.group( 'remove_product_out_of_stock_from_data' ); 4277 // attribute name 4278 // console.log( attribute, 'attribute' ); 4279 // current clicked taxonomy 4280 console.log( tax, 'tax' ); 4281 // console.log( btn, 'btn' ); 4282 // console.log( variations, 'variations' ); 4283 4284 // console.log( $('.attribute-btn.active'), 'ACTIVE BUTTONS ' ); 4285 let selectedAttributes = []; 4286 let selectedTax = []; 4287 let arVariations = []; 4288 let currentPanel = ''; 4289 4290 4291 var attributes = getChosenAttributes( variationForm ), 4292 currentAttributes = attributes.data; 4293 var checkAttributes = $.extend( true, {}, currentAttributes ); 4294 var matching_variations = OcWooFindMatchingVariations(variations, checkAttributes );
4295 console.log( matching_variations, 'matching_variations' ); 4296 console.log( checkAttributes, 'checkAttributes' ); 4297 4298 4299 4300 // if ( $('.attribute-btn.active').length > 0 ){ 4301 // // console.log( 'el' ); 4302 // $('.attribute-btn.active').each( function( index, el ){ 4303 // let panel = $(el).closest('.buttons-attrs-panel--wrapper'); 4304 // let panelTax = panel.data('tax') 4305 // // selectedAttributes.push( 'attribute_' + panel.data('tax') ); 4306 4307 // selectedTax.push( 'attribute_' + panel.data('tax') ); 4308 // selectedAttributes.push( $(el).data('val') ); 4309 4310 // // console.log( panel.data('tax'), 'panel tax' ); 4311 // // console.log( el, 'el' ); 4312 // }); 4313 4314 // $('.attribute-btn').each( function( index, el ){ 4315 // let panel = $(el).closest('.buttons-attrs-panel--wrapper'); 4316 // let panelTax = panel.data('tax'); 4317 4318 // // if ( !selectedAttributes.includes( property ) ){ 4319 4320 // // } 4321 // // panel to update 4322 // if ( panelTax !== tax ){ 4323 // console.log( $(el), 'el ' ); 4324 // console.log( $(el).data('val'), 'el.data.vak ' ); 4325 4326 // for (var i = matching_variations.length - 1; i >= 0; i--) { 4327 // if ( typeof ( matching_variations[i] ) !== 'undefined' ){ 4328 // var attributes = matching_variations[i].attributes; 4329 // console.log( attributes, 'attributes' ); 4330 // console.log( matching_variations[i].is_in_stock, '.is_in_stock' ); 4331 4332 // } 4333 // } 4334 4335 // } 4336 // }); 4337 // } 4338 4339 // console.log( selectedAttributes, 'selectedAttributes' ); 4340 // console.log( selectedTax, 'selectedTax' ); 4341 // console.groupEnd(); 4342 4343 // return; 4344 4345 for ( var i = variationsLength; i >= 0; i-- ) { 4346 if ( typeof ( variations[i] ) !== 'undefined' ){ 4347 var variation = variations[i]; 4348 var variationAttributeVal = variation.attributes; 4349 console.group( 'VARIATIOB' ); 4350 // console.log( variationAttributeVal, 'variationAttributeVal' ); 4351 4352 if ( typeof variationAttributeVal === 'object' ){ 4353 // console.log( variationAttributeVal, 'variationAttributeVal' ); 4354 4355 for (const property in variationAttributeVal) { 4356 // console.log(`${property}: ${variationAttributeVal[property]}`); 4357 let objectVal = variationAttributeVal[property]; 4358 // console.log( property, 'property' ); 4359 console.log( objectVal, 'objectVal' ); 4360 // checked attributes 4361 4362 // here select only variation with selected attributes ! 4363 if ( selectedTax.includes( property ) ){ 4364 if ( selectedAttributes.includes( objectVal ) ){ 4365 console.log( property , 'property' ) 4366 console.log( objectVal , 'objectVal' ); 4367 arVariations.push( variation ); 4368 } 4369 } 4370 4371 // if ( selectedAttributes.includes( property ) ){ 4372 // console.log( objectVal, 'objectVal' ); 4373 // console.log( variation.is_in_stock, 'variation' ); 4374 // } 4375 4376 } 4377 } 4378 4379 4380 console.groupEnd(); 4381 } 4382 }; 4383 // console.log( arVariations, 'arVariations' ); 4384 console.group('START LOOP '); 4385 4386 for ( var i = arVariations.length - 1; i >= 0; i-- ) { 4387 // console.log( arVariations[i], 'arVariations[i]' ); 4388 console.log( arVariations[i].attributes, 'arVariations[i].attributes' ); 4389 console.log( arVariations[i].is_in_stock, 'arVariations[i].is_in_stock' ); 4390 } 4391 console.groupEnd(); 4392 } 4393 4394 // copy from woocommerce 4395 var OcWooVariationisMatch = function( variation_attributes, attributes ) { 4396 var match = true; 4397 for ( var attr_name in variation_attributes ) { 4398 if ( variation_attributes.hasOwnProperty( attr_name ) ) { 4399 var val1 = variation_attributes[ attr_name ]; 4400 var val2 = attributes[ attr_name ]; 4401 if ( val1 !== undefined && val2 !== undefined && val1.length !== 0 && val2.length !== 0 && val1 !== val2 ) { 4402 match = false; 4403 } 4404 } 4405 } 4406 return match; 4407 }; 4408 4409 4410 var OcWooFindMatchingVariations = function( variations, attributes ) { 4411 var matching = []; 4412 for ( var i = 0; i < variations.length; i++ ) { 4413 var variation = variations[i]; 4414 4415 if ( OcWooVariationisMatch( variation.attributes, attributes ) ) { 4416 matching.push( variation ); 4417 } 4418 } 4419 return matching; 4420 }; 4421 4422 // var getChosenAttributes = function(form) { 4423 // var data = {}; 4424 // var count = 0; 4425 // var chosen = 0; 4426 // form.find('.variations select').each( function() { 4427 // var attribute_name = $( this ).data( 'attribute_name' ) || $( this ).attr( 'name' ); 4428 // var value = $( this ).val() || ''; 4429 // if ( value.length > 0 ) { 4430 // chosen ++; 4431 // } 4432 // count ++; 4433 // data[ attribute_name ] = value; 4434 // }); 4435 // return { 4436 // 'count' : count, 4437 // 'chosenCount': chosen, 4438 // 'data' : data 4439 // }; 4440 // }; 4441 4442 // console.clear(); 4443 // check 4444 function remove_product_out_of_stock_from_data( attribute, tax, btn ){ 4445 // console.clear(); 4446 // // START 4447 // console.group( 'remove_product_out_of_stock_from_data' ); 4448 // // // console.log( sizeTax, 'sizeTax' ); 4449 // // // console.log( colorTax, 'colorTax' ); 4450 // // // console.log( tax, 'tax' ); 4451 // console.log( tax, 'tax as param ' ); 4452 // console.groupEnd(); 4453 4454 // console.group( 'remove_product_out_of_stock_from_data|| START ' ); 4455 // console.log( tax, 'tax' ); 4456 // // console.log( attribute, 'attribute as parametr ' ); 4457 // console.groupEnd(); 4458 4459 var variationForm = $('form.variations_form.cart'); 4460 if ( variationForm.length == 0 ){ 4461 return; 4462 } 4463 4464 // tax = tax.toLowerCase(); 4465 // console.log( tax, 'tax + lowercase at beginign ' ); 4466 // // fixed hebrew compability ! 4467 // tax = tax.replace( 'pa_', '' ).trim(); 4468 // console.log( tax, 'tax after replace ' ); 4469 // tax = encodeURI(tax); 4470 // tax = tax.toLowerCase(); 4471 // tax = tax.replace( 'NaN', '' ); 4472 // console.log( tax, 'tax after encodeURI ' ); 4473 // tax = 'pa_' + tax; 4474 // tax = encodeURIComponent( tax ); 4475 4476 // console.log( tax, 'tax encodeURI + lowercase! + repalce NAN !!!!!' ); 4477 4478 // console.log( colorTax, 'colorTax' ); 4479 // console.log( sizeTax, 'sizeTax' ); 4480 4481 var arOutOfStock = []; 4482 var parent = $('div.product .summary'); 4483 var variations = JSON.parse( variationForm.attr('data-product_variations') ); 4484 var variationsLength = variations.length - 1; 4485 // var numberReg = new RegExp(/[1-9]\d{0,3}/); 4486 var taxNameToExclude = ( tax == sizeTax ) ? colorTax : sizeTax ; 4487 var fullTaxName = 'attribute_' + tax; 4488 var fullTaxNameToExclude = 'attribute_' + taxNameToExclude; 4489 var panelToUpdate = parent.find('.buttons-attrs-panel--wrapper[data-tax="'+taxNameToExclude+'"]'); 4490 var secondPanel = parent.find('.buttons-attrs-panel--wrapper[data-tax="'+tax+'"]'); 4491 var attrBtns = panelToUpdate.find('.attribute-btn'); 4492 var secondPanelButtons = secondPanel.find('.attribute-btn'); 4493 var attributes = parent.find('.size-attribute .attribute-btn'); 4494 var selectedSize = parent.find('.size-attributes-container .attribute-btn.active'); 4495 var selectedColor = parent.find('.color-attributes-container .attribute-btn.active'); 4496 var maxq = 1; 4497 var variationId = false 4498 let sizeVal = selectedSize.data('val'); 4499 let colorVal = selectedColor.data('val'); 4500 let colorText = selectedColor.attr('aria-label'); 4501 4502 let addToCart = parent.find('button.single_add_to_cart_button'); 4503 var quantity = parent.find('input.input-text.qty'); 4504 var arInstock = []; 4505 var variationAvailability = false;
4506 4507 // console.log( variations[0].attributes, 'variations attributes' ); 4508 // fullTaxName currently clicked panel !!! 4509 // loop through all vairiation 4510 for ( var i = variationsLength; i >= 0; i-- ) { 4511 var variation = variations[i]; 4512 var variationAttributeVal = variation.attributes[fullTaxName]; 4513 var variationIsInstock = false; 4514 4515 // console.log( variation, 'variation' ); 4516 // console.log( variationAttributeVal, 'variationAttributeVal' ); 4517 // console.log( attribute, 'attribute' ); 4518 // console.log( fullTaxName, 'fullTaxName' ); 4519 4520 // console.log( '-------------------------------------------------------' ); 4521 // only for current attribute 4522 /* 4523 if ( variationAttributeVal == attribute ){ 4524 4525 if ( variation.availability_html != '' ){ 4526 let avaiabilityHtml = variation.availability_html; 4527 if ( avaiabilityHtml.indexOf('in-stock') != -1 ){ 4528 variationIsInstock = true; 4529 } 4530 } 4531 // console.log( variationIsInstock, 'variationIsInstock' ); 4532 4533 if ( !variation.is_in_stock ){ 4534 arOutOfStock.push( variation.attributes ); 4535 // if ( !variationIsInstock ){ 4536 // } 4537 } else { 4538 // added instock value 4539 // if ( variation.availability_html ){} 4540 // console.log( variation , 'variation' ); 4541 4542 arInstock.push( variation.attributes[fullTaxNameToExclude] ); 4543 // if ( variationIsInstock ) { 4544 // } 4545 } 4546 } 4547 */ 4548 if ( !variation.is_in_stock ){ 4549 arOutOfStock.push( variation.attributes ); 4550 } else { 4551 arInstock.push( variation.attributes[fullTaxNameToExclude] ); 4552 } 4553 }; 4554 4555 attrBtns.removeClass('inactive'); 4556 4557 // set attribute next to attribute label 4558 let nameAttr = secondPanel.find( '.attribute-name' ); 4559 if ( nameAttr.length > 0 ){ 4560 nameAttr.addClass('selected-value') 4561 4562 // console.group( 'Selected attr' ) 4563 // console.log( attribute, 'attribute' ); 4564 // console.log( attribute, 'attribute' ); 4565 // console.log( btn, 'btn' ); 4566 // console.groupEnd( '' ) 4567 // nameAttr.html( decodeURI( attribute ) ); 4568 4569 if ( $(btn).closest( '.buttons-attrs-panel--wrapper' ).length ) { 4570 let buttonText = ''; 4571 // slug in product attributes sometimes in hebrew 4572 if ( $(btn).closest( '.buttons-attrs-panel--wrapper' ).hasClass('color-attributes-container') ){ 4573 buttonText = decodeURI( colorText ); 4574 } else { 4575 buttonText = $(btn).html(); 4576 } 4577 nameAttr.html( buttonText ); 4578 } 4579 } 4580 4581 // new way 4582 /* 4583 for (var i = arOutOfStock.length - 1; i >= 0; i--) { 4584 var termId = arOutOfStock[i][fullTaxNameToExclude]; 4585 var inactiveValue = panelToUpdate.find('.attribute-btn[data-val="'+termId+'"]'); 4586 $(inactiveValue).addClass('inactive'); 4587 }; 4588 */ 4589 // work for 2 attributes 4590 /* 4591 for (var i = variationsLength; i >= 0; i--) { 4592 var variation = variations[i]; 4593 var attributes = variation.attributes; 4594 var color = attributes[ 'attribute_' + colorTax ]; 4595 var size = attributes[ 'attribute_' + sizeTax ]; 4596 if ( color == colorVal && size == sizeVal ){ 4597 if ( variation.is_in_stock ){ 4598 maxq = variation.max_qty; 4599 variationId = variation.variation_id; 4600 } 4601 } 4602 }; 4603 */ 4604 4605 // if ( panelToUpdate.find('.attribute-btn').length && taxNameToExclude != colorTax ){ 4606 // panelToUpdate.find('.attribute-btn').each( function( i, el ){ 4607 // var value = $(el).data('val'); 4608 // if ( arInstock.includes( value ) === false ){ 4609 // $(el).addClass('inactive') 4610 // $(el).removeClass('active') 4611 // } else { 4612 // $(el).removeClass('inactive') 4613 // } 4614 // // console.log( value, 'value' ); 4615 // }); 4616 // } 4617 4618 4619 var currentButtonValue = $(btn).data('val'); 4620 4621 // loop throug all attribute panels and 4622 // get object with all outofstock 4623 let arData = {}; 4624 let allAttributePanels = parent.find('.buttons-attrs-panel--wrapper'); 4625 if ( arOutOfStock.length> 0 ){ 4626 for (var i = arOutOfStock.length - 1; i >= 0; i--) { 4627 let element = arOutOfStock[i]; 4628 if ( element ){ 4629 for (const property in element) { 4630 if ( !arData[property] ){ 4631 arData[property] = []; 4632 } 4633 4634 // console.log( 'add only if nessesarry ' ); 4635 if ( !arData[property].includes( element[property] ) ){ 4636 arData[property].push( element[property] ) 4637 } 4638 // console.log(`${property}: ${element[property]}`); 4639 } 4640 } 4641 // console.log( element, 'element' ); 4642 } 4643 4644 console.group( 'TEST !' ); 4645 console.log( arData, 'arData' ); 4646 // console.log( btn, 'btn' ); 4647 console.log( currentButtonValue, 'currentButtonValue' ); 4648 4649 // console.log( panelToUpdate, 'panelToUpdate' ); 4650 console.log( allAttributePanels, 'allAttributePanels loop ' ); 4651 console.groupEnd(); 4652 4653 // loop trough all panels 4654 if ( allAttributePanels.length > 0 ){ 4655 4656 // console.log( panelToUpdate, 'PANEL TO UPDATE +++ inside ' ); 4657 4658 allAttributePanels.each( function( i, panel ){ 4659 let panelTax = $(panel).data('tax'); 4660 4661 // console.log( panelTax, 'PANEL tax ' ); 4662 4663 if ( panelTax != tax ){ 4664 // console.log( panelTax , 'panelTax, inside condiotion ' ); 4665 // console.log( panel , 'panel ' ); 4666 // console.log( panel.find('.attribute-btn') , 'attr buttin ' ) 4667 4668 // fixed attr name compability ! 4669 // panelTax = encodeURI( panelTax ); 4670 let attributeName = 'attribute_' + panelTax; 4671 let arAttributes = arData[ attributeName ]; 4672 // 4673 let tempTax = 'attribute_' + tax;
4674 let clickedParam = arData[ tempTax ]; 4675 4676 // let arAttributes = arData[ attributeName ]; 4677 4678 console.group( 'panelTax ' ); 4679 // console.log( attributeName, 'attributeName '); 4680 // console.log( arAttributes, 'arAttributes '); 4681 // console.log( arData, 'arData '); 4682 4683 // console.log( tempTax, 'tempTax '); 4684 // console.log( attributeName, 'attributeName '); 4685 // console.log( panelTax, 'panelTax '); 4686 // console.log( arAttributes, 'arAttributes '); 4687 // console.log( clickedParam, 'clickedParam '); 4688 console.log( currentButtonValue, 'currentButtonValue '); 4689 // console.log( clickedParam.includes( currentButtonValue ), 'clickedParam passed attribute '); 4690 4691 $(panel).find('.attribute-btn').each(function(index, el){ 4692 var value = $(el).data('val'); 4693 // variation is not in stock 4694 // if ( arAttributes.includes( value ) != false ){ 4695 // console.log( arAttributes.includes( value ), 'arAttributes.includes( value )' ); 4696 // additional param 4697 4698 if ( clickedParam.includes( currentButtonValue ) != true && arAttributes.includes( value ) == true ){ 4699 console.log( $(el), 'active element first condition remove block !' ); 4700 $(el).removeClass('inactive'); 4701 $(el).removeClass('outstock'); 4702 4703 } else if ( arAttributes.includes( value ) != false ){ 4704 // console( $(el), 'inactive element !' ); 4705 // console.log( 'not in stock!' ) 4706 $(el).addClass('inactive'); 4707 $(el).removeClass('active'); 4708 4709 $(el).addClass('outstock'); 4710 4711 } else { 4712 $(el).removeClass('inactive'); 4713 $(el).removeClass('outstock'); 4714 4715 console.log( $(el), 'active element !' ); 4716 } 4717 4718 console.log('___________________'); 4719 }); 4720 4721 console.groupEnd( 'panelTax' ); 4722 } 4723 // allAttributePanels.log( value, 'value' ); 4724 }); 4725 } 4726 } 4727 4728 // console.group( 'remove_product_out_of_stock_from_data ' ); 4729 // console.log( arOutOfStock, 'arOutOfStock'); 4730 // console.log( variationId, 'variationId !!!!!!!!!!'); 4731 // console.groupEnd(); 4732 4733 // console.log( arInstock, 'arInstock'); 4734 // console.log( tax, 'tax'); 4735 // max value to quantity button 4736 quantity.attr( 'max', maxq ); 4737 4738 return; 4739 // This is 4740 if ( variationId ){ 4741 $('.woocommerce-variation-add-to-cart input.variation_id').val( variationId ); 4742 addToCart.removeClass( 'disabled wc-variation-is-unavailable' ); 4743 } else { 4744 // console.log( 'add disabled class ' ); 4745 // if variation id false block add to cart dutton 4746 addToCart.addClass( 'disabled wc-variation-is-unavailable' ); 4747 } 4748 } 4749 4750 // reinit photoswipe on click 4751 $(document).on('click', 'div.product .woocommerce-product-gallery__image a', function(e){ 4752 // return 4753 // e.preventDefault(); 4754 let colorSelect = $('select#' + colorTax ); 4755 let colorval = $('.color-attributes-container button.attribute-btn.active').val(); 4756 4757 e.preventDefault(); 4758 // NEW 4759 // let galleryWrapper = $(this).closest('.woocommerce-product-gallery__inner'); 4760 // console.log( galleryWrapper.hasClass( 'initial-block' ), 'has class initial-block' ); 4761 // if ( galleryWrapper.hasClass( 'initial-block' ) ){ 4762 // return; 4763 // } 4764 4765 console.group( 'clic kwoocommerce-product-gallery__image a' ); 4766 4767 // console.log( colorSelect, 'colorSelect' ); 4768 4769 // console.log( colorSelect.children(), 'colorSelect.children()' ); 4770 // console.log( colorval, 'colorval' ); 4771 let currentIndex; 4772 if ( colorSelect.children().length > 2 && colorSelect.hasClass('changed') ){} 4773 // if ( colorSelect.children().length > 2){ 4774 // if ( $('body').hasClass('product-gallery-mobile-regular-slider') || $('body').hasClass('product-gallery-mobile-center-mode') ){ 4775 if ( $('body').hasClass('product-gallery-mobile-regular-slider') ){ 4776 currentIndex = $(this).parent().index() - 1; 4777 } else { 4778 currentIndex = $(this).parent().index(); 4779 } 4780 4781 // let mainSlider = $('div.product .main-gallery#attr-color-'+colorval + ' .woocommerce-product-gallery__image:not(.slick-cloned)' ); 4782 let mainSlider = $('div.product .main-gallery#attr-color-'+colorval + ' .woocommerce-product-gallery__image:not(.slick-cloned)' ); 4783 // console.log( reinitPhotoswipe, 'reinitPhotoswipe' ); 4784 // console.log( currentIndex, 'currentIndex + div' ); 4785 // console.log( mainSlider.length, 'mainSlider.length ' ); 4786 // console.log( $(this).parent(), '$(this).parent() ' ); 4787 4788 if ( mainSlider.length == 0 ){ 4789 currentIndex = $(this).closest( '.woocommerce-product-gallery__image' ).data( 'slick-index' ) ; 4790 mainSlider = $('div.product .woocommerce-product-gallery__inner:not(.main-gallery) .woocommerce-product-gallery__image:not(.slick-cloned)' ); 4791 // galleryWrapper.addClass( 'initial-block' ) 4792 // console.log( currentIndex, 'currentIndex if slider is emty ' ); 4793 } 4794 4795 // make index for one-per-row or two-per-row 4796 if ( $('body').hasClass( 'product-gallery-one-per-row' ) || $('body').hasClass( 'product-gallery-two-per-row' ) ){ 4797 currentIndex = $(this).parent().data('index'); 4798 // console.log( currentIndex, 'currentIndex + ONE_ROW' ); 4799 } 4800 4801 // console.log( mainSlider, 'mainSlider before reinit photoswipe' ); 4802 console.groupEnd(); 4803 // $('div.product .woocommerce-product-gallery__inner .woocommerce-product-gallery__image:not(.slick-cloned)' ); 4804 4805 reinitPhotoswipe( mainSlider, currentIndex ); 4806 4807 }); 4808 4809 // need init on woo-gallery a click 4810 function reinitPhotoswipe( mainSlider, indexStart ){
4811 let $pswp = $('.pswp')[0]; 4812 // move to global 4813 let items; 4814 let options = { 4815 index: indexStart, 4816 }; 4817 let newItems = []; 4818 4819 // console.group( mainSlider, 'mainSlider before !!!! ' ); 4820 4821 // mainSlider.find('.woocommerce-product-gallery__image').each( function(index, el) { 4822 console.log(mainSlider, 'mainSlider'); 4823 mainSlider.each( function(index, el) { 4824 // let $pic = $(this); 4825 if ( !$(el).hasClass('slick-cloned') ){ 4826 4827 $(el).find('a').each(function(i, el) { 4828 console.log('uno'); 4829 // console.log( el, 'el' ); 4830 let $href = $(el).attr('href'); 4831 let item = { 4832 src : $href 4833 } 4834 let img = $(el).find('img') 4835 if(img.length == 0) return; 4836 if ( typeof img != 'undefined' && img.length > 0 ){ 4837 item.w = img.attr( 'data-large_image_width' ); 4838 item.h = img.attr('data-large_image_height'); 4839 } 4840 newItems.push(item); 4841 }); 4842 } 4843 }); 4844 // console.log( options, 'options ' ) 4845 // console.log( newItems, 'newItems ' ) 4846 // console.groupEnd() 4847 4848 // let initialPhotoswap = new PhotoSwipe( $pswp, PhotoSwipeUI_Default ); 4849 // initialPhotoswap.destroy(); 4850 // console.log( initialPhotoswap, 'initialPhotoswap' ); 4851 console.log($pswp); 4852 console.log(PhotoSwipeUI_Default); 4853 console.log(newItems); 4854 console.log(options); 4855 let lightBox = new PhotoSwipe( $pswp, PhotoSwipeUI_Default, newItems, options ); 4856 console.log( lightBox, 'lightBox' ); 4857 // lightBox.destroy(); 4858 lightBox.init(); 4859 4860 // console.log( 'DESTROY photoswipe !!!!!!' ); 4861 // return; 4862 4863 lightBox.listen('destroy', function() { 4864 // let container = $('.pswp'); 4865 // container.css({'visibility': 'hidden'}); 4866 // lightBox.close(); 4867 // console.log( 'Destroy, use method desctroy, renomove class' ) 4868 // console.log( lightBox, 'lightBox' ) 4869 // console.log( $pswp, '$pswp' ); 4870 4871 $('.pswp').removeClass('pswp--open'); 4872 lightBox.destroy(); 4873 // $(window).resize(); 4874 }); 4875 } 4876 4877 var originalBreadcrumbs; 4878 // for get product via ajax problem 4879 if ( $('body').hasClass( 'single-product' ) ){ 4880 originalBreadcrumbs = $('.summary.entry-summary .woocommerce-breadcrumb').clone(); 4881 originalBreadcrumbs.hide(); 4882 4883 $('.site-main div.product').after('<div class="hidden-breadcrumbs" style="display:none;">' + originalBreadcrumbs.html() + '</div>'); 4884 } 4885 4886 // console.log( originalBreadcrumbs, 'originalBreadcrumbs' ) 4887 4888 // On connected product get via ajax ! 4889 $(document).on( 'click', '.color-attributes-container .connected-product-color', function(e){ 4890 $('body').addClass( 'additional-product-colors' ); 4891 let productContainer = $(this).closest('div.product'); 4892 let color = $(this).data('color'); 4893 var product_id = $(this).val(); 4894 4895 // let connectedProduct = $('.connected-product') 4896 // if ( connectedProduct.length > 0 ){ 4897 // // productContainer.replaceWith( connectedProduct.html() ) 4898 // } 4899 e.preventDefault(); 4900 4901 // console.log( productContainer, 'productContainer | on connected color click' ); 4902 4903 // additiobnal popup 4904 if ( productContainer.length == 0 ){ 4905 // console.log( productContainer, 'productContainer | POPUP' );
4906 productContainer = $(this).closest('.oc-variable-product-upsells-popup--inner'); 4907 4908 console.log( "I AM HERE !!!!" ); 4909 console.log( color, "color" ); 4910 console.log( product_id, "product_id" ); 4911 4912 oc_connected_color_for_upsells( productContainer, product_id ); 4913 return; 4914 } 4915 4916 productContainer.css({ 4917 opacity: 0.5 4918 }); 4919 4920 4921 $.ajax({ 4922 type: 'POST', 4923 dataType: 'json', 4924 url: woocommerce_params.ajax_url, 4925 data: { 4926 action: "oc_get_color_connected_product", 4927 product_id: product_id, 4928 }, 4929 success: function(response) { 4930 var objResponse = $(response); 4931 4932 // console.log( $(response, '<div class="product">'), '$.response div product' ); 4933 // console.log( objResponse.find( 'div.product' ), '$.objResponse product' ); 4934 4935 // $(response).find( '.related.products' ).remove(); 4936 if ( $(response).length > 0 ){ 4937 // $(response).each( function(i, el){ 4938 // let attributeID = $(el).attr('id'); 4939 // console.log( attributeID, 'attributeID' ); 4940 // if ( typeof attributeID != undefined && attributeID != '' ){ 4941 // console.log( $(el), '$(el) 1111111111' ); 4942 // } 4943 // }) 4944 4945 productContainer.replaceWith( $(response)[1] ); 4946 4947 let breadCrumbsSummary = $('.summary.entry-summary .woocommerce-breadcrumb'); 4948 let title = $( '.product_title.entry-title' ); 4949 4950 // if ( breadCrumbsSummary.length > 0 && originalBreadcrumbs.length > 0 ){ 4951 $('.hidden-breadcrumbs').find('.crumb').html( title.html() ); 4952 breadCrumbsSummary.html( $('.hidden-breadcrumbs').html() ); 4953 // } 4954 4955 // reinit variation form js events 4956 $('form.variations_form.cart').wc_variation_form(); 4957 4958 // console.log( breadCrumbsSummary, 'breadCrumbsSummary' ); 4959 // console.log( originalBreadcrumbs, 'originalBreadcrumbs' ); 4960 // console.log( $('.hidden-breadcrumbs'), 'hidden 1' ); 4961 4962 // make gallry visible 4963 // reinit gallery ! 4964 $('.woocommerce-product-gallery').css({opacity: 1}); 4965 4966 // set first color active 4967 let firstColorBtn = $('.buttons-attrs-panel--wrapper.color-attributes-container .attribute-btn'); 4968 firstColorBtn.first().click(); 4969 if ( $('select#' + colorTax ).length > 0 ){ 4970 $('select#' + colorTax).trigger('change') 4971 } 4972 4973 // console.log( $('.buttons-attrs-panel--wrapper.color-attributes-container .attribute-btn').first(), '.buttons-attrs-panel--wrapper.color-attributes-container .attribute-btn' ); 4974 // reinit accordion 4975 if ( $('body').hasClass('single-product-tab-style-accordion') ){ 4976 $('.wc-tabs-accordion-wrapper').accordion({ 4977 collapsible:true, 4978 heightStyle: "content", 4979 active :false 4980 }); 4981 } 4982 4983 // set quantity placeholder 4984 $('.input-text.qty').attr( 'placeholder', 1 ); 4985 4986 // console.log( $('.woocommerce-product-gallery__inner .woocommerce-product-gallery__image a'), 'IMAGE A' ) 4987 // console.log( $('body.additional-product-colors .woocommerce-product-gallery__inner .woocommerce-product-gallery__image a'), 'NEW A' ) 4988 oc_reasign_photoswipe(); 4989 single_product_gallery_slick(); 4990 4991 $(window).resize(); 4992 4993 if ( $('body').hasClass('product-content-summary-sticky') ){ 4994 $(window).trigger( 'scroll' ) 4995 } 4996 // console.log( 'reload fragmenbts ' ) 4997 // reinit wishlist 4998 if ( $('body').hasClass('single-product') ){ 4999 $(document).trigger( 'yith_wcwl_reload_fragments' ); 5000 } else { 5001 console.log( 'NOT need for reload fragment s !!!' ); 5002 5003 } 5004 5005 // console.log( 'change.wc-variation-form !!!!!!!!!!!!!' ); 5006 $('.variations select').trigger( 'change.wc-variation-form' ); 5007 5008 5009 // console.log( 'check_variations !!!' ); 5010 // $( '.variations_form' ).each( function() { 5011 // $( this ).wc_variation_form(); 5012 // console.log( 'addd !!!!!!!!!!' ) 5013 // }); 5014 5015 // $('form.variations_form').trigger( 'check_variations' ); 5016 5017 // console.group( 'check_variations' ); 5018 // console.log( $('form.variations_form'), 'form.variations_form' ); 5019 // console.groupEnd( 'check_variations' ); 5020 5021 // console.log( '!!!' ); 5022 // let currentIndex = 0; 5023 // let mainSlider = $('.woocommerce-product-gallery__inner' ); 5024 // reinitPhotoswipe( mainSlider, currentIndex ); 5025 } 5026
5027 productContainer.css({ 5028 opacity: 1 5029 }); 5030 5031 // productContainer.removeClass('preloader') 5032 5033 }, 5034 error: function( response ){ 5035 console.log(response, 'response') 5036 }, 5037 complete: function( res ){ 5038 } 5039 }); 5040 }); 5041 5042 // connected color for upsells 5043 function oc_connected_color_for_upsells( productContainer, product_id ){ 5044 // console.clear(); 5045 5046 $('.drawer-panel.cart-panel').addClass('panel-under'); 5047 5048 // productContainer.css({ 5049 // opacity: 0.1 5050 // }); 5051 5052 console.log( productContainer, 'ADD PRELOADer ') 5053 // productContainer.addClass('preloader'); 5054 $('.oc-variable-product-upsells-popup--container').addClass('preloader'); 5055 5056 $.ajax({ 5057 type: 'POST', 5058 dataType: 'json', 5059 url: woocommerce_params.ajax_url, 5060 data: { 5061 action: "oc_get_variable_product_upsell_popup", 5062 product_id: product_id, 5063 }, 5064 success: function(response) { 5065 // console.log( response, 'response' ); 5066 if ( response.data ){ 5067 let inner = $(response.data); 5068 // console.log( response.data, 'response.data' ); 5069 // console.log( inner, 'inner html ' ); 5070 console.log( productContainer, 'productContainer ' ); 5071 5072 // console.log( $(response.data).find('.oc-variable-product-upsells-popup--inner'), '$.response' ); 5073 productContainer.find('.oc-variable-product-upsells-container').html( response.data ); 5074 5075 let firstColorBtn = productContainer.find('.buttons-attrs-panel--wrapper.color-attributes-container .attribute-btn'); 5076 firstColorBtn.first().click(); 5077 5078 // reinit variation form 5079 productContainer.find('form.variations_form.cart').wc_variation_form(); 5080 5081 // alert("BEFORE INSERT !"); 5082 // console.group('start group'); 5083 // console.log( inner, 'inner' ); 5084 // console.log( firstColorBtn, 'firstColorBtn' ); 5085 // console.log( firstColorBtn.first(), 'firstColorBtn.first()' ); 5086 // console.groupEnd(''); 5087 } 5088 // productContainer.css({ 5089 // opacity: 1 5090 // }); 5091 // productContainer.removeClass('preloader'); 5092 $('.oc-variable-product-upsells-popup--container').removeClass('preloader'); 5093 // $('.drawer-panel.cart-panel').removeClass('panel-under'); 5094 }, 5095 error: function(error) { 5096 productContainer.removeClass('preloader'); 5097 // $('.drawer-panel.cart-panel').removeClass('panel-under'); 5098 } 5099 }); 5100 } 5101 5102 $(document).on( 'click', '.oc-variable-product-upsells-popup--container .close-button', function(e){ 5103 $('.oc-variable-product-upsells-popup--container').removeClass('active'); 5104 $('.drawer-panel.cart-panel').removeClass('panel-under'); 5105 // $('.oc-variable-product-upsells-popup--container').addClass('hidden') 5106 }) 5107 5108 // 5109 function oc_reasign_photoswipe(){ 5110 // console.group( 'oc_reasign_photoswipe!!!!!!!!!!!!' ); 5111 $(document).off('click', 'div.product .woocommerce-product-gallery__image a'); 5112 5113 // Reinit photoSwipe 5114 $(document).on('click', 'div.product .woocommerce-product-gallery__image a', function(e){ 5115 e.preventDefault(); 5116 let currentIndex = 0; 5117 5118 if ( $(this).parent().hasClass('slick-slide') ){ 5119 if ( $(this).parent().data('data-slick-index') ){ 5120 5121 currentIndex = $(this).parent().data('data-slick-index'); 5122 } else { 5123 5124 currentIndex = $(this).parent().index() - 1 ; 5125 } 5126 } else{ 5127 currentIndex = $(this).parent().index(); 5128 } 5129 if ($(this).closest('.woocommerce-product-gallery__inner').children('.oc-product-video-container').length > 0) { 5130 currentIndex = currentIndex + 1; 5131 } 5132 let mainSlider = $('div.product .woocommerce-product-gallery__inner:not(.main-gallery) .woocommerce-product-gallery__image.slick-slide:not(.slick-cloned)' ); 5133 if ( $('body').hasClass('product-gallery-one-per-row') || $('body').hasClass('product-gallery-two-per-row') ) { 5134 mainSlider = $('div.product .woocommerce-product-gallery__inner .woocommerce-product-gallery__image'); 5135 5136 } 5137 reinitPhotoswipe( mainSlider, currentIndex ); 5138 }); 5139 5140 } 5141 $('.woocommerce-product-gallery__wrapper').css('opacity', '1'); 5142 $('.woocommerce-product-gallery__wrapper').css('min-height', '465px'); 5143 5144 // on page load if there is size in url 5145 function on_single_product_load_size_select(){ 5146 if ( $('body').hasClass( 'single-product' ) ){ 5147 let locationSearch = window.location.hash; 5148 5149 if ( $('body').hasClass('product-content-summary-sticky') ){ 5150 $(window).trigger( 'scroll' ) 5151 } 5152 5153 // console.group( 'on_single_product_load_size_select' ); 5154 // console.log( locationSearch, 'locationSearch' ); 5155 // console.log( locationSearch.indexOf( sizeTax ), 'indexOf sizetax' ); 5156 // console.log( window.location, 'window.location' ); 5157 if ( colorTax != '' ){ 5158 if ( locationSearch.indexOf( colorTax ) != -1 ){
5159 let colorVal = locationSearch.replace( '#' + colorTax + '=' , '' ); 5160 let colorBtn = $('.buttons-attrs-panel--wrapper.color-attributes-container button.attribute-btn[value="'+colorVal+'"]'); 5161 5162 if (colorBtn.length ){ 5163 colorBtn.click() 5164 } 5165 } else { 5166 let colorBtn = $('.buttons-attrs-panel--wrapper.color-attributes-container button.attribute-btn:first'); 5167 // console.log( colorBtn, 'colorBtn'); 5168 if (colorBtn.length ){ 5169 colorBtn.click() 5170 if ( !$('body').hasClass('postid-3194') && !$('body').hasClass('postid-4409') ){ 5171 } 5172 } 5173 } 5174 } 5175 5176 if ( sizeTax != '' ){ 5177 if ( locationSearch.indexOf( sizeTax ) != -1 ){ 5178 // let urlParams = new URLSearchParams( locationSearch ); 5179 // let sizeVal = urlParams.get( sizeTax ); 5180 // let sizeVal = locationSearch.replace( '#' + sizeTax + '=' , '' ); 5181 let sizeVal = false ; 5182 5183 let indexOfAmp = locationSearch.indexOf( '&' ); 5184 if ( indexOfAmp != -1 ){ 5185 let sub = locationSearch.substring( indexOfAmp ); 5186 sizeVal = sub.replace( '&' + sizeTax + '=' , '' ); 5187 } 5188 5189 console.log( indexOfAmp, 'indexOfAmp' ); 5190 // console.log( sizeVal, 'sizeVal' ); 5191 // console.log( urlParams, 'urlParams' ); 5192 5193 // let colorBtn = $('.buttons-attrs-panel--wrapper.color-attributes-container button.attribute-btn:first'); 5194 // console.log( colorBtn, 'colorBtn !!' ); 5195 // if ( colorBtn.length > 0 ){ 5196 // // 5197 // // colorBtn[0].click(); 5198 // colorBtn.click(); 5199 // // colorBtn.trigger('click'); 5200 // console.log( 'color clicked!! ' ) 5201 // console.log( colorBtn[0], 'colorBtn[0]' ); 5202 // } 5203 if ( sizeVal ){ 5204 let sizeBtn = $('.buttons-attrs-panel--wrapper.size-attributes-container button.attribute-btn[data-val='+sizeVal+']'); 5205 if ( sizeBtn.length > 0 ){ 5206 if ( !sizeBtn.hasClass('inactive') && !sizeBtn.hasClass('outstock') ){ 5207 sizeBtn.click( ); 5208 } 5209 // console.log( sizeBtn, 'sizeBtn' ); 5210 } 5211 5212 } 5213 } 5214 5215 } 5216 // console.groupEnd(); 5217 } 5218 } 5219 5220 on_single_product_load_size_select(); 5221 // recently-viewed-products-container 5222 // $('.recently-viewed-products-container ul.products').slick({ 5223 // slidesToShow: 1, 5224 // slidesToScroll:1, 5225 // rtl: rtl, 5226 // }); 5227 5228 //mobile share on image open 5229 if ( $(window).width() < mobileWidth ){ 5230 $('body.woocommerce #content div.product div.images .share-product-links--container').click(function () { 5231 $(this).toggleClass("active"); 5232 }); 5233 } 5234 5235 // scroll to top vertical 5236 $(document).on( 'click', '.vertical-thumbnails--container .top-button', function(){ 5237 // $('.vertical-thumbnails--container').scrollTop() = 100; 5238 // console.log( 'click' ); 5239 // console.log( $('.vertical-thumbnails--container').scrollTop(), 'scrollTop' ); 5240 $('.vertical-thumbnails--container').animate({scrollTop: 150 }, 500); 5241 }); 5242 5243 //scroll to top 5244 $(document).on( 'click', 'a.back-to-top', function(){ 5245 $("html, body").animate({ scrollTop: 0 }, "500"); 5246 }); 5247 5248 $(window).on( 'scroll', function(){ 5249 if($(this).scrollTop() > 600) { 5250 $('a.back-to-top').addClass('active'); 5251 }else{ 5252 $('a.back-to-top').removeClass('active'); 5253 } 5254 }); 5255 5256 // Page speed optimization 5257 $(window).on( 'load', function(){ 5258 // oc_open_front_page_blocks(); 5259 // let nagishutUrl = 'https://cdn.userway.org/widget.js'; 5260 // $('<script>').attr('data-account', 'T1PAnIqMjH').attr('src', nagishutUrl).appendTo('body'); 5261 // window.scrollTo(window.scrollX, window.scrollY - 1); 5262 }); 5263 5264 // speed optimization: include script of nagishut via ajax 5265 $(document).ready( function(){ 5266 // console.log( 'DOC READY, load script ' ) 5267 setTimeout( function(){ 5268 //let nagishutUrl = 'https://cdn.userway.org/widget.js'; 5269 //$('<script>').attr('data-account', 'T1PAnIqMjH').attr('src', nagishutUrl).attr('defer', 'defer').appendTo('body'); 5270 // console.clear(); 5271 }, 1500 ) 5272 }); 5273 5274 // click on button panel, button display type 5275 $(document).on( 'click', '.oc-product-variable-panel button.attribute-button', function(){ 5276 // clciked attribute panel 5277 let val = $(this).val(); 5278 let slug = $(this).data( 'slug' ); 5279 let panel = $(this).closest( '.oc-product-variable-panel' ); 5280 // closest productBox 5281 let product = $(this).closest( '.product' ); 5282 // get object for checking variation 5283 let variationObject = product.find('.product-available-variations-object'); 5284 let variations = variationObject.data('variations'); 5285 // temp ! need get field value ! 5286 let product_id = variationObject.data( 'product_id' ); 5287 let quantity = 1; 5288 let matched = ''; 5289 let li = $(this).closest( 'li' ); 5290 // new message 5291 mobilePanel = product.find( '.oc-product-quick-add-to-cart-panel-1.mobile' ); 5292 let variationMessage = mobilePanel.find('.availability-variation'); 5293 // moved 5294 panel.attr( 'data-value', slug ); 5295 // can`t click on outofstock 5296 if ( $(this).hasClass('outofstock') ){ 5297 // console.log( 'outofstock' ) 5298 return; 5299 } 5300 5301 // $(this).siblings().removeClass('active'); 5302 5303 // up 1 level 5304 // add active class only to current button 5305 li.siblings().find('button').removeClass('active'); 5306 $(this).addClass('active'); 5307 // set slug to panel attr 5308 // panel.attr( 'data-value', val ); 5309 var attrs = getChosenAttributes( product ); 5310 5311 // console.group( 'CLICK on !!!!!!!! + button.attribute-button' ); 5312 // console.log( slug, 'slug' ); 5313 // console.log( $(this).siblings(), 'siblings' ); 5314 // console.log( $(this), 'this' ); 5315 // console.log( panel, 'panel' ); 5316 // console.log( val, 'val' ); 5317 // console.groupEnd(); 5318 // 5319 let attributeTitle = panel.find('.attr-title'); 5320 if ( attributeTitle.length > 0 ){ 5321 attributeTitle.find('.selected-attribute').html( $(this).html() ) 5322 } 5323 5324 // var addToCartVariationCallback = add_to_cart_variation_callback( $(this) ); 5325 var addToCartVariationCallback = ''; 5326 var mobileAddToCart = product.find('.mobile .add-to-cart-mobile'); 5327 var addToCartIco = product.find('.add-to-cart-icon'); 5328 5329 if ( attrs ){ 5330 matched = ocFindMatchingVariations( variations, attrs.data ); 5331 5332 // console.log( attrs, 'attrs passed !!!!' ); 5333 console.log( matched, 'matched AFTER' ); 5334 // console.log( attrs.data, 'attrs.data' ); 5335 5336 // variation found !!!!!!!!!! 5337 if ( attrs.count && attrs.count === attrs.chosenCount ) { 5338 variation = matched.shift(); 5339 var variation_id = variation.variation_id; 5340 5341 // console.log( matched, 'matched' ) 5342 // console.log( variationSecond, 'variationSecond shift ' ) 5343 // console.log( variation, 'variation' ); 5344 // console.log( product_id, 'product_id' ); 5345 // console.log( variation_id, 'variation_id' ); 5346 5347 if ( !isMobile() ){ 5348 // console.log( variation.is_in_stock, 'variation.is_in_stock' ); 5349 panel.removeClass('active'); 5350 add_to_cart_variation_callback( $(this) ); 5351 5352 //remove slug 5353 // panel.attr( 'data-value', '' ); 5354 // console.log( 'ATTR DATA VLUE ' ); 5355 product.find( '.oc-product-variable-panel' ).attr( 'data-value', '' ); 5356 addToCartAjax( product_id, variation_id, quantity, $(this), addToCartVariationCallback ); 5357 5358 } else { 5359 mobileAddToCart.removeClass('disabled'); 5360 variationMessage.addClass('hidden'); 5361 } 5362 } else { 5363 // alert('Need to choose some attributes '); 5364 mobileAddToCart.addClass('disabled'); 5365 // variationMessage.removeClass('hidden'); 5366 } 5367 } else { 5368 mobileAddToCart.addClass('disabled'); 5369 // variationMessage.removeClass('hidden'); 5370 // addToCartIco.removeClass('disabled'); 5371 } 5372 5373 // console.log( panel, 'panel ' ); 5374 // console.log( attrs, 'attrs ' ); 5375 // console.log( matched, 'matched ' ); 5376 // console.log( variation, 'variation FOUND !!!! ' ); 5377 // console.log( panel, 'panel ' ); 5378 // console.log( slug, 'slug ' ); 5379 // console.log( val, 'val ' ); 5380 // console.log( product, 'product ' ); 5381 // console.log( variations, 'variations' ); 5382 console.groupEnd(); 5383 }); 5384 5385 // 5386 // function oc_check_minicart_for_product( product_id, variation_id ){ 5387 // console.log( 'oc_check_minicart_for_product' ); 5388 // let minicartItem = $('.mini-cart-widget--container .woocommerce-mini-cart li.mini_cart_item'); 5389 // if ( minicartItem.length > 0 ){ 5390 // minicartItem.each( function( index, cartItem ){ 5391 // // console.log( cartItem, 'cartItem' ); 5392 // }); 5393 // } 5394 // } 5395 5396 // oc_check_minicart_for_product( false, false ) 5397 // close closest button panel 5398 $(document).on( 'click', '.oc-product-variable-panel button.close-panel', function(){ 5399 // console.log( ' close click!' ) 5400 let panel = $(this).closest('.oc-product-variable-panel'); 5401 panel.removeClass('active'); 5402 }); 5403 5404 // console.log( $('.oc-product-quick-add-to-cart-panel-1 button.close-panel'), '.oc-product-variable-panel-1 button.close-panel' ); 5405 5406 // close closest button panel 5407 $(document).on( 'click', '.oc-product-quick-add-to-cart-panel-1 button.close-panel', function(){ 5408 // console.log( ' close click! !!!!!!!!!!!' ) 5409 if ( isMobile() ){ 5410 let product = $(this).closest('.product'); 5411 let mobilePanelToShow = product.find( '.oc-product-quick-add-to-cart-panel-1.mobile' ); 5412 5413 // console.log( 'mobile close !' ) 5414 $('body').removeClass('no-scroll'); 5415 5416 $('.quick-add-to-cart-overlay').removeClass('active'); 5417 mobilePanelToShow.removeClass('active'); 5418 5419 if ( $('body').hasClass( 'single-product' ) ){ 5420 // slider init 5421 if ( $(this).closest('.products.slick-slider').length ){ 5422 // $(this).closest('.products.slick-slider').removeClass('no-transform'); 5423 // $(this).closest('.products.slick-slider').slick('slickPlay'); 5424 } 5425 5426 // console.log( product, 'product' ); 5427 // console.log( product.index(), 'product.index()' ); 5428 let index 5429 if ( product.length > 0 ){ 5430 index = product.index() >= 1 ? product.index() - 1 : 0; 5431 } else { 5432 index = 0; 5433 } 5434 5435 $objRelatedProductSlick = get_related_product_object( index ); 5436 5437 if ( $(this).closest('.products').length && !$(this).hasClass('slick-slider') ){ 5438 // console.log( 'slick init true !' ) 5439 $(this).closest('.products').slick( $objRelatedProductSlick ); 5440 } 5441 } 5442 return; 5443 } 5444 }); 5445 5446 // close overlay 5447 $(document).on( 'click', '.quick-add-to-cart-overlay.active', function(){ 5448 $(this).removeClass('active'); 5449 $( '.oc-product-quick-add-to-cart-panel-1.mobile.active' ).removeClass('active'); 5450 $('body').removeClass('no-scroll'); 5451 5452 if ( $('body').hasClass( 'single-product' ) ){ 5453 $('.oc-product-quick-add-to-cart-panel-1 button.close-panel').click(); 5454 5455 // slider init 5456 if ( $(this).closest('.products.slick-slider').length ){ 5457 // $(this).closest('.products.slick-slider').removeClass('no-transform'); 5458 } 5459 // 5460 if ( $(this).closest('.products').length && !$(this).closest('.products').hasClass( 'slick-slider' ) ){ 5461 let index = 0; 5462 $objRelatedProductSlick = get_related_product_object( index ); 5463 $(this).closest('.products').slick( $objRelatedProductSlick ); 5464 } 5465 } 5466 }); 5467 5468 var ocIsMatchVariation = function( variation_attributes, attributes ) { 5469 var match = true; 5470 for ( var attr_name in variation_attributes ) { 5471 if ( variation_attributes.hasOwnProperty( attr_name ) ) { 5472 var val1 = variation_attributes[ attr_name ]; 5473 var val2 = attributes[ attr_name ]; 5474 // console.log( val1, 'val1' ); 5475 // console.log( val2, 'val2' ); 5476 // console.log( attr_name, 'attr_name' ); 5477 5478 5479 if ( val1 !== undefined && val2 !== undefined && val1.length !== 0 && val2.length !== 0 && val1 !== val2 ) { 5480 match = false;
5481 } 5482 } 5483 } 5484 return match; 5485 }; 5486 5487 // mobile add to cart functionalitty 5488 $(document).on( 'click', '.oc-product-quick-add-to-cart-panel-1.mobile .add-to-cart-mobile', function(){ 5489 let product = $(this).closest( '.product' ); 5490 let variationObject = product.find('.product-available-variations-object'); 5491 let variations = variationObject.data('variations'); 5492 // temp ! need get field value ! 5493 var quantity = 1; 5494 var product_id = variationObject.data( 'product_id' ); 5495 var attrs = getChosenAttributes( product ); 5496 var matched = ''; 5497 5498 // 5499 var mobilePanel = $(this).closest('.oc-product-quick-add-to-cart-panel-1.mobile'); 5500 var availability = mobilePanel.find('.availability-variation'); 5501 // 5502 var attrName = ''; 5503 if ( mobilePanel.find( '.oc-product-variable-panel').length > 0 ){ 5504 mobilePanel.find( '.oc-product-variable-panel').each( function(index, el){ 5505 console.log( el, 'el' ); 5506 // if ( ) 5507 let value = $(el).data('value'); 5508 if ( value == '' && attrName == '' ){ 5509 attrName = $(el).find('.attr-title .attribute-name').html(); 5510 attrName = attrName.replace(':', ''); 5511 } 5512 }); 5513 } 5514 5515 console.log( attrs, 'attrs' ); 5516 console.log( attrName, 'attrName' ); 5517 // console.log( mobilePanel, 'mobilePanel' ); 5518 // console.log( availability, 'availability' ); 5519 5520 if ( attrs ){ 5521 // var matched = ocIsMatchVariation( variations, attrs ) 5522 matched = ocFindMatchingVariations( variations, attrs.data ); 5523 5524 availability.find('.attribute-label').html( attrName ); 5525 5526 // console.log( attrs, 'attrs passed !!!!' ); 5527 // console.log( matched, 'matched AFTER' ); 5528 // console.log( attrs.data, 'attrs.data' );4 5529 5530 // variation found !!!!!!!!!! 5531 if ( attrs.count && attrs.count === attrs.chosenCount ) { 5532 variation = matched.shift(); 5533 var variation_id = variation.variation_id; 5534 5535 // alert( 'variation found! cann add to cart' ); 5536 // console.log( matched, 'matched' ) 5537 // console.log( variationSecond, 'variationSecond shift ' ) 5538 console.log( variation, 'variation' ); 5539 console.log( product_id, 'product_id' ); 5540 console.log( variation_id, 'variation_id' ); 5541 5542 availability.removeClass( 'active' ); 5543 5544 // panel.removeClass('active'); 5545 var addToCartVariationCallback = add_to_cart_variation_callback( $(this) ) 5546 addToCartAjax( product_id, variation_id, quantity, $(this), addToCartVariationCallback ); 5547 } else { 5548 // alert('Need to choose some attributes '); 5549 availability.addClass( 'active' ); 5550 } 5551 } 5552 }); 5553 5554 var ocFindMatchingVariations = function( variations, attributes ) { 5555 // console.group('stast') 5556 // console.log( variations, 'variations' ); 5557 // console.log( attributes, 'attributes' ); 5558 var matching = []; 5559 if(!variations) return matching; 5560 for ( var i = 0; i < variations.length; i++ ) { 5561 var variation = variations[i]; 5562 if ( ocIsMatchVariation( variation.attributes, attributes ) ) { 5563 matching.push( variation ); 5564 } 5565 } 5566 // console.log( matching, 'matching' ); 5567 // console.groupEnd(); 5568 return matching; 5569 }; 5570 5571 // get object with selected attributes from attributes panels! , get value from data attributes 5572 var getChosenAttributes = function( currentProduct ) { 5573 var data = {}; 5574 var count = 0; 5575 var chosen = 0; 5576 5577 // $attributeFields = currentProduct.find('.oc-product-variable-panel'); 5578 5579 if ( isMobile() ){ 5580 $attributeFields = currentProduct.find('.oc-product-quick-add-to-cart-panel-1.mobile .oc-product-variable-panel'); 5581 } else { 5582 $attributeFields = currentProduct.find('.oc-product-quick-add-to-cart-panel.desktop .oc-product-variable-panel'); 5583 } 5584 // $attributeFields = currentProduct.find('.oc-product-quick-add-to-cart-panel.desktop .oc-product-variable-panel'); 5585 5586 // was here ! 5587 // $attributeFields = currentProduct.find('.oc-product-quick-add-to-cart-panel .oc-product-variable-panel'); 5588 5589 // console.log( $attributeFields, '$attributeFields +++ getChosenAttributes' ); 5590 // console.log( currentProduct, 'currentProduct' ); 5591 // console.group( 'getChosenAttributes, only from 1 panel' ); 5592 5593 $attributeFields.each( function() { 5594 var attribute_name = 'attribute_' + $( this ).attr( 'data-attribute_name' ) || $( this ).attr( 'name' ); 5595 // var value = $( this ).val() || ''; 5596 // var value = $( this ).data('value') || ''; 5597 var value = $( this ).attr('data-value') || ''; 5598 5599 // console.log( value , 'value data, SET !!!!!!!!!!!' ); 5600 // console.log( $( this ) , 'THIS ' ); 5601 // console.log( $( this ).attr('data-value') , 'THIS.attr valyue ' ); 5602 // console.log( attribute_name, 'attribute_name' ); 5603 5604 if ( typeof value !== undefined && value ) { 5605 chosen ++; 5606 } 5607 5608 count ++; 5609 data[ attribute_name ] = value; 5610 }); 5611 5612 // console.log( chosen, 'chosen ' ); 5613 // console.groupEnd( 'getChosenAttributes' ); 5614 5615 return { 5616 'count' : count, 5617 'chosenCount': chosen, 5618 'data' : data 5619 }; 5620 }; 5621 5622 var add_to_cart_variation_callback = function( button ){ 5623 5624 5625 let product = button.closest('.product'); 5626 let iconBtn = product.find( '.add-to-cart-icon' ); 5627 5628 iconBtn.addClass('added-to-cart'); 5629 5630 if ( $('body').hasClass( 'single-product' ) ){ 5631 // slider init 5632 if ( button.closest('.products.slick-slider').length ){ 5633 // button.closest('.products.slick-slider').removeClass('no-transform'); 5634 // button.closest('.products.slick-slider').slick('slickPlay'); 5635 5636 } 5637 } 5638 5639 // console.log( button, 'button!!!' ); 5640 // console.log( product, 'product!!!' ); 5641 // console.log( iconBtn, 'iconBtn' ); 5642 if ( isMobile() ){ 5643 if ( product.find('.oc-product-quick-add-to-cart-panel-1.mobile.active').length ){ 5644 product.find('.oc-product-quick-add-to-cart-panel-1.mobile').removeClass('active'); 5645 $('.quick-add-to-cart-overlay').removeClass('active'); 5646 } 5647 } 5648 setTimeout( function(){ 5649 iconBtn.removeClass('added-to-cart'); 5650 }, 2000 ) 5651 } 5652 5653 // new add to cart vairable 5654 $(document).on( 'click', '.wrap-for-top-part button.add-to-cart-icon' , function(e){ 5655 // $(document).on( 'mouseenter', '.wrap-for-top-part button.add-to-cart-icon' , function(e){ 5656 let product_id = $(this).val(); 5657 5658 // closest product 5659 let product = $(this).closest( '.product' ); 5660 5661 // toppart panel ! 5662 // let panelToShow = product.find( '.wrap-for-top-part .oc-product-variable-panel' ); 5663 // let attributePanels = product.find( '.oc-product-variable-panel' ); 5664 let attributePanels; 5665 let panelToShow; 5666 5667 // if it is desktop version ! 5668 if ( !isMobile() ){ 5669 attributePanels = product.find( '.oc-product-quick-add-to-cart-panel.desktop .oc-product-variable-panel' ); 5670 panelToShow = product.find( '.oc-product-quick-add-to-cart-panel .oc-product-variable-panel' ); 5671 } else { 5672 attributePanels = product.find( '.oc-product-quick-add-to-cart-panel-1.mobile .oc-product-variable-panel' ); 5673 panelToShow = product.find( '.oc-product-quick-add-to-cart-panel-1.mobile' ); 5674 setTimeout( function(){ 5675 panelToShow.removeClass('warning-message') 5676 console.log( panelToShow, 'panelToShow !!!!!!' ) 5677 }, 2500 ) 5678 } 5679 5680 let variationObject = product.find( '.product-available-variations-object' ); 5681 5682 // moved !!!!!!!!!!! 5683 // console.log( isMobile(), 'isMobile check' ); 5684 // console.log( panelToShow, 'panelToShow' ); 5685 // console.log( attributePanels, 'attributePanels' ); 5686 5687 panelToShow.toggleClass('active'); 5688 5689 5690 5691 // emulate click | select on first color 5692 if ( attributePanels.length ){ 5693 attributePanels.each( function( i, el ){ 5694 if ( $(el).hasClass('image') && $(el).attr('data-value') == '' ){ 5695 console.log( $(el), 'EL ! emulate click' ); 5696 $(el).find( '.product-colors-container .color-attribute:first' ).trigger('click'); 5697 } 5698 }); 5699 } 5700 5701 if ( !$(this).hasClass('simple-product') && isMobile() ){ 5702 // console.log( 'MOBILE !' ); 5703 // // mobile panel 5704 $('.quick-add-to-cart-overlay').addClass('active'); 5705 $('body').addClass( 'no-scroll' ); 5706 5707 // function called from related product, probably from slider ! 5708 if ( $('body').hasClass( 'single-product' ) ){ 5709 // slider init 5710 if ( $(this).closest('.products.slick-slider').length ){ 5711 // $(this).closest('.products.slick-slider').addClass('no-transform'); 5712 // console.log( 'unslick slider ' ) 5713 $(this).closest('.products.slick-slider').slick( 'unslick' ); 5714 // $(this).closest('.products.slick-slider').slick('slickPause'); 5715 } 5716 } 5717 // if ( attributePanels.length && attributePanels.length == 1 && attributePanels.hasClass('image') ){ 5718 // // emulate click on first color 5719 // if ( attributePanels.attr('data-value') == undefined || attributePanels.attr('data-value') == '' ){ 5720 // console.log( attributePanels.find( '.product-colors-container .color-attribute:first' ), 'first color ' ) 5721 // let activeColor = attributePanels.find( '.product-colors-container .color-attribute:first' ).trigger('click'); 5722 // } 5723 // } 5724 return; 5725 } 5726 5727 // callback function 5728 // var addToCartVariationCallback = add_to_cart_variation_callback( $(this) ); 5729 var addToCartVariationCallback = ''; 5730 5731 // if this simple product add to cart 5732 if ( $(this).hasClass('simple-product') ){ 5733 5734 var variation_id = false;
5735 var quantity = 1; 5736 // pass button 5737 addToCartVariationCallback = add_to_cart_variation_callback( $(this) ); 5738 addToCartAjax( product_id, variation_id, quantity, $(this), addToCartVariationCallback ); 5739 } else if ( attributePanels.length && attributePanels.length == 1 && attributePanels.hasClass('image') ){ 5740 5741 // if ( isMobile() ){ 5742 // console.log( 'MOBILE !' ); 5743 // // mobile panel 5744 // let mobilePanelToShow = product.find( '.oc-product-quick-add-to-cart-panel-1.mobile' ); 5745 // mobilePanelToShow.toggleClass('active'); 5746 // $('.quick-add-to-cart-overlay').addClass('active'); 5747 // $('body').addClass( 'no-scroll' ); 5748 // return; 5749 // } 5750 5751 if ( isMobile() ){ 5752 $('body').addClass( 'no-scroll' ); 5753 } 5754 // panelToShow.toggleClass('active'); 5755 5756 if ( attributePanels.attr('data-value') == undefined || attributePanels.attr('data-value') == '' ){ 5757 let activeColor = attributePanels.find( '.product-colors-container .color-attribute.active' ); 5758 // if ( activeColor.length ){ 5759 let colorSlug = activeColor.data('slug'); 5760 // set slug value for quick add 5761 attributePanels.attr('data-value', colorSlug ) 5762 // } 5763 } 5764 // console.log( colorSlug, 'colorSlug' ) ; 5765 5766 // set new PRODUCT ID 5767 // variationObject.attr('data-product_id', product_id ); 5768 5769 5770 let variations = variationObject.data('variations'); 5771 var attrs = getChosenAttributes( product ); 5772 var matched = ''; 5773 5774 // console.log( attrs, 'attrs' ) 5775 5776 if ( attrs ){ 5777 matched = ocFindMatchingVariations( variations, attrs.data ); 5778 if ( attrs.count && attrs.count === attrs.chosenCount ) { 5779 variation = matched.shift(); 5780 // console.log( variation, 'variation' ) 5781 5782 var variation_id = variation.variation_id; 5783 5784 // alert( 'variation found! cann add to cart' ); 5785 // console.log( variationSecond, 'variationSecond shift ' ) 5786 // console.log( matched, 'matched' ) 5787 // console.log( attrs, 'attrs' ) 5788 // console.log( variationObject, 'variationObject' ) 5789 5790 addToCartVariationCallback = add_to_cart_variation_callback( $(this) ); 5791 addToCartAjax( product_id, variation_id, quantity, $(this), addToCartVariationCallback ); 5792 } 5793 } 5794 } else if ( attributePanels.length && attributePanels.length > 1 ) { 5795 // panelToShow.toggleClass('active'); 5796 } 5797 // console.log( 'clic k!' ) 5798 // console.log( panelToShow, 'panelToShow' ) 5799 // console.log( attributePanels, 'attributePanels' ) 5800 }); 5801 5802 // make visible on hover 5803 $(document).on( 'mouseenter', '.wrap-for-top-part button.add-to-cart-icon' , function(e){ 5804 if ( isMobile() ){ 5805 return; 5806 } 5807 5808 // console.log( e, ' e ' ); 5809 // console.log( e.target, ' etarget ' ); 5810 // console.log( e.currentTarget, ' currentTarget ' ); 5811 let hoverTarget = $(e.target); 5812 5813 if ( !hoverTarget.hasClass( 'add-to-cart-icon' ) ){ 5814 return; 5815 } 5816 5817 let product = $(this).closest( '.product' ); 5818 let attributePanels = product.find( '.oc-product-quick-add-to-cart-panel.desktop .oc-product-variable-panel' ); 5819 let panelToShow = product.find( '.oc-product-quick-add-to-cart-panel .oc-product-variable-panel' ); 5820 if ( panelToShow.length > 0 ){ 5821 panelToShow.addClass('active'); 5822 } 5823 }); 5824 5825 // close 5826 $(document).on( 'mouseleave', 'li.product .wrap-for-top-part' , function(e) { 5827 if ( isMobile() ){ 5828 return; 5829 } 5830 let panel = $(this).closest('.product').find( '.oc-product-quick-add-to-cart-panel .oc-product-variable-panel' ); 5831 if ( panel.length ){ 5832 panel.removeClass('active'); 5833 } 5834 }); 5835 5836 $('.contact-row').on('click', function(e) { 5837 // Optionally prevent the default action 5838 e.preventDefault(); 5839 var url = $(this).find('a').attr('href'); 5840 if (url) { 5841 window.open(url, '_blank'); // '_blank' to open in a new tab 5842 } 5843 }); 5844 5845 $(document).ready(function() { 5846 $('.bottom-part').each(function() { 5847 var $quickAddCarts = $(this).find('.oc-product-quick-add-to-cart-panel'); 5848 if ($quickAddCarts.length > 1) { 5849 // Remove all but the first .oc-product-quick-add-to-cart-panel div 5850 $quickAddCarts.not(':first').remove(); 5851 } 5852 }); 5853 }); 5854 5855 5856 5857 5858});
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.