$('body').ready(function() { $(".nav-tabs > li > a").tab(); var sprites_retailer = $('meta[name="jymeo_sprite"]').attr('content'); var data = { width: $('meta[name="jymeo_width"]').attr('content'), height: $('meta[name="jymeo_height"]').attr('content'), diameter: $('meta[name="jymeo_diameter"]').attr('content'), speed: $('meta[name="jymeo_speed"]').attr('content'), load: $('meta[name="jymeo_load"]').attr('content'), model: $('meta[name="jymeo_model"]').attr('content'), quantity: $('meta[name="jymeo_quantity"]').attr('content'), brand: $('meta[name="jymeo_brand"]').attr('content'), }; $('[data-toggle="tooltip"]').tooltip(); // Used to put a uppercase on first character of each word function ucwords(str) { return (str + '') .replace(/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g, function($1) { return $1.toUpperCase(); }); } // Used to redirect on click to the given product $('.results-body').on('click', '.btn-offer, .btn-offer-mobile', function (e) { e.stopPropagation(); $('#jwt-redirect').val($(this).parents('.result-item').attr('data-token')); var url = base_url + 'redirect.htm'; $('.view-offer').attr('action', url); $('.view-offer').submit(); }); $('html').on('click', '.offer', function() { $('#click-id').val($(this).attr('data-id')); url = base_url + 'redirect.htm'; $('.view-offer').attr('action', url); $('.view-offer').submit(); }) $('.results-body').on('click', '.show-details, .discountPrice', function(e) { e.stopPropagation(); if($(e.target).hasClass('show-details')) var parent = $(this).parent().parent(); else var parent = $(this); var index = parent.index(); var details = parent.parent().children('div:nth-child(' + (index+parseInt(1)+1) + ')').first(); if (parent.hasClass('open')) { $('.open').removeClass('open'); details.hide(); } else { $('.open').removeClass('open'); parent.addClass('open'); $('.details').hide(); details.show(); } }); // Particle filter var particlesSelected = []; $('.particle-filter').on('click', function(e){ e.stopPropagation(); var particle = $(this).attr('data-particle'); var index = particlesSelected.indexOf(particle); if(index === -1){ particlesSelected.push(particle); $(this).parent().addClass('active'); } else { particlesSelected.splice(index, 1); $(this).parent().removeClass('active'); } sortProduct(); }); function sortProduct(){ var particleRegex = new RegExp(' ('+particlesSelected.join('|')+')(?= |$)', 'gi'); $('.results-body .result-item').show(); $('.results-body .result-item').each(function(i){ if(particlesSelected.length > 0){ try { var model = $(this).find('.result-item-model').text(); var result = model.match(particleRegex) ; if(result === null || result.length !== particlesSelected.length){ if($(this).hasClass('open')){ var index = $(this).index(); var details = $(this).parent().children('div:nth-child(' + (index+parseInt(1)+1) + ')').first(); $('.open').removeClass('open'); details.hide(); } $(this).hide(); } } catch(err) { console.error(err); } } }); } if( !/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) { compare_selects = $('.selectize-drop').selectize({ plugins:['input_disable'], onChange: function(val) { getProducts(); }, onInitialize: function() { this.$wrapper.closest('.select-wrapper').removeClass('select-wrapper'); }, onFocus: function() { var value = this.getValue(); this.setTextboxValue(''); this.oldValue = value; }, onDropdownClose: function() { var self = this; if (self.getValue() === '' && self.oldValue != "") { self.setTextboxValue(this.oldValue); self.setValue(this.oldValue, true); } } }); } else { $('#input-nbr').change(function(e) { getProducts(); }); } $('[data-discount=true]').each(function() { getDiscount($(this).attr('data-id')); }); function getDiscount(id) { $.getJSON('/discount/model/' + id, {}, function(json, textStatus) { if (json.success === true) { var cell = $('#discount-' + id +' > .discountCode'); cell.append('