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// Cart add remove functions 139var cart = { 140 'add': function(product_id, quantity) { 141 $.ajax({ 142 url: 'index.php?route=checkout/cart/add', 143 type: 'post', 144 data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1), 145 dataType: 'json', 146 beforeSend: function() { 147 $('#cart > button').button('loading'); 148 }, 149 complete: function() { 150 $('#cart > button').button('reset'); 151 }, 152 success: function(json) { 153 $('.alert-dismissible, .text-danger').remove(); 154 155 if (json['redirect']) { 156 location = json['redirect']; 157 } 158 159 if (json['success']) { 160 // $('#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>'); 161 162 // // Need to set timeout otherwise it wont update the total 163 // setTimeout(function () { 164 // $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>'); 165 // }, 100); 166 167 // $('html, body').animate({ scrollTop: 0 }, 'slow'); 168 169 // $('#cart > ul').load('index.php?route=common/cart/info ul li'); 170 171 $('#cart > a').trigger('click') 172 } 173 }, 174 error: function(xhr, ajaxOptions, thrownError) { 175 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 176 } 177 }); 178 }, 179 'update': function(key, quantity) { 180 $.ajax({ 181 url: 'index.php?route=checkout/cart/edit', 182 type: 'post', 183 data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1), 184 dataType: 'json', 185 beforeSend: function() { 186 $('#cart > button').button('loading'); 187 },
188 complete: function() { 189 $('#cart > button').button('reset'); 190 }, 191 success: function(json) { 192 // Need to set timeout otherwise it wont update the total 193 setTimeout(function () { 194 $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>'); 195 }, 100); 196 197 if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') { 198 location = 'index.php?route=checkout/cart'; 199 } else { 200 $('#cart > ul').load('index.php?route=common/cart/info ul li'); 201 } 202 }, 203 error: function(xhr, ajaxOptions, thrownError) { 204 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 205 } 206 }); 207 }, 208 'remove': function(key) { 209 $.ajax({ 210 url: 'index.php?route=checkout/cart/remove', 211 type: 'post', 212 data: 'key=' + key, 213 dataType: 'json', 214 beforeSend: function() { 215 $('#cart > button').button('loading'); 216 }, 217 complete: function() { 218 $('#cart > button').button('reset'); 219 }, 220 success: function(json) { 221 // Need to set timeout otherwise it wont update the total 222 setTimeout(function () { 223 $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>'); 224 }, 100); 225 226 if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') { 227 location = 'index.php?route=checkout/cart'; 228 } else { 229 $('#cart > ul').load('index.php?route=common/cart/info ul li'); 230 } 231 }, 232 error: function(xhr, ajaxOptions, thrownError) { 233 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 234 } 235 }); 236 } 237} 238 239var voucher = { 240 'add': function() { 241 242 }, 243 'remove': function(key) { 244 $.ajax({ 245 url: 'index.php?route=checkout/cart/remove', 246 type: 'post', 247 data: 'key=' + key, 248 dataType: 'json', 249 beforeSend: function() { 250 $('#cart > button').button('loading'); 251 }, 252 complete: function() { 253 $('#cart > button').button('reset'); 254 }, 255 success: function(json) { 256 // Need to set timeout otherwise it wont update the total 257 setTimeout(function () { 258 $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>'); 259 }, 100); 260 261 if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') { 262 location = 'index.php?route=checkout/cart'; 263 } else { 264 $('#cart > ul').load('index.php?route=common/cart/info ul li'); 265 } 266 }, 267 error: function(xhr, ajaxOptions, thrownError) { 268 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 269 } 270 }); 271 } 272} 273 274var wishlist = { 275 'add': function(product_id) { 276 $.ajax({ 277 url: 'index.php?route=account/wishlist/add', 278 type: 'post', 279 data: 'product_id=' + product_id, 280 dataType: 'json', 281 success: function(json) { 282 $('.alert-dismissible').remove(); 283 284 if (json['redirect']) { 285 location = json['redirect']; 286 } 287 288 if (json['success']) { 289 $('#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>'); 290 } 291 292 $('#wishlist-total span').html(json['total']); 293 $('#wishlist-total').attr('title', json['total']); 294 295 $('html, body').animate({ scrollTop: 0 }, 'slow'); 296 }, 297 error: function(xhr, ajaxOptions, thrownError) { 298 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 299 } 300 }); 301 }, 302 'remove': function() { 303 304 } 305} 306 307var compare = { 308 'add': function(product_id) { 309 $.ajax({ 310 url: 'index.php?route=product/compare/add', 311 type: 'post', 312 data: 'product_id=' + product_id, 313 dataType: 'json', 314 success: function(json) { 315 $('.alert-dismissible').remove(); 316 317 if (json['success']) { 318 $('#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>'); 319 320 $('#compare-total').html(json['total']); 321 322 $('html, body').animate({ scrollTop: 0 }, 'slow'); 323 } 324 }, 325 error: function(xhr, ajaxOptions, thrownError) { 326 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 327 } 328 }); 329 }, 330 'remove': function() { 331 332 } 333} 334 335/* Agree to Terms */ 336$(document).delegate('.agree', 'click', function(e) { 337 e.preventDefault(); 338
339 $('#modal-agree').remove(); 340 341 var element = this; 342 343 $.ajax({ 344 url: $(element).attr('href'), 345 type: 'get', 346 dataType: 'html', 347 success: function(data) { 348 html = '<div id="modal-agree" class="modal">'; 349 html += ' <div class="modal-dialog">'; 350 html += ' <div class="modal-content">'; 351 html += ' <div class="modal-header">'; 352 html += ' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'; 353 html += ' <h4 class="modal-title">' + $(element).text() + '</h4>'; 354 html += ' </div>'; 355 html += ' <div class="modal-body">' + data + '</div>'; 356 html += ' </div>'; 357 html += ' </div>'; 358 html += '</div>'; 359 360 $('body').append(html); 361 362 $('#modal-agree').modal('show'); 363 } 364 }); 365}); 366 367// Autocomplete */ 368(function($) { 369 $.fn.autocomplete = function(option) { 370 return this.each(function() { 371 this.timer = null; 372 this.items = new Array(); 373 374 $.extend(this, option); 375 376 $(this).attr('autocomplete', 'off'); 377 378 // Focus 379 $(this).on('focus', function() { 380 this.request(); 381 }); 382 383 // Blur 384 $(this).on('blur', function() { 385 setTimeout(function(object) { 386 object.hide(); 387 }, 200, this); 388 }); 389 390 // Keydown 391 $(this).on('keydown', function(event) { 392 switch(event.keyCode) { 393 case 27: // escape 394 this.hide(); 395 break; 396 default: 397 this.request(); 398 break; 399 } 400 }); 401 402 // Click 403 this.click = function(event) { 404 event.preventDefault(); 405 406 value = $(event.target).parent().attr('data-value'); 407 408 if (value && this.items[value]) { 409 this.select(this.items[value]); 410 } 411 } 412 413 // Show 414 this.show = function() { 415 var pos = $(this).position(); 416 417 $(this).siblings('ul.dropdown-menu').css({ 418 top: pos.top + $(this).outerHeight(), 419 left: pos.left 420 }); 421 422 $(this).siblings('ul.dropdown-menu').show(); 423 } 424 425 // Hide 426 this.hide = function() { 427 $(this).siblings('ul.dropdown-menu').hide(); 428 } 429 430 // Request 431 this.request = function() { 432 clearTimeout(this.timer); 433 434 this.timer = setTimeout(function(object) { 435 object.source($(object).val(), $.proxy(object.response, object)); 436 }, 200, this); 437 } 438 439 // Response 440 this.response = function(json) { 441 html = ''; 442 443 if (json.length) { 444 for (i = 0; i < json.length; i++) { 445 this.items[json[i]['value']] = json[i]; 446 } 447 448 for (i = 0; i < json.length; i++) { 449 if (!json[i]['category']) { 450 html += '<li data-value="' + json[i]['value'] + '"><a href="#">' + json[i]['label'] + '</a></li>'; 451 } 452 } 453 454 // Get all the ones with a categories 455 var category = new Array(); 456 457 for (i = 0; i < json.length; i++) { 458 if (json[i]['category']) { 459 if (!category[json[i]['category']]) { 460 category[json[i]['category']] = new Array(); 461 category[json[i]['category']]['name'] = json[i]['category']; 462 category[json[i]['category']]['item'] = new Array(); 463 } 464 465 category[json[i]['category']]['item'].push(json[i]); 466 } 467 } 468 469 for (i in category) { 470 html += '<li class="dropdown-header">' + category[i]['name'] + '</li>'; 471 472 for (j = 0; j < category[i]['item'].length; j++) { 473 html += '<li data-value="' + category[i]['item'][j]['value'] + '"><a href="#"> ' + category[i]['item'][j]['label'] + '</a></li>'; 474 } 475 } 476 } 477 478 if (html) { 479 this.show(); 480 } else { 481 this.hide(); 482 } 483 484 $(this).siblings('ul.dropdown-menu').html(html); 485 } 486 487 $(this).after('<ul class="dropdown-menu"></ul>'); 488 $(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this)); 489 490 }); 491 } 492})(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.