1// JavaScript Document 2 3 4 // Check for jQuery 5 jQuery.exists = function(selector) {return ($(selector).length > 0);}; 6 // 7 var messagewait = false; 8 var webSize = 'full'; 9 var browser = 'Other'; 10 var scrolling = false; 11 12 13 // reCaptcha options 14 var RecaptchaOptions = { 15 theme: 'custom', 16 custom_theme_widget: 'recaptcha_widget' 17 }; 18 19 20 $(document).ready(function() { 21 "use strict"; 22 23 // Get websize 24 get_web_size(); 25 26 // Get browser 27 get_browser(); 28 29 // Set up smooth scroll in edge 30 if(browser === 'Edge' && $.scrollSpeed) { 31 // 32 jQuery.scrollSpeed(120,900); 33 } 34 35 // Resize event 36 $(window).resize(function() { 37 38 // Get winodw size 39 get_web_size(); 40 41 // Refresh parallax calculations 42 /*$('.background.parallax').each(function() { 43 // 44 var bgobj = $(this); 45 parallax(bgobj,true); 46 });*/ 47 }); 48 49 50 // Show element that need javascript 51 $(".js-show").show(); 52 53 54 // Animated anchor scrolling 55 $('a[href*="#"]').on('click',function(event) { 56 57 var hashVal = this.hash.substr(1); 58 var target = $('a[name="'+hashVal+'"]'); 59 60 if($(target).length > 0) { 61 62 event.preventDefault(); 63 64 // 65 var scroll = $(window).scrollTop(); 66 var max = $(document).height()-$(window).height(); 67 var top = ($(target).offset().top > max) ? max : $(target).offset().top; 68 69 // 70 var scrollSpeed = parseInt((top-scroll)/1.5); 71 if(scrollSpeed < 0) {scrollSpeed = scrollSpeed*-1;} 72 73 // 74 $('html, body').stop().animate({ 75 'scrollTop': top 76 77 },scrollSpeed,'swing',function() { 78 // 79 window.location.hash = hashVal; 80 }); 81 } 82 }); 83 84 85 // Back link 86 $(".backlink").on("click",function(event) { 87 88 event.preventDefault(); 89 90 history.go(-1); 91 return false; 92 }); 93 94 95 // Search box script 96 $("#search-box #search-box-input").addClass("search-off"); 97 $("#search-box #search-box-input").focus(function() { 98 // 99 var curText = $(this).val(); 100 var defaultText = $(this).data("default"); 101 102 if(curText === defaultText) { 103 // 104 $(this).val(""); 105 $(this).removeClass("search-off"); 106 } 107 }).blur(function() { 108 // 109 var curText = $(this).val(); 110 var defaultText = $(this).data("default"); 111 112 if(curText === "") { 113 // 114 $(this).val(defaultText); 115 $(this).addClass("search-off"); 116 } 117 }); 118 119 120 // Send password in cart 121 $(".checkout-send-pass").click(function() { 122 var passEmail = $(this).attr("rel"); 123 124 $.ajax({ 125 type: "POST", 126 url: "../edit/shop/cart.ajax.php?sendpassword=1&email="+passEmail, 127 success: function(data) { 128 if(data) { 129 $(".pass-changer").html('<div class="colour green">'+data+'</div>'); 130 } 131 } 132 }); 133 }); 134 135 136 // Mobile menu 137 $("#mobile-menu a, .close-menu").click(function(event) { 138 139 // 140 event.preventDefault(); 141 142 if($("#mobile-navigation").is(":hidden")) { 143 144 $("html").addClass("mobile-active"); 145 $("#mobile-navigation").show(); 146 $("#mobile-navigation").data("eventtype","user"); 147 } 148 else { 149 150 $("html").removeClass("mobile-active"); 151 $("#mobile-navigation").hide(); 152 $("#mobile-navigation").data("eventtype",""); 153 } 154 }); 155 156 157 // Open images in magnific popup 158 if($.fn.magnificPopup) { 159 // 160 $('a.lightboximage').magnificPopup({ 161 type:'image' 162 }); 163 } 164 165 // Open images in colorbox 166 else if($.fn.colorbox) { 167 // 168 $("a[class=\'lightboximage\']").colorbox({photo:true},function(){ 169 var titleheight = $("#cboxTitle").height(); 170 $("#colorbox").height($("#colorbox").height() + titleheight); 171 $("#cboxWrapper").height($("#cboxWrapper").height() + titleheight); 172 $("#cboxMiddleLeft").height($("#cboxMiddleLeft").height() + titleheight); 173 $("#cboxMiddleRight").height($("#cboxMiddleRight").height() + titleheight); 174 $("#cboxContent").height($("#cboxContent").height() + titleheight); 175 $("#cboxLoadedContent").height($("#cboxLoadedContent").height() + titleheight); 176 }); 177 } 178 179 180 // Check for date field and create fallback 181 if(!Modernizr.inputtypes.date) { 182 // 183 var dateInputs = $('input[type="date"]'); 184 // 185 if($(dateInputs).length > 0) { 186 $(dateInputs).each(function() { 187 $(this).datepicker({dateFormat:"d M yy"}); 188 }); 189 } 190 } 191 192 193 // Hide site messages 194 $(document).on("click","#site-messages .close-msg",function() { 195 196 var msgId = $(this).closest(".error-message").attr("id"); 197 hide_site_message(msgId); 198 }); 199 200 201 if($.fn.lazyload) { 202 203 $("img.lazy").show(); 204 205 // Lazy load images 206 $("img.lazy").lazyload({ 207 effect: "fadeIn", 208 load : function() { 209 // 210 } 211 }).removeClass("lazy"); 212 } 213 214 215 // Open all youtube and vimeo links in popup (Remove "&& false" to enable) 216 if($.fn.magnificPopup && false) { 217 // 218 $('a[href*="youtube.com/watch"]').magnificPopup({ 219 type:'iframe', 220 iframe: { 221 patterns: { 222 youtube: { 223 index: 'youtube.com/', 224 id: function(url) { 225 // 226 return qs(url,'v'); 227 }, 228 src: '//www.youtube.com/embed/%id%?controls=0&modestbranding=1&rel=0&showinfo=0&color=white&autoplay=1' 229 } 230 } 231 } 232 }); 233 234 // 235 $('a[href*="vimeo.com/"]').magnificPopup({ 236 type:'iframe', 237 iframe: { 238 patterns: { 239 vimeo: { 240 index: 'vimeo.com/', 241 id: function(url) { 242 // 243 if(url.indexOf('external') > -1) { 244 return 'external/' + url.substr(url.lastIndexOf('/')+1, url.length); 245 } 246 else { 247 return 'video/' + url.substr(url.lastIndexOf('/')+1, url.length); 248 } 249 }, 250 src: '//player.vimeo.com/%id%?autoplay=1' 251 } 252 } 253 } 254 }); 255 } 256 257 258 // Convert svg image to svg path 259 $('.svg-with-path img[src*=svg]').each(function() { 260 // 261 var $img = $(this); 262 var imgID = $img.attr('id'); 263 var imgClass = $img.attr('class'); 264 var imgURL = $img.attr('src'); 265 266 // Get SVG data 267 $.get(imgURL,function(data) { 268 269 // Get the SVG tag, ignore the rest 270 var $svg = $(data).find('svg'); 271 272 // Add replaced image's ID to the new SVG 273 if(typeof imgID !== 'undefined') { 274 // 275 $svg = $svg.attr('id',imgID); 276 } 277 278 // Add replaced image's classes to the new SVG 279 if(typeof imgClass !== 'undefined') { 280 // 281 $svg = $svg.attr('class',imgClass+' replaced-svg'); 282 } 283
284 // Remove any invalid XML tags as per http://validator.w3.org 285 $svg = $svg.removeAttr('xmlns:a'); 286 287 // Replace image with new SVG 288 $img.replaceWith($svg); 289 290 },'xml'); 291 }); 292 293 294 // Address finder setup 295 if($(".address-finder").length > 0) { 296 297 // Load address finder api 298 $.getScript('https://api.addressfinder.io/assets/v3/widget.js',function() { 299 300 // Add widget to address-finder class 301 var widget = new AddressFinder.Widget( 302 $(".address-finder")[0], 303 $(".address-finder-key").data("key"), 304 'NZ',{ 305 byline: false, 306 //manual_style: true 307 } 308 ); 309 310 // Get results 311 widget.on('result:select',function(fullAddress,metaData) { 312 313 // Populate selected variable 314 var selected = new AddressFinder.NZSelectedAddress(fullAddress, metaData); 315 316 // Build address 317 var address = ""; 318 address += selected.address_line_1(); 319 address += selected.address_line_2(); 320 address += selected.suburb(); 321 address += selected.city(); 322 address += selected.postcode(); 323 324 alert(address); 325 }); 326 }); 327 } 328 329 330 // Check for waypoint class 331 if($.fn.waypoint) { 332 333 // Set waypoints as active 334 $("html").addClass("waypoints-active"); 335 336 // 337 $(".waypoint").each(function() { 338 // 339 var $element = $(this); 340 var offset = $element.data("waypoint-offset"); 341 342 // Check for offset 343 if(offset === undefined) { 344 // 345 offset = '70%'; 346 } 347 348 $element.waypoint({ 349 handler: function(direction) { 350 // 351 if(direction === 'down') { 352 // 353 $element.addClass("waypoint-down"); 354 $element.addClass("waypoint-on"); 355 } 356 else { 357 // 358 $element.addClass("waypoint-up"); 359 $element.removeClass("waypoint-on"); 360 } 361 }, 362 offset: offset 363 }); 364 }); 365 } 366 367 368 // Check for number counter plugin 369 if($.fn.numbercounter) { 370 // 371 $(".number-counter").numbercounter({ 372 duration: 5000, 373 easing: 'easeOutQuad', 374 before: function() {}, 375 complete: function() {}, 376 }); 377 } 378 379 380 // Check for match height class (matchheight) 381 if($.fn.matchHeight && $(".matchheight").length > 0) { 382 // 383 $(".matchheight").matchHeight({ 384 byRow: true, 385 property: "height" 386 }); 387 } 388 389
390 // Check for collapsable elements 391 if($(".collapser").length > 0) { 392 393 // Collapse containers 394 $(".collapser").addClass("collapsed"); 395 $(".collapsable").hide(); 396 397 // Show any that start shown 398 $(".collapser.show").each(function(event) { 399 400 collapse_expand($(this),false,0); 401 }); 402 403 // On expandable clicked 404 $("body").on("click",".collapser",function(event) { 405 406 collapse_expand($(this),event,500); 407 }); 408 } 409 410 411 // Bacground image 412 if($(".background-image").length > 0) { 413 414 // Backgrounds 415 $(".background-image").backgroundimage(); 416 } 417 418 419 // Force initial scroll and resize 420 { 421 setTimeout(function() { 422 $(window,"html,body").scroll(); 423 if(browser !== "IE") {window.dispatchEvent(new Event('resize'));} 424 },100); 425 } 426 427 // Manually add wf-active if 3 seconds passed 428 { 429 setTimeout(function() { 430 $("html").addClass("wf-active"); 431 },3000); 432 } 433 }); 434 435 436 // Collapsable content 437 function collapse_expand(obj,event,spd) { 438 "use strict"; 439 440 // 441 if(event !== false) { 442 event.preventDefault(); 443 } 444 445 var element = obj; 446 447 // Parent 448 var parent = $(element).closest(".collapse-holder"); 449 parent = (parent === undefined) ? $(element).closest(".layout") : parent; 450 451 // Get speed 452 var speed = $(element).data("speed"); 453 speed = (speed === undefined) ? spd : parseInt(speed); 454 455 // Get if accordian 456 var accordion = $(element).data("accordion"); 457 accordion = (accordion === undefined) ? false : true; 458 459 // Collapse all others 460 if(accordion) { 461 462 // 463 $(parent).find(".collapser").each(function() { 464 // 465 if($(this).is($(element))) {} 466 else { 467 // 468 $(this).removeClass("uncollapsed"); 469 $(this).addClass("collapsed"); 470 // 471 $(this).next(".collapsable").slideUp({ 472 duration: parseInt(speed), 473 //easing: 'easeOutQuart' 474 }); 475 } 476 }); 477 } 478 479 // Expand 480 if($(element).hasClass("collapsed")) { 481 // 482 $(element).removeClass("collapsed"); 483 $(element).addClass("uncollapsed"); 484 485 // Slide down collapse 486 $(element).nextAll(".collapsable").eq(0).slideDown({ 487 duration: speed, 488 //easing: 'easeOutQuart' 489 }); 490 } 491 492 // Collapse 493 else { 494 // 495 $(element).removeClass("uncollapsed"); 496 $(element).addClass("collapsed"); 497 498 // Slide up collapse 499 $(element).nextAll(".collapsable").eq(0).slideUp({ 500 duration: parseInt(speed), 501 //easing: 'easeOutQuart' 502 }); 503 } 504 } 505 506 507 // Generic ajax function (ajax starting point) 508 function generic_ajax() { 509 "use strict"; 510 511 if(true) { 512 // Run ajax call 513 $.ajax({ 514 type: "GET", 515 url: pageRelativity+'edit/template.ajax.php', 516 dataType: "jsonp", 517 jsonp: "callback", 518 timeout: 5000, 519 data: { 520 type: 'ajax', 521 relative: pageRelativity 522 }, 523 success: function(data) { 524 // If data 525 if(data.results) { 526 // 527 alert(data.results); 528 } 529 }, 530 error: function(request, status, error) { 531 // 532 alert(request.responseText); 533 } 534 }); 535 } 536 } 537 538 539 // Update cart summary 540 function updateCartSummery() { 541 "use strict"; 542 543 // Change inner cart summary 544 $("#shopping-cart-summery-inner").slideUp(350,function() { 545 546 // 547 $.ajax({ 548 type: "POST", 549 url: pageRelativity+"edit/shop/cart.ajax.php?update=1&relative="+pageRelativity, 550 data: "", 551 success: function(data) { 552 553 if(data) { 554 // Format text with holder 555 var htmlText = data; 556 557 // hide / show / append 558 $("#shopping-cart-summery").html(""); 559 $("#shopping-cart-summery").append(htmlText); 560 $("#shopping-cart-summery").show(); 561 562 $("#shopping-cart-summery .shopping-cart-none").remove(""); 563 $("#shopping-cart-proceed").show(); 564 565 $("#shopping-cart-summery-inner").slideDown(350); 566 } 567 } 568 }); 569 }); 570 } 571 572 573 // Hide website message 574 function hide_site_message(msgId) { 575 "use strict"; 576 577 // hide message 578 $("#"+msgId).slideUp(400,"easeInBack"); 579 580 var hideString = "hideid="+msgId; 581 $.ajax({ 582 type: "POST", 583 url: pageRelativity+"edit/core/core_functions/messaging.inc.php?remove-message=1", 584 data: hideString, 585 success: function(data) { 586 if(data) { 587 //alert(data); 588 } 589 } 590 }); 591 } 592 593
594 // Update website message 595 function update_messages() { 596 "use strict"; 597 598 // 599 $.ajax({ 600 type: "POST", 601 url: pageRelativity+"edit/shop/cart.ajax.php?getmessages=1", 602 success: function(data) { 603 if(data) { 604 $("#site-messages").html(data); 605 $("#site-messages").slideDown(400);//,"easeOutSine" 606 clearInterval(messagewait); 607 messagewait = setInterval(hide_messages, 6000); 608 } 609 else { 610 611 } 612 } 613 }); 614 } 615 616 617 function hide_messages() { 618 "use strict"; 619 620 // hide message 621 $("#site-messages").slideUp(400);//,"easeInBack" 622 623 clearInterval(messagewait); 624 } 625 626 627 // Get viewport size 628 function get_web_size() { 629 "use strict"; 630 631 var docWidth = window.innerWidth; 632 var viewPort = $('meta[name="viewport"]'); 633 634 if(docWidth <= mediaSteps['mobile'] && viewPort.attr('content') !== undefined) { 635 webSize = 'mobile'; 636 $("#navigation ul li ul").hide(0); 637 } 638 else if(docWidth <= mediaSteps['smalltablet'] && viewPort.attr('content') !== undefined) { 639 webSize = 'smalltablet'; 640 $("#navigation ul li ul").hide(0); 641 } 642 else if(docWidth <= mediaSteps['midtablet'] && viewPort.attr('content') !== undefined) { 643 webSize = 'midtablet'; 644 $("#navigation ul li ul").hide(0); 645 } 646 else if(docWidth <= mediaSteps['tablet'] && viewPort.attr('content') !== undefined) { 647 webSize = 'tablet'; 648 $("#navigation ul li ul").hide(0); 649 } 650 else { 651 webSize = 'full'; 652 $("#navigation ul li ul").hide(0); 653 } 654 655 656 if(docWidth > mediaSteps['midtablet']) { 657 $("#mobile-navigation").hide(0); 658 } 659 else if(docWidth > mediaSteps['mobile']) { 660 $("#mobile-navigation").show(0); 661 } 662 else if(docWidth <= mediaSteps['mobile']) { 663 if($("#mobile-navigation").data("eventtype") === "user") {} 664 else { 665 $("#mobile-navigation").hide(0); 666 } 667 } 668 669 // Set webSize to body element 670 $("body").data("websize",webSize); 671 } 672 673 674 // Basic browser detection 675 function get_browser() { 676 "use strict"; 677 678 var ua = window.navigator.userAgent; 679 var msie = ua.indexOf('MSIE '); 680 var trident = ua.indexOf('Trident/'); 681 var edge = ua.indexOf('Edge/'); 682 683 // IE 684 if(parseInt(msie) > 0 || parseInt(trident) > 0) { 685 // 686 browser = 'IE'; 687 } 688 // Edge 689 else if(parseInt(edge) > 0) { 690 // 691 browser = 'Edge'; 692 } 693 // Other 694 else { 695 // 696 browser = 'Other'; 697 } 698 699 // Set browser to body element 700 $("body").data("browser",browser); 701 } 702 703 704 // Get query value from url and key 705 function qs(url,key) { 706 "use strict"; 707 708 url = url.split("?"); 709 url = "?"+url[1]; 710 key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx control chars 711 var match = url.match(new RegExp("[?&]" + key + "=([^&]+)(&|$)")); 712 return match && decodeURIComponent(match[1].replace(/\+/g, " ")); 713 } 714 715 716 // FlexSlider Video functions 717 function vidAddEvent(element,eventName,callback) { 718 "use strict"; 719 720 // 721 if(element.addEventListener) { 722 element.addEventListener(eventName,callback,false) 723 } 724 else { 725 element.attachEvent(eventName,callback,false); 726 } 727 } 728 729 function vidReady(player_id) { 730 "use strict"; 731 732 // 733 var froogaloop = $f(player_id); 734 735 froogaloop.addEvent('play',function(data) { 736 $('.flexslider').flexslider("pause"); 737 }); 738 739 froogaloop.addEvent('pause',function(data) { 740 $('.flexslider').flexslider("play"); 741 }); 742 } 743 744 745 (function() { 746 "use strict"; 747 748 var lastTime = 0; 749 var vendors = ['ms', 'moz', 'webkit', 'o']; 750 for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { 751 window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; 752 window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] 753 || window[vendors[x]+'CancelRequestAnimationFrame']; 754 } 755 756 if (!window.requestAnimationFrame) 757 window.requestAnimationFrame = function(callback, element) { 758 var currTime = new Date().getTime(); 759 var timeToCall = Math.max(0, 16 - (currTime - lastTime)); 760 var id = window.setTimeout(function() { callback(currTime + timeToCall); }, 761 timeToCall); 762 lastTime = currTime + timeToCall; 763 return id; 764 }; 765 766 if (!window.cancelAnimationFrame) 767 window.cancelAnimationFrame = function(id) { 768 clearTimeout(id); 769 }; 770 }());
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.