Skip to content

Commit fda4d90

Browse files
committed
Code fixes/cleanup after running JSHint
1 parent 250c668 commit fda4d90

File tree

1 file changed

+68
-62
lines changed

1 file changed

+68
-62
lines changed

daterangepicker.js

+68-62
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
'</div>' +
3737
'</div>';
3838

39-
this.parentEl = (typeof options == 'object' && options.parentEl && $(options.parentEl)) || $(this.parentEl);
39+
this.parentEl = (typeof options === 'object' && options.parentEl && $(options.parentEl)) || $(this.parentEl);
4040
this.container = $(DRPTemplate).appendTo(this.parentEl);
4141

4242
//custom options
43-
if (typeof options != 'object')
43+
if (typeof options !== 'object')
4444
options = {};
4545
this.setOptions(options, cb);
4646

@@ -136,59 +136,59 @@
136136

137137
this.cb = function () { };
138138

139-
if (typeof options.format == 'string')
139+
if (typeof options.format === 'string')
140140
this.format = options.format;
141141

142-
if (typeof options.separator == 'string')
142+
if (typeof options.separator === 'string')
143143
this.separator = options.separator;
144144

145-
if (typeof options.startDate == 'string')
145+
if (typeof options.startDate === 'string')
146146
this.startDate = moment(options.startDate, this.format);
147147

148-
if (typeof options.endDate == 'string')
148+
if (typeof options.endDate === 'string')
149149
this.endDate = moment(options.endDate, this.format);
150150

151-
if (typeof options.minDate == 'string')
151+
if (typeof options.minDate === 'string')
152152
this.minDate = moment(options.minDate, this.format);
153153

154-
if (typeof options.maxDate == 'string')
154+
if (typeof options.maxDate === 'string')
155155
this.maxDate = moment(options.maxDate, this.format);
156156

157-
if (typeof options.startDate == 'object')
157+
if (typeof options.startDate === 'object')
158158
this.startDate = moment(options.startDate);
159159

160-
if (typeof options.endDate == 'object')
160+
if (typeof options.endDate === 'object')
161161
this.endDate = moment(options.endDate);
162162

163-
if (typeof options.minDate == 'object')
163+
if (typeof options.minDate === 'object')
164164
this.minDate = moment(options.minDate);
165165

166-
if (typeof options.maxDate == 'object')
166+
if (typeof options.maxDate === 'object')
167167
this.maxDate = moment(options.maxDate);
168168

169-
if (typeof options.applyClass == 'string')
169+
if (typeof options.applyClass === 'string')
170170
this.applyClass = options.applyClass;
171171

172-
if (typeof options.cancelClass == 'string')
172+
if (typeof options.cancelClass === 'string')
173173
this.cancelClass = options.cancelClass;
174174

175-
if (typeof options.dateLimit == 'object')
175+
if (typeof options.dateLimit === 'object')
176176
this.dateLimit = options.dateLimit;
177177

