Skip to content

Commit b987ff3

Browse files
committed
simplified HTML5 input type support check
1 parent 34f483d commit b987ff3

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

script/EntryEditor.js

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,32 @@ var EntryEditor = function($form) {
1414
$form.find('.struct .hashint').tooltip();
1515

1616
/**
17-
* Attach datepicker to date types.
18-
* Only if browser does not support HTML5 date input.
17+
* Attach datepicker to date types, if lacking HTML5 support.
1918
*/
20-
var testelem = document.createElement('input');
21-
testelem.setAttribute("type", "date");
22-
if (testelem.type === "text") {
23-
$form.find('input.struct_date').datepicker({
24-
dateFormat: 'yyyy-mm-dd',
25-
changeYear: true,
26-
});
27-
}
19+
var ftypetext = function() { return this.type === 'text'; };
20+
$form.find('input.struct_date').filter(ftypetext).datepicker({
21+
dateFormat: 'yyyy-mm-dd',
22+
changeYear: true,
23+
});
2824

2925
/**
3026
* Attach datepicker to datetype types, keeps time part.
3127
* Only if browser does not support HTML5 datetime-local input.
3228
*/
33-
testelem.setAttribute("type", "datetime-local");
34-
if (testelem.type === "text") {
35-
$form.find('input.struct_datetime').datepicker({
36-
dateFormat: 'yyyy-mm-dd',
37-
changeYear: true,
38-
onSelect: function (date, inst) {
39-
var $input = jQuery(this);
40-
var both = inst.lastVal.split(' ', 2);
41-
if (both.length == 2) {
42-
date += ' ' + both[1];
43-
} else {
44-
date += ' 00:00:00';
45-
}
46-
$input.val(date);
29+
$form.find('input.struct_datetime').filter(ftypetext).datepicker({
30+
dateFormat: 'yyyy-mm-dd',
31+
changeYear: true,
32+
onSelect: function (date, inst) {
33+
var $input = jQuery(this);
34+
var both = inst.lastVal.split(' ', 2);
35+
if (both.length == 2) {
36+
date += ' ' + both[1];
37+
} else {
38+
date += ' 00:00:00';
4739
}
48-
});
49-
}
40+
$input.val(date);
41+
}
42+
});
5043

5144
/**
5245
* Attach image dialog to image types

0 commit comments

Comments
 (0)