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