Skip to content

Commit d55f141

Browse files
author
hirenpatel
committed
Adding option to prevent collapse
1 parent 7fa7c73 commit d55f141

File tree

3 files changed

+55
-48
lines changed

3 files changed

+55
-48
lines changed

README.md

+47-41
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ Lightpick can be bound to an input field:
4040
Include Lightpick script to the end of your document:
4141

4242
```html
43-
<link rel="stylesheet" type="text/css" href="css/lightpick.css">
44-
...
43+
<link rel="stylesheet" type="text/css" href="css/lightpick.css">
44+
...
4545
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
46-
<script src="lightpick.js"></script>
47-
<script>
48-
var picker = new Lightpick({ field: document.getElementById('datepicker') });
46+
<script src="lightpick.js"></script>
47+
<script>
48+
var picker = new Lightpick({ field: document.getElementById('datepicker') });
4949
</script>
5050
```
5151

@@ -55,13 +55,13 @@ var picker = new Lightpick({ field: document.getElementById('datepicker') });
5555

5656
### field
5757
- Type: `Element`
58-
- Default: `null`
58+
- Default: `null`
5959

6060
Bind the datepicker to a form field
6161

6262
### secondField
6363
- Type: `Element`
64-
- Default: `null`
64+
- Default: `null`
6565

6666
If exists then end of date range will set here.
6767

@@ -73,7 +73,7 @@ ISO day of the week (1: Monday, ..., 7: Sunday).
7373

7474
### parentEl
7575
- Type: `String`
76-
- Default: `body`
76+
- Default: `body`
7777

7878
Selector of the parent element that the date range picker will be added to, if not provided this will be 'body'.
7979

@@ -107,6 +107,12 @@ Number of visible months.
107107

108108
Number of columns months.
109109

