Skip to content

Commit 479628e

Browse files
author
Goldman Kim~
committed
Add developer guide for Natural-JS Popup component
1 parent b792659 commit 479628e

File tree

2 files changed

+439
-112
lines changed

2 files changed

+439
-112
lines changed

docs/DEVELOPER-GUIDE-UI-Datepicker.md

Lines changed: 168 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -10,155 +10,211 @@ Datepicker (N.datepicker) displays a calendar popup for selecting a date or mont
1010
- See the [Form], [List], and [Grid] menus' [Declarative Options] tab and the [Formatter] menu's [Format Rule List] tab for rules like ["date", 4|6|8|10|12|14, "month"|"date"].
1111
- For an explanation of declarative options, see the **Declarative Options** section in the [API Documentation Guide].
1212

13+
## Table of Contents
14+
15+
- Constructor
16+
- Default Options
17+
- Methods
18+
- Events
19+
- Examples
20+
1321
## Constructor
1422

1523
- `N.datepicker(context, opts)`
1624
- context: jQuery object or selector string (input element to apply Datepicker)
1725
- opts: options object
1826
- Returns: N.datepicker instance
27+
1928
- `N(obj).datepicker(opts)`
2029
- jQuery plugin method to create an N.datepicker instance
2130

2231
## Default Options
2332

24-
- context: jQuery object or selector string (Required)
33+
- **context**: jQuery object or selector string (Required)
2534
- The input element to apply N.datepicker to.
26-
- yearsPanelPosition: string ("left" | "top") (default: "left")
35+
- **yearsPanelPosition**: string ("left" | "top") (default: "left")
2736
- If set to "top", the year selection element is created at the top.
28-
- monthsPanelPosition: string ("left" | "top") (default: "left")
37+
- **monthsPanelPosition**: string ("left" | "top") (default: "left")
2938
- If set to "top", the month selection element is created at the top.
30-
- minYear: number (default: 200)
39+
- **minYear**: number (default: 200)
3140
- When yearsPanelPosition is "top", sets the number of previous years that can be selected.
32-
- maxYear: number (default: 200)
41+
- **maxYear**: number (default: 200)
3342
- When yearsPanelPosition is "top", sets the number of future years that can be selected.
34-
- yearChangeInput: boolean (default: false)
43+
- **yearChangeInput**: boolean (default: false)
3544
- If true, the changed date is immediately applied to the input when the year changes.
36-
- monthChangeInput: boolean (default: false)
45+
- **monthChangeInput**: boolean (default: false)
3746
- If true, the changed date is immediately applied to the input when the month changes.
38-
- touchMonthChange: boolean (default: false)
47+
- **touchMonthChange**: boolean (default: false)
3948
- If true, swiping left/right changes the month.
40-
- scrollMonthChange: boolean (default: false)
49+
- **scrollMonthChange**: boolean (default: false)
4150
- If true, scrolling the mouse wheel changes the month.
42-
- monthonly: boolean (default: false)
51+
- **monthonly**: boolean (default: false)
4352
- If true, only year and month can be selected (Monthpicker).
44-
- focusin: boolean (default: true)
53+
- **focusin**: boolean (default: true)
4554
- If false, Datepicker does not appear when the input is focused.
46-
- minDate: string (default: null)
55+
- **minDate**: string (default: null)
4756
- Prevents selection/input of dates before this value.
48-
- maxDate: string (default: null)
57+
- **maxDate**: string (default: null)
4958
- Prevents selection/input of dates after this value.
50-
- holiday: object (default: { repeat: null, once: null })
51-
- Sets holidays to be displayed in the Datepicker. See below for details.
52-
- onSelect: function
53-
- Event handler executed when a date or month is selected.
54-
- onBeforeShow: function
55-
- Event handler executed before the Datepicker is shown.
56-
- onShow: function
57-
- Event handler executed after the Datepicker is shown.
58-
- onBeforeHide: function
59-
- Event handler executed before the Datepicker is hidden.
60-
- onHide: function
61-
- Event handler executed after the Datepicker is hidden.
62-
- onChangeYear: function
63-
- Event handler executed when the year changes.
64-
- onChangeMonth: function
65-
- Event handler executed when the month changes.
66-
67-
### Example of holiday option
59+
- **holiday**: object (default: { repeat: null, once: null })
60+
- If set, holidays are displayed in the Datepicker.
61+
- **onSelect**: function (default: null)
62+
- Event handler called when a date or month (if monthonly is true) is selected.
63+
- **onBeforeShow**: function (default: null)
64+
- Event handler before the datepicker is shown.
65+
- **onShow**: function (default: null)
66+
- Event handler after the datepicker is shown.
67+
- **onBeforeHide**: function (default: null)
68+
- Event handler before the datepicker is hidden.
69+
- **onHide**: function (default: null)
70+
- Event handler after the datepicker is hidden.
71+
- **onChangeYear**: function (default: null)
72+
- Event handler when the year is changed.
73+
- **onChangeMonth**: function (default: null)
74+
- Event handler when the month is changed.
75+
76+
### Example: Setting the holiday option
6877

