1function getURLVar(key) { 2 var value = []; 3 4 var query = String(document.location).split('?'); 5 6 if (query[1]) { 7 var part = query[1].split('&'); 8 9 for (i = 0; i < part.length; i++) { 10 var data = part[i].split('='); 11 12 if (data[0] && data[1]) { 13 value[data[0]] = data[1]; 14 } 15 } 16 17 if (value[key]) { 18 return value[key]; 19 } else { 20 return ''; 21 } 22 } 23} 24 25 26$(document).ready(function() { 27 // Highlight any found errors 28 $('.text-danger').each(function() { 29 var element = $(this).parent().parent(); 30 31 if (element.hasClass('form-group')) { 32 element.addClass('has-error'); 33 } 34 }); 35 36 // Currency 37 $('#form-currency .currency-select').on('click', function(e) { 38 e.preventDefault(); 39 40 $('#form-currency input[name=\'code\']').val($(this).attr('name')); 41 42 $('#form-currency').submit(); 43 }); 44 45 // Magnific popup 46 if ($(".about-images").length) { 47 $('.about-images').magnificPopup({ 48 delegate: 'a.popup-gallery', 49 type: 'image', 50 tLoading: 'Loading image #%curr%...', 51 mainClass: 'mfp-img-mobile', 52 gallery: { 53 enabled: true, 54 navigateByImgClick: true, 55 preload: [0, 1] 56 }, 57 image: { 58 tError: '<a href="%url%">The image #%curr%</a> could not be loaded.', 59 titleSrc: function(item) { 60 return item.el.attr('title') + ''; 61 } 62 } 63 }); 64 } 65 66 // Language 67 $('#form-language .language-select').on('click', function(e) { 68 e.preventDefault(); 69 70 $('#form-language input[name=\'code\']').val($(this).attr('name')); 71 72 $('#form-language').submit(); 73 }); 74 75 /* Search */ 76 $('#search input[name=\'search\']').parent().find('button').on('click', function() { 77 var url = $('base').attr('href') + 'index.php?route=product/search'; 78 79 var value = $('header #search input[name=\'search\']').val(); 80 81 if (value) { 82 url += '&search=' + encodeURIComponent(value); 83 } 84 85 location = url; 86 }); 87 88 $('#search input[name=\'search\']').on('keydown', function(e) { 89 if (e.keyCode == 13) { 90 $('header #search input[name=\'search\']').parent().find('button').trigger('click'); 91 } 92 }); 93 94 // Menu 95 $('#menu .dropdown-menu').each(function() { 96 var menu = $('#menu').offset(); 97 var dropdown = $(this).parent().offset(); 98 99 var i = (dropdown.left + $(this).outerWidth()) - (menu.left + $('#menu').outerWidth()); 100 101 if (i > 0) { 102 $(this).css('margin-left', '-' + (i + 10) + 'px'); 103 } 104 }); 105 106 // Product List 107 $('#list-view').click(function() { 108 $('#content .product-grid > .clearfix').remove(); 109 110 $('#content .row > .product-grid').attr('class', 'product-layout product-list col-xs-12'); 111 $('#grid-view').removeClass('active'); 112 $('#list-view').addClass('active'); 113 114 localStorage.setItem('display', 'list'); 115 }); 116 117 // Product Grid 118 $('#grid-view').click(function() { 119 // What a shame bootstrap does not take into account dynamically loaded columns 120 var cols = $('#column-right, #column-left').length; 121 122 if (cols == 2) { 123 $('#content .product-list').attr('class', 'product-layout product-grid col-lg-6 col-md-6 col-sm-12 col-xs-12'); 124 } else if (cols == 1) { 125 $('#content .product-list').attr('class', 'product-layout product-grid col-lg-4 col-md-4 col-sm-6 col-xs-12'); 126 } else { 127 $('#content .product-list').attr('class', 'product-layout product-grid col-lg-3 col-md-3 col-sm-6 col-xs-12'); 128 } 129 130 $('#list-view').removeClass('active'); 131 $('#grid-view').addClass('active'); 132 133 localStorage.setItem('display', 'grid'); 134 }); 135 136 if (localStorage.getItem('display') == 'list') { 137 $('#list-view').trigger('click'); 138 $('#list-view').addClass('active'); 139 } else { 140 $('#grid-view').trigger('click'); 141 $('#grid-view').addClass('active'); 142 } 143 144 145 146 147 // Checkout 148 $(document).on('keydown', '#collapse-checkout-option input[name=\'email\'], #collapse-checkout-option input[name=\'password\']', function(e) { 149 if (e.keyCode == 13) { 150 $('#collapse-checkout-option #button-login').trigger('click'); 151 } 152 }); 153 154 // tooltips on hover 155 $('[data-toggle=\'tooltip\']').tooltip({ container: 'body' }); 156 157 // Makes tooltips work on ajax generated content 158 $(document).ajaxStop(function() { 159 $('[data-toggle=\'tooltip\']').tooltip({ container: 'body' }); 160 }); 161 162 163 $('.product-thumb .caption').matchHeight(); 164 165 // FB Pixel eventi 166 if (typeof fbq === "function") { 167 168 if ($('#product-search').length) {
169 var string = $('#input-search').val(); 170 if (string) { 171 // console.log('Search = string: ' + string); 172 fbq('track', 'Search', { search_string: string }); 173 } 174 } 175 176 if ($('#product-product').length) { 177 var product = $('#product-product'); 178 var product_id = product.data('product-id'); 179 var price = parseFloat(product.data('price').replace(',', '.')); 180 // console.log('ViewContent = id: ' + product_id + ' price:' + price); 181 fbq('track', 'ViewContent', { content_ids: product_id, content_type: 'product', currency: 'EUR', value: price }); 182 } 183 184 $('button').on('click', function() { 185 if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('cart.add') != -1) { 186 187 if (!$(this).hasClass('btn-danger')) { 188 var product_id = parseInt($(this).attr('onclick').match(/(\d+)/)); 189 } else { 190 var product_id = parseInt($(this).attr('onclick').replace(", '1'", '').match(/(\d+)/)); 191 } 192 193 var price = parseFloat($(this).closest('.product-thumb').find('span.price-new').text().replace(',', '.')); 194 if (!price) price = parseFloat($(this).closest('.product-thumb').find('.price').text().replace(',', '.')); 195 196 if (price && product_id) { 197 console.log('AddToCart = id: ' + product_id + ' price:' + price); 198 fbq('track', 'AddToCart', { content_ids: product_id, content_type: 'product', currency: 'EUR', value: price }); 199 } 200 } 201 }); 202 203 $('#button-cart').on('click', function() { 204 var product = $('#product-product'); 205 if (product.length) { 206 var product_id = product.data('product-id'); 207 var price = parseFloat(product.data('price').replace(',', '.')); 208 209 // console.log('AddToCart = id: ' + product_id + ' price:' + price); 210 fbq('track', 'AddToCart', { content_ids: product_id, content_type: 'product', currency: 'EUR', value: price }); 211 } 212 }); 213 214 if ($('#checkout-checkout').length) { 215 var product_ids = []; 216 $('tr.single-product').each(function() { 217 if ($(this).data('price').length) { 218 var product_id = $(this).data('product-id'); 219 product_ids.push(product_id); 220 } 221 }); 222 var price = parseFloat($('#cart .price-field').last().text().replace(',', '.')); 223 224 // console.log('InitiateCheckout = ids: ' + product_ids + ' price:' + price); 225 fbq('track', 'InitiateCheckout', { content_ids: product_ids, content_type: 'product', currency: 'EUR', value: price }); 226 } 227 228 $('#checkout-checkout').on('click', '#button-confirm', function() { 229 var product_ids = []; 230 $('tr.single-product').each(function() { 231 if ($(this).data('price').length) { 232 var product_id = $(this).data('product-id'); 233 product_ids.push(product_id); 234 } 235 }); 236 var price = parseFloat($('#collapse-checkout-confirm .text-right').last().text().replace(',', '.')); 237 238 // console.log('Purchase = ids: ' + product_ids + ' price:' + price); 239 fbq('track', 'Purchase', { content_ids: product_ids, content_type: 'product', currency: 'EUR', value: price }); 240 }); 241 } 242 243 $('.product-layout .btn-danger, #product-product .btn-danger').on('click', function() { 244 var times = readCookie("modal_shown"); 245 if (times != 'preorder_info') { 246 setTimeout(function() { 247 $('#infoModal').modal('show'); 248 249 $('#not_show_again').on('click', function(e) { 250 createCookie('modal_shown', 'preorder_info', 14); 251 $('#infoModal').modal('toggle'); 252 e.preventDefault(); 253 }); 254 }, 500); 255 } 256 }); 257 258 259 function createCookie(name, value, days) { 260 var expires; 261 262 if (days) { 263 var date = new Date(); 264 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 265 expires = "; expires=" + date.toGMTString(); 266 } else { 267 expires = ""; 268 } 269 document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/"; 270 } 271 272 function readCookie(name) { 273 var nameEQ = encodeURIComponent(name) + "="; 274 var ca = document.cookie.split(';'); 275 for (var i = 0; i < ca.length; i++) { 276 var c = ca[i]; 277 while (c.charAt(0) === ' ') 278 c = c.substring(1, c.length); 279 if (c.indexOf(nameEQ) === 0) 280 return decodeURIComponent(c.substring(nameEQ.length, c.length)); 281 } 282 return null; 283 } 284 285}); 286 287// Cart add remove functions 288var cart = { 289 'add': function(product_id, quantity) { 290 $.ajax({ 291 url: 'index.php?route=checkout/cart/add', 292 type: 'post', 293 data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1), 294 dataType: 'json', 295 beforeSend: function() { 296 $('#cart > button').button('loading'); 297 }, 298 complete: function() { 299 $('#cart > button').button('reset'); 300 }, 301 success: function(json) { 302 $('.alert-dismissible, .text-danger').remove(); 303 304 if (json['redirect']) { 305 location = json['redirect']; 306 } 307 308 if (json['success']) { 309 $('#content').parent().before('<div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">×</button></div>'); 310 311 // Need to set timeout otherwise it wont update the total 312 setTimeout(function() { 313 $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>'); 314 }, 100); 315 316 $('html, body').animate({ scrollTop: 0 }, 'slow'); 317 318 $('#cart > ul').load('index.php?route=common/cart/info ul li'); 319 } 320 }, 321 error: function(xhr, ajaxOptions, thrownError) { 322 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 323 } 324 }); 325 }, 326 'update': function(key, quantity) { 327 $.ajax({ 328 url: 'index.php?route=checkout/cart/edit', 329 type: 'post', 330 data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1), 331 dataType: 'json', 332 beforeSend: function() { 333 $('#cart > button').button('loading'); 334 }, 335 complete: function() { 336 $('#cart > button').button('reset'); 337 }, 338 success: function(json) { 339 // Need to set timeout otherwise it wont update the total 340 setTimeout(function() { 341 $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>'); 342 }, 100); 343 344 if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') { 345 location = 'index.php?route=checkout/cart'; 346 } else { 347 $('#cart > ul').load('index.php?route=common/cart/info ul li'); 348 } 349 }, 350 error: function(xhr, ajaxOptions, thrownError) { 351 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 352 } 353 }); 354 }, 355 'remove': function(key) { 356 $.ajax({ 357 url: 'index.php?route=checkout/cart/remove', 358 type: 'post', 359 data: 'key=' + key, 360 dataType: 'json', 361 beforeSend: function() { 362 $('#cart > button').button('loading'); 363 }, 364 complete: function() { 365 $('#cart > button').button('reset'); 366 }, 367 success: function(json) { 368 // Need to set timeout otherwise it wont update the total 369 setTimeout(function() { 370 $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>'); 371 }, 100); 372 373 if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') { 374 location = 'index.php?route=checkout/cart'; 375 } else { 376 $('#cart > ul').load('index.php?route=common/cart/info ul li'); 377 } 378 }, 379 error: function(xhr, ajaxOptions, thrownError) { 380 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 381 } 382 }); 383 } 384} 385 386var voucher = { 387 'add': function() { 388 389 }, 390 'remove': function(key) { 391 $.ajax({ 392 url: 'index.php?route=checkout/cart/remove', 393 type: 'post', 394 data: 'key=' + key, 395 dataType: 'json', 396 beforeSend: function() { 397 $('#cart > button').button('loading'); 398 }, 399 complete: function() { 400 $('#cart > button').button('reset'); 401 }, 402 success: function(json) { 403 // Need to set timeout otherwise it wont update the total 404 setTimeout(function() { 405 $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>'); 406 }, 100); 407 408 if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') { 409 location = 'index.php?route=checkout/cart'; 410 } else { 411 $('#cart > ul').load('index.php?route=common/cart/info ul li'); 412 } 413 }, 414 error: function(xhr, ajaxOptions, thrownError) { 415 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 416 } 417 }); 418 } 419} 420 421var wishlist = { 422 'add': function(product_id) { 423 $.ajax({ 424 url: 'index.php?route=account/wishlist/add', 425 type: 'post', 426 data: 'product_id=' + product_id, 427 dataType: 'json', 428 success: function(json) { 429 $('.alert-dismissible').remove(); 430 431 if (json['redirect']) { 432 location = json['redirect']; 433 } 434 435 if (json['success']) { 436 $('#content').parent().before('<div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">×</button></div>'); 437 } 438 439 $('#wishlist-total span').html(json['total']); 440 $('#wishlist-total').attr('title', json['total']); 441 442 $('html, body').animate({ scrollTop: 0 }, 'slow'); 443 }, 444 error: function(xhr, ajaxOptions, thrownError) { 445 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 446 } 447 }); 448 }, 449 'remove': function() { 450 451 } 452} 453 454var compare = { 455 'add': function(product_id) { 456 $.ajax({ 457 url: 'index.php?route=product/compare/add', 458 type: 'post', 459 data: 'product_id=' + product_id, 460 dataType: 'json', 461 success: function(json) { 462 $('.alert-dismissible').remove(); 463 464 if (json['success']) { 465 $('#content').parent().before('<div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">×</button></div>'); 466 467 $('#compare-total').html(json['total']); 468 469 $('html, body').animate({ scrollTop: 0 }, 'slow'); 470 } 471 }, 472 error: function(xhr, ajaxOptions, thrownError) { 473 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 474 } 475 }); 476 }, 477 'remove': function() { 478 479 } 480} 481 482/* Agree to Terms */ 483$(document).delegate('.agree', 'click', function(e) { 484 e.preventDefault(); 485
486 $('#modal-agree').remove(); 487 488 var element = this; 489 490 $.ajax({ 491 url: $(element).attr('href'), 492 type: 'get', 493 dataType: 'html', 494 success: function(data) { 495 html = '<div id="modal-agree" class="modal">'; 496 html += ' <div class="modal-dialog">'; 497 html += ' <div class="modal-content">'; 498 html += ' <div class="modal-header">'; 499 html += ' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'; 500 html += ' <h4 class="modal-title">' + $(element).text() + '</h4>'; 501 html += ' </div>'; 502 html += ' <div class="modal-body">' + data + '</div>'; 503 html += ' </div>'; 504 html += ' </div>'; 505 html += '</div>'; 506 507 $('body').append(html); 508 509 $('#modal-agree').modal('show'); 510 } 511 }); 512}); 513 514// Autocomplete */ 515(function($) { 516 $.fn.autocomplete = function(option) { 517 return this.each(function() { 518 this.timer = null; 519 this.items = new Array(); 520 521 $.extend(this, option); 522 523 $(this).attr('autocomplete', 'off'); 524 525 // Focus 526 $(this).on('focus', function() { 527 this.request(); 528 }); 529 530 // Blur 531 $(this).on('blur', function() { 532 setTimeout(function(object) { 533 object.hide(); 534 }, 200, this); 535 }); 536 537 // Keydown 538 $(this).on('keydown', function(event) { 539 switch (event.keyCode) { 540 case 27: // escape 541 this.hide(); 542 break; 543 default: 544 this.request(); 545 break; 546 } 547 }); 548 549 // Click 550 this.click = function(event) { 551 event.preventDefault(); 552 553 value = $(event.target).parent().attr('data-value'); 554 555 if (value && this.items[value]) { 556 this.select(this.items[value]); 557 } 558 } 559 560 // Show 561 this.show = function() { 562 var pos = $(this).position(); 563 564 $(this).siblings('ul.dropdown-menu').css({ 565 top: pos.top + $(this).outerHeight(), 566 left: pos.left 567 }); 568 569 $(this).siblings('ul.dropdown-menu').show(); 570 } 571 572 // Hide 573 this.hide = function() { 574 $(this).siblings('ul.dropdown-menu').hide(); 575 } 576 577 // Request 578 this.request = function() { 579 clearTimeout(this.timer); 580 581 this.timer = setTimeout(function(object) { 582 object.source($(object).val(), $.proxy(object.response, object)); 583 }, 200, this); 584 } 585 586 // Response 587 this.response = function(json) { 588 html = ''; 589 590 if (json.length) { 591 for (i = 0; i < json.length; i++) { 592 this.items[json[i]['value']] = json[i]; 593 } 594 595 for (i = 0; i < json.length; i++) { 596 if (!json[i]['category']) { 597 html += '<li data-value="' + json[i]['value'] + '"><a href="#">' + json[i]['label'] + '</a></li>'; 598 } 599 } 600 601 // Get all the ones with a categories 602 var category = new Array(); 603 604 for (i = 0; i < json.length; i++) { 605 if (json[i]['category']) { 606 if (!category[json[i]['category']]) { 607 category[json[i]['category']] = new Array(); 608 category[json[i]['category']]['name'] = json[i]['category']; 609 category[json[i]['category']]['item'] = new Array(); 610 } 611 612 category[json[i]['category']]['item'].push(json[i]); 613 } 614 } 615 616 for (i in category) { 617 html += '<li class="dropdown-header">' + category[i]['name'] + '</li>'; 618 619 for (j = 0; j < category[i]['item'].length; j++) { 620 html += '<li data-value="' + category[i]['item'][j]['value'] + '"><a href="#"> ' + category[i]['item'][j]['label'] + '</a></li>'; 621 } 622 } 623 } 624 625 if (html) { 626 this.show(); 627 } else { 628 this.hide(); 629 } 630 631 $(this).siblings('ul.dropdown-menu').html(html); 632 } 633 634 $(this).after('<ul class="dropdown-menu"></ul>'); 635 $(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this)); 636 637 }); 638 } 639})(window.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.