1// Global utility functions that may be used by different script files - loaded early 2var desktopScreenSize = 1025; // Mobile-desktop screen size cutoff in pixels 3 4// jQuery-based scroll position animation 5function animateScroll(animateScrollLocation, scrollTimeMilliseconds) { 6 // Set default value for time if none provided 7 scrollTimeMilliseconds = scrollTimeMilliseconds || 400; 8 9 jQuery("html, body").animate( 10 { 11 scrollTop: animateScrollLocation, 12 }, 13 scrollTimeMilliseconds 14 ); 15} 16 17// Returns true if window is above mobile size 18function isDesktopScreen() { 19 if (window.innerWidth >= desktopScreenSize) { 20 return true; 21 } 22 return false; 23} 24 25// Returns true if window is mobile size 26function isMobileScreen() { 27 if (window.innerWidth < desktopScreenSize) { 28 return true; 29 } 30 return false; 31} 32 33// Returns a random integer between a minimum and maximum 34// Minimum is INCLUSIVE, maximum is EXCLUSIVE (min. 1, max. 3 will returns 1s and 2s) 35function getRandomInt(min, max) { 36 min = Math.ceil(min); 37 max = Math.floor(max); 38 return Math.floor(Math.random() * (max - min) + min); 39} 40 41// Returns TRUE if page contains any of selected elements 42// Usage: if ($(selector).exists()) 43jQuery.fn.exists = function () { 44 return this.length !== 0; 45}; 46 47// Adds "active" class to an element 48// Usage: $(selector).addActive() 49jQuery.fn.addActive = function () { 50 jQuery(this).addClass("active"); 51}; 52 53// Removes "active" class from an element 54jQuery.fn.removeActive = function () { 55 jQuery(this).removeClass("active"); 56}; 57 58// Adds OR removes "active" class to an element, depending on current state 59// Usage: $(selector).toggleActive() 60jQuery.fn.toggleActive = function () { 61 if (jQuery(this).hasClass("active")) { 62 jQuery(this).removeClass("active"); 63 return; 64 } 65 jQuery(this).addClass("active"); 66}; 67 68// Returns TRUE if an element has the "active" class 69// Usage: if ($(selector).isActive()) 70jQuery.fn.isActive = function () { 71 return jQuery(this).hasClass("active"); 72}; 73 74// Sorts elements based on data attribute after load 75// Call in document ready like so: $('.search-results-attorneys').sortItems("li", "relevance", true); 76// HTML setup has parent container with class "search-results-attorneys" and list items with custom data attribute, e.g. <li data-relevance="50"> 77jQuery.fn.sortItems = function sortItems(elementType, dataAttribute, ascending) { 78 if (ascending) { 79 jQuery("> " + elementType, this[0]) 80 .sort(asc_sort) 81 .appendTo(this[0]); 82 } else { 83 jQuery("> " + elementType, this[0]) 84 .sort(desc_sort) 85 .appendTo(this[0]); 86 } 87 88 function asc_sort(a, b) { 89 return jQuery(b).data(dataAttribute) > jQuery(a).data(dataAttribute) ? 1 : -1; 90 } 91 function desc_sort(a, b) { 92 return jQuery(b).data(dataAttribute) < jQuery(a).data(dataAttribute) ? 1 : -1; 93 } 94}; 95 96// Resets a form's input and select fields 97function resetFormFields(formId) { 98 // Get the form element by its ID 99 const form = document.getElementById(formId); 100 101 // Check if the form element exists 102 if (form) { 103 // Get all input and select elements within the form 104 const formElements = form.querySelectorAll("input, select"); 105 106 // Loop through selected inputs and reset 107 formElements.forEach((element) => { 108 if (element.tagName === "SELECT") { 109 // For <select> elements, set the selected index to the default option (usually index 0) 110 element.selectedIndex = 0; 111 } else { 112 element.value = ""; 113 } 114 }); 115 116 console.log("Form #" + formId + " values reset."); 117 } else { 118 console.error('Form #"' + formId + '" not found; cannot reset.'); 119 } 120} 121 122// Returns value between 0-1 indicating how far down the page the user is scrolled 123function getScrollPercent() { 124 var h = document.documentElement, 125 b = document.body, 126 st = "scrollTop", 127 sh = "scrollHeight"; 128 return (h[st] || b[st]) / ((h[sh] || b[sh]) - h.clientHeight); 129} 130 131// Check "GET" variable in URL 132// http://dummy.com/?technology=jquery&blog=jquerybyexample 133// var tech = getURLParameter('technology'); 134var getURLParameter = function getURLParameter(sParam) { 135 var sPageURL = decodeURIComponent(window.location.search.substring(1)), 136 sURLVariables = sPageURL.split("&"), 137 sParameterName, 138 i; 139 140 for (i = 0; i < sURLVariables.length; i++) { 141 sParameterName = sURLVariables[i].split("="); 142 143 if (sParameterName[0] === sParam) { 144 return sParameterName[1] === undefined ? true : sParameterName[1]; 145 } 146 } 147};
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.