1/** 2 * modal my-modal-enquete 3 * 4 * å¶å¾¡é ç® 5 * school_code: 妿 ¡ã³ã¼ã 6 * school_name: 妿 ¡å 7 * school_type: 妿 ¡ç¨® 8 * school_ownership_type: è¨ç«ï¼è¨ç½®åºåï¼ 9 * school_post_code: éµä¾¿çªå· 10 * school_prefecture: é½éåºç 11 * school_address: 使 12 */ 13 14jQuery(function ($) { 15 16 const modalId = 'modal-school_code'; 17 18 // ãã©ã¼ã æ å ±ãåå¾ãã 19 const getSchoolList = async(postCode)=>{ 20 21 // JSONã®èªåè§£æãä¸å¯ã¨ããçºãjQueryéä¾åã®å½¢å¼ã«å¯ãã 22 const formData = new URLSearchParams(); 23 formData.append('action', 'my_school_list'); 24 formData.append('_ajax_nonce', my_school_code_params.nonce); 25 formData.append('post_code', postCode); 26 const body = formData.toString(); // 'key1=value1&key2=value2' 27 28 const res = await fetch(my_school_code_params.url, { 29 method: 'POST', 30 headers: { 31 'Content-Type': 'application/x-www-form-urlencoded' 32 }, 33 body: body 34 }) 35 const json = await res.json(); 36 37 return json; 38 }; 39 40 // 妿 ¡é¸æã¢ã¼ãã«è¡¨ç¤º 41 const showSchoolSelectModal = ()=>{ 42 return new Promise((resolve, reject) => { 43 // console.log('showSchoolSelectModal') 44 45 $(`#${modalId}`).remove(); 46 47 const modal = ` 48 <div class="overlay overlay--displayFlex overlay--module overlay--isDisplayed" id="${modalId}"> 49 <section class="modal modal--school_code"> 50 <div class="modal__body"> 51 <div class="modal__contents"> 52 <h1 class="modal__hdg">妿 ¡ã³ã¼ã鏿</h1> 53 <div class="modal__school_code-header"> 54 <div>éµä¾¿çªå·</div> 55 <div><input type="text" inputmode="numeric" class="input-text" placeholder="æ°å7æ¡ï¼åè§ã»ãã¤ãã³ãªãï¼"></div> 56 <span class="btn btn--small">æ¤ç´¢</span> 57 <button type="button" class="btn btn--small-border">ãªã»ãã</button> 58 </div> 59 <div class="modal__school_code-error"> 60 <div class="modal__error-text">éµä¾¿çªå·ããã¤ãã³ãªãã§åè§æ°å7æ¡ã§å ¥åãã¦ãã ãã</div> 61 </div> 62 </div> 63 <div class="modal__school_code-scroll"> 64 <table class="modal__school_code-table"> 65 <thead> 66 <tr> 67 <th>妿 ¡å</th> 68 <th></th> 69 </tr> 70 </thead> 71 <tbody> 72 <!-- 73 <tr> 74 <td>åæµ·éæè²å¤§å¦éå±å½é¤¨å¹¼ç¨ååæµ·éæè²å¤§å¦éå±å½é¤¨å¹¼ç¨å</td> 75 <td><button class="btn btn--small">鏿ãã</button></td> 76 </tr> 77 --> 78 </tbody> 79 </table> 80 <div class="modal__school_code-nohit"> 81 <p>çµæãè¦ã¤ããã¾ããã§ããã<br>éµä¾¿çªå·ã確èªãã¦å度ã試ããã ããã</p> 82 </div> 83 </div> 84 <div class="modal__school_code-btns-area"> 85 <a href="" class="btn btn--small-border jsModalClose">éãã</a> 86 </div> 87 </div> 88 </section> 89 </div> 90 `; 91 92 const $modal = $(modal); 93 const $input = $('.modal__school_code-header input', $modal); 94 const $table = $('table', $modal); 95 const $tbody = $('table tbody', $modal); 96 const $error = $('.modal__school_code-error', $modal); 97 const $nohit = $('.modal__school_code-nohit', $modal); 98 99 100 // éãã 101 $(".jsModalClose", $modal) 102 .off("click") 103 .on("click", function () { 104 $modal.css("display", "none"); 105 html.classList.remove("html--isOverflowHidden"); 106 resolve(null); 107 return false; 108 }); 109 110 // æ¤ç´¢ 111 $(`.modal__school_code-header span.btn`, $modal).off('click').on('click',async function(e){ 112 113 e.preventDefault(); 114 115 $table.css('display', 'none'); 116 $error.css('display', 'none'); 117 $nohit.css('display', 'none'); 118 119 let list = []; 120 const postCode = $input.val(); 121 if (!(postCode||"").match(/^\d{7}$/)) { 122 $error.css('display', 'block'); 123 return false;
124 } 125 126 try { 127 list = await getSchoolList(postCode); 128 } catch(error) { 129 console.log(error); 130 } 131 132 if ((list || []).length == 0) { 133 $nohit.css('display', 'block'); 134 return false; 135 } 136 137 $tbody.empty(); 138 for (const item of list) { 139 const $tr = $(` 140 <tr> 141 <td> </td> 142 <td><button type="button" class="btn btn--small">鏿ãã</button></td> 143 </tr> 144 `); 145 $('td:first', $tr).text(item?.name); 146 $('button', $tr).on('click', function(){ 147 $modal.css("display", "none"); 148 html.classList.remove("html--isOverflowHidden"); 149 resolve(item); 150 return false; 151 }) 152 $tbody.append($tr); 153 } 154 155 $table.css('display', 'table'); 156 157 return false; 158 }); 159 160 // ãªã»ãã 161 $(`.modal__school_code-header button`, $modal).off('click').on('click',function(e){ 162 e.preventDefault(); 163 $table.css('display', 'none'); 164 $error.css('display', 'none'); 165 $nohit.css('display', 'none'); 166 $input.val(""); 167 $tbody.empty(); 168 }); 169 170 // åæé表示 171 $table.css('display', 'none'); 172 $error.css('display', 'none'); 173 $nohit.css('display', 'none'); 174 175 // ã¢ã¼ãã«è¡¨ç¤º 176 const html = document.querySelector("html"); 177 html.classList.add("html--isOverflowHidden"); 178 $modal.css("display", "flex"); 179 $modal.appendTo("main"); 180 181 }); 182 } 183 184 // å ¥åé¨åã䏿´»æ§å 185 const inactiveSchoolData = ($form)=>{ 186 $('input[name="school_name"]', $form).prop('readonly', true); 187 $('select[name="school_type"]', $form).off('mousedown').on('mousedown',function(){ return false;}); 188 $('select[name="school_type"]', $form).off('touchstart').on('touchstart',function(){return false;}); 189 $('select[name="school_type"]', $form).addClass('input-select--readonly'); 190 $('select[name="school_type"] option', $form).each(function(){ 191 if (!$(this).prop('selected')){ 192 $(this).prop('disabled', true); 193 } 194 }); 195 $('input[name="school_ownership_type"][type=radio]', $form).off('mousedown').on('mousedown',function(){ return false;}); 196 $('input[name="school_ownership_type"][type=radio]', $form).off('touchstart').on('touchstart',function(){ return false;}); 197 // $('input[name="school_ownership_type"]', $form).addClass('input-select--readonly'); 198 $('input[name="school_ownership_type"][type=radio]', $form).each(function(){ 199 console.log($(this).attr('value'),$(this).prop('checked'),$(this).prop('disabled')); 200 if ($(this).prop('checked')){ 201 $(this).prop('disabled', false); 202 } else { 203 $(this).prop('disabled', true); 204 } 205 }); 206 $('input[name="school_post_code"]', $form).prop('readonly', true); 207 $('select[name="school_prefecture"]', $form).off('mousedown').on('mousedown',function(){ return false;}); 208 $('select[name="school_prefecture"]', $form).off('touchstart').on('touchstart',function(){ return false;}); 209 $('select[name="school_prefecture"]', $form).addClass('input-select--readonly'); 210 $('select[name="school_prefecture"] option', $form).each(function(){ 211 if (!$(this).prop('selected')){ 212 $(this).prop('disabled', true); 213 } 214 }); 215 $('input[name="school_address"]', $form).prop('readonly', true); 216 } 217 218 // å ¥åé¨åãæ´»æ§å 219 const activeSchoolData = ($form)=>{ 220 $('input[name="school_name"]', $form).prop('readonly', false); 221 $('select[name="school_type"]', $form).off('mousedown'); 222 $('select[name="school_type"]', $form).off('touchstart'); 223 $('select[name="school_type"]', $form).removeClass('input-select--readonly'); 224 $('select[name="school_type"] option', $form).each(function(){ 225 $(this).prop('disabled', false); 226 }); 227 $('input[name="school_ownership_type"]', $form).off('mousedown'); 228 $('input[name="school_ownership_type"]', $form).off('touchstart'); 229 // $('input[name="school_ownership_type"]', $form).removeClass('input-select--readonly'); 230 $('input[name="school_ownership_type"][type=radio]', $form).each(function(){ 231 $(this).prop('disabled', false); 232 }); 233 $('input[name="school_post_code"]', $form).prop('readonly', false); 234 $('select[name="school_prefecture"]', $form).off('mousedown'); 235 $('select[name="school_prefecture"]', $form).off('touchstart'); 236 $('select[name="school_prefecture"]', $form).removeClass('input-select--readonly'); 237 $('select[name="school_prefecture"] option', $form).each(function(){ 238 $(this).prop('disabled', false); 239 }); 240 $('input[name="school_address"]', $form).prop('readonly', false); 241 } 242 243 // å ¥åé¨åã®ãã¼ã¿ã»ãã 244 const setSchoolData = ($form, data)=>{ 245 $('input[name="school_code"]', $form).val(data?.code || ""); 246 $('input[name="school_name"]', $form).val(data?.name || ""); 247 $('select[name="school_type"] option', $form).each(function(){ 248 if ($(this).val()==data?.type) { 249 $(this).prop('disabled', false).prop('selected', true); 250 } else { 251 $(this).prop('selected', false); 252 } 253 }); 254 $('input[name="school_ownership_type"][type=radio]', $form).each(function(){ 255 if ($(this).attr('value')==data?.ownership_type) { 256 $(this).prop('checked', true); 257 } else { 258 $(this).prop('checked', false); 259 } 260 }); 261 $('input[name="school_post_code"]', $form).val(data?.post_code || ""); 262 $('select[name="school_prefecture"] option', $form).each(function(){ 263 if ($(this).val()==data?.prefecture) { 264 $(this).prop('disabled', false).prop('selected', true); 265 } else { 266 $(this).prop('selected', false); 267 } 268 }); 269 $('input[name="school_address"]', $form).val(data?.address || ""); 270 }; 271 272 // å ¥åé¨åã®ãã¼ã¿ã¯ãªã¢ 273 const unsetSchoolData = ($form)=>{ 274 $('input[name="school_code"]', $form).val(""); 275 $('input[name="school_name"]', $form).val(""); 276 $('select[name="school_type"] option', $form).each(function(){ 277 if ($(this).val()=="") { 278 $(this).prop('selected', true); 279 } else { 280 $(this).prop('selected', false); 281 } 282 }); 283 $('input[name="school_ownership_type"][type=radio]', $form).each(function(){ 284 $(this).prop('checked', false); 285 }); 286 $('input[name="school_post_code"]', $form).val(""); 287 $('select[name="school_prefecture"] option', $form).each(function(){ 288 if ($(this).val()=="") { 289 $(this).prop('selected', true); 290 } else { 291 $(this).prop('selected', false); 292 } 293 }); 294 $('input[name="school_address"]', $form).val(""); 295 }; 296 297 // 妿 ¡ã³ã¼ãããé¨åã®æ´æ° 298 const refreshSchoolCodeForm = ()=>{ 299 300 // ã¢ã¼ãã«è¡¨ç¤ºä¸ã®å¦çã¯ãªã 301 if ($(`#${modalId}`).css('display') === 'flex') { 302 return; 303 } 304 $('form').each(function(){ 305 // console.log('a') 306 const $form = $(this); 307 const $inputSchoolCode = $('input[type="text"][name="school_code"]:visible', $form); 308 const $inputSchoolCodeCheck = $('input[name=school_code_check]:visible', $form) 309 310 // 表示ã¿ã¤ãã³ã°ãããããçºãå ¥åå¯è½æéã®å¶å¾¡ã¯ form.js ã«ã¦è¡ã 311 // å ¥åæ¬ããã§ãã¯ããã¯ã¹ãé表示ã®å ´åãå¦çãªã
311 312 if ($inputSchoolCode.length != 1 || $inputSchoolCodeCheck.length != 1) { 313 return; 314 } 315 316 // 妿 ¡ã³ã¼ãããã®å ´åãèªåå ¥åã¢ã¼ãä¸å¯ 317 if (($inputSchoolCode.val() || "").length == 0) { 318 $inputSchoolCodeCheck.prop('disabled', false); 319 } else { 320 $inputSchoolCodeCheck.prop('disabled', true); 321 } 322 323 // èªåå ¥åã»æåå ¥ååæ¿ 324 if($('input[name=school_code_check]', $form).prop('checked')) { 325 activeSchoolData(); 326 }else { 327 inactiveSchoolData(); 328 } 329 330 // 妿 ¡ã³ã¼ã鏿 331 $('[id="_school_code_select_btn"]', $form).off('click').on('click',async function(e){ 332 e.preventDefault(); 333 const data = await showSchoolSelectModal(); 334 if (data !== null) { 335 setSchoolData($form, data); 336 inactiveSchoolData($form) 337 $inputSchoolCodeCheck.prop('disabled', true).prop('checked', false); 338 } 339 // console.log("data", data) 340 return false; 341 }); 342 343 // 妿 ¡ã³ã¼ãã¯ãªã¢ 344 $('[id="_school_code_clear_btn"]', $form).off('click').on('click',function(){ 345 unsetSchoolData($form); 346 $inputSchoolCodeCheck.prop('disabled', false); 347 return false; 348 }); 349 350 // èªåå ¥åã»æåå ¥ååæ¿ 351 $inputSchoolCodeCheck.off('change').on('change',function(){ 352 if ($(this).prop('checked')) { 353 $inputSchoolCode.val(""); 354 activeSchoolData(); 355 } else { 356 inactiveSchoolData(); 357 } 358 }); 359 360 }); 361 }; 362 363 364 365 refreshSchoolCodeForm(); 366 setInterval(() => { 367 refreshSchoolCodeForm(); 368 }, 5 * 1000); 369 370});
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.