1// Gumby is ready to go 2Gumby.ready(function() { 3 // console.log('Gumby is ready to go...', Gumby.debug()); 4 // placeholder polyfil 5 if (Gumby.isOldie || Gumby.$dom.find('html').hasClass('ie9')) { 6 $('input, textarea').placeholder(); 7 } 8 apply_sticky(); 9 //allows focus on a tab on a page thats wrapped with .tabs 10 var hash = window.location.hash; 11 if (hash.indexOf("tab") != -1) { 12 var index = hash.replace("#tab", ""); 13 $('.tabs').trigger('gumby.set', index - 1); 14 } 15 // Match heights 16 $(".match_ht").matchHeight(); 17 $(".match-f").matchHeight(); 18 //if you have a anchor query param that matches an element id 19 //this will take the header height value into account 20 //when scrolling to the element 21 var anchor = getUrlVars()['anchor']; 22 if (anchor !== undefined && anchor.length > 3) { 23 var ht = $('header').height(); 24 setTimeout(function() { 25 var offset = ($("#" + anchor).offset().top - (ht + 30)); //30px buffer added 26 $('html, body').animate({ 27 scrollTop: offset + 'px' 28 }, 'fast'); 29 }, 200); 30 } 31}); 32// Oldie document loaded 33Gumby.oldie(function() {}); 34//ready calls 35var ajax_working; 36$(window).resize(function() { 37 apply_sticky(); 38}); 39//Print page function 40 41function print_page() { 42 window.print(); 43} 44//function to return array of query params 45 46function getUrlVars() { 47 var vars = [], 48 hash; 49 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); 50 for (var i = 0; i < hashes.length; i++) { 51 hash = hashes[i].split('='); 52 vars.push(hash[0]); 53 vars[hash[0]] = hash[1]; 54 } 55 return vars; 56} 57 58function apply_sticky() { 59 var w = $(window).height(); 60 var p = $(document).height(); 61 var m = $(".container").height(); 62 var f = $("footer").height(); 63 var h = $("header").height(); 64 var ds = $(".domainsearch").height(); 65 var diff = (p - (m + ds + 395)); 66 if (diff > 0 && p >= w) {} 67 $("body > .container").css("marginBottom", "-" + f + "px"); 68 $(".push").css("height", f + "px"); 69} 70 71function dump(arr, level) { 72 var dumped_text = ""; 73 if (!level) level = 0; 74 //The padding given at the beginning of the line. 75 var level_padding = ""; 76 for (var j = 0; j < level + 1; j++) level_padding += " "; 77 if (typeof(arr) == 'object') { //Array/Hashes/Objects 78 for (var item in arr) { 79 var value = arr[item]; 80 if (typeof(value) == 'object') { //If it is an array, 81 dumped_text += level_padding + "'" + item + "' ...\n"; 82 dumped_text += dump(value, level + 1); 83 } else { 84 dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n"; 85 } 86 } 87 } else { //Stings/Chars/Numbers etc. 88 dumped_text = "===>" + arr + "<===(" + typeof(arr) + ")"; 89 } 90 return dumped_text; 91} 92 93function preload_images(arrayOfImages) { 94 $(arrayOfImages).each(function() { 95 $('<img/>')[0].src = this; 96 // Alternatively you could use: 97 // (new Image()).src = this; 98 }); 99} 100$(function() { 101 var click_ready = true; 102 // Clock -- Code from Fabulous.com 103 var clock = { 104 init: function() { 105 clock.time = new Date(registry_time * 1000); 106 clock.output = $('#time'); 107 clock.tick(); 108 }, 109 tick: function() { 110 clock.time.setUTCSeconds(clock.time.getUTCSeconds() + 1); 111 clock.output.html('Registry Time: ' + clock.time.toUTCString().replace(/gmt/i, 'UTC')); 112 setTimeout(clock.tick, 1000); 113 } 114 }; 115 clock.init(); /*If error, send to animate*/ 116 setTimeout(function() { 117 if ($("#message").is(":visible")) { 118 $("#message").hide(); 119 animate_msg($("#message").html()); 120 } 121 }, 2000); 122 $.ajaxSetup({ 123 beforeSend: function() { 124 $('html, body').css("cursor", "progress"); 125 NProgress.start(); 126 }, 127 error: function() { 128/* 129 if(data.message!=undefined){ 130 $("#message").html(data.message); 131 }*/ 132 $('html, body').css("cursor", "auto"); 133 NProgress.done(); 134 }, 135 always: function(data) { 136 if (data.redirect != undefined && data.redirect != "") { 137 window.location = data.redirect; 138 } 139 if (data.message != undefined) { 140 $("#message").html(data.message); 141 } 142 setTimeout("$('html, body').css('cursor','auto');", 1000); 143 NProgress.done(); 144 }, 145 complete: function(resp) { 146 if (typeof resp == 'object') { 147 var data = $.parseJSON(resp.responseText); 148 149 if(data != undefined && data!=""){ 150 if (data.redirect != undefined && data.redirect != "") { 151 window.location = data.redirect; 152 } 153 if (data.message != undefined && data.message != "") { 154 animate_msg(data.message); 155 /* 156 $("#message").fadeOut(500, function () { 157 $("#message").html(data.message); 158 $("#message").fadeIn(); 159 }); 160 */ 161 } 162 } 163 } 164 setTimeout("$('html, body').css('cursor','auto');", 1000); 165 NProgress.done(); 166 }, 167 }); 168 // Clicking anywhere on message popup body will dismiss entire 169 // flash message popup. 170 $(document).on("click", "#message", function(event) { 171 $("#message").fadeOut(); 172 $("#autocomplete_container").remove(); 173 });
174 $('input[name=query], form[name=search] input').focusout(function() { 175 //$("#autocomplete_container").remove(); // This just removes it before click even happens 176 // Have to wait 1 second in case item is clicked 177 setTimeout(function() { 178 $("#autocomplete_container").remove(); 179 }, 1000); 180 }); 181 $("#cart_button").hover(function() { 182 $("#cart-widget").stop().slideDown("fast"); 183 }, function() { 184 $("#cart-widget").stop().slideUp("fast"); 185 }); 186 $(document).on("submit", "[data-validate]", function(event) { 187 var frm = $(this).data("form"); 188 if (typeof(frm) != "undefined") { 189 return true; 190 } else { 191 var callback = $(this).data("validate"); 192 if (callback && callback !== "") { 193 var fn = window.stringToFunction(callback); 194 if (typeof fn === "function") { 195 return fn(this); 196 } 197 } 198 return validate_callback(this); 199 } 200 }); /*For non ajax forms*/ 201 $(document).on("submit", "[data-form-confirm-post]", function(event) { 202 var scope = $('#modal-confirm'); 203 var settings = $(this).data("modal"); 204 var cont = $(this).data("cont"); 205 var title = $(this).attr("title"); 206 var text = $(this).attr("text"); 207 var callback = $(this).data("callback"); 208 var modal = $('#modal-confirm').reveal({ 209 closeOnBackgroundClick: false 210 }); 211 var $this = this; 212 if (cont == true && typeof(cont) != "undefined") { 213 return true; 214 } else { 215 event.preventDefault(); 216 } 217 $("#modal-confirm-topbox").html(title); 218 $("#modal-confirm-text").html(text); 219 $("input[name='cancel']", scope).click(function() { 220 modal.trigger('reveal:close'); 221 $event.preventDefault(); 222 }); 223 $("input[name='confirm']", scope).click(function() { 224 $($this).data("cont", true); 225 $this.submit(); 226 }); 227 if (settings.x != undefined) { 228 if (settings.x.indexOf("%") != -1) { 229 var marginleft = (settings.x.replace("%", "") / 2) * -1 + "%"; 230 } else { 231 var marginleft = (settings.x.replace("px", "") / 2) * -1 + "px"; 232 } 233 $("#modal").animate({ 234 "width": settings.x, 235 "margin-left": marginleft 236 }); 237 } 238 return false; 239 }); 240 $(document).on("submit", "[data-form-confirm]", function(event) { 241 var scope = $('#modal-confirm'); 242 var settings = $(this).data("modal"); 243 var title = $(this).attr("title"); 244 var callback = $(this).data("callback"); 245 var modal = $('#modal-confirm').reveal({ 246 closeOnBackgroundClick: false 247 }); 248 var $this = this; 249 $event = event; 250 $("#modal-confirm-topbox").html(title); 251 $("input[name='cancel']", scope).click(function() { 252 modal.trigger('reveal:close'); 253 $event.preventDefault(); 254 }); 255 $("input[name='confirm']", scope).click(function() { 256 ajax.submit($this, $event); 257 }); 258 if (settings.x != undefined) { 259 if (settings.x.indexOf("%") != -1) { 260 var marginleft = (settings.x.replace("%", "") / 2) * -1 + "%"; 261 } else { 262 var marginleft = (settings.x.replace("px", "") / 2) * -1 + "px"; 263 } 264 $("#modal").animate({ 265 "width": settings.x, 266 "margin-left": marginleft 267 }); 268 } 269 }); 270 $(document).on("click", "[type='submit']", function(event) { 271 frm.spinner_on(this); 272 }); 273 $(document).on("click", ".chckupsell", function(event) { 274 $(this).closest('form').submit(); 275 }); 276 $(document).on("submit", "[data-form]", function(event) { 277 return ajax.submit(this, event); 278 }); 279 $(document).on("click", "[data-uri-confirm]", function(event) { 280 var scope = $('#modal-confirm'); 281 var settings = $(this).data("modal"); 282 var title = $(this).attr("title"); 283 var text = $(this).data("text"); 284 title = (typeof title == "undefined" ? "Please Confirm" : title); 285 var callback = $(this).data("callback"); 286 modal = $('#modal-confirm').reveal({ 287 closeOnBackgroundClick: false 288 }); 289 var $ele = this; 290 $event = event; 291 event.preventDefault(); 292 $("#modal-confirm-topbox").html(title); 293 $("input[name='cancel']", scope).click(function() { 294 modal.trigger('reveal:close'); 295 $event.preventDefault(); 296 }); 297 $("input[name='confirm']", scope).click(function() { 298 ajax.uri($ele, $event); 299 modal.trigger('reveal:close'); 300 $("input[name='confirm']", scope).unbind('click'); 301 }); 302 if(typeof text != "undefined") {
303 $('#modal-confirm-text').html(text); 304 } 305 if(settings && settings.x != undefined) { 306 if (settings.x.indexOf("%") != -1) { 307 var marginleft = (settings.x.replace("%", "") / 2) * -1 + "%"; 308 } else { 309 var marginleft = (settings.x.replace("px", "") / 2) * -1 + "px"; 310 } 311 $("#modal-confirm").animate({ 312 "width": settings.x, 313 "margin-left": marginleft 314 }); 315 } 316 }); 317 $(document).on("click", "[data-uri]", function(event) { 318 return ajax.uri(this, event); 319 }); /*Modal Handling*/ 320 $(document).on("click", "[data-modal]", function(event) { 321 event.preventDefault(); 322 var settings = $(this).data("modal"); 323 var href = $(this).attr("href"); 324 var title = $(this).attr("title"); 325 var callback = $(this).data("callback"); 326 var container = ""; 327 if (settings.x) { 328 if (settings.x.indexOf("%") != -1) { 329 var marginleft = (settings.x.replace("%", "") / 2) * -1 + "%"; 330 } else { 331 var marginleft = (settings.x.replace("px", "") / 2) * -1 + "px"; 332 } 333 $("#modal").animate({ 334 "width": settings.x, 335 "margin-left": marginleft 336 }).css({ 337 "overflow": "visible" 338 }); 339 } 340 if (settings.handler == "iframe" && href) { 341 var w = "100%"; 342 var h = (settings.y !== undefined ? settings.y : "100%"); 343 var container = $('<iframe />', { 344 name: 'modal_iframe', 345 id: 'modal_iframe', 346 src: href, 347 width: w, 348 height: h, 349 }); 350 $("#modal-container").html(container); 351 } 352 if (settings.handler == "ajax" && href) { 353 $.get(href, function(data) { 354 if (callback && callback !== "") { 355 var fn = window.stringToFunction(callback); 356 if (typeof fn === "function") { 357 fn(this, data); 358 } else { 359 console.log("Invalid Callback"); 360 } 361 } else { 362 if (data.payload) { 363 if(data.payload.modal) { 364 $("#modal-container").html(data.payload.modal); 365 } 366 else { 367 $("#modal-container").html(data.payload); 368 //console.log(data.payload); 369 } 370 } 371 } 372 }, "json").done(function() { 373 Gumby.init(); // Checkboxes, radio buttons in the modal wont work with out this 374 }); 375 } 376 if (settings.handler == "img" && href) { 377 var w = "100%"; 378 var h = (settings.y !== undefined ? settings.y : "100%"); 379 var container = $('<img />', { 380 name: 'modal_img', 381 id: 'modal_img', 382 src: href, 383 width: w, 384 height: h, 385 }); 386 $("#modal-container").html(container); 387 } 388 if (!title) { 389 title = ""; 390 } 391 if (!callback || callback == "") { 392 $("#modal-topbox").html(title); 393 } 394 $('#modal').reveal({ 395 closeOnBackgroundClick: false 396 }); 397 }); /*Attaches date handling to input*/ 398 $(document).on("keyup", "[data-date]", function() { 399 var reps = { 400 one: "1", 401 two: "2", 402 three: "3", 403 four: "4", 404 five: "5", 405 six: "6", 406 seven: "7", 407 eight: "8", 408 nine: "9", 409 ten: "10", 410 } 411 var val = $(this).val(); 412 var obj = $(this).data("container"); 413 var field = $(this).data("field"); //hidden form field 414 var width = $(this).width(); 415 var new_width = $(this).siblings('.date_message').width(); 416 $(this).next(".date_message").remove(); 417 if (new_width) new_width = new_width + 20; 418 width = width + new_width; 419 $(this).width(width); //Hard coded value for the border 420 for (key in reps) { 421 val = val.replace(key, reps[key]); 422 } 423 var dt = Date.parse(val); 424 if (!field) { 425 console.log("data-field not set"); 426 return; 427 } 428 if (dt == null) { 429 if (obj) { 430 $(obj).html("<span class='date_message adjoined hint--bottom relative' data-hint='Invalid Date'><i class='icon-thumbs-down'></i></span>"); 431 } else { 432 $(this).after("<span class='date_message adjoined hint--bottom relative' data-hint='Invalid Date'><i class='icon-thumbs-down'></i></span>"); 433 var new_width = $(this).siblings('.date_message').width(); 434 $(this).width(width - new_width - 20); //Hard coded value for the border 435 } 436 $(field).val(null); //set to null or old date might stay 437 return; 438 } 439 var short_date = dt.toString("yyyy-MM-dd h:mm:ss"); 440 if (obj) { 441 $(obj).html("<span class='date_message adjoined' >" + dt.toString("MMM dd, yyyy") + "</span>"); 442 } else { 443 $(this).after("<span class='date_message adjoined' >" + dt.toString("MMM dd, yyyy") + "</span>"); //"dddd, MMMM dd, yyyy h:mm:ss tt" 444 var new_width = $(this).siblings('.date_message').width(); 445 $(this).width(width - new_width - 20); //Hard coded value for the border 446 } 447 $(field).val(short_date); 448 }); /* Attaches a listener for on-change */ 449 //this was origially in a form, however there were html nesting issues, we now post to the app and then reload the page to avoid gumming up the url with unnecessary vars
450 $(document).on("change", "[data-perpage]", function(event) { 451 var url = window.location.href; 452 $.post(url, { 453 "perpage": this.value 454 }, function() { 455 window.location.reload(); 456 }); 457 }); /*Modal Handling*/ 458 $(document).on('click', "[data-file-button]", function(event) { 459 var $for = $(this).attr('for'); 460 var file = $("#" + $for); 461 var found = false; 462 }); 463 $(document).on('click', "[data-confirm]", function(event) { 464 event.preventDefault(); 465 var scope = $('#modal-confirm'); 466 var settings = $(this).data("modal"); 467 var title = $(this).attr("title"); 468 var callback = $(this).data("callback"); 469 var modal = $('#modal-confirm').reveal({ 470 closeOnBackgroundClick: false 471 }); 472 var $this = this; 473 $event = event; 474 $("#modal-confirm-topbox").html(title); 475 $("input[name='cancel']", scope).click(function() { 476 modal.trigger('reveal:close'); 477 $event.preventDefault(); 478 }); 479 $("input[name='confirm']", scope).click(function() { 480 window.location.href = $this.href; 481 }); 482 if (settings.x != undefined) { 483 if (settings.x.indexOf("%") != -1) { 484 var marginleft = (settings.x.replace("%", "") / 2) * -1 + "%"; 485 } else { 486 var marginleft = (settings.x.replace("px", "") / 2) * -1 + "px"; 487 } 488 $("#modal").animate({ 489 "width": settings.x, 490 "margin-left": marginleft 491 }); 492 } 493 }); 494 $(document).on("change", "[data-change-submit]", function(event) { 495 $(this).closest("form").submit(); 496 }); 497 $(document).on("change", "[data-change]", function(event) { 498 var vars = $(this).data("vars"); 499 var query = new Array(); 500 var callback = $(this).data("callback"); 501 var method = $(this).data("method"); 502 var error = $(this).data("error"); 503 var uri = $(this).data("change"); 504 var nomsg = $(this).data("nomsg"); 505 var $this = this; 506 var i = 0; 507 if (uri == "") { 508 console.log("data-uri must be set"); 509 } 510 for (var key in vars) { 511 var val = vars[key]; 512 query[i] = key + "=" + val; 513 i++; 514 } 515 if ($(this).is("select")) { 516 query[i] = this.name + "=" + this.value; 517 if (typeof vars == "undefined") { 518 var vars = {}; 519 } 520 vars[this.name] = this.value; 521 } 522 var args = query.join("&"); 523 var ts = new Date().getTime(); 524 if (query.length > 0) { 525 if (uri.indexOf("?") != -1) { 526 var url = uri + "&" + query + "&t=" + ts; 527 } else { 528 var url = uri + "?" + query + "&t=" + ts; 529 } 530 } else if (uri.indexOf("?") != -1) { 531 var url = uri + "&t=" + ts; 532 } else { 533 var url = uri + "?t=" + ts; 534 } 535 $.ajax({ 536 url: url, 537 type: (method ? method : "GET"), 538 data: vars, 539 dataType: "json", 540 }).complete(function(resp) { 541 data = $.parseJSON(resp.responseText); 542 if (nomsg == true) { 543 $("#message").fadeOut(500, function() { 544 $("#message").html(""); 545 }); 546 } 547 if (data.code == 200) { 548 if (callback && callback !== "") { 549 var fn = window.stringToFunction(callback); 550 if (typeof fn === "function") { 551 fn($this, data); 552 } else { 553 console.log("Invalid Callback"); 554 } 555 } else { 556 console.log("callback not defined set data-callback"); 557 } 558 } else { 559 if (error) { 560 var fn = window.stringToFunction(error); 561 if (typeof fn === "function") { 562 fn($this, data); 563 } else { 564 console.log("Invalid Callback") 565 } 566 } else { 567 console.log("callback data-error not defined, error: " + data.error); 568 } 569 } 570 }).fail(function(response) { 571 if (error) { 572 var fn = window.stringToFunction(error); 573 if (typeof fn === "function") { 574 fn($this); 575 } else { 576 console.log("Invalid Callback") 577 } 578 } else { 579 console.log("callback data-error not defined, error: " + response); 580 } 581 }); 582 return false; 583 }); /*Used on multiple pages*/ 584 $(document).on("change", "select[name='country']", function() { 585 var country = $(this).val(); 586 $.get("/account/states/" + country, function(data, elem) { 587 //console.log(data); 588 $('select[name="state"]').replaceWith(data.payload); 589 }, 'json') 590 }); 591 $('input[name="checkall"]').click(function() { 592 var form = $(this).closest("form"); 593 if (this.checked == true) { 594 $("input[type='checkbox']", form).prop('checked', true); 595 } else { 596 $("input[type='checkbox']", form).prop('checked', false); 597 } 598 }); 599 $(document).on("change", "input[type='file']", function() { 600 var val = $(this).val(); 601 var data = $(this).data("extensions"); 602 val = val.replace("C:\\fakepath\\", ""); //for chrome 603 $(this).next(".upload_source").html("Ready to upload: " + val); 604 var form = $(this).closest("form"); 605 $(form).removeAttr("data-form"); 606 $(form).removeAttr("data-form-confirm"); 607 var ck = val.split("."); 608 var ext = ck[ck.length - 1]; 609 if ($.inArray(ext.toLowerCase(), data) == -1) { 610 $(this).next(".upload_source").html("Not a valid extension " + val); 611 $("input[type='submit']", form).prop("disabled", true); 612 } else { 613 $("input[type='submit']", form).prop("disabled", false); 614 } 615 });
616 Autocomplete("input[name=query], form[name=search] input", "/search/autocomplete"); 617}); 618window.stringToFunction = function(str) { 619 var arr = str.split("."); 620 var fn = (window || this); 621 for (var i = 0, len = arr.length; i < len; i++) { 622 fn = fn[arr[i]]; 623 } 624 if (typeof fn !== "function") { 625 throw new Error("function not found"); 626 } 627 return fn; 628}; 629$(window).bind('scroll', function() { 630 if ($(window).scrollTop() > 40 || document.documentElement.scrollTop > 40) { 631 $('#accountbar, header, header nav.navbar').addClass('shrinkme'); 632 } else { 633 $('#accountbar, header, header nav.navbar').removeClass('shrinkme'); 634 } 635}); 636var cart = { 637 refresh: function() { 638 $.post('/cart/slimcart/', function(data, elem) { 639 console.log("cart.refresh"); 640 var d = $(data.payload)[0]; 641 $('span.total').html($(d).find('span.total').html()); 642 $('#cart-widget').empty().html($(d).find('.cart_content').html()); 643 var new_badge = $('span.total'); 644 var number = Number(new_badge.text()); 645 var count = new_badge.data("count"); 646 new_badge.html(number); 647 var icon_basket = $(".icon-basket"); 648 if (count < 1) { 649 $('.icon-basket').removeClass("green"); 650 } else { 651 $('.icon-basket').addClass("green"); 652 } 653 $("#cart-widget").height("auto"); 654 icon_basket.jrumble({ 655 speed: 50, 656 y: 4, 657 x: 0 658 }); 659 icon_basket.trigger('startRumble'); 660 setTimeout(function() { 661 icon_basket.trigger('stopRumble'); 662 }, 500); 663 }, 'json').done(function() { 664 if (window.search_status == true) { 665 controller.ListModel.resync_cart(); 666 } 667 window.click_ready = true; 668 $('body').removeClass("busy"); 669 $("#cart_nav_item").show(); 670 }); 671 }, 672 add: function(service_id, domain, quantity, callback) { 673 if (typeof domain == 'undefined') { 674 domain = ""; 675 } else if (typeof domain == 'function') { 676 callback = domain; 677 } else { 678 domain = "/" + domain; 679 quantity = (typeof quantity !== 'undefined') ? "/" + quantity : ""; 680 } 681 $.post("/cart/add/" + service_id + domain + quantity, function(data, elem) { 682 if (data.code == 200) { 683 if (typeof callback == 'function') { 684 callback(data, elem); 685 } 686 } else { 687 console.log("There was a problem"); 688 } 689 }, 'json'); 690 }, 691 cart_refresh: function() { 692 var ts = new Date().getTime(); 693 $.get("/cart/?t=" + ts, function(data) { 694 $('#main_cart_table').html(data.payload.table); 695 $('#main_cart_total').html(data.payload.total); 696 $('.reg-subtotal').html('$' + data.payload.subtotal); 697 698 console.log("cart.refresh"); 699 var d = $(data.payload.slimcart)[0]; 700 $('span.total').html($(d).find('span.total').html()); 701 $('#cart-widget').empty().html($(d).find('.cart_content').html()); 702 var new_badge = $('span.total'); 703 var number = Number(new_badge.text()); 704 var count = new_badge.data("count"); 705 new_badge.html(number); 706 var icon_basket = $(".icon-basket"); 707 if (count < 1) { 708 $('.icon-basket').removeClass("green"); 709 } else { 710 $('.icon-basket').addClass("green"); 711 } 712 $("#cart-widget").height("auto"); 713 icon_basket.jrumble({ 714 speed: 50, 715 y: 4, 716 x: 0 717 }); 718 icon_basket.trigger('startRumble'); 719 setTimeout(function() { 720 icon_basket.trigger('stopRumble'); 721 }, 500); 722 723 $("#cart_nav_item").show(); 724 725 }, "json"); 726 727 NProgress.done(); 728 console.log("cart_refresh"); 729 }, 730 upsell_refresh: function() { 731 var ts = new Date().getTime(); 732 $.get("/cart_upsell/?t=" + ts, function(data) { 733 if (data.payload.outhost != null && data.payload.outhost != '') { 734 $("#upsell_zone_1").html(data.payload.outhost); 735 $("#upsell_zone").html(data.payload.output); 736 } else { 737 $("#upsell_zone_1").html(data.payload.outsearch); 738 } 739 }, "json"); 740 //NProgress.done(); 741 } 742} 743 744// Format large numbers adding commas 745function addCommas(number) { 746 var parts = number.toString().split("."); 747 parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); 748 return parts.join("."); 749} 750 751 752//call to close modal 753function modal_close() { 754 $("#modal").trigger('reveal:close'); 755} 756//ele is the form element 757 758function validate_callback(ele) { 759 var errors = new Array(); 760 var checker = new Array(); 761 var names = new Array(); 762 var inputs_o = $("input[data-rule]", ele); 763 var selects = $("select[data-rule]", ele); 764 var ta = $("textarea[data-rule]", ele); 765 var handler = $(ele).data("handler"); 766 var inputs = $.merge($.merge(inputs_o, selects), ta); 767 try { 768 for (var i = 0; i < inputs.length; i++) {
769 var inp = inputs[i]; 770 var rule = $(inp).data("rule"); 771 var val = $(inp).val(); 772 var rules = rule.split("|"); 773 var name = $(inp).attr("name"); 774 if (rules.length > 0) { 775 for (var k = 0; k < rules.length; k++) { 776 fn = rules[k]; 777 param = ""; 778 if (fn.indexOf("=") != -1) { 779 parts = fn.split("="); 780 fn = parts[0]; 781 param = parts[1]; 782 } 783 if (validator[fn] && validator[fn](val, inp, param) == false) { 784 errors.push(name + "|" + fn); 785 checker.push(name); 786 $(inp).closest(".field").addClass("danger"); 787 } else if ($.inArray(name, checker) < 0) { 788 $(inp).closest(".field").removeClass("danger"); 789 } 790 } 791 } 792 } 793 } catch (err) { 794 console.log(err); 795 } 796 if (errors.length > 0) { 797 if (handler && handler !== "") { 798 var handle = window.stringToFunction(handler); 799 if (typeof handle === "function") { 800 handle(ele, errors); 801 } 802 } 803 //frm.spinner_off($("[type='submit']",ele)); 804 return false; 805 } 806 return true; 807} 808var validator = { 809 not_empty: function(val, ele) { 810 val = $.trim(val); 811 if($(ele).attr('name') == 'state' && val == '0'){ 812 val = ''; 813 } 814 if (val != "") { 815 return true; 816 } 817 return false; 818 }, 819 email: function(val, ele) { 820 var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 821 return re.test(String(val).toLowerCase()); 822 //return val.match('@') !== null ? true : false; 823 }, 824 phone: function(val, ele) { 825 if (val == "") { 826 return true; 827 } 828 var nv = val.replace(/[^0-9]/g, ''); 829 var ls = new Array(10, 11, 12, 13, 14, 15); 830 for (var i = 0; i <= ls.length; i++) { 831 if (nv.length == ls[i]) { 832 return true; 833 } 834 } 835 return false; 836 }, 837 checked: function(val, ele) { 838 if ($(ele).is(":checked")) { 839 return true; 840 } 841 return false; 842 }, 843 eq: function(val, ele, param) { 844 param = parseInt(param, 10); 845 if (val == param) { 846 return true; 847 } 848 return false; 849 }, 850 alpha: function(val, ele) {}, 851 numeric: function(val, ele) { 852 return /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(val); 853 }, 854 min_length: function(val, ele, param) { 855 var length = val.length; 856 param = parseInt(param, 10); 857 return length >= param; 858 }, 859 max_length: function(val, ele, param) { 860 var length = val.length; 861 param = parseInt(param, 10); 862 return length <= param; 863 }, 864 exact_length: function(val, ele, param) { 865 var length = val.length; 866 param = parseInt(param, 10); 867 return length == param; 868 }, 869 nameserver: function(val, ele, param) { 870 var test = isNaN(val.replace(/\./g, "")); 871 if (test == false) { 872 return false; 873 } 874 if (/^(?=.{1,254}$)((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}$/i.test(val)) { 875 //if (/^([a-zA-Z0-9-]{1,61}\.){2,}[a-zA-Z]{2,}$/.test(val)) { 876 return true; 877 } 878 return false; 879 }, 880 domain: function(val, ele, param) { 881 if (/^[a-zA-Z0-9-]{1,61}(\.[a-zA-Z]{2,}){1,2}$/.test(val)) { 882 return true; 883 } 884 return false; 885 }, 886 url: function(val, ele, param) { 887 if (/^(http(?:s)?\:\/\/[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:\/?|(?:\/[\w\-]+)*)(?:\/?|\/\w+\.[a-zA-Z]{2,4}).*)$/.test(val) == true) { 888 return true; 889 } 890 return false; 891 }, 892 callback: function(val, ele, callback) { 893 if (callback && callback !== "") { 894 var fn = window.stringToFunction(callback); 895 if (typeof fn === "function") { 896 return fn(val, ele); 897 } 898 } 899 return false; 900 }, 901 creditcard: function(val, ele) { 902 // accept only spaces, digits and dashes 903 if (/[^0-9 \-]+/.test(val)) { 904 return false; 905 } 906 var nCheck = 0, 907 nDigit = 0, 908 bEven = false; 909 value = val.replace(/\D/g, ""); 910 // Basing min and max length on 911 // http://developer.ean.com/general_info/Valid_Credit_Card_Types 912 if (value.length < 13 || value.length > 19) { 913 return false; 914 } 915 for (var n = value.length - 1; n >= 0; n--) { 916 var cDigit = value.charAt(n); 917 nDigit = parseInt(cDigit, 10); 918 if (bEven) { 919 if ((nDigit *= 2) > 9) { 920 nDigit -= 9; 921 } 922 } 923 nCheck += nDigit; 924 bEven = !bEven; 925 } 926 return (nCheck % 10) === 0; 927 }, 928} 929var frm = {
930 spinner_on: function(btn) { 931 //return; //not happy wiht the implementation 932 $(btn).prepend('<span class="spinner_med"> </span>'); 933 }, 934 spinner_off: function(btn) { 935 $(".spinner_med", $(btn)).remove(); 936 } 937} 938var ajax = { 939 submit: function(ele, event) { 940 event.preventDefault(); 941 var callback = $(ele).data("callback"); 942 var validate = $(ele).data("validate"); 943 var method = $(ele).attr("method"); 944 var error = $(ele).data("error"); 945 var url = $(ele).attr("action"); 946 var nomsg = $(ele).data("nomsg"); 947 var sub = $("[type='submit']", ele); 948 if (url == "") { 949 url = window.location.href; 950 } 951 //frm.spinner_on(sub); 952 var $ele = ele; 953 //run a pre validation check 954 if (validate) { 955 var fn = window.stringToFunction(validate); 956 if (typeof fn === "function") { 957 if (fn($ele) == false) { 958 return false; 959 } 960 } else { 961 console.log("Invalid validation callback"); 962 } 963 } else { 964 if (validate_callback($ele) == false) { 965 return false; 966 } 967 } 968 var ts = new Date().getTime(); 969 if (url.indexOf("?") > -1) { 970 url += "&t=" + ts; 971 } else { 972 url += "?t=" + ts; 973 } 974 $.ajax({ 975 url: url, 976 type: (method ? method : "POST"), 977 data: $(ele).serialize(), 978 dataType: "json", 979 }).done(function(data) { 980 if (nomsg == true) { 981 $("#message").fadeOut(500, function() { 982 $("#message").html(""); 983 }); 984 } 985 if (data.code == 200) { 986 if (data.redirect && data.redirect !== "") { 987 window.location = data.redirect; 988 } 989 if (callback && callback !== "") { 990 var fn = window.stringToFunction(callback); 991 if (typeof fn === "function") { 992 fn($ele, data); 993 } else { 994 console.log("Invalid Callback") 995 } 996 } else { 997 console.log("callback not defined set data-callback"); 998 } 999 } else { 1000 if (error) { 1001 var fn = window.stringToFunction(error); 1002 if (typeof fn === "function") { 1003 fn($ele, data); 1004 } else { 1005 console.log("Invalid Callback") 1006 } 1007 } else { 1008 console.log("callback data-error not defined, error: " + data.error); 1009 } 1010 } 1011 }).fail(function(response) { 1012 if (error) { 1013 var fn = window.stringToFunction(error); 1014 if (typeof fn === "function") { 1015 fn($ele, data, response); 1016 } else { 1017 console.log("Invalid Callback") 1018 } 1019 } else { 1020 console.log("callback data-error not defined, error: " + response.responseText); 1021 } 1022 }); 1023 frm.spinner_off(sub); 1024 return false; 1025 }, 1026 uri: function(ele, event) { 1027 try { 1028 var vars = $(ele).data("vars"); 1029 var query = new Array(); 1030 var callback = $(ele).data("callback"); 1031 var pre = $(ele).data("pre"); 1032 var method = $(ele).data("method"); 1033 var error = $(ele).data("error"); 1034 var uri = $(ele).data("uri"); 1035 var href = $(ele).attr("href"); 1036 var nomsg = $(ele).data("nomsg"); 1037 var i = 0; 1038 if (typeof pre !== 'undefined') { 1039 var fn = window.stringToFunction(pre); 1040 if (typeof fn === "function") { 1041 fn(event); 1042 } 1043 } 1044 if (uri == "" || typeof uri == "undefined" || uri == true) { 1045 uri = href; 1046 } 1047 for (var key in vars) { 1048 var val = vars[key]; 1049 query[i] = key + "=" + val; 1050 i++; 1051 } 1052 var args = query.join("&"); 1053 var ts = new Date().getTime(); 1054 if (query.length > 0) { 1055 if (uri.indexOf("?") != -1) { 1056 var url = uri + "&" + query + "&t=" + ts; 1057 } else { 1058 var url = uri + "?" + query + "&t=" + ts; 1059 } 1060 } else if (uri.indexOf("?") != -1) { 1061 var url = uri + "&t=" + ts; 1062 } else { 1063 var url = uri + "?t=" + ts; 1064 } 1065 $.ajax({ 1066 url: url, 1067 type: (method ? method : "GET"), 1068 data: vars, 1069 dataType: "json", 1070 }).done(function(data) { 1071 if (nomsg == true) { 1072 $("#message").fadeOut(500, function() { 1073 $("#message").html(""); 1074 }); 1075 } 1076 if (data.code == 200) { 1077 if (data.redirect && data.redirect !== "") { 1078 window.location = data.redirect; 1079 } 1080 if (callback && callback !== "") { 1081 var fn = window.stringToFunction(callback); 1082 if (typeof fn === "function") { 1083 fn(ele, data); 1084 } else { 1085 console.log("Invalid Callback") 1086 } 1087 } else { 1088 console.log("callback not defined set data-callback"); 1089 } 1090 } else { 1091 if (error) { 1092 var fn = window.stringToFunction(error); 1093 if (typeof fn === "function") { 1094 fn(ele, data); 1095 } else { 1096 console.log("Invalid Callback") 1097 } 1098 } else { 1099 console.log("callback data-error not defined, error: " + data.error); 1100 } 1101 } 1102 }).fail(function(response) { 1103 if (error) { 1104 var fn = window.stringToFunction(error); 1105 if (typeof fn === "function") { 1106 fn(ele); 1107 } else { 1108 console.log("Invalid Callback") 1109 } 1110 } else { 1111 console.log("callback data-error not defined, error: " + response); 1112 } 1113 }); 1114 return false;
1115 } catch (err) {} 1116 } 1117} 1118// Remove message automagically after 3 seconds 1119 1120function animate_msg(msg) { 1121 $("#message").html(msg); 1122 $("#message").show(); 1123 $("#message").animate({ 1124 top: "+" + 125 1125 }, { 1126 duration: 400, 1127 complete: function(){ 1128 // Can't break out of the delay() to close before the fade happens 1129 // So we have to use setTimeout 1130 setTimeout(function() { 1131 $("#message").fadeOut('slow', function() { 1132 $("#message").css("top", "-200px"); 1133 }); 1134 }, 3000); 1135 } 1136 }); 1137 1138} 1139//listens for a call to cart refresh from server task 1140 1141function http_push_cart_refresh(resp, id, channel) { 1142 cart.cart_refresh(); 1143 setTimeout("cart.refresh();", 1000); 1144} 1145 1146function http_push_flash_message(resp, id, channel) { 1147 $("#message").html(resp.payload.message); 1148 $("#message").fadeIn(); 1149} 1150 1151function news_subscription() { 1152 //grab the entered email, validate / check for account, 1153 // then redirect to correct page 1154 var email = $("#email_newsletter").val(); 1155 $.ajax({ 1156 timeout: 30000, 1157 url: "/newsletter/index", 1158 tryCount: 0, 1159 retryLimit: 3, 1160 data: { 1161 email: email 1162 }, 1163 success: function(response) { 1164 try { 1165 response = jQuery.parseJSON(response); 1166 jsonresp = response.payload; 1167 } catch (e) { 1168 var jsonresp = { 1169 status: 0, 1170 message: "Error Parsing JSON" 1171 }; 1172 } 1173 //100% successfull 1174 //1 = subscribed 1175 //2 = log into comm prefs 1176 //3 = invalid email 1177 if (jsonresp.status == 1) { 1178 $("#email_newsletter").val(""); 1179 } else if (jsonresp.status == 2) { 1180 //redirect to comm prefs 1181 window.location.href = jsonresp.url; 1182 } else if (jsonresp.status == 3) { 1183 //invalid email nothing needed 1184 } else { 1185 console.log(jsonresp.message); 1186 } 1187 }, 1188 error: function(xhr, textStatus, errorThrown) { 1189 console.log("error"); 1190 if (textStatus == 'timeout') { 1191 this.tryCount++; 1192 if (this.tryCount <= this.retryLimit) { 1193 $.ajax(this); 1194 return false; 1195 } 1196 } 1197 return false; 1198 } 1199 }); 1200} 1201 1202function active_filters_check(){ 1203 $("form.filter_form select").each(function(i){ 1204 if($(this).prop("selectedIndex") > 0){ 1205 $(this).parent().addClass("active"); 1206 }else{ 1207 $(this).parent().removeClass("active"); 1208 } 1209 }); 1210}
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.