1$(document).ready(function () { 2 // Does GaId URL Param exist? 3 doesGaIdUrlParamExist(); 4 5 checkAndUpdateTopbarBackground(); 6 7 // Call the function to set default General Assembly values on page load 8 setGaDefaultValues(); 9 10 // Call the function to load General Assembly options on page load 11 loadGaOptions(); 12 13 $("#btnSearch").click(function () { 14 // Get the selected value directly from the select element 15 const selectedOption = document.getElementById('ddlSearchOptions').value; 16 17 // Build the URL with the selected option and search text 18 //const searchUrl = '/Search?q=' + encodeURIComponent($('#TextSearch').val()) + '&base=' + selectedOption; 19 const searchUrl = '/Search?q=' + encodeURIComponent($('#TextSearch').val()) + '&base=Legis'; 20 // Redirect to the search URL 21 window.location.href = searchUrl; 22 }); 23 $("#btnMobileSearch").click(function () { 24 // Get the selected value directly from the select element 25 const selectedOption = document.getElementById('ddlMobileSearchOptions').value; 26 27 // Build the URL with the selected option and search text 28 //const searchUrl = '/Search?q=' + encodeURIComponent($('#TextSearch').val()) + '&base=' + selectedOption; 29 const searchUrl = '/Search?q=' + encodeURIComponent($('#MobileTextSearch').val()) + '&base=Legis'; 30 // Redirect to the search URL 31 window.location.href = searchUrl; 32 }); 33 34 // Function to get the value of a cookie by name 35 function getCookie(cookieName) { 36 var name = cookieName + "="; 37 var decodedCookie = decodeURIComponent(document.cookie); 38 var cookieArray = decodedCookie.split(';'); 39 for (var i = 0; i < cookieArray.length; i++) { 40 var cookie = cookieArray[i]; 41 while (cookie.charAt(0) == ' ') { 42 cookie = cookie.substring(1); 43 } 44 if (cookie.indexOf(name) == 0) { 45 return cookie.substring(name.length, cookie.length); 46 } 47 } 48 return null; 49 } 50 51 function checkAndUpdateTopbarBackground() { 52 var currentGaIdCookie = getCookie("ILGA.Web.CurrentGaId"); 53 var gaIdCookie = getCookie("ILGA.Web.GAId"); 54 // Set if ILGA.Web.CurrentGaId cookie 55 $.ajax({
56 url: '/API/Legislation/GetCurrentGeneralAssembly', 57 type: 'GET', 58 dataType: 'json', 59 success: function (data) { 60 if (data.length > 0) { 61 var apiGaId = data[0].gaId; 62 63 // Set ILGA.Web.CurrentGaId cookie with the value from the API 64 document.cookie = "ILGA.Web.CurrentGaId=" + apiGaId + "; path=/"; 65 } 66 }, 67 error: function (error) { 68 console.log('Error checking and updating topbar background:', error); 69 } 70 }); 71 if (currentGaIdCookie !== gaIdCookie) { 72 // Change the background color of the topbar to #666666 73 $('#topbar').css('background-color', '#999999'); 74 $('#mobileTopbar').css('background-color', '#999999'); 75 $('#header').css('background-color', '#666666'); 76 $("#desktopVirtualAgentButton").removeClass("btn-secondary").addClass("btn-gray"); 77 $("#mobileVirtualAgentButton").removeClass("btn-secondary").addClass("btn-gray"); 78 $("#mobileChangeLanguageButton").removeClass("btn-secondary").addClass("btn-gray"); 79 $("#desktopChangeLanguageButton").removeClass("btn-secondary").addClass("btn-gray"); 80 $("#learnButton").removeClass("btn-secondary").addClass("btn-gray"); 81 $("#mobileLearnButton").removeClass("btn-secondary").addClass("btn-gray"); 82 } else { 83 // Clear the background color of the topbar (reset to default) 84 $('#topbar').css('background-color', ''); 85 $('#mobileTopbar').css('background-color', ''); 86 $('#header').css('background-color', ''); 87 $("#desktopVirtualAgentButton").removeClass("btn-gray").addClass("btn-secondary"); 88 $("#mobileVirtualAgentButton").removeClass("btn-gray").addClass("btn-secondary"); 89 $("#mobileChangeLanguageButton").removeClass("btn-gray").addClass("btn-secondary"); 90 $("#desktopChangeLanguageButton").removeClass("btn-gray").addClass("btn-secondary"); 91 $("#learnButton").removeClass("btn-gray").addClass("btn-secondary"); 92 $("#mobileLearnButton").removeClass("btn-gray").addClass("btn-secondary"); 93 } 94 } 95 96 function doesGaIdUrlParamExist() { 97 // New refresh cookie 98 var gaRefreshCookie = getCookie("ILGA.Web.GaRefresh"); 99 var gaIdCookie = getCookie("ILGA.Web.GAId"); 100 // Check if GAId parameter is present in the URL 101 var urlParams = new URLSearchParams(window.location.search); 102 103 var urlGaId = urlParams.get('GAID') || urlParams.get('GAId') || urlParams.get('GaId') || urlParams.get('gaid'); 104 if (urlGaId !== null) { 105 if ((urlGaId && gaRefreshCookie == null) || (urlGaId !== gaIdCookie)) { 106 var getGaUrl = '/API/Legislation/GetGeneralAssemblyByGaId?GaId=' + urlGaId; 107 $.ajax({
108 url: getGaUrl, 109 type: 'GET', 110 dataType: 'json', 111 success: function (gadata) { 112 if (gadata) { 113 // Set the cookies 114 document.cookie = "ILGA.Web.GaRefresh=1;path=/"; 115 // Set values for the cookies 116 document.cookie = "ILGA.Web.GAId=" + gadata.gaId + ";path=/"; 117 document.cookie = "ILGA.Web.GANum=" + gadata.gaNumber + ";path=/"; 118 document.cookie = "ILGA.Web.GALabel=" + encodeURIComponent(gadata.gaLabel) + ";path=/"; 119 120 $.ajax({ 121 url: '/home/blank', 122 type: 'GET', // or 'POST' depending on your server-side method 123 success: function (response) { 124 // smile it worked 125 location.reload(); 126 }, 127 error: function (error) { 128 // Handle the error if needed 129 } 130 }); 131 } 132 }, 133 error: function (error) { 134 console.log('Error setting default values:', error); 135 } 136 }); 137 } 138 }; 139 } 140 141 function setGaDefaultValues() { 142 // Check if cookies already exist 143 var gaIdCookie = getCookie("ILGA.Web.GAId"); 144 var gaNumCookie = getCookie("ILGA.Web.GANum"); 145 var gaLabelCookie = getCookie("ILGA.Web.GALabel"); 146 147 if (gaIdCookie == null || gaNumCookie == null) { 148 // Cookies do not exist, fetch data from the API and set default values 149 $.ajax({
150 url: '/API/Legislation/GetCurrentGeneralAssembly', 151 type: 'GET', 152 dataType: 'json', 153 success: function (data) { 154 if (data.length > 0) { 155 var values = data[0].gaValue.split('|'); 156 var gaId = values[0]; 157 var gaNum = values[1]; 158 159 // Set default values for the cookies 160 document.cookie = "ILGA.Web.GAId=" + gaId + ";path=/"; 161 document.cookie = "ILGA.Web.GANum=" + gaNum + ";path=/"; 162 document.cookie = "ILGA.Web.GALabel=" + encodeURIComponent(data[0].gaLabel) + ";path=/"; 163 164 var checkGaIdCookie = getCookie("ILGA.Web.GAId"); 165 166 // Set ILGA.Web.CurrentGaId cookie with the value from the API 167 document.cookie = "ILGA.Web.CurrentGaId=" + gaId + "; path=/"; 168 169 // Set the placeholder for the input field 170 $('#TextSearch').attr('placeholder', 'Search ' + data[0].gaLabel); 171 $('#MobileTextSearch').attr('placeholder', 'Search ' + data[0].gaLabel); 172 173 // Check if the gaIdCookie matches the API data on page load 174 checkAndUpdateTopbarBackground(); 175 } 176 }, 177 error: function (error) { 178 console.log('Error setting default values:', error); 179 } 180 }); 181 } 182 else { 183 // Cookies already exist, set the value for the input field 184 $('#TextSearch').attr('placeholder', 'Search ' + gaLabelCookie); 185 $('#MobileTextSearch').attr('placeholder', 'Search ' + gaLabelCookie); 186 } 187 } 188 189 function loadGaOptions() { 190 $.ajax({
191 url: '/API/Legislation/GetGeneralAssemblies', 192 type: 'GET', 193 dataType: 'json', 194 success: function (data) { 195 // Clear existing options 196 $('#selectILGA').empty(); 197 198 // Add default option 199 $('#selectILGA').append('<option value="">Select General Assembly</option>'); 200 $('#selectMobileILGA').append('<option value="">Select General Assembly</option>'); 201 202 // Add options from the API response 203 $.each(data, function (index, item) { 204 $('#selectILGA').append('<option value="' + item.gaValue + '">' + item.gaLabel + '</option>'); 205 $('#selectMobileILGA').append('<option value="' + item.gaValue + '">' + item.gaLabel + '</option>'); 206 }); 207 }, 208 error: function (error) { 209 console.log('Error loading GA options:', error); 210 } 211 }); 212 } 213 214 215 // Event handler for Update ILGA button click 216 $('#btnUpdateILGA').click(function () { 217 // Get the selected value from the dropdown 218 var selectedValue = $('#selectILGA').val(); 219 220 if (selectedValue) { 221 var values = selectedValue.split('|'); 222 var gaId = values[0]; 223 var gaNum = values[1]; 224 225 // Get the selected label from the dropdown 226 var selectedLabel = $('#selectILGA option:selected').text(); 227 228 // Update cookies 229 document.cookie = "ILGA.Web.GAId=" + gaId + ";path=/"; 230 document.cookie = "ILGA.Web.GANum=" + gaNum + ";path=/"; 231 document.cookie = "ILGA.Web.GALabel=" + encodeURIComponent(selectedLabel) + ";path=/"; 232 233 // Set the placeholder for the input field 234 $('#TextSearch').attr('placeholder', 'Search ' + selectedLabel); 235 $('#MobileTextSearch').attr('placeholder', 'Search ' + selectedLabel); 236 237 checkAndUpdateTopbarBackground(); 238 window.location.href = "/"; 239 } 240 }); 241 $('#btnMobileUpdateILGA').click(function () { 242 // Get the selected value from the dropdown 243 var selectedValue = $('#selectMobileILGA').val(); 244 245 if (selectedValue) { 246 var values = selectedValue.split('|'); 247 var gaId = values[0]; 248 var gaNum = values[1]; 249 250 // Get the selected label from the dropdown 251 var selectedLabel = $('#selectMobileILGA option:selected').text(); 252 253 // Update cookies 254 document.cookie = "ILGA.Web.GAId=" + gaId + ";path=/"; 255 document.cookie = "ILGA.Web.GANum=" + gaNum + ";path=/"; 256 document.cookie = "ILGA.Web.GALabel=" + encodeURIComponent(selectedLabel) + ";path=/"; 257 258 // Set the placeholder for the input field 259 $('#TextSearch').attr('placeholder', 'Search ' + selectedLabel); 260 $('#MobileTextSearch').attr('placeholder', 'Search ' + selectedLabel); 261 262 checkAndUpdateTopbarBackground(); 263 window.location.href = "/"; 264 } 265 }); 266});
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.