6978
The holiday option can be set as follows:
7079

7180
```javascript
7281
{
73-
repeat: {
74-
"0619": "Holiday1",
75-
"0620": "Holiday3",
76-
"0621": ["Holiday6", "Holiday7"],
77-
"0622": ["Holiday9", "Holiday10"]
78-
},
79-
once: {
80-
"20200619": "Holiday2",
81-
"20200620": ["Holiday4", "Holiday5"],
82-
"20200621": "Holiday8",
83-
"20200622": ["Holiday11", "Holiday12"]
84-
}
82+
repeat: {
83+
"0619": "Holiday1",
84+
"0620": "Holiday3",
85+
"0621": ["Holiday6", "Holiday7"],
86+
"0622": ["Holiday9", "Holiday10"]
87+
},
88+
once: {
89+
"20200619": "Holiday2",
90+
"20200620": ["Holiday4", "Holiday5"],
91+
"20200621": "Holiday8",
92+
"20200622": ["Holiday11", "Holiday12"]
93+
}
8594
}
8695
```
8796

88-
- The repeat object is for holidays that repeat every year (exclude the year).
89-
- The once object is for holidays that do not repeat every year (use YYYYMMDD format).
97+
- Use the repeat object for holidays that repeat every year (exclude the year).
98+
- Use the once object for holidays that do not repeat every year (use the full date: year, month, day).
9099
- If there are multiple holidays on the same date, use an array of names.
91-
- If you set the N.context.attr("ui").datepicker.holiday property in Config (natural.config.js), it applies to all Datepickers.
100+
101+
If you set the N.context.attr("ui").datepicker.holiday property in [Config(natural.config.js)](https://bbalganjjm.github.io/natural_js/?page=html/naturaljs/refr/refr0102.html), it will apply to all Datepickers.
92102

93103
```javascript
94-
N.comm("getHolidayList.json").submit(function(data) {
95-
var once = {};
96-
N(data).each(function() {
97-
once[this.holidayDate] = this.holidayName;
98-
});
99-
if(N.context.attr("ui").datepicker.holiday === undefined) {
100-
N.context.attr("ui").datepicker.holiday = {};
101-
}
102-
N.context.attr("ui").datepicker.holiday.once = once;
104+
N.comm("getHolidayList.json").submit(data => {
105+
const once = {};
106+
N(data).each(function() {
107+
once[this.holidayDate] = this.holidayName;
108+
});
109+
if (N.context.attr("ui").datepicker.holiday === undefined) {
110+
N.context.attr("ui").datepicker.holiday = {};
111+
}
112+
N.context.attr("ui").datepicker.holiday.once = once;
103113
});
104114
```
105115

106-
Elements marked as holidays get the class "Datepicker_holiday__".
116+
Elements marked as holidays will have the class "Datepicker_holiday__".
107117

108118
## Events
109119

110120
Datepicker defines the following events for the input element specified as context. Event handlers can be set as options during initialization or attached separately. If an event with the same name is already bound, the handler specified during initialization takes precedence.
111121

112-
- onSelect: Executed when a date or month is selected
113-
- onBeforeShow: Executed before the Datepicker is shown
114-
- onShow: Executed after the Datepicker is shown
115-
- onBeforeHide: Executed before the Datepicker is hidden
116-
- onHide: Executed after the Datepicker is hidden
117-
- onChangeYear: Executed when the year changes
118-
- onChangeMonth: Executed when the month changes
119-
120-
### Event handler function parameters
121-
122-
- onSelect: function(context, selDate, monthonly)
123-
- this: N.datepicker instance
124-
- context: context element
125-
- selDate: selected date object
126-
- obj: Date object
127-
- format: date format string
128-
- Example: selDate.obj.formatDate("d/m/Y") => "26/09/2024"
129-
- monthonly: value of monthonly option
130-
- onBeforeShow: function(context, contents)
131-
- this: N.datepicker instance
132-
- context: context element
133-
- contents: Datepicker panel element
134-
- onShow: function(context, contents)
135-
- this: N.datepicker instance
136-
- context: context element
137-
- contents: Datepicker panel element
138-
- onBeforeHide: function(context, contents)
139-
- this: N.datepicker instance
140-
- context: context element
141-
- contents: Datepicker panel element
142-
- onHide: function(context)
143-
- this: N.datepicker instance
144-
- context: context element
145-
- onChangeYear: function(context, year, e)
146-
- this: N.datepicker instance
147-
- context: context element
148-
- year: selected year
149-
- e: event object
150-
- onChangeMonth: function(context, month, year, e)
151-
- this: N.datepicker instance
152-
- context: context element
153-
- month: selected month
154-
- year: selected year
155-
- e: event object
122+
- **onSelect**: Called when a date or month (if monthonly is true) is selected.
123+
- **onBeforeShow**: Called before the datepicker is shown.
124+
- **onShow**: Called after the datepicker is shown.
125+
- **onBeforeHide**: Called before the datepicker is hidden.
126+
- **onHide**: Called after the datepicker is hidden.
127+
- **onChangeYear**: Called when the year is changed.
128+
- **onChangeMonth**: Called when the month is changed.
129+
130+
### Event Handler Parameters
131+
132+
- **onSelect**
133+
134+
```javascript
135+
(context, selDate, monthonly) => {
136+
// this: N.datepicker instance
137+
// context: context element
138+
// selDate: selected date object
139+
// selDate = {
140+
// obj: Date object,
141+
// format: date format string
142+
// }
143+
// selDate.obj.formatDate("d/m/Y") => "26/09/2024"
144+
// monthonly: value of the monthonly option
145+
}
146+
```
147+
148+
- **onBeforeShow**
149+
150+
```javascript
151+
(context, contents) => {
152+
// this: N.datepicker instance
153+
// context: context element
154+
// contents: Datepicker panel element
155+
}
156+
```
157+
158+
- **onShow**
159+
160+
```javascript
161+
(context, contents) => {
162+
// this: N.datepicker instance
163+
// context: context element
164+
// contents: Datepicker panel element
165+
}
166+
```
167+
168+
- **onBeforeHide**
169+
170+
```javascript
171+
(context, contents) => {
172+
// this: N.datepicker instance
173+
// context: context element
174+
// contents: Datepicker panel element
175+
}
176+
```
177+
178+
- **onHide**
179+
180+
```javascript
181+
(context) => {
182+
// this: N.datepicker instance
183+
// context: context element
184+
}
185+
```
186+
187+
- **onChangeYear**
188+
189+
```javascript
190+
(context, year, e) => {
191+
// this: N.datepicker instance
192+
// context: context element
193+
// year: selected year
194+
// e: event object
195+
}
196+
```
197+
198+
- **onChangeMonth**
199+
200+
```javascript
201+
(context, month, year, e) => {
202+
// this: N.datepicker instance
203+
// context: context element
204+
// month: selected month
205+
// year: selected year
206+
// e: event object
207+
}
208+
```
156209

157210
## Methods
158211

159-
- context([selector]): Returns the context element(s). If a selector is provided, returns the element(s) within the context.
160-
- show(): Shows the Datepicker.
161-
- hide(): Hides the Datepicker.
212+
- **context([selector])**
213+
- Returns the context element. If a selector is provided, returns the element within the context.
214+
- **show()**
215+
- Shows the Datepicker.
216+
- **hide()**
217+
- Hides the Datepicker.
162218

163219
### Usage Example
164220

@@ -170,36 +226,36 @@ datepicker.hide();
170226

171227
## Examples
172228

173-
1. Creating a Datepicker
229+
### 1. Creating a Datepicker
174230

175231
```html
176232
<input class="datepicker" type="text">
177233

178234
<script type="text/javascript">
179-
N(".datepicker").datepicker();
235+
N(".datepicker").datepicker();
180236
</script>
181237
```
182238

183-
2. Creating a Monthpicker
239+
### 2. Creating a Monthpicker
184240

185241
```html
186242
<input class="datepicker" type="text">
187243

188244
<script type="text/javascript">
189-
N(".datepicker").datepicker({
190-
monthonly: true
191-
});
245+
N(".datepicker").datepicker({
246+
monthonly: true
247+
});
192248
</script>
193249
```
194250

195-
3. Automatically creating a Datepicker by specifying the "date" format rule when binding data with N.form, N.grid, or N.list
251+
### 3. Automatically creating a Datepicker by specifying the "date" format rule when binding data with N.form, N.grid, or N.list
196252

197253
```html
198254
<div class="form">
199-
<input id="datepicker" type="text" data-format='[["date", 8, "date"]]'>
255+
<input id="datepicker" type="text" data-format='[["date", 8, "date"]]'>
200256
</div>
201257

202258
<script type="text/javascript">
203-
N({ datepicker: "20141212" }).form(".form").bind();
259+
N({ datepicker: "20141212" }).form(".form").bind();
204260
</script>
205261
```

0 commit comments

Comments
 (0)