178178
// update day names order to firstDay
179-
if (typeof options.locale == 'object') {
179+
if (typeof options.locale === 'object') {
180180

181-
if (typeof options.locale.daysOfWeek == 'object') {
181+
if (typeof options.locale.daysOfWeek === 'object') {
182182
// Create a copy of daysOfWeek to avoid modification of original
183183
// options object for reusability in multiple daterangepicker instances
184184
this.locale.daysOfWeek = options.locale.daysOfWeek.slice();
185185
}
186186

187-
if (typeof options.locale.monthNames == 'object') {
187+
if (typeof options.locale.monthNames === 'object') {
188188
this.locale.monthNames = options.locale.monthNames.slice();
189189
}
190190

191-
if (typeof options.locale.firstDay == 'number') {
191+
if (typeof options.locale.firstDay === 'number') {
192192
this.locale.firstDay = options.locale.firstDay;
193193
var iterator = options.locale.firstDay;
194194
while (iterator > 0) {
@@ -197,91 +197,93 @@
197197
}
198198
}
199199

200-
if (typeof options.locale.applyLabel == 'string') {
200+
if (typeof options.locale.applyLabel === 'string') {
201201
this.locale.applyLabel = options.locale.applyLabel;
202202
}
203203

204-
if (typeof options.locale.cancelLabel == 'string') {
204+
if (typeof options.locale.cancelLabel === 'string') {
205205
this.locale.cancelLabel = options.locale.cancelLabel;
206206
}
207207

208-
if (typeof options.locale.fromLabel == 'string') {
208+
if (typeof options.locale.fromLabel === 'string') {
209209
this.locale.fromLabel = options.locale.fromLabel;
210210
}
211211

212-
if (typeof options.locale.toLabel == 'string') {
212+
if (typeof options.locale.toLabel === 'string') {
213213
this.locale.toLabel = options.locale.toLabel;
214214
}
215215

216-
if (typeof options.locale.weekLabel == 'string') {
216+
if (typeof options.locale.weekLabel === 'string') {
217217
this.locale.weekLabel = options.locale.weekLabel;
218218
}
219219

220-
if (typeof options.locale.customRangeLabel == 'string') {
220+
if (typeof options.locale.customRangeLabel === 'string') {
221221
this.locale.customRangeLabel = options.locale.customRangeLabel;
222222
}
223223
}
224224

225-
if (typeof options.opens == 'string')
225+
if (typeof options.opens === 'string')
226226
this.opens = options.opens;
227227

228-
if (typeof options.showWeekNumbers == 'boolean') {
228+
if (typeof options.showWeekNumbers === 'boolean') {
229229
this.showWeekNumbers = options.showWeekNumbers;
230230
}
231231

232-
if (typeof options.buttonClasses == 'string') {
232+
if (typeof options.buttonClasses === 'string') {
233233
this.buttonClasses = [options.buttonClasses];
234234
}
235235

236-
if (typeof options.buttonClasses == 'object') {
236+
if (typeof options.buttonClasses === 'object') {
237237
this.buttonClasses = options.buttonClasses;
238238
}
239239

240-
if (typeof options.showDropdowns == 'boolean') {
240+
if (typeof options.showDropdowns === 'boolean') {
241241
this.showDropdowns = options.showDropdowns;
242242
}
243243

244-
if (typeof options.singleDatePicker == 'boolean') {
244+
if (typeof options.singleDatePicker === 'boolean') {
245245
this.singleDatePicker = options.singleDatePicker;
246246
}
247247

248-
if (typeof options.timePicker == 'boolean') {
248+
if (typeof options.timePicker === 'boolean') {
249249
this.timePicker = options.timePicker;
250250
}
251251

252-
if (typeof options.timePickerIncrement == 'number') {
252+
if (typeof options.timePickerIncrement === 'number') {
253253
this.timePickerIncrement = options.timePickerIncrement;
254254
}
255255

256-
if (typeof options.timePicker12Hour == 'boolean') {
256+
if (typeof options.timePicker12Hour === 'boolean') {
257257
this.timePicker12Hour = options.timePicker12Hour;
258258
}
259259

260+
var start, end, range;
261+
260262
//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') {
262264
if ($(this.element).is('input[type=text]')) {
263265
var val = $(this.element).val();
264266
var split = val.split(this.separator);
265-
var start, end;
267+
start = end = null;
266268
if (split.length == 2) {
267269
start = moment(split[0], this.format);
268270
end = moment(split[1], this.format);
269271
} else if (this.singleDatePicker) {
270272
start = moment(val, this.format);
271273
end = moment(val, this.format);
272274
}
273-
if (start != null && end != null) {
275+
if (start !== null && end !== null) {
274276
this.startDate = start;
275277
this.endDate = end;
276278
}
277279
}
278280
}
279281

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) {
282284

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]);
285287

286288
// If we have a min/max date set, bound this range
287289
// to it, but only if it would otherwise fall
@@ -303,7 +305,7 @@
303305
}
304306

305307
var list = '<ul>';
306-
for (var range in this.ranges) {
308+
for (range in this.ranges) {
307309
list += '<li>' + range + '</li>';
308310
}
309311
list += '<li>' + this.locale.customRangeLabel + '</li>';
@@ -312,7 +314,7 @@
312314
this.container.find('.ranges').prepend(list);
313315
}
314316

315-
if (typeof callback == 'function') {
317+
if (typeof callback === 'function') {
316318
this.cb = callback;
317319
}
318320

@@ -354,22 +356,22 @@
354356
right.removeClass('right').addClass('left');
355357
}
356358

357-
if (typeof options.ranges == 'undefined' && !this.singleDatePicker) {
359+
if (typeof options.ranges === 'undefined' && !this.singleDatePicker) {
358360
this.container.find('.calendar').show();
359361
}
360362

361363
this.container.addClass('opens' + this.opens);
362364

363365
this.updateView();
364-
this.updateCalendars()
366+
this.updateCalendars();
365367

366368
},
367369

368370
setStartDate: function(startDate) {
369-
if (typeof startDate == 'string')
371+
if (typeof startDate === 'string')
370372
this.startDate = moment(startDate, this.format);
371373

372-
if (typeof startDate == 'object')
374+
if (typeof startDate === 'object')
373375
this.startDate = moment(startDate);
374376

375377
if (!this.timePicker)
@@ -382,10 +384,10 @@
382384
},
383385

384386
setEndDate: function(endDate) {
385-
if (typeof endDate == 'string')
387+
if (typeof endDate === 'string')
386388
this.endDate = moment(endDate, this.format);
387389

388-
if (typeof endDate == 'object')
390+
if (typeof endDate === 'object')
389391
this.endDate = moment(endDate);
390392

391393
if (!this.timePicker)
@@ -431,7 +433,6 @@
431433
end = start;
432434
}
433435

434-
if (start == null || end == null) return;
435436
if (end.isBefore(start)) return;
436437

437438
this.oldStartDate = this.startDate.clone();
@@ -606,19 +607,20 @@
606607
var col = title.substr(3, 1);
607608
var cal = $(e.target).parents('.calendar');
608609

610+
var startDate, endDate;
609611
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') {
613615
var maxDate = moment(startDate).add(this.dateLimit).startOf('day');
614616
if (endDate.isAfter(maxDate)) {
615617
endDate = maxDate;
616618
}
617619
}
618620
} 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') {
622624
var minDate = moment(endDate).subtract(this.dateLimit).startOf('day');
623625
if (startDate.isBefore(minDate)) {
624626
startDate = minDate;
@@ -762,9 +764,11 @@
762764

763765
var dayOfWeek = firstDay.day();
764766

767+
var i;
768+
765769
//initialize a 6 rows x 7 columns array for the calendar
766770
var calendar = [];
767-
for (var i = 0; i < 6; i++) {
771+
for (i = 0; i < 6; i++) {
768772
calendar[i] = [];
769773
}
770774

@@ -777,8 +781,9 @@
777781
startDay = daysInLastMonth - 6;
778782

779783
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) {
782787
col = 0;
783788
row++;
784789
}
@@ -903,6 +908,7 @@
903908
html += '</table>';
904909
html += '</div>';
905910

911+
var i;
906912
if (this.timePicker) {
907913

908914
html += '<div class="calendar-time">';
@@ -915,11 +921,11 @@
915921
end = 12;
916922
if (selected_hour >= 12)
917923
selected_hour -= 12;
918-
if (selected_hour == 0)
924+
if (selected_hour === 0)
919925
selected_hour = 12;
920926
}
921927

922-
for (var i = start; i <= end; i++) {
928+
for (i = start; i <= end; i++) {
923929
if (i == selected_hour) {
924930
html += '<option value="' + i + '" selected="selected">' + i + '</option>';
925931
} else {
@@ -931,7 +937,7 @@
931937

932938
html += '<select class="minuteselect">';
933939

934-
for (var i = 0; i < 60; i += this.timePickerIncrement) {
940+
for (i = 0; i < 60; i += this.timePickerIncrement) {
935941
var num = i;
936942
if (num < 10)
937943
num = '0' + num;

0 commit comments

Comments
 (0)