cf7-datepicker-ie-fixer.js
4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
jQuery(document).ready(function($) {
var net = {};
net.touchdata = {};
net.touchdata.datepickerFix = function() {
this.supportHtml5 = {
date: false,
email: false,
number: false,
placeholder: false,
range: false,
tel: false,
url: false
};
this.supportHtml5 = this.setHtml5Support();
};
net.touchdata.datepickerFix.prototype.getInternetExplorerVersion = function() {
/* thx to http://stackoverflow.com/questions/17907445/how-to-detect-ie11 */
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat(RegExp.$1);
}
else if (navigator.appName == 'Netscape')
{
var ua = navigator.userAgent;
var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat(RegExp.$1);
}
return rv;
};
net.touchdata.datepickerFix.prototype.isInternetExplorer = function() {
var isMSIE = eval("/*@cc_on!@*/0");
var isMSIE2 = ('\v' == 'v');
if (this.getInternetExplorerVersion() !== -1) {
return true;
}
return (isMSIE || isMSIE2);
};
net.touchdata.datepickerFix.prototype.setHtml5Support = function() {
var features = {};
var input = document.createElement('input');
features.placeholder = 'placeholder' in input;
var inputTypes = ['email', 'url', 'tel', 'number', 'range', 'date'];
$.each(inputTypes, function(index, value) {
input.setAttribute('type', value);
features[value] = input.type !== 'text';
});
return features;
};
net.touchdata.datepickerFix.prototype.addSpinnerToObject = function(object) {
var options = {};
var min = object.attr('min');
var max = object.attr('max');
var step = object.attr('step');
if (min != "undefined" && min != undefined) {
options.min = min;
}
if (max != "undefined" && max != undefined) {
options.max = max;
}
if (step != "undefined" && step != undefined) {
options.step = step;
}
object.spinner(options);
};
net.touchdata.datepickerFix.prototype.doMagic = function() {
var that = this;
if (this.isInternetExplorer() || !this.supportHtml5.date) {
$.each($('[type="date"][class*="wpcf7-date"]'), function() {
var min = "-100";
var max = "+0"
var min_v =$(this).attr('min');
var max_v =$(this).attr('max');
if (min_v !== undefined && min_v !== "undefined") {
var t = min_v.split("-");
min = t[0];
}
if (max_v !== undefined && max_v !== "undefined") {
var t = max_v.split("-");
max = t[0];
}
$(this).datepicker({
autoclose: true,
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true,
yearRange: min +":" + max
});
});
}
if (this.isInternetExplorer() || !this.supportHtml5.number) {
$.each($('[type="number"][class*="wpcf7-number"]'), function() {
that.addSpinnerToObject($(this));
});
$.each($('[type="text"][class*="wpcf7-number"]'), function() {
that.addSpinnerToObject($(this));
});
}
};
var datepickerFix = new net.touchdata.datepickerFix();
datepickerFix.doMagic();
});