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