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