PageSourceSearch

https://www.lion-dent-health.or.jp/wp-cms/wp-content/themes/ldh-sys/my-school-code/school-code.js

js lion-dent-health.or.jp collected 2026-10-02 07:49:12 UTC 13,269 bytes, 370 lines download raw bytes

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>&nbsp;</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.