110+
### preventCollapse
111+
- Type: `Boolean`
112+
- Default: `false`
113+
114+
Prevent collapsing to single month on devices with screen smaller than 480px wide.
115+
110116
### singleDate
111117
- Type: `Boolean`
112118
- Default: `true`
@@ -201,7 +207,7 @@ Calc date range in nights. (For hotels when last date doesn't include to range)
201207
- Type: `String`
202208
- Default: `auto`
203209

204-
A space-separated string consisting of one or two of “left” or “right”, “top” or “bottom”, and “auto” (may be omitted); for example, “top left”, “bottom” (horizontal orientation will default to “auto”), “right” (vertical orientation will default to “auto”), “auto top”.
210+
A space-separated string consisting of one or two of “left” or “right”, “top” or “bottom”, and “auto” (may be omitted); for example, “top left”, “bottom” (horizontal orientation will default to “auto”), “right” (vertical orientation will default to “auto”), “auto top”.
205211

206212
### disableWeekends
207213
- Type: `Boolean`
@@ -217,52 +223,52 @@ Show calendar inline. If `true` and `parentEl` is not provided then will use `pa
217223

218224
### dropdowns
219225
- Type: `Object|Boolean`
220-
- Default:
226+
- Default:
221227
```
222-
{
223-
years: {
224-
min: 1900,
225-
max: null,
226-
},
227-
months: true,
228+
{
229+
years: {
230+
min: 1900,
231+
max: null,
232+
},
233+
months: true,
228234
}
229235
```
230-
Dropdown selections for years, months. Can be `false` for disable both dropdowns.
231-
`years` _(Object|Boolean)_ - Object must contains `min` and `max` range of years or can be `false` for disable dropdown of years.
232-
`months` _(Boolean)_ - `true/false` for enable/disable dropdown of months.
236+
Dropdown selections for years, months. Can be `false` for disable both dropdowns.
237+
`years` _(Object|Boolean)_ - Object must contains `min` and `max` range of years or can be `false` for disable dropdown of years.
238+
`months` _(Boolean)_ - `true/false` for enable/disable dropdown of months.
233239

234240

235241
### locale
236242
- Type: `Object`
237-
- Default:
243+
- Default:
238244
```
239-
{
240-
buttons: {
241-
prev: '&leftarrow;',
242-
next: '&rightarrow;',
243-
close: '&times;',
244-
reset: 'Reset',
245+
{
246+
buttons: {
247+
prev: '&leftarrow;',
248+
next: '&rightarrow;',
249+
close: '&times;',
250+
reset: 'Reset',
245251
apply: 'Apply'
246-
},
247-
tooltip: {
248-
one: 'day',
252+
},
253+
tooltip: {
254+
one: 'day',
249255
other: 'days'
250256
},
251257
tooltipOnDisabled: null,
252258
pluralize: function(i, locale){
253259
if (typeof i === "string") i = parseInt(i, 10);
254-
260+
255261
if (i === 1 && 'one' in locale) return locale.one;
256262
if ('other' in locale) return locale.other;
257-
263+
258264
return '';
259265
}
260266
}
261267
```
262-
`buttons` - Text for buttons
263-
`tooltip` - Text for tooltip (one, few, many, other)
264-
`tooltipOnDisabled` (String) - Show tooltip text on disabled dates. (Eg. «Already booked»)
265-
`pluralize` (function) - Function for calc plural text. More examples for another locales on [betsol/numerous](https://github.com/betsol/numerous/tree/master/locales)
268+
`buttons` - Text for buttons
269+
`tooltip` - Text for tooltip (one, few, many, other)
270+
`tooltipOnDisabled` (String) - Show tooltip text on disabled dates. (Eg. «Already booked»)
271+
`pluralize` (function) - Function for calc plural text. More examples for another locales on [betsol/numerous](https://github.com/betsol/numerous/tree/master/locales)
266272

267273
### onSelect
268274
- Type: `Function`
@@ -287,23 +293,23 @@ Callback function for when the picker is hidden.
287293
- Default: `null`
288294

289295
Working when `disabledDatesInRange: false`
290-
Callback function for when user has select date range with disabled dates.
296+
Callback function for when user has select date range with disabled dates.
291297

292298
## Methods
293299

294300
* * *
295301

296302
### picker.setDate(date)
297303

298-
Set date when singleDate is true. `date` can be moment, string, number, date.
304+
Set date when singleDate is true. `date` can be moment, string, number, date.
299305
Eg. `picker.setDate(new Date());`
300306

301-
307+
302308
### picker.setDateRange(start, end)
303309

304-
Set date range. <code>start, end</code> can be moment, string, number, date.
310+
Set date range. <code>start, end</code> can be moment, string, number, date.
305311
Eg. `picker.setDateRange(new Date(), moment().add(7, 'day'));`
306-
312+
307313

308314
### picker.setDisableDates(array)
309315

@@ -325,7 +331,7 @@ Return current start of date range as moment object.
325331

326332
### picker.toString('YYYY-MM-DD')
327333

328-
Returns the date in a string format.
334+
Returns the date in a string format.
329335

330336
### picker.reloadOptions({})
331337

lightpick.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
separator: ' - ',
3535
numberOfMonths: 1,
3636
numberOfColumns: 2,
37+
preventCollapse: false,
3738
singleDate: true,
3839
autoclose: true,
3940
repick: false,
@@ -260,7 +261,7 @@
260261
return div.outerHTML;
261262
},
262263

263-
renderMonthsList = function(date, opts)
264+
renderMonthsList = function(date, opts)
264265
{
265266
var d = moment(date),
266267
select = document.createElement('select');
@@ -280,14 +281,14 @@
280281
}
281282

282283
select.className = 'lightpick__select lightpick__select-months';
283-
284+
284285
// for text align to right
285286
select.dir = 'rtl';
286287

287288
if (!opts.dropdowns || !opts.dropdowns.months) {
288289
select.disabled = true;
289290
}
290-
291+
291292
return select.outerHTML;
292293
},
293294

@@ -482,7 +483,7 @@
482483

483484
if (opts.parentEl instanceof Node) {
484485
opts.parentEl.appendChild(self.el)
485-
}
486+
}
486487
else if (opts.parentEl === 'body' && opts.inline) {
487488
opts.field.parentNode.appendChild(self.el);
488489
}
@@ -898,7 +899,7 @@
898899
opts.locale = Object.assign({}, defaults.locale, options.locale);
899900
}
900901

901-
if (window.innerWidth < 480 && opts.numberOfMonths > 1) {
902+
if (window.innerWidth < 480 && opts.numberOfMonths > 1 && !opts.preventCollapse) {
902903
opts.numberOfMonths = 1;
903904
opts.numberOfColumns = 1;
904905
}
@@ -1211,7 +1212,7 @@
12111212
}
12121213

12131214
this.syncFields();
1214-
1215+
12151216
if (this._opts.secondField && this._opts.secondField === target && this._opts.endDate) {
12161217
this.gotoDate(this._opts.endDate);
12171218
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lightpick",
3-
"version": "1.3.4",
3+
"version": "1.3.5",
44
"description": "Javascript date range picker - lightweight, no jQuery",
55
"main": "lightpick.js",
66
"scripts": {

0 commit comments

Comments
 (0)