|
36 | 36 | '</div>' +
|
37 | 37 | '</div>';
|
38 | 38 |
|
39 |
| - this.parentEl = (typeof options == 'object' && options.parentEl && $(options.parentEl)) || $(this.parentEl); |
| 39 | + this.parentEl = (typeof options === 'object' && options.parentEl && $(options.parentEl)) || $(this.parentEl); |
40 | 40 | this.container = $(DRPTemplate).appendTo(this.parentEl);
|
41 | 41 |
|
42 | 42 | //custom options
|
43 |
| - if (typeof options != 'object') |
| 43 | + if (typeof options !== 'object') |
44 | 44 | options = {};
|
45 | 45 | this.setOptions(options, cb);
|
46 | 46 |
|
|
136 | 136 |
|
137 | 137 | this.cb = function () { };
|
138 | 138 |
|
139 |
| - if (typeof options.format == 'string') |
| 139 | + if (typeof options.format === 'string') |
140 | 140 | this.format = options.format;
|
141 | 141 |
|
142 |
| - if (typeof options.separator == 'string') |
| 142 | + if (typeof options.separator === 'string') |
143 | 143 | this.separator = options.separator;
|
144 | 144 |
|
145 |
| - if (typeof options.startDate == 'string') |
| 145 | + if (typeof options.startDate === 'string') |
146 | 146 | this.startDate = moment(options.startDate, this.format);
|
147 | 147 |
|
148 |
| - if (typeof options.endDate == 'string') |
| 148 | + if (typeof options.endDate === 'string') |
149 | 149 | this.endDate = moment(options.endDate, this.format);
|
150 | 150 |
|
151 |
| - if (typeof options.minDate == 'string') |
| 151 | + if (typeof options.minDate === 'string') |
152 | 152 | this.minDate = moment(options.minDate, this.format);
|
153 | 153 |
|
154 |
| - if (typeof options.maxDate == 'string') |
| 154 | + if (typeof options.maxDate === 'string') |
155 | 155 | this.maxDate = moment(options.maxDate, this.format);
|
156 | 156 |
|
157 |
| - if (typeof options.startDate == 'object') |
| 157 | + if (typeof options.startDate === 'object') |
158 | 158 | this.startDate = moment(options.startDate);
|
159 | 159 |
|
160 |
| - if (typeof options.endDate == 'object') |
| 160 | + if (typeof options.endDate === 'object') |
161 | 161 | this.endDate = moment(options.endDate);
|
162 | 162 |
|
163 |
| - if (typeof options.minDate == 'object') |
| 163 | + if (typeof options.minDate === 'object') |
164 | 164 | this.minDate = moment(options.minDate);
|
165 | 165 |
|
166 |
| - if (typeof options.maxDate == 'object') |
| 166 | + if (typeof options.maxDate === 'object') |
167 | 167 | this.maxDate = moment(options.maxDate);
|
168 | 168 |
|
169 |
| - if (typeof options.applyClass == 'string') |
| 169 | + if (typeof options.applyClass === 'string') |
170 | 170 | this.applyClass = options.applyClass;
|
171 | 171 |
|
172 |
| - if (typeof options.cancelClass == 'string') |
| 172 | + if (typeof options.cancelClass === 'string') |
173 | 173 | this.cancelClass = options.cancelClass;
|
174 | 174 |
|
175 |
| - if (typeof options.dateLimit == 'object') |
| 175 | + if (typeof options.dateLimit === 'object') |
176 | 176 | this.dateLimit = options.dateLimit;
|
177 | 177 |
|
178 | 178 | // update day names order to firstDay
|
179 |
| - if (typeof options.locale == 'object') { |
| 179 | + if (typeof options.locale === 'object') { |
180 | 180 |
|
181 |
| - if (typeof options.locale.daysOfWeek == 'object') { |
| 181 | + if (typeof options.locale.daysOfWeek === 'object') { |
182 | 182 | // Create a copy of daysOfWeek to avoid modification of original
|
183 | 183 | // options object for reusability in multiple daterangepicker instances
|
184 | 184 | this.locale.daysOfWeek = options.locale.daysOfWeek.slice();
|
185 | 185 | }
|
186 | 186 |
|
187 |
| - if (typeof options.locale.monthNames == 'object') { |
| 187 | + if (typeof options.locale.monthNames === 'object') { |
188 | 188 | this.locale.monthNames = options.locale.monthNames.slice();
|
189 | 189 | }
|
190 | 190 |
|
191 |
| - if (typeof options.locale.firstDay == 'number') { |
| 191 | + if (typeof options.locale.firstDay === 'number') { |
192 | 192 | this.locale.firstDay = options.locale.firstDay;
|
193 | 193 | var iterator = options.locale.firstDay;
|
194 | 194 | while (iterator > 0) {
|
|
197 | 197 | }
|
198 | 198 | }
|
199 | 199 |
|
200 |
| - if (typeof options.locale.applyLabel == 'string') { |
| 200 | + if (typeof options.locale.applyLabel === 'string') { |
201 | 201 | this.locale.applyLabel = options.locale.applyLabel;
|
202 | 202 | }
|
203 | 203 |
|
204 |
| - if (typeof options.locale.cancelLabel == 'string') { |
| 204 | + if (typeof options.locale.cancelLabel === 'string') { |
205 | 205 | this.locale.cancelLabel = options.locale.cancelLabel;
|
206 | 206 | }
|
207 | 207 |
|
208 |
| - if (typeof options.locale.fromLabel == 'string') { |
| 208 | + if (typeof options.locale.fromLabel === 'string') { |
209 | 209 | this.locale.fromLabel = options.locale.fromLabel;
|
210 | 210 | }
|
211 | 211 |
|
212 |
| - if (typeof options.locale.toLabel == 'string') { |
| 212 | + if (typeof options.locale.toLabel === 'string') { |
213 | 213 | this.locale.toLabel = options.locale.toLabel;
|
214 | 214 | }
|
215 | 215 |
|
216 |
| - if (typeof options.locale.weekLabel == 'string') { |
| 216 | + if (typeof options.locale.weekLabel === 'string') { |
217 | 217 | this.locale.weekLabel = options.locale.weekLabel;
|
218 | 218 | }
|
219 | 219 |
|
220 |
| - if (typeof options.locale.customRangeLabel == 'string') { |
| 220 | + if (typeof options.locale.customRangeLabel === 'string') { |
221 | 221 | this.locale.customRangeLabel = options.locale.customRangeLabel;
|
222 | 222 | }
|
223 | 223 | }
|
224 | 224 |
|
225 |
| - if (typeof options.opens == 'string') |
| 225 | + if (typeof options.opens === 'string') |
226 | 226 | this.opens = options.opens;
|
227 | 227 |
|
228 |
| - if (typeof options.showWeekNumbers == 'boolean') { |
| 228 | + if (typeof options.showWeekNumbers === 'boolean') { |
229 | 229 | this.showWeekNumbers = options.showWeekNumbers;
|
230 | 230 | }
|
231 | 231 |
|
232 |
| - if (typeof options.buttonClasses == 'string') { |
| 232 | + if (typeof options.buttonClasses === 'string') { |
233 | 233 | this.buttonClasses = [options.buttonClasses];
|
234 | 234 | }
|
235 | 235 |
|
236 |
| - if (typeof options.buttonClasses == 'object') { |
| 236 | + if (typeof options.buttonClasses === 'object') { |
237 | 237 | this.buttonClasses = options.buttonClasses;
|
238 | 238 | }
|
239 | 239 |
|
240 |
| - if (typeof options.showDropdowns == 'boolean') { |
| 240 | + if (typeof options.showDropdowns === 'boolean') { |
241 | 241 | this.showDropdowns = options.showDropdowns;
|
242 | 242 | }
|
243 | 243 |
|
244 |
| - if (typeof options.singleDatePicker == 'boolean') { |
| 244 | + if (typeof options.singleDatePicker === 'boolean') { |
245 | 245 | this.singleDatePicker = options.singleDatePicker;
|
246 | 246 | }
|
247 | 247 |
|
248 |
| - if (typeof options.timePicker == 'boolean') { |
| 248 | + if (typeof options.timePicker === 'boolean') { |
249 | 249 | this.timePicker = options.timePicker;
|
250 | 250 | }
|
251 | 251 |
|
252 |
| - if (typeof options.timePickerIncrement == 'number') { |
| 252 | + if (typeof options.timePickerIncrement === 'number') { |
253 | 253 | this.timePickerIncrement = options.timePickerIncrement;
|
254 | 254 | }
|
255 | 255 |
|
256 |
| - if (typeof options.timePicker12Hour == 'boolean') { |
| 256 | + if (typeof options.timePicker12Hour === 'boolean') { |
257 | 257 | this.timePicker12Hour = options.timePicker12Hour;
|
258 | 258 | }
|
259 | 259 |
|
| 260 | + var start, end, range; |
| 261 | + |
260 | 262 | //if no start/end dates set, check if an input element contains initial values
|
261 |
| - if (typeof options.startDate == 'undefined' && typeof options.endDate == 'undefined') { |
| 263 | + if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') { |
262 | 264 | if ($(this.element).is('input[type=text]')) {
|
263 | 265 | var val = $(this.element).val();
|
264 | 266 | var split = val.split(this.separator);
|
265 |
| - var start, end; |
| 267 | + start = end = null; |
266 | 268 | if (split.length == 2) {
|
267 | 269 | start = moment(split[0], this.format);
|
268 | 270 | end = moment(split[1], this.format);
|
269 | 271 | } else if (this.singleDatePicker) {
|
270 | 272 | start = moment(val, this.format);
|
271 | 273 | end = moment(val, this.format);
|
272 | 274 | }
|
273 |
| - if (start != null && end != null) { |
| 275 | + if (start !== null && end !== null) { |
274 | 276 | this.startDate = start;
|
275 | 277 | this.endDate = end;
|
276 | 278 | }
|
277 | 279 | }
|
278 | 280 | }
|
279 | 281 |
|
280 |
| - if (typeof options.ranges == 'object') { |
281 |
| - for (var range in options.ranges) { |
| 282 | + if (typeof options.ranges === 'object') { |
| 283 | + for (range in options.ranges) { |
282 | 284 |
|
283 |
| - var start = moment(options.ranges[range][0]); |
284 |
| - var end = moment(options.ranges[range][1]); |
| 285 | + start = moment(options.ranges[range][0]); |
| 286 | + end = moment(options.ranges[range][1]); |
285 | 287 |
|
286 | 288 | // If we have a min/max date set, bound this range
|
287 | 289 | // to it, but only if it would otherwise fall
|
|
303 | 305 | }
|
304 | 306 |
|
305 | 307 | var list = '<ul>';
|
306 |
| - for (var range in this.ranges) { |
| 308 | + for (range in this.ranges) { |
307 | 309 | list += '<li>' + range + '</li>';
|
308 | 310 | }
|
309 | 311 | list += '<li>' + this.locale.customRangeLabel + '</li>';
|
|
312 | 314 | this.container.find('.ranges').prepend(list);
|
313 | 315 | }
|
314 | 316 |
|
315 |
| - if (typeof callback == 'function') { |
| 317 | + if (typeof callback === 'function') { |
316 | 318 | this.cb = callback;
|
317 | 319 | }
|
318 | 320 |
|
|
354 | 356 | right.removeClass('right').addClass('left');
|
355 | 357 | }
|
356 | 358 |
|
357 |
| - if (typeof options.ranges == 'undefined' && !this.singleDatePicker) { |
| 359 | + if (typeof options.ranges === 'undefined' && !this.singleDatePicker) { |
358 | 360 | this.container.find('.calendar').show();
|
359 | 361 | }
|
360 | 362 |
|
361 | 363 | this.container.addClass('opens' + this.opens);
|
362 | 364 |
|
363 | 365 | this.updateView();
|
364 |
| - this.updateCalendars() |
| 366 | + this.updateCalendars(); |
365 | 367 |
|
366 | 368 | },
|
367 | 369 |
|
368 | 370 | setStartDate: function(startDate) {
|
369 |
| - if (typeof startDate == 'string') |
| 371 | + if (typeof startDate === 'string') |
370 | 372 | this.startDate = moment(startDate, this.format);
|
371 | 373 |
|
372 |
| - if (typeof startDate == 'object') |
| 374 | + if (typeof startDate === 'object') |
373 | 375 | this.startDate = moment(startDate);
|
374 | 376 |
|
375 | 377 | if (!this.timePicker)
|
|
382 | 384 | },
|
383 | 385 |
|
384 | 386 | setEndDate: function(endDate) {
|
385 |
| - if (typeof endDate == 'string') |
| 387 | + if (typeof endDate === 'string') |
386 | 388 | this.endDate = moment(endDate, this.format);
|
387 | 389 |
|
388 |
| - if (typeof endDate == 'object') |
| 390 | + if (typeof endDate === 'object') |
389 | 391 | this.endDate = moment(endDate);
|
390 | 392 |
|
391 | 393 | if (!this.timePicker)
|
|
431 | 433 | end = start;
|
432 | 434 | }
|
433 | 435 |
|
434 |
| - if (start == null || end == null) return; |
435 | 436 | if (end.isBefore(start)) return;
|
436 | 437 |
|
437 | 438 | this.oldStartDate = this.startDate.clone();
|
|
606 | 607 | var col = title.substr(3, 1);
|
607 | 608 | var cal = $(e.target).parents('.calendar');
|
608 | 609 |
|
| 610 | + var startDate, endDate; |
609 | 611 | if (cal.hasClass('left')) {
|
610 |
| - var startDate = this.leftCalendar.calendar[row][col]; |
611 |
| - var endDate = this.endDate; |
612 |
| - if (typeof this.dateLimit == 'object') { |
| 612 | + startDate = this.leftCalendar.calendar[row][col]; |
| 613 | + endDate = this.endDate; |
| 614 | + if (typeof this.dateLimit === 'object') { |
613 | 615 | var maxDate = moment(startDate).add(this.dateLimit).startOf('day');
|
614 | 616 | if (endDate.isAfter(maxDate)) {
|
615 | 617 | endDate = maxDate;
|
616 | 618 | }
|
617 | 619 | }
|
618 | 620 | } else {
|
619 |
| - var startDate = this.startDate; |
620 |
| - var endDate = this.rightCalendar.calendar[row][col]; |
621 |
| - if (typeof this.dateLimit == 'object') { |
| 621 | + startDate = this.startDate; |
| 622 | + endDate = this.rightCalendar.calendar[row][col]; |
| 623 | + if (typeof this.dateLimit === 'object') { |
622 | 624 | var minDate = moment(endDate).subtract(this.dateLimit).startOf('day');
|
623 | 625 | if (startDate.isBefore(minDate)) {
|
624 | 626 | startDate = minDate;
|
|
762 | 764 |
|
763 | 765 | var dayOfWeek = firstDay.day();
|
764 | 766 |
|
| 767 | + var i; |
| 768 | + |
765 | 769 | //initialize a 6 rows x 7 columns array for the calendar
|
766 | 770 | var calendar = [];
|
767 |
| - for (var i = 0; i < 6; i++) { |
| 771 | + for (i = 0; i < 6; i++) { |
768 | 772 | calendar[i] = [];
|
769 | 773 | }
|
770 | 774 |
|
|
777 | 781 | startDay = daysInLastMonth - 6;
|
778 | 782 |
|
779 | 783 | var curDate = moment([lastYear, lastMonth, startDay, 12, minute]);
|
780 |
| - for (var i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add('hour', 24)) { |
781 |
| - if (i > 0 && col % 7 == 0) { |
| 784 | + var col, row; |
| 785 | + for (i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add('hour', 24)) { |
| 786 | + if (i > 0 && col % 7 === 0) { |
782 | 787 | col = 0;
|
783 | 788 | row++;
|
784 | 789 | }
|
|
903 | 908 | html += '</table>';
|
904 | 909 | html += '</div>';
|
905 | 910 |
|
| 911 | + var i; |
906 | 912 | if (this.timePicker) {
|
907 | 913 |
|
908 | 914 | html += '<div class="calendar-time">';
|
|
915 | 921 | end = 12;
|
916 | 922 | if (selected_hour >= 12)
|
917 | 923 | selected_hour -= 12;
|
918 |
| - if (selected_hour == 0) |
| 924 | + if (selected_hour === 0) |
919 | 925 | selected_hour = 12;
|
920 | 926 | }
|
921 | 927 |
|
922 |
| - for (var i = start; i <= end; i++) { |
| 928 | + for (i = start; i <= end; i++) { |
923 | 929 | if (i == selected_hour) {
|
924 | 930 | html += '<option value="' + i + '" selected="selected">' + i + '</option>';
|
925 | 931 | } else {
|
|
931 | 937 |
|
932 | 938 | html += '<select class="minuteselect">';
|
933 | 939 |
|
934 |
| - for (var i = 0; i < 60; i += this.timePickerIncrement) { |
| 940 | + for (i = 0; i < 60; i += this.timePickerIncrement) { |
935 | 941 | var num = i;
|
936 | 942 | if (num < 10)
|
937 | 943 | num = '0' + num;
|
|
0 commit comments