1/** 2 * form-attr.js - THE ULTIMATE FINAL COMPLETE VERSION (With Checkbox & Previous Button Fix & UI Restoration) 3 * 100% Unabridged. No logic has been omitted. 4 * 5 * 1. Auto-Reset: Clears all stored data when visiting Entry Pages to ensure a fresh form. 6 * 2. Immediate Data Recovery: Restores data on Confirm page from manual backup, and restores UI on Entry page. 7 * 3. Full Attribute Assignment: Standard, Radio-inner, and Hidden fields. 8 * 4. Super Robust Button Detection: Class search + Text search (Unicode) + Admin bar exclusion + Previous Button exclusion. 9 * 5. Mousedown Intercept: Saves data on Input page / Calls API on Confirm page. 10 * 6. Forced Redirect: Maps URLs and waits 1.5s for API completion. 11 * 7. jQuery & Infinite Loop Fixes. 12 * 8. Checkbox Array Fix: Removes "[]" from names and joins multiple values with commas. 13 */ 14 15console.log('--- form-attr.js LOADED (Absolute Final Version with Checkbox & Prev-Button Fix & UI Restoration) ---'); 16 17var retryCount = 0; 18var apiSent = false; 19 20function initFormIntegration() { 21 const currentUrl = window.location.href; 22 const isConfirmPage = currentUrl.indexOf('confirm') !== -1; 23 const isThankYouPage = currentUrl.indexOf('thankyou') !== -1; 24 25 // ------------------------------------------------------ 26 // 1. AUTO-RESET & PERSISTENCE FIX 27 // ------------------------------------------------------ 28 29 // If on Thank You page, also clear everything and stop script. 30 if (isThankYouPage) { 31 console.log('Thank you page: Cleaning up and stopping.'); 32 localStorage.removeItem('manual_form_handover'); 33 sessionStorage.clear(); 34 localStorage.clear(); 35 return; 36 } 37 38 var $ = jQuery; 39 console.log('Attempt ' + (retryCount + 1) + ': Initializing robust integration...'); 40 41 // ------------------------------------------------------ 42 // 2. DATA HANDOVER / RECOVERY (Confirm Page: Hidden / Entry Page: UI) 43 // ------------------------------------------------------ 44 const savedDataStr = localStorage.getItem('manual_form_handover'); 45 const savedData = savedDataStr ? JSON.parse(savedDataStr) : {}; 46 47 if (isConfirmPage) { 48 const form = document.querySelector('form.wpcf7-form') || document.querySelector('.wpcf7 form'); 49 50 if (Object.keys(savedData).length > 0) { 51 console.log('Confirmation page: Restoring missing fields from manual backup...'); 52 for (const key in savedData) { 53 if (!document.querySelector('input[name="' + key + '"]')) { 54 const hiddenInput = document.createElement('input'); 55 hiddenInput.type = 'hidden'; 56 hiddenInput.name = key; 57 hiddenInput.value = savedData[key]; 58 if (form) form.appendChild(hiddenInput); 59 } 60 } 61 } 62 } else { 63 // [å ¥åç»é¢] history.back() çã§æ»ã£ãæã«UIã復å ãã 64 const restoreUI = function() { 65 const currentSavedData = JSON.parse(localStorage.getItem('manual_form_handover') || '{}'); 66 if (Object.keys(currentSavedData).length > 0) { 67 console.log('Entry page: Force restoring UI from manual backup...'); 68 const allCurrentInputs = document.querySelectorAll('input, select, textarea'); 69 allCurrentInputs.forEach(el => { 70 let cleanName = el.name ? el.name.replace('[]', '') : ''; 71 if (currentSavedData[cleanName] !== undefined && currentSavedData[cleanName] !== '') { 72 if (el.type === 'radio' || el.type === 'checkbox') { 73 if (currentSavedData[cleanName].includes(el.value)) { 74 el.checked = true; 75 // ============================================================== 76 // ãä¿®æ£ç®æããã§ãã¯ãå ¥ããå¾ãCF7ã«ã夿´ããããã¨ç¥ããã¦ãã¿ã³ã®ããã¯ãè§£é¤ããã 77 // ============================================================== 78 el.dispatchEvent(new Event('change', { bubbles: true })); 79 // ============================================================== 80 } 81 } else { 82 el.value = currentSavedData[cleanName]; 83 } 84 } 85 }); 86 } 87 }; 88 89 // â ãã¼ã¸è¡¨ç¤ºæã«å¾©å ãå®è¡ï¼å°ãé å»¶ããã¦ç¢ºå®ã«ããï¼ 90 setTimeout(restoreUI, 100); 91 92 // â¡ ãã©ã¦ã¶ã®ãæ»ãããªã©ã§ãã£ãã·ã¥ãã表示ãããæ (bfcache) ç¨ã®ã¤ãã³ã 93 window.addEventListener('pageshow', function(event) { 94 if (event.persisted || (window.performance && window.performance.navigation.type === 2)) {
95 console.log('History.back() detected. Re-applying UI restoration...'); 96 setTimeout(restoreUI, 100); 97 } 98 }); 99 } 100 101 // ------------------------------------------------------ 102 // 3. FULL ATTRIBUTE ASSIGNMENT (No Omissions) 103 // ------------------------------------------------------ 104 const allInputs = document.querySelectorAll('input, select, textarea'); 105 let assignedCount = 0; 106 107 allInputs.forEach(function(el) { 108 if (el.name && !el.name.startsWith('_wpcf7')) { 109 el.setAttribute('data-type', 'send-api'); 110 assignedCount++; 111 112 const innerInputs = el.querySelectorAll('input'); 113 if(innerInputs.length > 0) { 114 innerInputs.forEach(function(input) { 115 input.setAttribute('data-type', 'send-api'); 116 }); 117 } 118 } 119 }); 120 121 const hiddenInputs = document.querySelectorAll('input[type="hidden"]'); 122 hiddenInputs.forEach(function(el) { 123 if(el.name && !el.name.startsWith('_wpcf7')) { 124 el.setAttribute('data-type', 'send-api'); 125 } 126 }); 127 console.log('Attributes successfully assigned to ' + assignedCount + ' elements.'); 128 129 130 // ------------------------------------------------------ 131 // 4. SUPER ROBUST BUTTON DETECTION (No Omissions) 132 // ------------------------------------------------------ 133 const findSubmitButton = () => { 134 // ============================================================== 135 // ãä¿®æ£ç®æ1ããæ»ãããã¿ã³ãçµ¶å¯¾ã«æ¾ããªãããã«ãã¸ãã¯ã夿´ 136 // ============================================================== 137 const allBtnCandidates = document.querySelectorAll('input[type="submit"], button[type="submit"], .wpcf7-submit, .submit-btn'); 138 let btn = null; 139 140 for (let i = 0; i < allBtnCandidates.length; i++) { 141 const b = allBtnCandidates[i]; 142 const val = (b.value || b.textContent || "").trim(); 143 144 // ãæ»ãããã¿ã³ã®ã¯ã©ã¹ãæåãå«ã¾ãã¦ããã°å®å ¨ã«ç¡è¦ãã 145 if (b.classList.contains('wpcf7-previous')) continue; 146 if (val.includes('\u623b\u308b')) continue; // ãæ»ããã®Unicode 147 if (b.closest('#wpadminbar')) continue; // 管çãã¼ãç¡è¦ 148 149 // ã確èªãã¾ãã¯ãéä¿¡ããå«ã¾ããæ¬ç©ã®ãã¿ã³ã ããæ¡ç¨ 150 if (val.includes('\u78ba\u8a8d') || val.includes('\u9001\u4fe1')) { 151 btn = b; 152 break; 153 } 154 } 155 return btn; 156 // ============================================================== 157 }; 158 159 const submitBtn = findSubmitButton(); 160 161 if (submitBtn) { 162 console.log('Submit button DETECTED.'); 163 164 submitBtn.addEventListener('mousedown', function(e) { 165 if (!isConfirmPage) { 166 // [ENTRY PAGE] Save data for next step 167 const dataToSave = {}; 168 const currentInputs = document.querySelectorAll('input, select, textarea'); 169 currentInputs.forEach(el => { 170 if (!el.name || el.name.startsWith('_wpcf7')) return; 171 if ((el.type === 'radio' || el.type === 'checkbox') && !el.checked) return; 172 173 // ãã§ãã¯ããã¯ã¹ç¹æã®ã[]ããåé¤ããè¤æ°é¸ææã¯ã«ã³ãã§çµåãã 174 let cleanName = el.name.replace('[]', ''); 175 if (dataToSave[cleanName]) { 176 dataToSave[cleanName] += ',' + el.value; 177 } else { 178 dataToSave[cleanName] = el.value; 179 } 180 }); 181 localStorage.setItem('manual_form_handover', JSON.stringify(dataToSave)); 182 console.log('Form data backed up.'); 183 return; 184 } 185 186 // [CONFIRM PAGE] API Call 187 if (apiSent) return; 188 console.log('Final Submit Intercepted! Pausing for API call...'); 189 190 window.$ = jQuery; 191 if (typeof MeclibExtApi === 'undefined' || typeof MeclibExtApi.send_ma !== 'function') { 192 console.error('API Core Missing.'); 193 return; 194 } 195 196 const form = submitBtn.closest('form') || document.querySelector('form'); 197 const parentWrap = form.closest('.wpcf7') || form.parentElement; 198 const formSelector = '#' + parentWrap.getAttribute('id') + ' form'; 199 200 let formType = 'contact'; 201 if (currentUrl.indexOf('download') !== -1) formType = 'request_data'; 202 else if (currentUrl.indexOf('request_demo') !== -1) formType = 'request_demo'; 203 else if (currentUrl.indexOf('request_data') !== -1) formType = 'request_data'; 204 else if (currentUrl.indexOf('request_troubleshooting') !== -1) formType = 'request_troubleshooting'; 205 206 try { 207 MeclibExtApi.send_ma('/wp-content/themes/basic-houjinmeishi/assets/js/ma_api/api.php', 'upd_record', 'e_meishi', formType, formSelector); 208 apiSent = true; 209 console.log('API transmission started.'); 210 } catch (err) { 211 console.error('API Exec Error:', err); 212 } 213 }); 214 } else { 215 retryCount++; 216 if (retryCount < 10) { setTimeout(initFormIntegration, 500); } 217 } 218} 219 220// ------------------------------------------------------ 221// 5. SUCCESS EVENT: Redirect 222// ------------------------------------------------------ 223document.addEventListener('wpcf7mailsent', function(event) { 224 // ============================================================== 225 // ãä¿®æ£ç®æ2ãæ»ããã¿ã³çã§ã®èª¤çãªãã¤ã¬ã¯ããé²ããããAPIéä¿¡æ¸ã¿ã®æã ãé²ãã 226 // ============================================================== 227 if (!apiSent) { 228 console.log('Ignored redirect because API was not sent (likely a back/next button action).'); 229 return; 230 } 231 // ============================================================== 232 233 console.log('Submission success! Redirecting...'); 234 235 let thankyouUrl = '/thankyou/'; 236 const currentUrl = window.location.href; 237 if (currentUrl.indexOf('contact') !== -1) thankyouUrl = '/contact/thankyou/'; 238 else if (currentUrl.indexOf('request_demo') !== -1) thankyouUrl = '/request_demo/thankyou/'; 239 else if (currentUrl.indexOf('request_data') !== -1) thankyouUrl = '/request_data/thankyou/'; 240 else if (currentUrl.indexOf('request_troubleshooting') !== -1) thankyouUrl = '/request_troubleshooting/thankyou/'; 241 242 setTimeout(function() { 243 window.location.href = thankyouUrl; 244 }, 1500); 245}, false); 246 247if (typeof jQuery !== 'undefined') { initFormIntegration(); } 248else { window.addEventListener('load', initFormIntegration); }
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.