1jQuery( function($) 2{ 3 cart_improvement_functions(); 4 cart_dropdown_improvement(); 5 track_ajax_add_to_cart(); 6 7 if( $.fn.avia_sc_slider ) 8 { 9 $(".shop_slider_yes ul").avia_sc_slider( { appendControlls: false, group: true, slide: '.product', arrowControll: true, autorotationInterval: 'parent' } ); 10 } 11 12 13 //make woocommerce 3.6 gallery search icon clickable and open lightbox 14 $( 'body.single-product' ).on( 'click', '.single-product-main-image .avia-wc-30-product-gallery-lightbox', function( e ) 15 { 16 e.preventDefault(); 17 var clicked = $(this), 18 container = clicked.parents('.single-product-main-image'), 19 img = container.find('.flex-active-slide a.lightbox-added').eq(0); 20 21 //if no gallery is used we need to find the original image size differently 22 if(img.length == 0) 23 { 24 img = container.find( 'a.lightbox-added' ).eq(0); 25 } 26 27 if( clicked.hasClass( 'av-remove-size-attr' ) ) 28 { 29 let img_tag = img.find( 'img' ).eq(0); 30 if( img_tag.length ) 31 { 32 img_tag.removeAttr( 'sizes' ); 33 } 34 } 35 36 img.trigger('click'); 37 }); 38 39 40 product_add_to_cart_click(); 41 42 43 function avia_apply_quant_btn() 44 { 45 $( ".quantity input[type=number]" ).each( function() 46 { 47 var number = $(this), 48 current_val = number.val(), 49 cloned = number.clone( true ); 50 51 // WC 4.0 renders '' for grouped products 52 if( ( 'undefined' == typeof( current_val ) ) || ( '' == ( current_val + '' ).trim() ) ) 53 { 54 var placeholder = cloned.attr( 'placeholder' ); 55 placeholder = ( ( 'undefined' == typeof( placeholder ) ) || ( '' == ( placeholder + '' ).trim() ) ) ? 1 : placeholder; 56 cloned.attr( 'value', placeholder ); 57 } 58 59 var max = parseFloat( number.attr( 'max' ) ), 60 min = parseFloat( number.attr( 'min' ) ), 61 step = parseInt( number.attr( 'step' ), 10 ), 62 newNum = cloned.insertAfter( number ); 63 newNum.addClass('no-spin-num'); 64 number.remove(); 65 66 setTimeout(function() 67 { 68 var minus = null, 69 plus = null; 70 71 if( newNum.next( '.plus' ).length === 0 ) 72 { 73 minus = $( '<input type="button" value="-" class="minus">' ).insertBefore( newNum ), 74 plus = $( '<input type="button" value="+" class="plus">' ).insertAfter( newNum ); 75 } 76 else 77 { 78 minus = newNum.prev( '.minus' ); 79 plus = newNum.next( '.plus' ); 80 } 81 82 minus.on( 'click', function() 83 { 84 var the_val = parseInt( newNum.val(), 10 ); 85 if( isNaN( the_val ) ) 86 { 87 the_val = 0; 88 } 89 90 // https://github.com/KriesiMedia/enfold-library/pull/24/files 91 let new_step = parseInt( newNum.attr( 'step' ), 10 ); 92 if( isNaN( new_step ) ) 93 { 94 new_step = step; 95 } 96 97 the_val -= new_step; 98 99 the_val = the_val < 0 ? 0 : the_val; 100 the_val = the_val < min ? min : the_val; 101 newNum.val(the_val).trigger( "change" ); 102 }); 103 104 plus.on( 'click', function() 105 { 106 var the_val = parseInt( newNum.val(), 10 ); 107 if( isNaN( the_val ) ) 108 { 109 the_val = 0; 110 } 111 112 // https://github.com/KriesiMedia/enfold-library/pull/24/files 113 let new_step = parseInt( newNum.attr( 'step' ), 10 ); 114 if( isNaN( new_step ) ) 115 { 116 new_step = step; 117 } 118 119 the_val += new_step; 120 121 the_val = the_val > max ? max : the_val; 122 newNum.val(the_val).trigger( "change" ); 123 124 }); 125 126 }, 10 ); 127 128 }); 129 } 130 131 avia_apply_quant_btn(); 132 133 //if the cart gets updated via ajax (woocommerce 2.6 and higher) we need to re apply the +/- buttons 134 $( document ).on( 'updated_cart_totals', avia_apply_quant_btn ); 135 136 setTimeout(first_load_amount, 10); 137 $('body').on( 'added_to_cart', update_cart_dropdown ); 138 $('body').on( 'wc_fragments_refreshed', avia_cart_dropdown_changed ); 139 140 141 // small fix for the hover menu for woocommerce sort buttons since it does no seem to work on mobile devices. 142 // even if no event is actually bound the css dropdown works. if the binding is removed dropdown does no longer work. 143 $('.avia_mobile .sort-param').on('touchstart', function(){}); 144 145 /** 146 * see: https://kriesi.at/support/topic/bug-abuse-of-avia_extended_shop_select-queries/ 147 */ 148 function routeSorting() 149 { 150 let links = $( '.avia-product-sorting .avia-product-sorting-link' ); 151 152 links.on( 'click', function() 153 { 154 let el = $(this), 155 href = el.attr('data-href'), 156 li = el.closest('li'); 157 158 if( li.hasClass('current-param') ) 159 { 160 return; 161 } 162 163 if( 'undefined' != typeof href && '' != href ) 164 { 165 window.location.href = href; 166 } 167 } ); 168 } 169 170 routeSorting(); 171}); 172 173 174/** 175 * The ajax cart dropdown counter needs to be changed on cart page when user removes items or changes amount - 176 * we have to check for changed amount of products in cart dropdown to update the cart counter 177 * (reacts on remove items and changes to quantity) 178 */ 179function avia_cart_dropdown_changed() 180{ 181 var the_html = jQuery('html'),
182 cart = jQuery('body').is('.woocommerce-cart'), 183 cart_counter = jQuery('.cart_dropdown .av-cart-counter'), 184 menu_cart = jQuery('.cart_dropdown'), 185 counter = 0, 186 wc30 = jQuery( 'body' ).hasClass( 'avia-woocommerce-30' ); 187 188 if( ! cart ) 189 { 190 return; 191 } 192 193 if( ! wc30 ) 194 { 195 menu_cart.find('.cart_list li .quantity').each(function() 196 { 197 counter += parseInt( jQuery(this).text(), 10 ); 198 }); 199 } 200 else 201 { 202 counter = parseInt( cart_counter.text(), 10 ); 203 } 204 205 if( counter == 0 ) 206 { 207 cart_counter.removeClass('av-active-counter').text(counter); 208 setTimeout( function() { the_html.removeClass('html_visible_cart'); }, 200); 209 } 210 else if( ( cart_counter.length > 0 ) && ( counter > 0 ) ) 211 { 212 setTimeout( function() 213 { 214 cart_counter.addClass('av-active-counter').text(counter); 215 the_html.addClass('html_visible_cart'); 216 }, 10 ); 217 } 218 219 return; 220} 221 222 223//updates the shopping cart in the sidebar, hooks into the added_to_cart event which is triggered by woocommerce 224function update_cart_dropdown( event ) 225{ 226 var the_html = jQuery('html'), 227 menu_cart = jQuery('.cart_dropdown'), 228 cart_counter = jQuery('.cart_dropdown .av-cart-counter'), 229 empty = menu_cart.find('.empty'), 230 msg_success = menu_cart.data('success'), 231 product = jQuery.extend({name:"Product", price:"", image:""}, avia_clicked_product), 232 counter = 0, 233 wc30 = jQuery( 'body' ).hasClass( 'avia-woocommerce-30' ); 234 235 // removed by theme option ? 236 if( cart_counter.length == 0 ) 237 { 238 return; 239 } 240 241 // trigger changed in WC 3.0.0 - must check for event explecit 242 if( ( empty.length > 0 ) && ( 'undefined' != typeof event ) ) 243 { 244 the_html.addClass( 'html_visible_cart' ); 245 } 246 247 if( typeof event !== 'undefined' ) 248 { 249 var header = jQuery('.html_header_sticky #header_main .cart_dropdown_first, .html_header_sidebar #header_main .cart_dropdown_first'), 250 oldTemplates = jQuery('.added_to_cart_notification').trigger('avia_hide'), 251 template = jQuery("<div class='added_to_cart_notification'><span class='avia-arrow'></span><div class='added-product-text'><strong>\"" + product.name +"\"</strong> "+ msg_success+ "</div> " + product.image +"</div>").css( 'opacity', 0 ); 252 253 if( ! header.length ) 254 { 255 header = 'body'; 256 } 257 258 template.on('mouseenter avia_hide', function() 259 { 260 template.animate({opacity:0, top: parseInt(template.css('top'), 10) + 15 }, function() 261 { 262 template.remove(); 263 }); 264 265 }).appendTo(header).animate({opacity:1},500); 266 267 setTimeout(function() 268 { 269 template.trigger('avia_hide'); 270 }, 2500); 271 } 272 273 274 if( 'object' == typeof event && 'added_to_cart' == event.type && wc30 ) 275 { 276 return; 277 } 278 279 // with WC 3.0.0 DOM is not ready - wrong calculation of counter (last element missing) 280 setTimeout( function() 281 { 282 if( ! wc30 ) 283 { 284 menu_cart.find('.cart_list li .quantity').each(function() 285 { 286 counter += parseInt( jQuery(this).text(), 10 ); 287 }); 288 } 289 else 290 { 291 counter = cart_counter.text(); 292 } 293 294 if( ( cart_counter.length > 0 ) && ( counter > 0) ) 295 { 296 setTimeout( function() 297 { 298 cart_counter.addClass( 'av-active-counter' ).text( counter ); 299 }, 10 ); 300 } 301 }, 300 ); 302} 303 304 305var avia_clicked_product = {}; 306function track_ajax_add_to_cart() 307{ 308 jQuery('body').on( 'click','.add_to_cart_button', function(e) 309 { 310 var productContainer = jQuery(this).parents('.product').eq(0), 311 product = {}; 312 313 product.name = productContainer.find( '.woocommerce-loop-product__title' ).text(); 314 product.image = productContainer.find( '.thumbnail_container img' ); 315 product.price = productContainer.find( '.price .amount' ).last().text(); 316 317 //lower than woocommerce 3.0.0 318 if( product.name === "" ) 319 { 320 product.name = productContainer.find('.inner_product_header h3').text(); 321 } 322 323 /*fallbacks*/ 324 if( productContainer.length === 0 ) 325 {
326 productContainer = jQuery(this); 327 product.name = productContainer.find('.av-cart-update-title').text(); 328 product.image = productContainer.find('.av-cart-update-image'); 329 product.price = productContainer.find('.av-cart-update-price').text(); 330 } 331 332 if(product.image.length) 333 { 334 product.image = "<img class='added-product-image' src='" + product.image.get(0).src + "' title='' alt='' />"; 335 } 336 else 337 { 338 product.image = ""; 339 } 340 341 avia_clicked_product = product; 342 }); 343} 344 345 346//function that pre fills the amount value of the cart 347function first_load_amount() 348{ 349 var counter = 0, 350 limit = 15, 351 ms = 500, 352 check = function() 353 { 354 var new_total = jQuery( '.cart_dropdown .dropdown_widget_cart' ).eq( 0 ).find( '.total .amount' ); 355 356 if(new_total.length) 357 { 358 update_cart_dropdown(); 359 } 360 else 361 { 362 counter++; 363 if(counter < limit) 364 { 365 setTimeout(check, ms); 366 } 367 } 368 }; 369 370 check(); 371 372 //display the cart for a short moment on page load if a product was added but no notice was delivered (eg template builder page) 373 if( jQuery('.av-display-cart-on-load').length && jQuery('.woocommerce-message').length === 0 ) 374 { 375 var dropdown = jQuery('.cart_dropdown'); 376 377 setTimeout( function() 378 { 379 dropdown.trigger('mouseenter'); 380 }, 500 ); 381 382 setTimeout( function() 383 { 384 dropdown.trigger('mouseleave'); 385 }, 2500 ); 386 } 387} 388 389function product_add_to_cart_click() 390{ 391 var jbody = jQuery( 'body' ), 392 catalogue = jQuery( '.av-catalogue-item' ), 393 loader = false;
394 395 if( catalogue.length ) 396 { 397 loader = jQuery.avia_utilities.loading(); 398 } 399 400 jbody.on('click', '.add_to_cart_button', function(e) 401 { 402 var button = jQuery(this); 403 button.parents('.product').eq( 0 ).addClass('adding-to-cart-loading').removeClass('added-to-cart-check'); 404 405 if(button.is('.av-catalogue-item')) 406 { 407 loader.show(); 408 } 409 410 var $html = jQuery('html'); 411 if( ! $html.hasClass( 'html_visible_cart' ) ) 412 { 413 $html.addClass( 'html_visible_cart' ); 414 } 415 416 //e.preventDefault(); 417 }); 418 419 jbody.on( 'added_to_cart', function() 420 { 421 jQuery( '.adding-to-cart-loading').removeClass('adding-to-cart-loading' ).addClass( 'added-to-cart-check' ); 422 423 if( loader !== false ) 424 { 425 loader.hide(); 426 } 427 }); 428 429} 430 431 432// little fixes and modifications to the dom 433function cart_improvement_functions() 434{ 435 //single products are added via ajax //doesnt work currently 436 //jQuery('.summary .cart .button[type=submit]').addClass('add_to_cart_button product_type_simple'); 437 438 //downloadable products are now added via ajax as well 439 jQuery('.product_type_downloadable, .product_type_virtual').addClass('product_type_simple'); 440 441 //clicking tabs dont activate smoothscrooling 442 jQuery('.woocommerce-tabs .tabs a').addClass('no-scroll'); 443 444 //connect thumbnails on single product page via lightbox 445 jQuery('.single-product-main-image>.images a').attr('rel','product_images[grouped]'); 446} 447 448 449//small function that improves shoping cart hover behaviour in the menu 450function cart_dropdown_improvement() 451{ 452 var dropdown = jQuery('.cart_dropdown'), 453 icon = dropdown.find( '.cart_dropdown_link' ), 454 subelement = dropdown.find('.dropdown_widget').css({display:'none', opacity:0}); 455 456 icon.on( 'focus', function() 457 { 458 dropdown.trigger( 'mouseenter' ); 459 }).on( 'blur', function() 460 { 461 dropdown.trigger( 'mouseleave' ); 462 }); 463 464 dropdown.on( 'mouseenter', function() 465 { 466 const content = dropdown.find('.widget_shopping_cart_content'); 467 468 if( jQuery.trim( content.html() ).length ) 469 { 470 subelement.css({display:'block'}).stop().animate({opacity:1}); 471 } 472 }).on( 'mouseleave', function() 473 { 474 subelement.stop().animate({opacity:0}
474, function(){ subelement.css({display:'none'}); }); 475 }); 476}
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.