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 147 148/** 149 * The ajax cart dropdown counter needs to be changed on cart page when user removes items or changes amount - 150 * we have to check for changed amount of products in cart dropdown to update the cart counter 151 * (reacts on remove items and changes to quantity) 152 */ 153function avia_cart_dropdown_changed() 154{ 155 var the_html = jQuery('html'),
156 cart = jQuery('body').is('.woocommerce-cart'), 157 cart_counter = jQuery('.cart_dropdown .av-cart-counter'), 158 menu_cart = jQuery('.cart_dropdown'), 159 counter = 0, 160 wc30 = jQuery( 'body' ).hasClass( 'avia-woocommerce-30' ); 161 162 if( ! cart ) 163 { 164 return; 165 } 166 167 if( ! wc30 ) 168 { 169 menu_cart.find('.cart_list li .quantity').each(function() 170 { 171 counter += parseInt( jQuery(this).text(), 10 ); 172 }); 173 } 174 else 175 { 176 counter = parseInt( cart_counter.text(), 10 ); 177 } 178 179 if( counter == 0 ) 180 { 181 cart_counter.removeClass('av-active-counter').text(counter); 182 setTimeout( function() { the_html.removeClass('html_visible_cart'); }, 200); 183 } 184 else if( ( cart_counter.length > 0 ) && ( counter > 0 ) ) 185 { 186 setTimeout( function() 187 { 188 cart_counter.addClass('av-active-counter').text(counter); 189 the_html.addClass('html_visible_cart'); 190 }, 10 ); 191 } 192 193 return; 194} 195 196 197//updates the shopping cart in the sidebar, hooks into the added_to_cart event which is triggered by woocommerce 198function update_cart_dropdown( event ) 199{ 200 var the_html = jQuery('html'), 201 menu_cart = jQuery('.cart_dropdown'), 202 cart_counter = jQuery('.cart_dropdown .av-cart-counter'), 203 empty = menu_cart.find('.empty'), 204 msg_success = menu_cart.data('success'), 205 product = jQuery.extend({name:"Product", price:"", image:""}, avia_clicked_product), 206 counter = 0, 207 wc30 = jQuery( 'body' ).hasClass( 'avia-woocommerce-30' ); 208 209 // removed by theme option ? 210 if( cart_counter.length == 0 ) 211 { 212 return; 213 } 214 215 // trigger changed in WC 3.0.0 - must check for event explecit 216 if( ( empty.length > 0 ) && ( 'undefined' != typeof event ) ) 217 { 218 the_html.addClass( 'html_visible_cart' ); 219 } 220 221 if( typeof event !== 'undefined' ) 222 { 223 var header = jQuery('.html_header_sticky #header_main .cart_dropdown_first, .html_header_sidebar #header_main .cart_dropdown_first'), 224 oldTemplates = jQuery('.added_to_cart_notification').trigger('avia_hide'), 225 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 ); 226 227 if( ! header.length ) 228 { 229 header = 'body'; 230 } 231 232 template.on('mouseenter avia_hide', function() 233 { 234 template.animate({opacity:0, top: parseInt(template.css('top'), 10) + 15 }, function() 235 { 236 template.remove(); 237 }); 238 239 }).appendTo(header).animate({opacity:1},500); 240 241 setTimeout(function() 242 { 243 template.trigger('avia_hide'); 244 }, 2500); 245 } 246 247 248 if( 'object' == typeof event && 'added_to_cart' == event.type && wc30 ) 249 { 250 return; 251 } 252 253 // with WC 3.0.0 DOM is not ready - wrong calculation of counter (last element missing) 254 setTimeout( function() 255 { 256 if( ! wc30 ) 257 { 258 menu_cart.find('.cart_list li .quantity').each(function() 259 { 260 counter += parseInt( jQuery(this).text(), 10 ); 261 }); 262 } 263 else 264 { 265 counter = cart_counter.text(); 266 } 267 268 if( ( cart_counter.length > 0 ) && ( counter > 0) ) 269 { 270 setTimeout( function() 271 { 272 cart_counter.addClass( 'av-active-counter' ).text( counter ); 273 }, 10 ); 274 } 275 }, 300 ); 276} 277 278 279var avia_clicked_product = {}; 280function track_ajax_add_to_cart() 281{ 282 jQuery('body').on( 'click','.add_to_cart_button', function(e) 283 { 284 var productContainer = jQuery(this).parents('.product').eq(0), 285 product = {}; 286 287 product.name = productContainer.find( '.woocommerce-loop-product__title' ).text(); 288 product.image = productContainer.find( '.thumbnail_container img' ); 289 product.price = productContainer.find( '.price .amount' ).last().text(); 290 291 //lower than woocommerce 3.0.0 292 if( product.name === "" ) 293 { 294 product.name = productContainer.find('.inner_product_header h3').text(); 295 } 296 297 /*fallbacks*/ 298 if( productContainer.length === 0 ) 299 {
300 productContainer = jQuery(this); 301 product.name = productContainer.find('.av-cart-update-title').text(); 302 product.image = productContainer.find('.av-cart-update-image'); 303 product.price = productContainer.find('.av-cart-update-price').text(); 304 } 305 306 if(product.image.length) 307 { 308 product.image = "<img class='added-product-image' src='" + product.image.get(0).src + "' title='' alt='' />"; 309 } 310 else 311 { 312 product.image = ""; 313 } 314 315 avia_clicked_product = product; 316 }); 317} 318 319 320//function that pre fills the amount value of the cart 321function first_load_amount() 322{ 323 var counter = 0, 324 limit = 15, 325 ms = 500, 326 check = function() 327 { 328 var new_total = jQuery( '.cart_dropdown .dropdown_widget_cart' ).eq( 0 ).find( '.total .amount' ); 329 330 if(new_total.length) 331 { 332 update_cart_dropdown(); 333 } 334 else 335 { 336 counter++; 337 if(counter < limit) 338 { 339 setTimeout(check, ms); 340 } 341 } 342 }; 343 344 check(); 345 346 //display the cart for a short moment on page load if a product was added but no notice was delivered (eg template builder page) 347 if( jQuery('.av-display-cart-on-load').length && jQuery('.woocommerce-message').length === 0 ) 348 { 349 var dropdown = jQuery('.cart_dropdown'); 350 351 setTimeout( function() 352 { 353 dropdown.trigger('mouseenter'); 354 }, 500 ); 355 356 setTimeout( function() 357 { 358 dropdown.trigger('mouseleave'); 359 }, 2500 ); 360 } 361} 362 363function product_add_to_cart_click() 364{ 365 var jbody = jQuery( 'body' ), 366 catalogue = jQuery( '.av-catalogue-item' ), 367 loader = false;
368 369 if( catalogue.length ) 370 { 371 loader = jQuery.avia_utilities.loading(); 372 } 373 374 jbody.on('click', '.add_to_cart_button', function(e) 375 { 376 var button = jQuery(this); 377 button.parents('.product').eq( 0 ).addClass('adding-to-cart-loading').removeClass('added-to-cart-check'); 378 379 if(button.is('.av-catalogue-item')) 380 { 381 loader.show(); 382 } 383 384 var $html = jQuery('html'); 385 if( ! $html.hasClass( 'html_visible_cart' ) ) 386 { 387 $html.addClass( 'html_visible_cart' ); 388 } 389 390 //e.preventDefault(); 391 }); 392 393 jbody.on( 'added_to_cart', function() 394 { 395 jQuery( '.adding-to-cart-loading').removeClass('adding-to-cart-loading' ).addClass( 'added-to-cart-check' ); 396 397 if( loader !== false ) 398 { 399 loader.hide(); 400 } 401 }); 402 403} 404 405 406// little fixes and modifications to the dom 407function cart_improvement_functions() 408{ 409 //single products are added via ajax //doesnt work currently 410 //jQuery('.summary .cart .button[type=submit]').addClass('add_to_cart_button product_type_simple'); 411 412 //downloadable products are now added via ajax as well 413 jQuery('.product_type_downloadable, .product_type_virtual').addClass('product_type_simple'); 414 415 //clicking tabs dont activate smoothscrooling 416 jQuery('.woocommerce-tabs .tabs a').addClass('no-scroll'); 417 418 //connect thumbnails on single product page via lightbox 419 jQuery('.single-product-main-image>.images a').attr('rel','product_images[grouped]'); 420} 421 422 423//small function that improves shoping cart hover behaviour in the menu 424function cart_dropdown_improvement() 425{ 426 var dropdown = jQuery('.cart_dropdown'), 427 icon = dropdown.find( '.cart_dropdown_link' ), 428 subelement = dropdown.find('.dropdown_widget').css({display:'none', opacity:0}); 429 430 icon.on( 'focus', function() 431 { 432 dropdown.trigger( 'mouseenter' ); 433 }).on( 'blur', function() 434 { 435 dropdown.trigger( 'mouseleave' ); 436 }); 437 438 dropdown.on( 'mouseenter', function() 439 { 440 const content = dropdown.find('.widget_shopping_cart_content'); 441 442 if( jQuery.trim( content.html() ).length ) 443 { 444 subelement.css({display:'block'}).stop().animate({opacity:1}); 445 } 446 }).on( 'mouseleave', function() 447 { 448 subelement.stop().animate({opacity:0}
448, function(){ subelement.css({display:'none'}); }); 449 }); 450}
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.