PageSourceSearch

https://git.or.th/front/template/default/assets/js/calendar.js?u=20262509015259

js git.or.th collected 2026-09-24 18:53:46 UTC 4,809 bytes, 142 lines download raw bytes

1// JavaScript Document
2function getCalendarDetailAll() {
3  var formData = new FormData($('#myCalendarForm')[0])
4  var path = $('base').attr('href') + base_url_lang
5  $.ajax({
6    url: path + '/calendar/load-calendar-list',
7    type: 'POST',
8    success: function (data) {
9      jQuery('#calendarList').show()
10      //  jQuery("#calendarList").html(data);
11      safeHtml('#calendarList', data)
12    },
13    data: formData,
14    cache: false,
15    contentType: false,
16    processData: false
17  })
18}
19
20function GetCalendar() {
21  var formData = new FormData($('#myCalendarForm')[0])
22  var path = $('base').attr('href') + base_url_lang
23  // console.log(path);
24  $.ajax({
25    url: path + '/calendar/load-calendar',
26    type: 'POST',
27    success: function (data) {
28      // console.log(data);
29      jQuery('#calendar').show()
30      // jQuery('#calendar').html(data)
31      safeHtml('#calendar', data)
32      getCalendarDetailAll()
33      $('.select-control.select-year').select2({
34        theme: 'option-year',
35        minimumResultsForSearch: -1
36      })
37    },
38    data: formData,
39    cache: false,
40    contentType: false,
41    processData: false
42  })
43}
44
45function getCalendarAllHome() {
46  var TYPE = 'POST'
47  var URL = path + '/' + base_url_lang + '/calendar/load-carlendar-home'
48
49  var dataSet = jQuery('#myCalendarForm').serialize()
50  jQuery.ajax({
51    type: TYPE,
52    url: URL,
53    data: dataSet,
54    success: function (html) {
55      jQuery('#calendar').show()
56      // jQuery('#calendar').html(html)
57      safeHtml('#calendar', html)
58    }
59  })
60}
61
62function safeHtml(selector, data) {
63  var scripts = []
64
65  var cleanHtml = data.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi, function (match, scriptContent) {
66    if (scriptContent.trim()) scripts.push(scriptContent)
67    return ''
68  })
69
70  jQuery(selector).html(cleanHtml)
71
72  var existingScript = document.querySelector('script[nonce]')
73  var nonce = existingScript ? existingScript.nonce : ''
74
75  scripts.forEach(function (code) {
76    var script = document.createElement('script')
77    script.textContent = code
78    if (nonce) script.setAttribute('nonce', nonce)
79    document.body.appendChild(script)
80  })
81}
82
83// ---------------------------------------------------------------------------
84// ปุ่ม/dropdown ของปฏิทิน (CSP-safe)
85// CSP ของเว็บใช้ script-src 'self' 'nonce-...' โดยไม่มี 'unsafe-inline'
86// เบราว์เซอร์จึงไม่รันโค้ดใน attribute onclick/onChange ของ HTML (nonce ใช้ได้เฉพาะ <script>)
87// จึง bind แบบ delegate ที่ document เพื่อให้ยังทำงานหลัง GetCalendar() render ใหม่ทุกครั้ง
88// ---------------------------------------------------------------------------
89function setCalendarDate(dateStr) {
90  var form = document.myCalendarForm
91  if (!form || !dateStr) return
92
93  form.myCalendarDate.value = dateStr
94  form.action.value = ''
95  form.myCalendarDatePer.value = ''
96  GetCalendar()
97}
98
99var calOpenDropdown = null
100
101jQuery(document)
102  // ปุ่ม ย้อนกลับ / ถัดไป
103  .on('click', '#calendar [data-cal-goto]', function (e) {
104    e.preventDefault()
105    setCalendarDate(this.getAttribute('data-cal-goto'))
106  })
107  // dropdown เดือน / ปี (select2 ยิง change ผ่าน jQuery จึง bubble มาถึง document)
108  .on('change', '#calendar [data-cal-select]', function () {
109    var form = document.myCalendarForm
110    if (!form) return
111    var day = form.myCalendarDate_Day.value
112
113    if (this.getAttribute('data-cal-select') === 'month') {
114      if (!(this.value > 0)) {
115        form.myCalendarDate.value = ''
116        form.action.value = ''
117        form.myCalendarDatePer.value = ''
118        return
119      }
120      setCalendarDate(this.getAttribute('data-cal-year') + '-' + this.value + '-' + day)
121    } else {
122      setCalendarDate(this.value + '-' + this.getAttribute('data-cal-month') + '-' + day)
123    }
124  })
125  // "+N เพิ่มเติม" ในช่องวันที่
126  .on('click', '#calendar [data-cal-more]', function () {
127    var wrapper = this.closest('.event-more')
128    var dropdown = wrapper ? wrapper.querySelector('.event-drop-show') : null
129    if (!dropdown) return
130
131    if (calOpenDropdown && calOpenDropdown !== dropdown) {
132      calOpenDropdown.classList.add('visually-hidden')
133    }
134    dropdown.classList.toggle('visually-hidden')
135    calOpenDropdown = dropdown.classList.contains('visually-hidden') ? null : dropdown
136  })
137  // ปุ่มปิด dropdown
138  .on('click', '#calendar [data-cal-close]', function () {
139    var dropdown = this.closest('.event-drop-show')
140    if (dropdown) dropdown.classList.add('visually-hidden')
141    calOpenDropdown = null
142  })

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.