1jQuery(document).ready(function ($) { 2 // GravityView: Track Last Modified Date 3 function trackLastModifiedDate(entryId, action) { 4 if (entryId && action) { 5 $.ajax({ 6 url: gravityviewAjax.ajax_url, 7 type: 'POST', 8 data: { 9 action: 'update_last_modified_date', 10 entry_id: entryId, 11 action_type: action, 12 nonce: gravityviewAjax.nonce, 13 }, 14 }); 15 } 16 } 17 18 $('.gv-table-view').on('click mousedown keydown', '.gv-action-view-link, .gv-action-edit-link', function (event) { 19 let entryId = $(this).data('entry-id'); 20 let action = $(this).data('action'); 21 22 if (event.type === 'click' || (event.type === 'mousedown' && event.which === 2)) { 23 trackLastModifiedDate(entryId, action); 24 } else if (event.type === 'keydown' && (event.key === 'Enter' || event.key === ' ')) { 25 trackLastModifiedDate(entryId, action); 26 } 27 }); 28 29 // Add loading animation class 30 function setLoadingState(button, isLoading) { 31 if (isLoading) { 32 button.prop('disabled', true).addClass('loading'); 33 34 // Save original button text if not already saved 35 if (!button.data('original-text')) { 36 button.data('original-text', button.text()); 37 } 38 39 button.text('Processing...'); // Set loading text 40 } else { 41 button.prop('disabled', false).removeClass('loading'); 42 button.text(button.data('original-text')); // Restore original text 43 } 44 } 45 46 47 // Registration Form Submission 48 $('#custom-register-form').on('submit', function (e) { 49 e.preventDefault(); 50 51 const $submitButton = $('#register-submit'); 52 $submitButton.data('original-text', $submitButton.text()); // Save original text 53 54 const formData = { 55 action: 'custom_woocommerce_register', 56 security: customRegister.nonce, 57 username: $('#reg_username').val(), 58 email: $('#reg_email').val(), 59 password: $('#reg_password').val(), 60 }; 61 62 // Clear previous messages and show loading state 63 $('.ajax-response-message').html(''); 64 setLoadingState($submitButton, true); 65 66 // Perform AJAX for registration 67 $.ajax({ 68 url: customRegister.ajax_url, 69 type: 'POST', 70 data: formData, 71 success: function (response) { 72 if (response.success) { 73 // Move message to the login tab and switch to it 74 $('.ajax-response-message').html(''); 75 $('.tab-content#login').prepend( 76 `<div class="success-message">${response.data.message}</div>` 77 ); 78 $('.tab-button.log-in').trigger('click'); 79 } else { 80 // Display error messages in the "Create Account" tab 81 const errors = response.data.errors.join('<br>'); 82 $('.ajax-response-message').html( 83 `<div class="error-message">${errors}</div>` 84 ); 85 } 86 }, 87 error: function () { 88 $('.ajax-response-message').html( 89 `<div class="error-message">An unexpected error occurred. Please try again.</div>` 90 ); 91 }, 92 complete: function () { 93 setLoadingState($submitButton, false); // Reset button state 94 }, 95 }); 96 }); 97 98 $('#custom-login-form').on('submit', function (e) { 99 e.preventDefault(); 100 101 const $submitButton = $('#login-submit'); 102 $submitButton.data('original-text', $submitButton.text()); 103 104 const formData = { 105 action: 'custom_woocommerce_login', 106 security: customRegister.nonce, // reuse the same nonce object for simplicity 107 username: $('#login_username').val(), 108 password: $('#login_password').val(), 109 }; 110 111 // Clear previous messages and show loading state 112 $('.ajax-login-response-message').html('');
113 setLoadingState($submitButton, true); 114 115 $.ajax({ 116 url: customRegister.ajax_url, 117 type: 'POST', 118 data: formData, 119 success: function (response) { 120 if (response.success) { 121 $('.ajax-login-response-message').html( 122 `<div class="success-message">${response.data.message}</div>` 123 ); 124 125 setTimeout(function () { 126 location.reload(); // Or redirect to a custom dashboard 127 }, 1200); 128 } else { 129 let errorHTML = `<div class="error-message">${response.data.error}</div>`; 130 $('.ajax-login-response-message').html(errorHTML); 131 } 132 }, 133 error: function () { 134 $('.ajax-login-response-message').html( 135 `<div class="error-message">An unexpected error occurred. Please try again.</div>` 136 ); 137 }, 138 complete: function () { 139 setLoadingState($submitButton, false); 140 }, 141 }); 142 }); 143 144 145 $(document).ready(function () { 146 // Select the form wrapper dynamically 147 const $formWrapper = $('.gv-edit-entry-wrapper .ahat-survey-form_wrapper'); 148 const $formBody = $formWrapper.find('.gform-body'); 149 150 if ($formWrapper.length && $formBody.length) { 151 // Dynamically extract the form ID from the wrapper 152 const formId = $formWrapper.closest('form').attr('id').split('_')[1]; 153 const stepsContainerId = `gf_page_steps_${formId}`; 154 155 // Create steps container dynamically 156 const $stepsContainer = $(`<div id="${stepsContainerId}" class="gf_page_steps"></div>`); 157 $formBody.before($stepsContainer); 158 159 // Iterate through all custom-anchor-* elements 160 $formBody.find('[class*="custom-anchor-"]').each(function () { 161 const $anchor = $(this); 162 const classList = $anchor.attr('class') || ''; 163 const anchorMatch = classList.match(/custom-anchor-(\d+)/); 164 165 if (anchorMatch) { 166 const stepIndex = anchorMatch[1]; 167 168 // Extract text from the <h3> inside the anchor 169 const stepText = $anchor.find('h3').text().trim(); 170 171 // Create step element 172 const $stepElement = $(` 173 <div id="gf_step_${formId}_${stepIndex}" class="gf_step" data-step="${stepIndex}"> 174 <span class="gf_step_number">${stepIndex}</span> 175 <span class="gf_step_label">${stepText}</span> 176 </div> 177 `); 178 $stepsContainer.append($stepElement); 179 180 // Group fields into tab content with gform_page and gform_fields classes 181 const $tabGroup = $(` 182 <div class="tab-content tab-content-${stepIndex} gform_page"> 183 <div class="gform_fields"></div> 184 </div> 185 `); 186 187 $tabGroup.find('.gform_fields').append($anchor); // Append the anchor first 188 $formBody.find(`.field-tab-${stepIndex}`).each(function () { 189 $tabGroup.find('.gform_fields').append($(this)); // Append all matching fields 190 }); 191 $formBody.append($tabGroup); 192 } 193 }); 194 195 // Move gform_footer inside gform-body 196 const $footer = $formWrapper.find('.gform_footer'); 197 if ($footer.length) { 198 $formBody.append($footer); 199 } 200 201 // Add classes to the first step and its content on page load 202 $stepsContainer.find('.gf_step').first().addClass('visited nt-step-active'); 203 $formBody.find('.tab-content').hide().first().show(); 204 205 // Highlight tabs and steps with errors after page reload 206 $formWrapper.find('.gfield_error').each(function () { 207 const $errorField = $(this); 208 const errorTabClass = $errorField.attr('class').match(/field-tab-(\d+)/); 209 210 if (errorTabClass) { 211 const stepIndex = errorTabClass[1]; 212 213 // Highlight the step and tab-content with errors 214 $stepsContainer.find(`.gf_step[data-step="${stepIndex}"]`).addClass('error'); 215 $formBody.find(`.tab-content-${stepIndex}`).addClass('error'); 216 } 217 }); 218 219 // Function to update the "visited" class based on radio field values 220 function updateVisitedSteps() { 221 $stepsContainer.find('.gf_step').each(function () { 222 const $step = $(this); 223 const stepDataIndex = $step.data('step'); 224 const $tabContent = $formBody.find(`.tab-content-${stepDataIndex}`); 225 const $tabRadioField = $tabContent.find(".have-visited-field input[type='radio'][value='yes']:checked"); 226 227 // Add or remove the "visited" class based on the radio f
227ield's state 228 if ($tabRadioField.length || $step.hasClass('gf_step_active')) { 229 $step.addClass('visited'); 230 } 231 232 }); 233 } 234 235 // Step navigation functionality 236 $stepsContainer.on('click', '.gf_step', function () { 237 const $clickedStep = $(this); 238 const stepIndex = $clickedStep.data('step'); 239 const $currentTabContent = $formBody.find(`.tab-content-${stepIndex}`); 240 241 // â Update classes for step navigation 242 $stepsContainer.find('.gf_step').removeClass('gf_step_active nt-step-active'); 243 $clickedStep.addClass('gf_step_active nt-step-active visited'); // Add visited class 244 245 // â Show the corresponding tab content and hide others 246 $formBody.find('.tab-content').hide(); 247 $currentTabContent.show(); 248 }); 249 250 updateVisitedSteps(); 251 252 // Ensure the first step has its radio button checked if it's active 253 const $firstStep = $stepsContainer.find('.gf_step').first(); 254 if ($firstStep.hasClass('gf_step_active')) { 255 const stepIndex = $firstStep.data('step'); 256 const $firstTabContent = $formBody.find(`.tab-content-${stepIndex}`); 257 const $radioField = $firstTabContent.find(".have-visited-field input[type='radio'][value='yes']"); 258 259 if ($radioField.length) { 260 $radioField.prop("checked", true); 261 } 262 263 // Re-run to ensure the first step gets the "visited" class if needed 264 updateVisitedSteps(); 265 } 266 } 267 268 //Hide Contact Us section on the Edit form page 269 if ($('.gv-edit-entry-wrapper').length > 0) { 270 // Hide elements with the class 'ahat-contact-us' 271 $('.ahat-contact-us').hide(); 272 } 273 }); 274 275 //Update updated field to today date 276 if ($('.updated-date-field').length) { 277 var $dateField = $('.updated-date-field input'); 278 279 var today = new Date(); 280 var yyyy = today.getFullYear(); 281 var mm = String(today.getMonth() + 1).padStart(2, '0'); 282 var dd = String(today.getDate()).padStart(2, '0'); 283 var formattedDate = mm + '/' + dd + '/' + yyyy; 284 285 $dateField.val(formattedDate); 286 } 287 288 if ($(".ahat-healthcare-survey").length) { 289 290 var $surveyContainer = $('.ahat-healthcare-survey'); 291 var $noResultsTables = $surveyContainer.find('.gv-table-view.gv-container-no-results'); 292 293 // Check if exactly 2 "no results" tables exist 294 if ($noResultsTables.length === 2) { 295 // Make sure both are hidden (in case display:none is used) 296 var bothHidden = true; 297 298 $noResultsTables.each(function() { 299 if ($(this).is(':visible')) { 300 bothHidden = false; 301 return false; // Exit loop early 302 } 303 }); 304 305 var $viewReports = $surveyContainer.find('.ahat-view-reports'); 306 307 if (bothHidden) { 308 // Append the message (you can change the selector or location later) 309 $viewReports.prepend( 310 '<div class="ahat-no-reports-message" style="max-width: 800px; margin: 0 auto; padding: 20px 0 50px 0; text-align: center; font-size: 18px;">' + 311 '<p>You do not currently have any saved reports from the AASPIRE Autism Healthcare Accommodations Tool. Any reports you create will show up here.</p>' + 312 '<p><a href="/healthcaretoolkit/accommodationsreport/">Click here</a> to start creating a personalized accommodation report. Or click the âBack to Homepageâ button to explore the AASPIRE Healthcare Toolkit for autistic patients and their healthcare providers.</p>' + 313 '</div>' 314 ); 315 } 316 } 317 } 318 319 320});
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.