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$(document).ready(function() { 26 // Highlight any found errors 27 $('.text-danger').each(function() { 28 var element = $(this).parent().parent(); 29 30 if (element.hasClass('form-group')) { 31 element.addClass('has-error'); 32 } 33 }); 34 35 // Currency 36 $('#form-currency .currency-select').on('click', function(e) { 37 e.preventDefault(); 38 39 $('#form-currency input[name=\'code\']').val($(this).attr('name')); 40 41 $('#form-currency').submit(); 42 }); 43 44 // Language 45 $('#form-language .language-select').on('click', function(e) { 46 e.preventDefault(); 47 48 $('#form-language input[name=\'code\']').val($(this).attr('name')); 49 50 $('#form-language').submit(); 51 }); 52 53 /* Search */ 54 $('#search input[name=\'search\']').parent().find('button').on('click', function() { 55 var url = $('base').attr('href') + 'index.php?route=product/search'; 56 57 var value = $('header #search input[name=\'search\']').val(); 58 59 if (value) { 60 url += '&search=' + encodeURIComponent(value); 61 } 62 63 location = url; 64 }); 65 66 $('#search input[name=\'search\']').on('keydown', function(e) { 67 if (e.keyCode == 13) { 68 $('header #search input[name=\'search\']').parent().find('button').trigger('click'); 69 } 70 }); 71 72 // Menu 73 $('#menu .dropdown-menu').each(function() { 74 var menu = $('#menu').offset(); 75 var dropdown = $(this).parent().offset(); 76 77 var i = (dropdown.left + $(this).outerWidth()) - (menu.left + $('#menu').outerWidth()); 78 79 if (i > 0) { 80 $(this).css('margin-left', '-' + (i + 10) + 'px'); 81 } 82 }); 83 84 // Product List 85 $('#list-view').click(function() { 86 $('#content .product-grid > .clearfix').remove(); 87 88 $('#content .row > .product-grid').attr('class', 'product-layout product-list col-xs-12'); 89 $('#grid-view').removeClass('active'); 90 $('#list-view').addClass('active'); 91 92 localStorage.setItem('display', 'list'); 93 }); 94 95 // Product Grid 96 $('#grid-view').click(function() { 97 // What a shame bootstrap does not take into account dynamically loaded columns 98 var cols = $('#column-right, #column-left').length; 99 100 if (cols == 2) { 101 $('#content .product-list').attr('class', 'product-layout product-grid col-lg-6 col-md-6 col-sm-12 col-xs-12'); 102 } else if (cols == 1) { 103 $('#content .product-list').attr('class', 'product-layout product-grid col-lg-4 col-md-4 col-sm-6 col-xs-12'); 104 } else { 105 $('#content .product-list').attr('class', 'product-layout product-grid col-lg-3 col-md-3 col-sm-6 col-xs-12'); 106 } 107 108 $('#list-view').removeClass('active'); 109 $('#grid-view').addClass('active'); 110 111 localStorage.setItem('display', 'grid'); 112 }); 113 114 if (localStorage.getItem('display') == 'list') { 115 $('#list-view').trigger('click'); 116 $('#list-view').addClass('active'); 117 } else { 118 $('#grid-view').trigger('click'); 119 $('#grid-view').addClass('active'); 120 } 121 122 // Checkout 123 $(document).on('keydown', '#collapse-checkout-option input[name=\'email\'], #collapse-checkout-option input[name=\'password\']', function(e) { 124 if (e.keyCode == 13) { 125 $('#collapse-checkout-option #button-login').trigger('click'); 126 } 127 }); 128 129 // tooltips on hover 130 $('[data-toggle=\'tooltip\']').tooltip({container: 'body'}); 131 132 // Makes tooltips work on ajax generated content 133 $(document).ajaxStop(function() { 134 $('[data-toggle=\'tooltip\']').tooltip({container: 'body'}); 135 }); 136 137 138 mobile_menu(); 139 140}); 141 142 143function mobile_menu() { 144 var categoryBlock = document.getElementById('category'); 145 var toggleButton = document.querySelector('.navbar-toggle'); 146 147 148 categoryBlock.addEventListener('click', function() { 149 toggleButton.click(); 150 }); 151} 152 153 154// Cart add remove functions 155var cart = { 156 'add': function(product_id, quantity) { 157 $.ajax({
158 url: 'index.php?route=checkout/cart/add', 159 type: 'post', 160 data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1), 161 dataType: 'json', 162 beforeSend: function() { 163 $('#cart > button').button('loading'); 164 }, 165 complete: function() { 166 $('#cart > button').button('reset'); 167 }, 168 success: function(json) { 169 $('.alert-dismissible, .text-danger').remove(); 170 171 if (json['redirect']) { 172 location = json['redirect']; 173 } 174 175 if (json['success']) { 176 $('#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>'); 177 178 // Need to set timeout otherwise it wont update the total 179 setTimeout(function () { 180 $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>'); 181 }, 100); 182 183 // $('html, body').animate({ scrollTop: 0 }, 'slow'); 184 185 $('#cart > ul').load('index.php?route=common/cart/info ul li'); 186 } 187 }, 188 error: function(xhr, ajaxOptions, thrownError) { 189 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 190 } 191 }); 192 }, 193 'update': function(key, quantity) { 194 $.ajax({ 195 url: 'index.php?route=checkout/cart/edit', 196 type: 'post', 197 data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1), 198 dataType: 'json', 199 beforeSend: function() { 200 $('#cart > button').button('loading'); 201 }, 202 complete: function() { 203 $('#cart > button').button('reset'); 204 }, 205 success: function(json) { 206 // Need to set timeout otherwise it wont update the total 207 setTimeout(function () { 208 $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>'); 209 }, 100); 210 211 if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') { 212 location = 'index.php?route=checkout/cart'; 213 } else { 214 $('#cart > ul').load('index.php?route=common/cart/info ul li'); 215 } 216 }, 217 error: function(xhr, ajaxOptions, thrownError) { 218 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 219 } 220 }); 221 }, 222 'remove': function(key) { 223 $.ajax({ 224 url: 'index.php?route=checkout/cart/remove', 225 type: 'post', 226 data: 'key=' + key, 227 dataType: 'json', 228 beforeSend: function() { 229 $('#cart > button').button('loading'); 230 }, 231 complete: function() { 232 $('#cart > button').button('reset'); 233 }, 234 success: function(json) { 235 // Need to set timeout otherwise it wont update the total 236 setTimeout(function () { 237 $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>'); 238 }, 100); 239 240 if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') { 241 location = 'index.php?route=checkout/cart'; 242 } else { 243 $('#cart > ul').load('index.php?route=common/cart/info ul li'); 244 } 245 }, 246 error: function(xhr, ajaxOptions, thrownError) { 247 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 248 } 249 }); 250 } 251} 252 253var voucher = { 254 'add': function() { 255 256 }, 257 'remove': function(key) { 258 $.ajax({ 259 url: 'index.php?route=checkout/cart/remove', 260 type: 'post', 261 data: 'key=' + key, 262 dataType: 'json', 263 beforeSend: function() { 264 $('#cart > button').button('loading'); 265 }, 266 complete: function() { 267 $('#cart > button').button('reset'); 268 }, 269 success: function(json) { 270 // Need to set timeout otherwise it wont update the total 271 setTimeout(function () { 272 $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>'); 273 }, 100); 274 275 if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') { 276 location = 'index.php?route=checkout/cart'; 277 } else { 278 $('#cart > ul').load('index.php?route=common/cart/info ul li'); 279 } 280 }, 281 error: function(xhr, ajaxOptions, thrownError) { 282 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 283 } 284 }); 285 } 286} 287 288var wishlist = { 289 'add': function(product_id) { 290 $.ajax({
291 url: 'index.php?route=account/wishlist/add', 292 type: 'post', 293 data: 'product_id=' + product_id, 294 dataType: 'json', 295 success: function(json) { 296 $('.alert-dismissible').remove(); 297 298 if (json['redirect']) { 299 location = json['redirect']; 300 } 301 302 if (json['success']) { 303 $('#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>'); 304 } 305 306 $('#wishlist-total span').html(json['total']); 307 $('#wishlist-total').attr('title', json['total']); 308 309 $('html, body').animate({ scrollTop: 0 }, 'slow'); 310 }, 311 error: function(xhr, ajaxOptions, thrownError) { 312 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 313 } 314 }); 315 }, 316 'remove': function() { 317 318 } 319} 320 321var compare = { 322 'add': function(product_id) { 323 $.ajax({ 324 url: 'index.php?route=product/compare/add', 325 type: 'post', 326 data: 'product_id=' + product_id, 327 dataType: 'json', 328 success: function(json) { 329 $('.alert-dismissible').remove(); 330 331 if (json['success']) { 332 $('#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>'); 333 334 $('#compare-total').html(json['total']); 335 336 $('html, body').animate({ scrollTop: 0 }, 'slow'); 337 } 338 }, 339 error: function(xhr, ajaxOptions, thrownError) { 340 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 341 } 342 }); 343 }, 344 'remove': function() { 345 346 } 347} 348 349/* Agree to Terms */ 350$(document).delegate('.agree', 'click', function(e) { 351 e.preventDefault(); 352 353 $('#modal-agree').remove(); 354 355 var element = this; 356 357 $.ajax({ 358 url: $(element).attr('href'), 359 type: 'get', 360 dataType: 'html', 361 success: function(data) { 362 html = '<div id="modal-agree" class="modal">'; 363 html += ' <div class="modal-dialog">'; 364 html += ' <div class="modal-content">'; 365 html += ' <div class="modal-header">'; 366 html += ' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'; 367 html += ' <h4 class="modal-title">' + $(element).text() + '</h4>'; 368 html += ' </div>'; 369 html += ' <div class="modal-body">' + data + '</div>'; 370 html += ' </div>'; 371 html += ' </div>'; 372 html += '</div>'; 373 374 $('body').append(html); 375
376 $('#modal-agree').modal('show'); 377 } 378 }); 379}); 380 381// Autocomplete */ 382(function($) { 383 $.fn.autocomplete = function(option) { 384 return this.each(function() { 385 this.timer = null; 386 this.items = new Array(); 387 388 $.extend(this, option); 389 390 $(this).attr('autocomplete', 'off'); 391 392 // Focus 393 $(this).on('focus', function() { 394 this.request(); 395 }); 396 397 // Blur 398 $(this).on('blur', function() { 399 setTimeout(function(object) { 400 object.hide(); 401 }, 200, this); 402 }); 403 404 // Keydown 405 $(this).on('keydown', function(event) { 406 switch(event.keyCode) { 407 case 27: // escape 408 this.hide(); 409 break; 410 default: 411 this.request(); 412 break; 413 } 414 }); 415 416 // Click 417 this.click = function(event) { 418 event.preventDefault(); 419 420 value = $(event.target).parent().attr('data-value'); 421 422 if (value && this.items[value]) { 423 this.select(this.items[value]); 424 } 425 } 426 427 // Show 428 this.show = function() { 429 var pos = $(this).position(); 430 431 $(this).siblings('ul.dropdown-menu').css({ 432 top: pos.top + $(this).outerHeight(), 433 left: pos.left 434 }); 435 436 $(this).siblings('ul.dropdown-menu').show(); 437 } 438 439 // Hide 440 this.hide = function() { 441 $(this).siblings('ul.dropdown-menu').hide(); 442 } 443 444 // Request 445 this.request = function() { 446 clearTimeout(this.timer); 447 448 this.timer = setTimeout(function(object) { 449 object.source($(object).val(), $.proxy(object.response, object)); 450 }, 200, this); 451 } 452 453 // Response 454 this.response = function(json) { 455 html = ''; 456 457 if (json.length) { 458 for (i = 0; i < json.length; i++) { 459 this.items[json[i]['value']] = json[i]; 460 } 461 462 for (i = 0; i < json.length; i++) { 463 if (!json[i]['category']) { 464 html += '<li data-value="' + json[i]['value'] + '"><a href="#">' + json[i]['label'] + '</a></li>'; 465 } 466 } 467 468 // Get all the ones with a categories 469 var category = new Array(); 470 471 for (i = 0; i < json.length; i++) { 472 if (json[i]['category']) { 473 if (!category[json[i]['category']]) { 474 category[json[i]['category']] = new Array(); 475 category[json[i]['category']]['name'] = json[i]['category']; 476 category[json[i]['category']]['item'] = new Array(); 477 } 478 479 category[json[i]['category']]['item'].push(json[i]); 480 } 481 } 482 483 for (i in category) { 484 html += '<li class="dropdown-header">' + category[i]['name'] + '</li>'; 485 486 for (j = 0; j < category[i]['item'].length; j++) { 487 html += '<li data-value="' + category[i]['item'][j]['value'] + '"><a href="#"> ' + category[i]['item'][j]['label'] + '</a></li>'; 488 } 489 } 490 } 491 492 if (html) { 493 this.show(); 494 } else { 495 this.hide(); 496 } 497 498 $(this).siblings('ul.dropdown-menu').html(html); 499 } 500 501 $(this).after('<ul class="dropdown-menu"></ul>'); 502 $(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this)); 503 504 }); 505 } 506})(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.