function getURLVar(key) { var value = []; var query = String(document.location).split('?'); if( key === 'route' && query.indexOf('route') === -1 ){ return window.locationRoute ; } 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 ''; } } } function isEmpty( el ){ return !$.trim(el.html()) } $(document).ajaxStop(function() { function isEmpty( el ){ return !$.trim(el.html()) } if (!isEmpty($('#product'))) { $('#product .option-container').addClass('has-option'); } }); function divWidthMenu() { var width_br = $(".container-fix .block-right").outerWidth(true); var width_count = $(".container-fix > .container").width(); var width_bl = $("#logo img").outerWidth(true); $('.home1 .container-fix .main-menu').outerWidth(width_count - width_bl - width_br-30); } function customResponsive(){ var window_w = parseInt($(window).width()); $(".group1 #logo img").each(function() { if( this.complete ) { divWidthMenu.call( this ); } else { $(this).one('load', divWidthMenu); } }); var offsetMargin = 0-$('.wrapper').outerWidth(true)*2.6/100; $('.home2 .banner7').css('margin-left',offsetMargin); $('.home2 .banner7').css('margin-right',offsetMargin); } $(window).resize(function() { customResponsive(); }); $(document).ready(function() { // move breadcrumbs $("header").after(''); var breadcrumb = $('ul.breadcrumb'); var breadcrumbs_container = $('.breadcrumbs .container'); breadcrumb.appendTo(breadcrumbs_container); $('.breadcrumb').before($('.category-name')); $('.breadcrumb').before($('.block-2 .heading-title')); var sticky_menu = $('#sticky-menu').attr('data-sticky'); if (sticky_menu==1){ var headerSpaceH = $('header').outerHeight(true); $('header').after('
'); } // Scroll var currentP = 0; var stickyOffset = 0; stickyOffset = $('header').offset().top; stickyOffset += $('header').outerHeight(); stickyOffset += 30; $(window).scroll(function(){ var headerH = $('header').height(); var scrollP = $(window).scrollTop(); if($(window).width() > 1024){ if(scrollP != currentP){ //Sticky header if (sticky_menu==1){ if(scrollP >= stickyOffset){ $('.group1 .container-fix').addClass('fix-header'); $('.group2 .main-menu').addClass('fix-header'); $('.headerSpace').removeClass('unvisible'); } else { $('.group1 .container-fix').removeClass('fix-header'); $('.group2 .main-menu').removeClass('fix-header'); $('.headerSpace').addClass('unvisible'); } } currentP = $(window).scrollTop(); } } }); $('.container-fix').hover(function(){ $(this).addClass("fix-header-act"); },function(){ $(this).removeClass("fix-header-act"); }); customResponsive(); if (!isEmpty($('#product'))) { $('#product .option-container').addClass('has-option'); } if (!isEmpty($('#product2'))) { $('#product2 .option-container').addClass('has-option'); } // move toolbar category $('.layer-category').prepend($('.custom-category .toolbar')); // Highlight any found errors $('.text-danger').each(function() { var element = $(this).parent().parent(); if (element.hasClass('form-group')) { element.addClass('has-error'); } }); // Currency $('#form-currency .currency-select').on('click', function(e) { e.preventDefault(); $('#form-currency input[name=\'code\']').val($(this).attr('name')); $('#form-currency').submit(); }); // Language $('#form-language .language-select').on('click', function(e) { e.preventDefault(); $('#form-language input[name=\'code\']').val($(this).attr('name')); $('#form-language').submit(); }); /* Search */ $('#search input[name=\'search\']').parent().find('button').on('click', function() { var url = $('base').attr('href') + 'index.php?route=product/search'; var value = $('header #search 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 #search 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 + 10) + 'px'); } }); // Product List $('#list-view').click(function() { $('.custom-products').removeClass('custom-products-row'); $(this).addClass('selected'); $('#grid-view').removeClass('selected'); $('#content .product-grid > .clearfix').remove(); //$('#content .product-layout').attr('class', 'product-layout product-list col-xs-12'); $('#content .product-grid').attr('class', 'product-layout product-list col-xs-12'); $('#content .product-list .caption').addClass('col-xs-8'); $('#content .product-list .image').addClass('col-xs-4'); localStorage.setItem('display', 'list'); }); // Product Grid $('#grid-view').click(function() { $('.custom-products').addClass('custom-products-row'); $(this).addClass('selected'); $('#list-view').removeClass('selected'); // 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-md-6 col-sm-6 col-xs-6 two-items'); } else if (cols == 1) { $('#content .product-layout').attr('class', 'product-layout product-grid col-md-4 col-sm-6 col-xs-6 three-items'); } else { $('#content .product-layout').attr('class', 'product-layout product-grid col-md-3 col-sm-6 col-xs-6 four-items'); } $('#content .product-grid .caption').removeClass('col-xs-8'); $('#content .product-grid .image').removeClass('col-xs-4'); localStorage.setItem('display', 'grid'); }); if (localStorage.getItem('display') == 'list') { $('#list-view').trigger('click'); } else { $('#grid-view').trigger('click'); } // Checkout $(document).on('keydown', '#collapse-checkout-option input[name=\'email\'], #collapse-checkout-option input[name=\'password\']', function(e) { if (e.keyCode == 13) { $('#collapse-checkout-option #button-login').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'); }, complete: function() { $('#cart > button').button('reset'); }, success: function(json) { $('.alert-dismissible, .text-danger').remove(); if (json['redirect']) { location = json['redirect']; } if (json['success']) { $('body').before('
' + json['success'] + '
'); // Need to set timeout otherwise it wont update the total setTimeout(function () { $('#cart > button').html('' + json['total'] + ''); }, 100); $('html, body').animate({ scrollTop: 0 }, 'slow'); $('#cart > ul').load('index.php?route=common/cart/info ul li'); } }, error: function(xhr, ajaxOptions, thrownError) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); }, 'update': function(key, quantity) { $.ajax({ url: 'index.php?route=checkout/cart/edit', type: 'post', data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1), dataType: 'json', beforeSend: function() { $('#cart > button').button('loading'); }, complete: function() { $('#cart > button').button('reset'); }, success: function(json) { // Need to set timeout otherwise it wont update the total setTimeout(function () { $('#cart > button').html('' + json['total'] + ''); }, 100); if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') { location = 'index.php?route=checkout/cart'; } else { $('#cart > ul').load('index.php?route=common/cart/info ul li'); } }, error: function(xhr, ajaxOptions, thrownError) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); }, 'remove': function(key) { $.ajax({ url: 'index.php?route=checkout/cart/remove', type: 'post', data: 'key=' + key, dataType: 'json', beforeSend: function() { $('#cart > button').button('loading'); }, complete: function() { $('#cart > button').button('reset'); }, success: function(json) { // Need to set timeout otherwise it wont update the total setTimeout(function () { $('#cart > button').html('' + json['total'] + ''); }, 100); if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') { location = 'index.php?route=checkout/cart'; } else { $('#cart > ul').load('index.php?route=common/cart/info ul li'); } }, error: function(xhr, ajaxOptions, thrownError) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); } } var voucher = { 'add': function() { }, 'remove': function(key) { $.ajax({ url: 'index.php?route=checkout/cart/remove', type: 'post', data: 'key=' + key, dataType: 'json', beforeSend: function() { $('#cart > button').button('loading'); }, complete: function() { $('#cart > button').button('reset'); }, success: function(json) { // Need to set timeout otherwise it wont update the total setTimeout(function () { $('#cart > button').html(' ' + json['total'] + ''); }, 100); if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') { location = 'index.php?route=checkout/cart'; } else { $('#cart > ul').load('index.php?route=common/cart/info ul li'); } }, error: function(xhr, ajaxOptions, thrownError) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); } } var wishlist = { 'add': function(product_id) { $.ajax({ url: 'index.php?route=account/wishlist/add', type: 'post', data: 'product_id=' + product_id, dataType: 'json', success: function(json) { $('.alert-dismissible').remove(); if (json['redirect']) { location = json['redirect']; } if (json['success']) { $('body').before('
' + json['success'] + '
'); } $('#wishlist-total span').html(json['total']); $('#wishlist-total').attr('title', json['total']); $('html, body').animate({ scrollTop: 0 }, 'slow'); }, error: function(xhr, ajaxOptions, thrownError) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); }, 'remove': function() { } } var compare = { 'add': function(product_id) { $.ajax({ url: 'index.php?route=product/compare/add', type: 'post', data: 'product_id=' + product_id, dataType: 'json', success: function(json) { $('.alert-dismissible').remove(); if (json['success']) { $('body').before('
' + json['success'] + '
'); $('#compare-total').html(json['total']); $('html, body').animate({ scrollTop: 0 }, 'slow'); } }, error: function(xhr, ajaxOptions, thrownError) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); }, 'remove': function() { } } /* Agree to Terms */ $(document).delegate('.agree', 'click', function(e) { e.preventDefault(); $('#modal-agree').remove(); var element = this; $.ajax({ url: $(element).attr('href'), type: 'get', dataType: 'html', success: function(data) { html = ''; $('body').append(html); $('#modal-agree').modal('show'); } }); }); // Autocomplete */ (function($) { $.fn.autocomplete = function(option) { return this.each(function() { this.timer = null; this.items = new Array(); $.extend(this, option); $(this).attr('autocomplete', 'off'); // Focus $(this).on('focus', function() { this.request(); }); // Blur $(this).on('blur', function() { setTimeout(function(object) { object.hide(); }, 200, this); }); // Keydown $(this).on('keydown', function(event) { switch(event.keyCode) { case 27: // escape this.hide(); break; default: this.request(); break; } }); // Click this.click = function(event) { event.preventDefault(); value = $(event.target).parent().attr('data-value'); if (value && this.items[value]) { this.select(this.items[value]); } } // Show this.show = function() { var pos = $(this).position(); $(this).siblings('ul.dropdown-menu').css({ top: pos.top + $(this).outerHeight(), left: pos.left }); $(this).siblings('ul.dropdown-menu').show(); } // Hide this.hide = function() { $(this).siblings('ul.dropdown-menu').hide(); } // Request this.request = function() { clearTimeout(this.timer); this.timer = setTimeout(function(object) { object.source($(object).val(), $.proxy(object.response, object)); }, 200, this); } // Response this.response = function(json) { html = ''; if (json.length) { for (i = 0; i < json.length; i++) { this.items[json[i]['value']] = json[i]; } for (i = 0; i < json.length; i++) { if (!json[i]['category']) { html += '
  • ' + json[i]['label'] + '
  • '; } } // Get all the ones with a categories var category = new Array(); for (i = 0; i < json.length; i++) { if (json[i]['category']) { if (!category[json[i]['category']]) { category[json[i]['category']] = new Array(); category[json[i]['category']]['name'] = json[i]['category']; category[json[i]['category']]['item'] = new Array(); } category[json[i]['category']]['item'].push(json[i]); } } for (i in category) { html += ''; for (j = 0; j < category[i]['item'].length; j++) { html += '
  •    ' + category[i]['item'][j]['label'] + '
  • '; } } } if (html) { this.show(); } else { this.hide(); } $(this).siblings('ul.dropdown-menu').html(html); } $(this).after(''); $(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this)); }); } })(window.jQuery);