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