function getURLVar(key) { var value = []; var query = String(document.location).split('?'); if (query[1]) { var part = query[1].split('&'); for (i = 0; i < part.length; i++) { var data = part[i].split('='); if (data[0] && data[1]) { value[data[0]] = data[1]; } } if (value[key]) { return value[key]; } else { return ''; } } } $(document).ready(function() { // Adding the clear Fix cols1 = $('#column-right, #column-left').length; if (cols1 == 2) { $('#content .product-layout:nth-child(2n+2)').after('
'); } else if (cols1 == 1) { $('#content .product-layout:nth-child(3n+3)').after(''); } else { $('#content .product-layout:nth-child(4n+4)').after(''); } // Highlight any found errors $('.text-danger').each(function() { var element = $(this).parent().parent(); if (element.hasClass('form-group')) { element.addClass('has-error'); } }); // Currency $('#currency .currency-select').on('click', function(e) { e.preventDefault(); $('#currency input[name=\'code\']').attr('value', $(this).attr('name')); $('#currency').submit(); }); // Language $('#language a').on('click', function(e) { e.preventDefault(); $('#language input[name=\'code\']').attr('value', $(this).attr('href')); $('#language').submit(); }); /* Search */ $('#search input[name=\'search\']').parent().find('button').on('click', function() { url = $('base').attr('href') + 'index.php?route=product/search'; var value = $('header input[name=\'search\']').val(); if (value) { url += '&search=' + encodeURIComponent(value); } location = url; }); $('#search input[name=\'search\']').on('keydown', function(e) { if (e.keyCode == 13) { $('header input[name=\'search\']').parent().find('button').trigger('click'); } }); // Menu $('#menu .dropdown-menu').each(function() { var menu = $('#menu').offset(); var dropdown = $(this).parent().offset(); var i = (dropdown.left + $(this).outerWidth()) - (menu.left + $('#menu').outerWidth()); if (i > 0) { $(this).css('margin-left', '-' + (i + 5) + 'px'); } }); // Product List $('#list-view').click(function() { $('#content .product-layout > .clearfix').remove(); $('#content .product-layout').attr('class', 'product-layout product-list col-xs-12'); localStorage.setItem('display', 'list'); }); // Product Grid $('#grid-view').click(function() { $('#content .product-layout > .clearfix').remove(); // What a shame bootstrap does not take into account dynamically loaded columns cols = $('#column-right, #column-left').length; if (cols == 2) { $('#content .product-layout').attr('class', 'product-layout product-grid col-lg-6 col-md-6 col-sm-12 col-xs-12'); } else if (cols == 1) { $('#content .product-layout').attr('class', 'product-layout product-grid col-lg-4 col-md-4 col-sm-6 col-xs-12'); } else { $('#content .product-layout').attr('class', 'product-layout product-grid col-lg-3 col-md-3 col-sm-6 col-xs-12'); } localStorage.setItem('display', 'grid'); }); if (localStorage.getItem('display') == 'list') { $('#list-view').trigger('click'); } else { $('#grid-view').trigger('click'); } // tooltips on hover $('[data-toggle=\'tooltip\']').tooltip({container: 'body'}); // Makes tooltips work on ajax generated content $(document).ajaxStop(function() { $('[data-toggle=\'tooltip\']').tooltip({container: 'body'}); }); }); // Cart add remove functions var cart = { 'add': function(product_id, quantity) { $.ajax({ url: 'index.php?route=checkout/cart/add', type: 'post', data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1), dataType: 'json', beforeSend: function() { $('#cart > button').button('loading'); }, success: function(json) { $('.alert, .text-danger').remove(); $('#cart > button').button('reset'); if (json['redirect']) { location = json['redirect']; } if (json['success']) { $('#content').parent().before('