1(function( $ ) { 2 'use strict'; 3 4 // Create the defaults once 5 var pluginName = "WooCommerceCatalogMode", 6 defaults = { 7 'modalHeightAuto' : '1', 8 }; 9 10 // The actual plugin constructor 11 function Plugin ( element, options ) { 12 this.element = element; 13 14 this.settings = $.extend( {}, defaults, options ); 15 this._defaults = defaults; 16 this.trans = this.settings.trans; 17 this._name = pluginName; 18 this.init(); 19 } 20 21 // Avoid Plugin.prototype conflicts 22 $.extend( Plugin.prototype, { 23 init: function() { 24 this.window = $(window); 25 this.documentHeight = $( document ).height(); 26 this.windowHeight = this.window.height(); 27 this.product = {}; 28 this.elements = {}; 29 30 this.singleProductEnquiry(); 31 this.loopProductEnquiry(); 32 this.variationsProductEnquiry(); 33 this.cartEnquiry(); 34 }, 35 singleProductEnquiry : function() { 36 37 // var enquiryButton = $('#enquiryButton'); 38 // if(enquiryButton.length < 1) { 39 // return; 40 // } 41 42 var that = this; 43 var overlay = $('#woocommerce-catalog-mode-enquiry-popup'); 44 var popup = $('#woocommerce-catalog-mode-enquiry-popup-container'); 45 46 var toggler = '#enquiryButton'; 47 $(document).on('click', toggler, function(e) { 48 e.preventDefault(); 49 50 // Insert SKU into form 51 var sku = $(that.settings.SKUSelector).first().text().trim(); 52 var enquiryModalSKU = popup.find('input[name*="' + that.settings.skuField + '"]'); 53 54 if(typeof sku != "undefined"){ 55 enquiryModalSKU.val(sku); 56 enquiryModalSKU.attr('value', sku); 57 } 58 59 // Insert Product into form 60 var product = $(that.settings.productSelector).first().text().trim(); 61 var enquiryModalProduct = popup.find('input[name*="' + that.settings.productField + '"]'); 62 63 if(!product || product == ""){ 64 product = $(that.settings.productSelectorFallback).first().text().trim(); 65 } 66 67 if(that.settings.singleProductAddQuantity == "1") { 68 var quantityField = $('input[name="quantity"]'); 69 if(quantityField.length > 0) { 70 product = $(quantityField).val() + ' x ' + product; 71 } 72 } 73 74 enquiryModalProduct.val(product); 75 enquiryModalProduct.attr('value', product); 76 77 overlay.fadeIn(); 78 popup.fadeIn(); 79 }); 80 81 $('.woocommerce-catalog-mode-popup-close').on('click', function(e) { 82 e.preventDefault(); 83 overlay.fadeOut(); 84 popup.fadeOut(); 85 }); 86 87 overlay.on('click', function(e) { 88 $(this).fadeOut(); 89 popup.fadeOut(); 90 }); 91 92 }, 93 loopProductEnquiry : function() { 94 95 var that = this; 96 // var enquiryLoopButton = $('.enquiryLoopButton'); 97 // if(enquiryLoopButton.length < 1) { 98 // return; 99 // } 100 101 var overlay = $('#woocommerce-catalog-mode-enquiry-popup'); 102 var popup = $('#woocommerce-catalog-mode-enquiry-popup-container'); 103 104 var toggler = '.enquiryLoopButton'; 105 $(document).on('click', toggler, function(e) { 106 e.preventDefault(); 107 108 var data = $(this).data('products'); 109 110 var enquiryModalSKU = popup.find('input[name*="' + that.settings.skuField + '"]'); 111 if(typeof data.sku != "undefined"){ 112 enquiryModalSKU.val(data.sku); 113 enquiryModalSKU.attr('value', data.sku); 114 } 115 116 var enquiryModalProduct = popup.find('input[name*="' + that.settings.productField + '"]'); 117 if(typeof data.name != "undefined" && data.name != ""){ 118 enquiryModalProduct.val(data.name); 119 enquiryModalProduct.attr('value', data.name); 120 } 121 122 overlay.fadeIn(); 123 popup.fadeIn(); 124 }); 125 126 $('.woocommerce-catalog-mode-popup-close').on('click', function(e) { 127 e.preventDefault(); 128 overlay.fadeOut(); 129 popup.fadeOut(); 130 }); 131 132 overlay.on('click', function(e) { 133 $(this).fadeOut(); 134 popup.fadeOut(); 135 }); 136 }, 137 variationsProductEnquiry : function() { 138 139 var enquiryButton = $('#enquiryButton'); 140 var checkVariations = $('.variations_form'); 141 if(checkVariations.length < 1 || enquiryButton.length < 1) { 142 return; 143 } 144 enquiryButton.hide(); 145 146 var availableVariations = $(checkVariations.data('product_variations')); 147 var variationText = $('<div id="variationText"></div>'); 148 variationText.insertBefore(enquiryButton); 149 150 $(document).on('change', '.variations select', function(e) { 151 var _this = $(this); 152 var optionSelected = _this.find('option:selected'); 153 var sku = $('.sku').text(); 154 155 if(sku.length > 0 && sku !== "N/A") { 156 availableVariations.each(function(i, val) { 157 158 if(val.sku === sku) { 159 var description = val.variation_description; 160 var price = val.price_html; 161 162 variationText.html(price + description); 163 164 variationText.fadeIn(); 165 enquiryButton.fadeIn(); 166 return false;
167 } 168 }); 169 170 } else { 171 variationText.hide(); 172 enquiryButton.hide(); 173 } 174 175 }) 176 setTimeout( function() { 177 $('.variations select').trigger('change'); 178 }, 150 ); 179 }, 180 cartEnquiry : function() { 181 182 183 var that = this; 184 var overlay = $('#woocommerce-catalog-mode-enquiry-cart-popup'); 185 var popup = $('#woocommerce-catalog-mode-enquiry-cart-popup-container'); 186 187 if(popup.length < 1) { 188 return; 189 } 190 191 var toggler = '#enquiryCartButton'; 192 $(document).on('click', toggler, function(e) { 193 e.preventDefault(); 194 195 var products = $(this).data('products'); 196 if(products == "") { 197 return false; 198 } 199 200 var products_txt = ""; 201 $.each(products, function(i, index) { 202 203 if(that.settings.enquiryCartShowQuantity == 1) { 204 products_txt += index.quantity + ' x ' + index.name; 205 } else { 206 products_txt += index.name; 207 } 208 209 if(that.settings.enquiryCartShowPrice == 1 && that.settings.enquiryCartShowSKU == 1) { 210 if(index.sku !== "") { 211 products_txt += ' (' + index.price + ' / ' + index.sku + ')\n'; 212 } else { 213 products_txt += ' (' + index.price + ')\n'; 214 } 215 216 } else if(that.settings.enquiryCartShowPrice == 1) { 217 products_txt += ' (' + index.price + ')\n'; 218 } else if(that.settings.enquiryCartShowSKU == 1 && index.sku !== "") { 219 products_txt += ' (' + index.sku + ')\n'; 220 } else { 221 products_txt += '\n'; 222 } 223 224 if(index.variationInformation) { 225 products_txt += index.variationInformation + '\n'; 226 } 227 228 }); 229 230 if(that.settings.enquiryCartShowTotal == 1) { 231 products_txt += '______________\n' + $(this).data('total'); 232 } 233 234 var enquiryCartModalProducts = popup.find('[name="' + that.settings.productsField + '"]'); 235 236 enquiryCartModalProducts.val(products_txt); 237 238 overlay.fadeIn(); 239 popup.fadeIn(); 240 }); 241 242 overlay.on('click', function(e) { 243 $(this).fadeOut(); 244 popup.fadeOut(); 245 }); 246 247 $('.woocommerce-catalog-mode-popup-close').on('click', function(e) { 248 e.preventDefault(); 249 overlay.fadeOut(); 250 popup.fadeOut(); 251 }); 252 253 document.addEventListener( 'wpcf7mailsent', function( event ) { 254 if($('.woocommerce-cart').length > 0) { 255 $.ajax({ 256 url: that.settings.ajaxURL, 257 data: { 258 'action':'woocommerce_catalog_mode_clear_cart', 259 }, 260 success:function(data) { 261 var delay = 1500; 262 setTimeout(function(){ location.reload(); }, delay); 263 }, 264 error: function(errorThrown){ 265 console.log(errorThrown); 266 } 267 }); 268 } 269 270 }, false ); 271 }, 272 } ); 273 274 // Constructor wrapper 275 $.fn[ pluginName ] = function( options ) { 276 return this.each( function() { 277 if ( !$.data( this, "plugin_" + pluginName ) ) { 278 $.data( this, "plugin_" + 279 pluginName, new Plugin( this, options ) ); 280 } 281 } ); 282 }; 283 284 $(document).ready(function() { 285 286 $( "body" ).WooCommerceCatalogMode( 287 woocommerce_catalog_mode_options 288 ); 289 290 } ); 291 292})( jQuery );
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.