|
|
1
|
+
|
|
|
2
|
+//datePicker日期控件 v1.0
|
|
|
3
|
+
|
|
|
4
|
+//var calendar = new datePicker();
|
|
|
5
|
+//calendar.init({
|
|
|
6
|
+// 'trigger': '#demo1', /*选择器,触发弹出插件*/
|
|
|
7
|
+// 'type': 'date',/*date 调出日期选择 datetime 调出日期时间选择 time 调出时间选择 ym 调出年月选择*/
|
|
|
8
|
+// 'minDate':'1900-1-1',/*最小日期*/
|
|
|
9
|
+// 'maxDate':new Date().getFullYear()+'-'+(new Date().getMonth()+1)+'-'+new Date().getDate(),/*最大日期*/
|
|
|
10
|
+// 'onSubmit':function(){/*确认时触发事件*/
|
|
|
11
|
+// var theSelectData=calendar.value;
|
|
|
12
|
+// },
|
|
|
13
|
+// 'onClose':function(){/*取消时触发事件*/
|
|
|
14
|
+// }
|
|
|
15
|
+//});
|
|
|
16
|
+
|
|
|
17
|
+window.datePicker = (function() {
|
|
|
18
|
+ var MobileCalendar = function() {
|
|
|
19
|
+ this.gearDate;
|
|
|
20
|
+ this.minY = 1900;
|
|
|
21
|
+ this.minM = 1;
|
|
|
22
|
+ this.minD = 1;
|
|
|
23
|
+ this.maxY = 2099;
|
|
|
24
|
+ this.maxM = 12;
|
|
|
25
|
+ this.maxD = 31;
|
|
|
26
|
+ this.value="";
|
|
|
27
|
+ };
|
|
|
28
|
+
|
|
|
29
|
+ var cssHtm='.gearYM,.gearDate,.gearDatetime,.gearTime{font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-size:10px;background-color:rgba(0,0,0,0.2);display:block;position:fixed;top:0;left:0;width:100%;height:100%;z-index:9900;overflow:hidden;-webkit-animation-fill-mode:both;animation-fill-mode:both}.date_ctrl{vertical-align:middle;background-color:#d5d8df;color:#000;margin:0;height:auto;width:100%;position:absolute;left:0;bottom:0;z-index:9901;overflow:hidden;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}.slideInUp{animation:slideInUp .3s ease;-webkit-animation:slideInUp .3s ease;}@-webkit-keyframes slideInUp{from{-webkit-transform:translate3d(0,100%,0);transform:translate3d(0,100%,0)}to{-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}}.ym_roll,.date_roll,.datetime_roll,.time_roll{display:-webkit-box;width:100%;height:auto;overflow:hidden;font-weight:bold;background-color:transparent;-webkit-mask:-webkit-gradient(linear,0% 50%,0% 100%,from(#debb47),to(rgba(36,142,36,0)));-webkit-mask:-webkit-linear-gradient(top,#debb47 50%,rgba(36,142,36,0))}.ym_roll>div,.date_roll>div,.datetime_roll>div,.time_roll>div{font-size:2.3em;height:6em;float:left;background-color:transparent;position:relative;overflow:hidden;-webkit-box-flex:4}.ym_roll>div .gear,.date_roll>div .gear,.datetime_roll>div .gear,.time_roll>div .gear{width:100%;float:left;position:absolute;z-index:9902;margin-top:-6em}.date_roll_mask{-webkit-mask:-webkit-gradient(linear,0% 40%,0% 0%,from(#debb47),to(rgba(36,142,36,0)));-webkit-mask:-webkit-linear-gradient(bottom,#debb47 50%,rgba(36,142,36,0));padding:0 0 3em 0}.date_roll>div:nth-child(2){-webkit-box-flex:2}.date_roll>div:nth-child(1),.datetime_roll>div:nth-child(1){-webkit-box-flex:4}.datetime_roll>div:first-child{-webkit-box-flex:6}.datetime_roll>div:last-child{-webkit-box-flex:6}.date_grid{position:relative;top:2em;width:100%;height:2em;margin:0;box-sizing:border-box;z-index:0;border-top:1px solid #abaeb5;border-bottom:1px solid #abaeb5}.date_grid>div{color:#000;position:absolute;right:0;top:0;font-size:.8em;line-height:2.5em}.date_roll>div:nth-child(3) .date_grid>div{left:42%}.datetime_roll>div .date_grid>div{right:0}.datetime_roll>div:first-child .date_grid>div{left:auto;right:0%}.datetime_roll>div:last-child .date_grid>div{left:50%}.time_roll>div:nth-child(1) .date_grid>div{right:1em}.ym_roll>div:nth-child(1) .date_grid>div{right:.1em}.ym_roll>div .date_grid>div,.time_roll>div .date_grid>div{right:5em}.date_btn{color:#0575f2;font-size:1.6em;font-weight:bold;line-height:1em;text-align:center;padding:.8em 1em}.date_btn_box:before,.date_btn_box:after{content:"";position:absolute;height:1px;width:100%;display:block;background-color:#96979b;z-index:15;-webkit-transform:scaleY(0.33);transform:scaleY(0.33)}.date_btn_box{display:-webkit-box;-webkit-box-pack:justify;-webkit-box-align:stretch;background-color:#f1f2f4;position:relative}.date_btn_box:before{left:0;top:0;-webkit-transform-origin:50% 20%;transform-origin:50% 20%}.date_btn_box:after{left:0;bottom:0;-webkit-transform-origin:50% 70%;transform-origin:50% 70%}.date_roll>div:nth-child(1) .gear{text-indent:20%}.date_roll>div:nth-child(2) .gear{text-indent:-20%}.date_roll>div:nth-child(3) .gear{text-indent:-55%}.datetime_roll>div .gear{width:100%;text-indent:-25%}.datetime_roll>div:first-child .gear{text-indent:-10%}.datetime_roll>div:last-child .gear{text-indent:-50%}.ym_roll>div .gear,.time_roll>div .gear{width:100%;text-indent:-70%}.ym_roll>div:nth-child(1) .gear,.time_roll>div:nth-child(1) .gear{width:100%;text-indent:10%}.tooth{height:2em;line-height:2em;text-align:center}';
|
|
|
30
|
+ var cssEle = document.createElement("style");
|
|
|
31
|
+ cssEle.type = "text/css";
|
|
|
32
|
+ cssEle.appendChild(document.createTextNode(cssHtm));
|
|
|
33
|
+ document.getElementsByTagName("head")[0].appendChild(cssEle);
|
|
|
34
|
+
|
|
|
35
|
+ MobileCalendar.prototype = {
|
|
|
36
|
+ init: function(params) {
|
|
|
37
|
+ this.type = params.type;
|
|
|
38
|
+ this.trigger = document.querySelector(params.trigger);
|
|
|
39
|
+ if (this.trigger.getAttribute("data-lcalendar") != null) {
|
|
|
40
|
+ var arr = this.trigger.getAttribute("data-lcalendar").split(',');
|
|
|
41
|
+ var minArr = arr[0].split('-');
|
|
|
42
|
+ this.minY = ~~minArr[0];
|
|
|
43
|
+ this.minM = ~~minArr[1];
|
|
|
44
|
+ this.minD = ~~minArr[2];
|
|
|
45
|
+ var maxArr = arr[1].split('-');
|
|
|
46
|
+ this.maxY = ~~maxArr[0];
|
|
|
47
|
+ this.maxM = ~~maxArr[1];
|
|
|
48
|
+ this.maxD = ~~maxArr[2];
|
|
|
49
|
+ };
|
|
|
50
|
+ if (params.minDate) {
|
|
|
51
|
+ var minArr = params.minDate.split('-');
|
|
|
52
|
+ this.minY = ~~minArr[0];
|
|
|
53
|
+ this.minM = ~~minArr[1];
|
|
|
54
|
+ this.minD = ~~minArr[2];
|
|
|
55
|
+ };
|
|
|
56
|
+ if (params.maxDate) {
|
|
|
57
|
+ var maxArr = params.maxDate.split('-');
|
|
|
58
|
+ this.maxY = ~~maxArr[0];
|
|
|
59
|
+ this.maxM = ~~maxArr[1];
|
|
|
60
|
+ this.maxD = ~~maxArr[2];
|
|
|
61
|
+ };
|
|
|
62
|
+ this.onClose= params.onClose;
|
|
|
63
|
+ this.onSubmit= params.onSubmit;
|
|
|
64
|
+ this.onChange= params.onChange;
|
|
|
65
|
+ this.bindEvent(this.type);
|
|
|
66
|
+ },
|
|
|
67
|
+ bindEvent: function(type) {
|
|
|
68
|
+ var _self = this;
|
|
|
69
|
+ var isTouched = false , isMoved = false;
|
|
|
70
|
+ var pree;
|
|
|
71
|
+ //呼出日期插件
|
|
|
72
|
+ function popupDate(e) {
|
|
|
73
|
+ _self.gearDate = document.createElement("div");
|
|
|
74
|
+ _self.gearDate.className = "gearDate";
|
|
|
75
|
+ _self.gearDate.innerHTML = '<div class="date_ctrl slideInUp">' +
|
|
|
76
|
+ '<div class="date_btn_box">' +
|
|
|
77
|
+ '<div class="date_btn lcalendar_cancel">取消</div>' +
|
|
|
78
|
+ '<div class="date_btn lcalendar_finish">确定</div>' +
|
|
|
79
|
+ '</div>' +
|
|
|
80
|
+ '<div class="date_roll_mask">' +
|
|
|
81
|
+ '<div class="date_roll">' +
|
|
|
82
|
+ '<div>' +
|
|
|
83
|
+ '<div class="gear date_yy" data-datetype="date_yy"></div>' +
|
|
|
84
|
+ '<div class="date_grid">' +
|
|
|
85
|
+ '<div>年</div>' +
|
|
|
86
|
+ '</div>' +
|
|
|
87
|
+ '</div>' +
|
|
|
88
|
+ '<div>' +
|
|
|
89
|
+ '<div class="gear date_mm" data-datetype="date_mm"></div>' +
|
|
|
90
|
+ '<div class="date_grid">' +
|
|
|
91
|
+ '<div>月</div>' +
|
|
|
92
|
+ '</div>' +
|
|
|
93
|
+ '</div>' +
|
|
|
94
|
+ '<div>' +
|
|
|
95
|
+ '<div class="gear date_dd" data-datetype="date_dd"></div>' +
|
|
|
96
|
+ '<div class="date_grid">' +
|
|
|
97
|
+ '<div>日</div>' +
|
|
|
98
|
+ '</div>' +
|
|
|
99
|
+ '</div>' +
|
|
|
100
|
+ '</div>' +
|
|
|
101
|
+ '</div>' +
|
|
|
102
|
+ '</div><div class="date_bg" style="width:100%;height:100%;"></div>';
|
|
|
103
|
+ document.body.appendChild(_self.gearDate);
|
|
|
104
|
+ dateCtrlInit();
|
|
|
105
|
+ var lcalendar_cancel = _self.gearDate.querySelector(".lcalendar_cancel");
|
|
|
106
|
+ lcalendar_cancel.addEventListener('touchstart', closeMobileCalendar);
|
|
|
107
|
+ var lcalendar_finish = _self.gearDate.querySelector(".lcalendar_finish");
|
|
|
108
|
+ lcalendar_finish.addEventListener('touchstart', finishMobileDate);
|
|
|
109
|
+ var lcalendar_bg = _self.gearDate.querySelector(".date_bg");
|
|
|
110
|
+ lcalendar_bg.addEventListener('click', closeMobileCalendar);
|
|
|
111
|
+ var date_yy = _self.gearDate.querySelector(".date_yy");
|
|
|
112
|
+ var date_mm = _self.gearDate.querySelector(".date_mm");
|
|
|
113
|
+ var date_dd = _self.gearDate.querySelector(".date_dd");
|
|
|
114
|
+ date_yy.addEventListener('touchstart', gearTouchStart);
|
|
|
115
|
+ date_mm.addEventListener('touchstart', gearTouchStart);
|
|
|
116
|
+ date_dd.addEventListener('touchstart', gearTouchStart);
|
|
|
117
|
+ date_yy.addEventListener('touchmove', gearTouchMove);
|
|
|
118
|
+ date_mm.addEventListener('touchmove', gearTouchMove);
|
|
|
119
|
+ date_dd.addEventListener('touchmove', gearTouchMove);
|
|
|
120
|
+ date_yy.addEventListener('touchend', gearTouchEnd);
|
|
|
121
|
+ date_mm.addEventListener('touchend', gearTouchEnd);
|
|
|
122
|
+ date_dd.addEventListener('touchend', gearTouchEnd);
|
|
|
123
|
+ //-------------------------------------------------------------
|
|
|
124
|
+ lcalendar_cancel.addEventListener('click', closeMobileCalendar);
|
|
|
125
|
+ lcalendar_finish.addEventListener('click', finishMobileDate);
|
|
|
126
|
+ date_yy.addEventListener('mousedown', gearTouchStart);
|
|
|
127
|
+ date_mm.addEventListener('mousedown', gearTouchStart);
|
|
|
128
|
+ date_dd.addEventListener('mousedown', gearTouchStart);
|
|
|
129
|
+ date_yy.addEventListener('mousemove', gearTouchMove);
|
|
|
130
|
+ date_mm.addEventListener('mousemove', gearTouchMove);
|
|
|
131
|
+ date_dd.addEventListener('mousemove', gearTouchMove);
|
|
|
132
|
+ date_yy.addEventListener('mouseup', gearTouchEnd);
|
|
|
133
|
+ date_mm.addEventListener('mouseup', gearTouchEnd);
|
|
|
134
|
+ date_dd.addEventListener('mouseup', gearTouchEnd);
|
|
|
135
|
+ _self.gearDate.querySelector(".date_roll_mask").addEventListener('mouseleave', gearTouchOut);
|
|
|
136
|
+ _self.gearDate.querySelector(".date_roll_mask").addEventListener('mouseup', gearTouchOut);
|
|
|
137
|
+ }
|
|
|
138
|
+ //初始化年月日插件默认值
|
|
|
139
|
+ function dateCtrlInit() {
|
|
|
140
|
+ var date = new Date();
|
|
|
141
|
+ var dateArr = {
|
|
|
142
|
+ yy: date.getYear(),
|
|
|
143
|
+ mm: date.getMonth(),
|
|
|
144
|
+ dd: date.getDate() - 1
|
|
|
145
|
+ };
|
|
|
146
|
+ if (/^\d{4}-\d{1,2}-\d{1,2}$/.test(_self.trigger.value)) {
|
|
|
147
|
+ rs = _self.trigger.value.match(/(^|-)\d{1,4}/g);
|
|
|
148
|
+ dateArr.yy = rs[0] - _self.minY;
|
|
|
149
|
+ dateArr.mm = rs[1].replace(/-/g, "") - 1;
|
|
|
150
|
+ dateArr.dd = rs[2].replace(/-/g, "") - 1;
|
|
|
151
|
+ } else {
|
|
|
152
|
+ dateArr.yy = dateArr.yy + 1900 - _self.minY;
|
|
|
153
|
+ }
|
|
|
154
|
+ _self.gearDate.querySelector(".date_yy").setAttribute("val", dateArr.yy);
|
|
|
155
|
+ _self.gearDate.querySelector(".date_mm").setAttribute("val", dateArr.mm);
|
|
|
156
|
+ _self.gearDate.querySelector(".date_dd").setAttribute("val", dateArr.dd);
|
|
|
157
|
+ setDateGearTooth();
|
|
|
158
|
+ }
|
|
|
159
|
+ //呼出年月插件
|
|
|
160
|
+ function popupYM(e) {
|
|
|
161
|
+ _self.gearDate = document.createElement("div");
|
|
|
162
|
+ _self.gearDate.className = "gearDate";
|
|
|
163
|
+ _self.gearDate.innerHTML = '<div class="date_ctrl slideInUp">' +
|
|
|
164
|
+ '<div class="date_btn_box">' +
|
|
|
165
|
+ '<div class="date_btn lcalendar_cancel">取消</div>' +
|
|
|
166
|
+ '<div class="date_btn lcalendar_finish">确定</div>' +
|
|
|
167
|
+ '</div>' +
|
|
|
168
|
+ '<div class="date_roll_mask">' +
|
|
|
169
|
+ '<div class="ym_roll">' +
|
|
|
170
|
+ '<div>' +
|
|
|
171
|
+ '<div class="gear date_yy" data-datetype="date_yy"></div>' +
|
|
|
172
|
+ '<div class="date_grid">' +
|
|
|
173
|
+ '<div>年</div>' +
|
|
|
174
|
+ '</div>' +
|
|
|
175
|
+ '</div>' +
|
|
|
176
|
+ '<div>' +
|
|
|
177
|
+ '<div class="gear date_mm" data-datetype="date_mm"></div>' +
|
|
|
178
|
+ '<div class="date_grid">' +
|
|
|
179
|
+ '<div>月</div>' +
|
|
|
180
|
+ '</div>' +
|
|
|
181
|
+ '</div>' +
|
|
|
182
|
+ '</div>' +
|
|
|
183
|
+ '</div>' +
|
|
|
184
|
+ '</div><div class="date_bg" style="width:100%;height:100%;"></div>';
|
|
|
185
|
+ document.body.appendChild(_self.gearDate);
|
|
|
186
|
+ ymCtrlInit();
|
|
|
187
|
+ var lcalendar_cancel = _self.gearDate.querySelector(".lcalendar_cancel");
|
|
|
188
|
+ lcalendar_cancel.addEventListener('touchstart', closeMobileCalendar);
|
|
|
189
|
+ var lcalendar_finish = _self.gearDate.querySelector(".lcalendar_finish");
|
|
|
190
|
+ lcalendar_finish.addEventListener('touchstart', finishMobileYM);
|
|
|
191
|
+ var lcalendar_bg = _self.gearDate.querySelector(".date_bg");
|
|
|
192
|
+ lcalendar_bg.addEventListener('click', closeMobileCalendar);
|
|
|
193
|
+ var date_yy = _self.gearDate.querySelector(".date_yy");
|
|
|
194
|
+ var date_mm = _self.gearDate.querySelector(".date_mm");
|
|
|
195
|
+ date_yy.addEventListener('touchstart', gearTouchStart);
|
|
|
196
|
+ date_mm.addEventListener('touchstart', gearTouchStart);
|
|
|
197
|
+ date_yy.addEventListener('touchmove', gearTouchMove);
|
|
|
198
|
+ date_mm.addEventListener('touchmove', gearTouchMove);
|
|
|
199
|
+ date_yy.addEventListener('touchend', gearTouchEnd);
|
|
|
200
|
+ date_mm.addEventListener('touchend', gearTouchEnd);
|
|
|
201
|
+ //-------------------------------------------------------------
|
|
|
202
|
+ lcalendar_cancel.addEventListener('click', closeMobileCalendar);
|
|
|
203
|
+ lcalendar_finish.addEventListener('click', finishMobileYM);
|
|
|
204
|
+ date_yy.addEventListener('mousedown', gearTouchStart);
|
|
|
205
|
+ date_mm.addEventListener('mousedown', gearTouchStart);
|
|
|
206
|
+ date_yy.addEventListener('mousemove', gearTouchMove);
|
|
|
207
|
+ date_mm.addEventListener('mousemove', gearTouchMove);
|
|
|
208
|
+ date_yy.addEventListener('mouseup', gearTouchEnd);
|
|
|
209
|
+ date_mm.addEventListener('mouseup', gearTouchEnd);
|
|
|
210
|
+ _self.gearDate.querySelector(".date_roll_mask").addEventListener('mouseleave', gearTouchOut);
|
|
|
211
|
+ _self.gearDate.querySelector(".date_roll_mask").addEventListener('mouseup', gearTouchOut);
|
|
|
212
|
+ }
|
|
|
213
|
+ //初始化年月插件默认值
|
|
|
214
|
+ function ymCtrlInit() {
|
|
|
215
|
+ var date = new Date();
|
|
|
216
|
+ var dateArr = {
|
|
|
217
|
+ yy: date.getYear(),
|
|
|
218
|
+ mm: date.getMonth()
|
|
|
219
|
+ };
|
|
|
220
|
+ if (/^\d{4}-\d{1,2}$/.test(_self.trigger.value)) {
|
|
|
221
|
+ rs = _self.trigger.value.match(/(^|-)\d{1,4}/g);
|
|
|
222
|
+ dateArr.yy = rs[0] - _self.minY;
|
|
|
223
|
+ dateArr.mm = rs[1].replace(/-/g, "") - 1;
|
|
|
224
|
+ } else {
|
|
|
225
|
+ dateArr.yy = dateArr.yy + 1900 - _self.minY;
|
|
|
226
|
+ }
|
|
|
227
|
+ _self.gearDate.querySelector(".date_yy").setAttribute("val", dateArr.yy);
|
|
|
228
|
+ _self.gearDate.querySelector(".date_mm").setAttribute("val", dateArr.mm);
|
|
|
229
|
+ setDateGearTooth();
|
|
|
230
|
+ }
|
|
|
231
|
+ //呼出日期+时间插件
|
|
|
232
|
+ function popupDateTime(e) {
|
|
|
233
|
+ _self.gearDate = document.createElement("div");
|
|
|
234
|
+ _self.gearDate.className = "gearDatetime";
|
|
|
235
|
+ _self.gearDate.innerHTML = '<div class="date_ctrl slideInUp">' +
|
|
|
236
|
+ '<div class="date_btn_box">' +
|
|
|
237
|
+ '<div class="date_btn lcalendar_cancel">取消</div>' +
|
|
|
238
|
+ '<div class="date_btn lcalendar_finish">确定</div>' +
|
|
|
239
|
+ '</div>' +
|
|
|
240
|
+ '<div class="date_roll_mask">' +
|
|
|
241
|
+ '<div class="datetime_roll">' +
|
|
|
242
|
+ '<div>' +
|
|
|
243
|
+ '<div class="gear date_yy" data-datetype="date_yy"></div>' +
|
|
|
244
|
+ '<div class="date_grid">' +
|
|
|
245
|
+ '<div>年</div>' +
|
|
|
246
|
+ '</div>' +
|
|
|
247
|
+ '</div>' +
|
|
|
248
|
+ '<div>' +
|
|
|
249
|
+ '<div class="gear date_mm" data-datetype="date_mm"></div>' +
|
|
|
250
|
+ '<div class="date_grid">' +
|
|
|
251
|
+ '<div>月</div>' +
|
|
|
252
|
+ '</div>' +
|
|
|
253
|
+ '</div>' +
|
|
|
254
|
+ '<div>' +
|
|
|
255
|
+ '<div class="gear date_dd" data-datetype="date_dd"></div>' +
|
|
|
256
|
+ '<div class="date_grid">' +
|
|
|
257
|
+ '<div>日</div>' +
|
|
|
258
|
+ '</div>' +
|
|
|
259
|
+ '</div>' +
|
|
|
260
|
+ '<div>' +
|
|
|
261
|
+ '<div class="gear time_hh" data-datetype="time_hh"></div>' +
|
|
|
262
|
+ '<div class="date_grid">' +
|
|
|
263
|
+ '<div>时</div>' +
|
|
|
264
|
+ '</div>' +
|
|
|
265
|
+ '</div>' +
|
|
|
266
|
+ '<div>' +
|
|
|
267
|
+ '<div class="gear time_mm" data-datetype="time_mm"></div>' +
|
|
|
268
|
+ '<div class="date_grid">' +
|
|
|
269
|
+ '<div>分</div>' +
|
|
|
270
|
+ '</div>' +
|
|
|
271
|
+ '</div>' +
|
|
|
272
|
+ '</div>' + //date_roll
|
|
|
273
|
+ '</div>' + //date_roll_mask
|
|
|
274
|
+ '</div><div class="date_bg" style="width:100%;height:100%;"></div>';
|
|
|
275
|
+ document.body.appendChild(_self.gearDate);
|
|
|
276
|
+ dateTimeCtrlInit();
|
|
|
277
|
+ var lcalendar_cancel = _self.gearDate.querySelector(".lcalendar_cancel");
|
|
|
278
|
+ lcalendar_cancel.addEventListener('touchstart', closeMobileCalendar);
|
|
|
279
|
+ var lcalendar_finish = _self.gearDate.querySelector(".lcalendar_finish");
|
|
|
280
|
+ lcalendar_finish.addEventListener('touchstart', finishMobileDateTime);
|
|
|
281
|
+ var lcalendar_bg = _self.gearDate.querySelector(".date_bg");
|
|
|
282
|
+ lcalendar_bg.addEventListener('click', closeMobileCalendar);
|
|
|
283
|
+ var date_yy = _self.gearDate.querySelector(".date_yy");
|
|
|
284
|
+ var date_mm = _self.gearDate.querySelector(".date_mm");
|
|
|
285
|
+ var date_dd = _self.gearDate.querySelector(".date_dd");
|
|
|
286
|
+ var time_hh = _self.gearDate.querySelector(".time_hh");
|
|
|
287
|
+ var time_mm = _self.gearDate.querySelector(".time_mm");
|
|
|
288
|
+ date_yy.addEventListener('touchstart', gearTouchStart);
|
|
|
289
|
+ date_mm.addEventListener('touchstart', gearTouchStart);
|
|
|
290
|
+ date_dd.addEventListener('touchstart', gearTouchStart);
|
|
|
291
|
+ time_hh.addEventListener('touchstart', gearTouchStart);
|
|
|
292
|
+ time_mm.addEventListener('touchstart', gearTouchStart);
|
|
|
293
|
+ date_yy.addEventListener('touchmove', gearTouchMove);
|
|
|
294
|
+ date_mm.addEventListener('touchmove', gearTouchMove);
|
|
|
295
|
+ date_dd.addEventListener('touchmove', gearTouchMove);
|
|
|
296
|
+ time_hh.addEventListener('touchmove', gearTouchMove);
|
|
|
297
|
+ time_mm.addEventListener('touchmove', gearTouchMove);
|
|
|
298
|
+ date_yy.addEventListener('touchend', gearTouchEnd);
|
|
|
299
|
+ date_mm.addEventListener('touchend', gearTouchEnd);
|
|
|
300
|
+ date_dd.addEventListener('touchend', gearTouchEnd);
|
|
|
301
|
+ time_hh.addEventListener('touchend', gearTouchEnd);
|
|
|
302
|
+ time_mm.addEventListener('touchend', gearTouchEnd);
|
|
|
303
|
+ //-------------------------------------------------------------
|
|
|
304
|
+ lcalendar_cancel.addEventListener('click', closeMobileCalendar);
|
|
|
305
|
+ lcalendar_finish.addEventListener('click', finishMobileDateTime);
|
|
|
306
|
+ date_yy.addEventListener('mousedown', gearTouchStart);
|
|
|
307
|
+ date_mm.addEventListener('mousedown', gearTouchStart);
|
|
|
308
|
+ date_dd.addEventListener('mousedown', gearTouchStart);
|
|
|
309
|
+ time_hh.addEventListener('mousedown', gearTouchStart);
|
|
|
310
|
+ time_mm.addEventListener('mousedown', gearTouchStart);
|
|
|
311
|
+ date_yy.addEventListener('mousemove', gearTouchMove);
|
|
|
312
|
+ date_mm.addEventListener('mousemove', gearTouchMove);
|
|
|
313
|
+ date_dd.addEventListener('mousemove', gearTouchMove);
|
|
|
314
|
+ time_hh.addEventListener('mousemove', gearTouchMove);
|
|
|
315
|
+ time_mm.addEventListener('mousemove', gearTouchMove);
|
|
|
316
|
+ date_yy.addEventListener('mouseup', gearTouchEnd);
|
|
|
317
|
+ date_mm.addEventListener('mouseup', gearTouchEnd);
|
|
|
318
|
+ date_dd.addEventListener('mouseup', gearTouchEnd);
|
|
|
319
|
+ time_hh.addEventListener('mouseup', gearTouchEnd);
|
|
|
320
|
+ time_mm.addEventListener('mouseup', gearTouchEnd);
|
|
|
321
|
+ _self.gearDate.querySelector(".date_roll_mask").addEventListener('mouseleave', gearTouchOut);
|
|
|
322
|
+ _self.gearDate.querySelector(".date_roll_mask").addEventListener('mouseup', gearTouchOut);
|
|
|
323
|
+ }
|
|
|
324
|
+ //初始化年月日时分插件默认值
|
|
|
325
|
+ function dateTimeCtrlInit() {
|
|
|
326
|
+ var date = new Date();
|
|
|
327
|
+ var dateArr = {
|
|
|
328
|
+ yy: date.getYear(),
|
|
|
329
|
+ mm: date.getMonth(),
|
|
|
330
|
+ dd: date.getDate() - 1,
|
|
|
331
|
+ hh: date.getHours(),
|
|
|
332
|
+ mi: date.getMinutes()
|
|
|
333
|
+ };
|
|
|
334
|
+ if (/^\d{4}-\d{1,2}-\d{1,2}\s\d{2}:\d{2}$/.test(_self.trigger.value)) {
|
|
|
335
|
+ rs = _self.trigger.value.match(/(^|-|\s|:)\d{1,4}/g);
|
|
|
336
|
+ dateArr.yy = rs[0] - _self.minY;
|
|
|
337
|
+ dateArr.mm = rs[1].replace(/-/g, "") - 1;
|
|
|
338
|
+ dateArr.dd = rs[2].replace(/-/g, "") - 1;
|
|
|
339
|
+ dateArr.hh = parseInt(rs[3].replace(/\s0?/g, ""));
|
|
|
340
|
+ dateArr.mi = parseInt(rs[4].replace(/:0?/g, ""));
|
|
|
341
|
+ } else {
|
|
|
342
|
+ dateArr.yy = dateArr.yy + 1900 - _self.minY;
|
|
|
343
|
+ }
|
|
|
344
|
+ _self.gearDate.querySelector(".date_yy").setAttribute("val", dateArr.yy);
|
|
|
345
|
+ _self.gearDate.querySelector(".date_mm").setAttribute("val", dateArr.mm);
|
|
|
346
|
+ _self.gearDate.querySelector(".date_dd").setAttribute("val", dateArr.dd);
|
|
|
347
|
+ setDateGearTooth();
|
|
|
348
|
+ _self.gearDate.querySelector(".time_hh").setAttribute("val", dateArr.hh);
|
|
|
349
|
+ _self.gearDate.querySelector(".time_mm").setAttribute("val", dateArr.mi);
|
|
|
350
|
+ setTimeGearTooth();
|
|
|
351
|
+ }
|
|
|
352
|
+ //呼出时间插件
|
|
|
353
|
+ function popupTime(e) {
|
|
|
354
|
+ _self.gearDate = document.createElement("div");
|
|
|
355
|
+ _self.gearDate.className = "gearDate";
|
|
|
356
|
+ _self.gearDate.innerHTML = '<div class="date_ctrl slideInUp">' +
|
|
|
357
|
+ '<div class="date_btn_box">' +
|
|
|
358
|
+ '<div class="date_btn lcalendar_cancel">取消</div>' +
|
|
|
359
|
+ '<div class="date_btn lcalendar_finish">确定</div>' +
|
|
|
360
|
+ '</div>' +
|
|
|
361
|
+ '<div class="date_roll_mask">' +
|
|
|
362
|
+ '<div class="time_roll">' +
|
|
|
363
|
+ '<div>' +
|
|
|
364
|
+ '<div class="gear time_hh" data-datetype="time_hh"></div>' +
|
|
|
365
|
+ '<div class="date_grid">' +
|
|
|
366
|
+ '<div>时</div>' +
|
|
|
367
|
+ '</div>' +
|
|
|
368
|
+ '</div>' +
|
|
|
369
|
+ '<div>' +
|
|
|
370
|
+ '<div class="gear time_mm" data-datetype="time_mm"></div>' +
|
|
|
371
|
+ '<div class="date_grid">' +
|
|
|
372
|
+ '<div>分</div>' +
|
|
|
373
|
+ '</div>' +
|
|
|
374
|
+ '</div>' +
|
|
|
375
|
+ '</div>' + //time_roll
|
|
|
376
|
+ '</div>' +
|
|
|
377
|
+ '</div><div class="date_bg" style="width:100%;height:100%;"></div>';
|
|
|
378
|
+ document.body.appendChild(_self.gearDate);
|
|
|
379
|
+ timeCtrlInit();
|
|
|
380
|
+ var lcalendar_cancel = _self.gearDate.querySelector(".lcalendar_cancel");
|
|
|
381
|
+ lcalendar_cancel.addEventListener('touchstart', closeMobileCalendar);
|
|
|
382
|
+ var lcalendar_finish = _self.gearDate.querySelector(".lcalendar_finish");
|
|
|
383
|
+ lcalendar_finish.addEventListener('touchstart', finishMobileTime);
|
|
|
384
|
+ var lcalendar_bg = _self.gearDate.querySelector(".date_bg");
|
|
|
385
|
+ lcalendar_bg.addEventListener('click', closeMobileCalendar);
|
|
|
386
|
+ var time_hh = _self.gearDate.querySelector(".time_hh");
|
|
|
387
|
+ var time_mm = _self.gearDate.querySelector(".time_mm");
|
|
|
388
|
+ time_hh.addEventListener('touchstart', gearTouchStart);
|
|
|
389
|
+ time_mm.addEventListener('touchstart', gearTouchStart);
|
|
|
390
|
+ time_hh.addEventListener('touchmove', gearTouchMove);
|
|
|
391
|
+ time_mm.addEventListener('touchmove', gearTouchMove);
|
|
|
392
|
+ time_hh.addEventListener('touchend', gearTouchEnd);
|
|
|
393
|
+ time_mm.addEventListener('touchend', gearTouchEnd);
|
|
|
394
|
+ //-------------------------------------------------------------
|
|
|
395
|
+ lcalendar_cancel.addEventListener('click', closeMobileCalendar);
|
|
|
396
|
+ lcalendar_finish.addEventListener('click', finishMobileTime);
|
|
|
397
|
+ time_hh.addEventListener('mousedown', gearTouchStart);
|
|
|
398
|
+ time_mm.addEventListener('mousedown', gearTouchStart);
|
|
|
399
|
+ time_hh.addEventListener('mousemove', gearTouchMove);
|
|
|
400
|
+ time_mm.addEventListener('mousemove', gearTouchMove);
|
|
|
401
|
+ time_hh.addEventListener('mouseup', gearTouchEnd);
|
|
|
402
|
+ time_mm.addEventListener('mouseup', gearTouchEnd);
|
|
|
403
|
+ _self.gearDate.querySelector(".date_roll_mask").addEventListener('mouseleave', gearTouchOut);
|
|
|
404
|
+ _self.gearDate.querySelector(".date_roll_mask").addEventListener('mouseup', gearTouchOut);
|
|
|
405
|
+ }
|
|
|
406
|
+ //初始化时分插件默认值
|
|
|
407
|
+ function timeCtrlInit() {
|
|
|
408
|
+ var d = new Date();
|
|
|
409
|
+ var e = {
|
|
|
410
|
+ hh: d.getHours(),
|
|
|
411
|
+ mm: d.getMinutes()
|
|
|
412
|
+ };
|
|
|
413
|
+ if (/^\d{2}:\d{2}$/.test(_self.trigger.value)) {
|
|
|
414
|
+ rs = _self.trigger.value.match(/(^|:)\d{2}/g);
|
|
|
415
|
+ e.hh = parseInt(rs[0].replace(/^0?/g, ""));
|
|
|
416
|
+ e.mm = parseInt(rs[1].replace(/:0?/g, ""))
|
|
|
417
|
+ }
|
|
|
418
|
+ _self.gearDate.querySelector(".time_hh").setAttribute("val", e.hh);
|
|
|
419
|
+ _self.gearDate.querySelector(".time_mm").setAttribute("val", e.mm);
|
|
|
420
|
+ setTimeGearTooth();
|
|
|
421
|
+ }
|
|
|
422
|
+ //重置日期节点个数
|
|
|
423
|
+ function setDateGearTooth() {
|
|
|
424
|
+ var passY = _self.maxY - _self.minY + 1;
|
|
|
425
|
+ var date_yy = _self.gearDate.querySelector(".date_yy");
|
|
|
426
|
+ var itemStr = "";
|
|
|
427
|
+ if (date_yy && date_yy.getAttribute("val")) {
|
|
|
428
|
+ //得到年份的值
|
|
|
429
|
+ var yyVal = parseInt(date_yy.getAttribute("val"));
|
|
|
430
|
+ //p 当前节点前后需要展示的节点个数
|
|
|
431
|
+ for (var p = 0; p <= passY - 1; p++) {
|
|
|
432
|
+ itemStr += "<div class='tooth'>" + (_self.minY + p) + "</div>";
|
|
|
433
|
+ }
|
|
|
434
|
+ date_yy.innerHTML = itemStr;
|
|
|
435
|
+ var top = Math.floor(parseFloat(date_yy.getAttribute('top')));
|
|
|
436
|
+ if (!isNaN(top)) {
|
|
|
437
|
+ top % 2 == 0 ? (top = top) : (top = top + 1);
|
|
|
438
|
+ top > 8 && (top = 8);
|
|
|
439
|
+ var minTop = 8 - (passY - 1) * 2;
|
|
|
440
|
+ top < minTop && (top = minTop);
|
|
|
441
|
+ date_yy.style["-webkit-transform"] = 'translate3d(0,' + top + 'em,0)';
|
|
|
442
|
+ date_yy.setAttribute('top', top + 'em');
|
|
|
443
|
+ yyVal = Math.abs(top - 8) / 2;
|
|
|
444
|
+ date_yy.setAttribute("val", yyVal);
|
|
|
445
|
+ } else {
|
|
|
446
|
+ date_yy.style["-webkit-transform"] = 'translate3d(0,' + (8 - yyVal * 2) + 'em,0)';
|
|
|
447
|
+ date_yy.setAttribute('top', 8 - yyVal * 2 + 'em');
|
|
|
448
|
+ }
|
|
|
449
|
+ } else {
|
|
|
450
|
+ return;
|
|
|
451
|
+ }
|
|
|
452
|
+ var date_mm = _self.gearDate.querySelector(".date_mm");
|
|
|
453
|
+ if (date_mm && date_mm.getAttribute("val")) {
|
|
|
454
|
+ itemStr = "";
|
|
|
455
|
+ //得到月份的值
|
|
|
456
|
+ var mmVal = parseInt(date_mm.getAttribute("val"));
|
|
|
457
|
+ var maxM = 11;
|
|
|
458
|
+ var minM = 0;
|
|
|
459
|
+ //当年份到达最大值
|
|
|
460
|
+ if (yyVal == passY - 1) {
|
|
|
461
|
+ maxM = _self.maxM - 1;
|
|
|
462
|
+ }
|
|
|
463
|
+ //当年份到达最小值
|
|
|
464
|
+ if (yyVal == 0) {
|
|
|
465
|
+ minM = _self.minM - 1;
|
|
|
466
|
+ }
|
|
|
467
|
+ //p 当前节点前后需要展示的节点个数
|
|
|
468
|
+ for (var p = 0; p < maxM - minM + 1; p++) {
|
|
|
469
|
+ itemStr += "<div class='tooth'>" + (minM + p + 1) + "</div>";
|
|
|
470
|
+ }
|
|
|
471
|
+ date_mm.innerHTML = itemStr;
|
|
|
472
|
+ if (mmVal > maxM) {
|
|
|
473
|
+ mmVal = maxM;
|
|
|
474
|
+ date_mm.setAttribute("val", mmVal);
|
|
|
475
|
+ } else if (mmVal < minM) {
|
|
|
476
|
+ mmVal = maxM;
|
|
|
477
|
+ date_mm.setAttribute("val", mmVal);
|
|
|
478
|
+ }
|
|
|
479
|
+ date_mm.style["-webkit-transform"] = 'translate3d(0,' + (8 - (mmVal - minM) * 2) + 'em,0)';
|
|
|
480
|
+ date_mm.setAttribute('top', 8 - (mmVal - minM) * 2 + 'em');
|
|
|
481
|
+ } else {
|
|
|
482
|
+ return;
|
|
|
483
|
+ }
|
|
|
484
|
+ var date_dd = _self.gearDate.querySelector(".date_dd");
|
|
|
485
|
+ if (date_dd && date_dd.getAttribute("val")) {
|
|
|
486
|
+ itemStr = "";
|
|
|
487
|
+ //得到日期的值
|
|
|
488
|
+ var ddVal = parseInt(date_dd.getAttribute("val"));
|
|
|
489
|
+ //返回月份的天数
|
|
|
490
|
+ var maxMonthDays = calcDays(yyVal, mmVal);
|
|
|
491
|
+ //p 当前节点前后需要展示的节点个数
|
|
|
492
|
+ var maxD = maxMonthDays - 1;
|
|
|
493
|
+ var minD = 0;
|
|
|
494
|
+ //当年份月份到达最大值
|
|
|
495
|
+ if (yyVal == passY - 1 && _self.maxM == mmVal + 1) {
|
|
|
496
|
+ maxD = _self.maxD - 1;
|
|
|
497
|
+ }
|
|
|
498
|
+ //当年、月到达最小值
|
|
|
499
|
+ if (yyVal == 0 && _self.minM == mmVal + 1) {
|
|
|
500
|
+ minD = _self.minD - 1;
|
|
|
501
|
+ }
|
|
|
502
|
+ for (var p = 0; p < maxD - minD + 1; p++) {
|
|
|
503
|
+ itemStr += "<div class='tooth'>" + (minD + p + 1) + "</div>";
|
|
|
504
|
+ }
|
|
|
505
|
+ date_dd.innerHTML = itemStr;
|
|
|
506
|
+ if (ddVal > maxD) {
|
|
|
507
|
+ ddVal = maxD;
|
|
|
508
|
+ date_dd.setAttribute("val", ddVal);
|
|
|
509
|
+ } else if (ddVal < minD) {
|
|
|
510
|
+ ddVal = minD;
|
|
|
511
|
+ date_dd.setAttribute("val", ddVal);
|
|
|
512
|
+ }
|
|
|
513
|
+ date_dd.style["-webkit-transform"] = 'translate3d(0,' + (8 - (ddVal - minD) * 2) + 'em,0)';
|
|
|
514
|
+ date_dd.setAttribute('top', 8 - (ddVal - minD) * 2 + 'em');
|
|
|
515
|
+ } else {
|
|
|
516
|
+ return;
|
|
|
517
|
+ }
|
|
|
518
|
+ }
|
|
|
519
|
+ //重置时间节点个数
|
|
|
520
|
+ function setTimeGearTooth() {
|
|
|
521
|
+ var time_hh = _self.gearDate.querySelector(".time_hh");
|
|
|
522
|
+ if (time_hh && time_hh.getAttribute("val")) {
|
|
|
523
|
+ var i = "";
|
|
|
524
|
+ var hhVal = parseInt(time_hh.getAttribute("val"));
|
|
|
525
|
+ for (var g = 0; g <= 23; g++) {
|
|
|
526
|
+ i += "<div class='tooth'>" + g + "</div>";
|
|
|
527
|
+ }
|
|
|
528
|
+ time_hh.innerHTML = i;
|
|
|
529
|
+ time_hh.style["-webkit-transform"] = 'translate3d(0,' + (8 - hhVal * 2) + 'em,0)';
|
|
|
530
|
+ time_hh.setAttribute('top', 8 - hhVal * 2 + 'em');
|
|
|
531
|
+ } else {
|
|
|
532
|
+ return
|
|
|
533
|
+ }
|
|
|
534
|
+ var time_mm = _self.gearDate.querySelector(".time_mm");
|
|
|
535
|
+ if (time_mm && time_mm.getAttribute("val")) {
|
|
|
536
|
+ var i = "";
|
|
|
537
|
+ var mmVal = parseInt(time_mm.getAttribute("val"));
|
|
|
538
|
+ for (var g = 0; g <= 59; g++) {
|
|
|
539
|
+ i += "<div class='tooth'>" + g + "</div>";
|
|
|
540
|
+ }
|
|
|
541
|
+ time_mm.innerHTML = i;
|
|
|
542
|
+ time_mm.style["-webkit-transform"] = 'translate3d(0,' + (8 - mmVal * 2) + 'em,0)';
|
|
|
543
|
+ time_mm.setAttribute('top', 8 - mmVal * 2 + 'em');
|
|
|
544
|
+ } else {
|
|
|
545
|
+ return
|
|
|
546
|
+ }
|
|
|
547
|
+ }
|
|
|
548
|
+ //求月份最大天数
|
|
|
549
|
+ function calcDays(year, month) {
|
|
|
550
|
+ if (month == 1) {
|
|
|
551
|
+ year += _self.minY;
|
|
|
552
|
+ if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0 && year % 4000 != 0)) {
|
|
|
553
|
+ return 29;
|
|
|
554
|
+ } else {
|
|
|
555
|
+ return 28;
|
|
|
556
|
+ }
|
|
|
557
|
+ } else {
|
|
|
558
|
+ if (month == 3 || month == 5 || month == 8 || month == 10) {
|
|
|
559
|
+ return 30;
|
|
|
560
|
+ } else {
|
|
|
561
|
+ return 31;
|
|
|
562
|
+ }
|
|
|
563
|
+ }
|
|
|
564
|
+ }
|
|
|
565
|
+ //触摸开始
|
|
|
566
|
+ function gearTouchStart(e) {
|
|
|
567
|
+ if (isMoved || isTouched) return;
|
|
|
568
|
+ isTouched = true;
|
|
|
569
|
+ e.preventDefault();
|
|
|
570
|
+ var target = e.target;
|
|
|
571
|
+ while (true) {
|
|
|
572
|
+ if (!target.classList.contains("gear")) {
|
|
|
573
|
+ target = target.parentElement;
|
|
|
574
|
+ } else {
|
|
|
575
|
+ break
|
|
|
576
|
+ }
|
|
|
577
|
+ }
|
|
|
578
|
+ clearInterval(target["int_" + target.id]);
|
|
|
579
|
+ target["old_" + target.id] = e.targetTouches ? e.targetTouches[0].screenY : e.pageY;
|
|
|
580
|
+ target["o_t_" + target.id] = (new Date()).getTime();
|
|
|
581
|
+ var top = target.getAttribute('top');
|
|
|
582
|
+ if (top) {
|
|
|
583
|
+ target["o_d_" + target.id] = parseFloat(top.replace(/em/g, ""));
|
|
|
584
|
+ } else {
|
|
|
585
|
+ target["o_d_" + target.id] = 0;
|
|
|
586
|
+ };
|
|
|
587
|
+ pree=e;
|
|
|
588
|
+ }
|
|
|
589
|
+ //手指移动
|
|
|
590
|
+ function gearTouchMove(e) {
|
|
|
591
|
+ if (!isTouched) return;
|
|
|
592
|
+ isMoved = true;
|
|
|
593
|
+ e.preventDefault();
|
|
|
594
|
+ if(pree) var target = pree.target; else
|
|
|
595
|
+ var target = e.target;
|
|
|
596
|
+ while (true) {
|
|
|
597
|
+ if (!target.classList.contains("gear")) {
|
|
|
598
|
+ target = target.parentElement;
|
|
|
599
|
+ } else {
|
|
|
600
|
+ break
|
|
|
601
|
+ }
|
|
|
602
|
+ }
|
|
|
603
|
+ target["new_" + target.id] = e.targetTouches ? e.targetTouches[0].screenY : e.pageY;
|
|
|
604
|
+ target["n_t_" + target.id] = (new Date()).getTime();
|
|
|
605
|
+ //var f = (target["new_" + target.id] - target["old_" + target.id]) * 18 / target.clientHeight;
|
|
|
606
|
+ var f = (target["new_" + target.id] - target["old_" + target.id]) * 18 / 370;
|
|
|
607
|
+ target["pos_" + target.id] = target["o_d_" + target.id] + f;
|
|
|
608
|
+ target.style["-webkit-transform"] = 'translate3d(0,' + target["pos_" + target.id] + 'em,0)';
|
|
|
609
|
+ target.setAttribute('top', target["pos_" + target.id] + 'em');
|
|
|
610
|
+ }
|
|
|
611
|
+ //离开屏幕
|
|
|
612
|
+ function gearTouchEnd(e) {
|
|
|
613
|
+ if (!isTouched || !isMoved) {
|
|
|
614
|
+ isTouched = isMoved = false;
|
|
|
615
|
+ return;
|
|
|
616
|
+ }
|
|
|
617
|
+ isTouched = isMoved = false;
|
|
|
618
|
+ e.preventDefault();
|
|
|
619
|
+ if(pree) var target = pree.target; else
|
|
|
620
|
+ var target = e.target;
|
|
|
621
|
+ while (true) {
|
|
|
622
|
+ if (!target.classList.contains("gear")) {
|
|
|
623
|
+ target = target.parentElement;
|
|
|
624
|
+ } else {
|
|
|
625
|
+ break;
|
|
|
626
|
+ }
|
|
|
627
|
+ }
|
|
|
628
|
+ var flag = (target["new_" + target.id] - target["old_" + target.id]) / (target["n_t_" + target.id] - target["o_t_" + target.id]);
|
|
|
629
|
+ if (Math.abs(flag) <= 0.2) {
|
|
|
630
|
+ target["spd_" + target.id] = (flag < 0 ? -0.08 : 0.08);
|
|
|
631
|
+ } else {
|
|
|
632
|
+ if (Math.abs(flag) <= 0.5) {
|
|
|
633
|
+ target["spd_" + target.id] = (flag < 0 ? -0.16 : 0.16);
|
|
|
634
|
+ } else {
|
|
|
635
|
+ target["spd_" + target.id] = flag / 2;
|
|
|
636
|
+ }
|
|
|
637
|
+ }
|
|
|
638
|
+ if (!target["pos_" + target.id]) {
|
|
|
639
|
+ target["pos_" + target.id] = 0;
|
|
|
640
|
+ }
|
|
|
641
|
+ rollGear(target);
|
|
|
642
|
+ pree=null;
|
|
|
643
|
+ };
|
|
|
644
|
+ //离开区域
|
|
|
645
|
+ function gearTouchOut(e) {
|
|
|
646
|
+ gearTouchEnd(pree);
|
|
|
647
|
+ };
|
|
|
648
|
+ //缓动效果
|
|
|
649
|
+ function rollGear(target) {
|
|
|
650
|
+ var d = 0;
|
|
|
651
|
+ var stopGear = false;
|
|
|
652
|
+ var passY = _self.maxY - _self.minY + 1;
|
|
|
653
|
+ clearInterval(target["int_" + target.id]);
|
|
|
654
|
+ target["int_" + target.id] = setInterval(function() {
|
|
|
655
|
+ var pos = target["pos_" + target.id];
|
|
|
656
|
+ var speed = target["spd_" + target.id] * Math.exp(-0.1 * d);
|
|
|
657
|
+ pos += speed;
|
|
|
658
|
+ if (Math.abs(speed) > 0.1) {} else {
|
|
|
659
|
+ speed = 0.1;
|
|
|
660
|
+ var b = Math.round(pos / 2) * 2;
|
|
|
661
|
+ if (Math.abs(pos - b) < 0.05) {
|
|
|
662
|
+ stopGear = true;
|
|
|
663
|
+ } else {
|
|
|
664
|
+ if (pos > b) {
|
|
|
665
|
+ pos -= speed
|
|
|
666
|
+ } else {
|
|
|
667
|
+ pos += speed
|
|
|
668
|
+ }
|
|
|
669
|
+ }
|
|
|
670
|
+ }
|
|
|
671
|
+ if (pos > 8) {
|
|
|
672
|
+ pos = 8;
|
|
|
673
|
+ stopGear = true;
|
|
|
674
|
+ }
|
|
|
675
|
+ switch (target.dataset.datetype) {
|
|
|
676
|
+ case "date_yy":
|
|
|
677
|
+ var minTop = 8 - (passY - 1) * 2;
|
|
|
678
|
+ if (pos < minTop) {
|
|
|
679
|
+ pos = minTop;
|
|
|
680
|
+ stopGear = true;
|
|
|
681
|
+ }
|
|
|
682
|
+ if (stopGear) {
|
|
|
683
|
+ var gearVal = Math.abs(pos - 8) / 2;
|
|
|
684
|
+ setGear(target, gearVal);
|
|
|
685
|
+ clearInterval(target["int_" + target.id]);
|
|
|
686
|
+ }
|
|
|
687
|
+ break;
|
|
|
688
|
+ case "date_mm":
|
|
|
689
|
+ var date_yy = _self.gearDate.querySelector(".date_yy");
|
|
|
690
|
+ //得到年份的值
|
|
|
691
|
+ var yyVal = parseInt(date_yy.getAttribute("val"));
|
|
|
692
|
+ var maxM = 11;
|
|
|
693
|
+ var minM = 0;
|
|
|
694
|
+ //当年份到达最大值
|
|
|
695
|
+ if (yyVal == passY - 1) {
|
|
|
696
|
+ maxM = _self.maxM - 1;
|
|
|
697
|
+ }
|
|
|
698
|
+ //当年份到达最小值
|
|
|
699
|
+ if (yyVal == 0) {
|
|
|
700
|
+ minM = _self.minM - 1;
|
|
|
701
|
+ }
|
|
|
702
|
+ var minTop = 8 - (maxM - minM) * 2;
|
|
|
703
|
+ if (pos < minTop) {
|
|
|
704
|
+ pos = minTop;
|
|
|
705
|
+ stopGear = true;
|
|
|
706
|
+ }
|
|
|
707
|
+ if (stopGear) {
|
|
|
708
|
+ var gearVal = Math.abs(pos - 8) / 2 + minM;
|
|
|
709
|
+ setGear(target, gearVal);
|
|
|
710
|
+ clearInterval(target["int_" + target.id]);
|
|
|
711
|
+ }
|
|
|
712
|
+ break;
|
|
|
713
|
+ case "date_dd":
|
|
|
714
|
+ var date_yy = _self.gearDate.querySelector(".date_yy");
|
|
|
715
|
+ var date_mm = _self.gearDate.querySelector(".date_mm");
|
|
|
716
|
+ //得到年份的值
|
|
|
717
|
+ var yyVal = parseInt(date_yy.getAttribute("val"));
|
|
|
718
|
+ //得到月份的值
|
|
|
719
|
+ var mmVal = parseInt(date_mm.getAttribute("val"));
|
|
|
720
|
+ //返回月份的天数
|
|
|
721
|
+ var maxMonthDays = calcDays(yyVal, mmVal);
|
|
|
722
|
+ var maxD = maxMonthDays - 1;
|
|
|
723
|
+ var minD = 0;
|
|
|
724
|
+ //当年份月份到达最大值
|
|
|
725
|
+ if (yyVal == passY - 1 && _self.maxM == mmVal + 1) {
|
|
|
726
|
+ maxD = _self.maxD - 1;
|
|
|
727
|
+ }
|
|
|
728
|
+ //当年、月到达最小值
|
|
|
729
|
+ if (yyVal == 0 && _self.minM == mmVal + 1) {
|
|
|
730
|
+ minD = _self.minD - 1;
|
|
|
731
|
+ }
|
|
|
732
|
+ var minTop = 8 - (maxD - minD) * 2;
|
|
|
733
|
+ if (pos < minTop) {
|
|
|
734
|
+ pos = minTop;
|
|
|
735
|
+ stopGear = true;
|
|
|
736
|
+ }
|
|
|
737
|
+ if (stopGear) {
|
|
|
738
|
+ var gearVal = Math.abs(pos - 8) / 2 + minD;
|
|
|
739
|
+ setGear(target, gearVal);
|
|
|
740
|
+ clearInterval(target["int_" + target.id]);
|
|
|
741
|
+ }
|
|
|
742
|
+ break;
|
|
|
743
|
+ case "time_hh":
|
|
|
744
|
+ if (pos < -38) {
|
|
|
745
|
+ pos = -38;
|
|
|
746
|
+ stopGear = true;
|
|
|
747
|
+ }
|
|
|
748
|
+ if (stopGear) {
|
|
|
749
|
+ var gearVal = Math.abs(pos - 8) / 2;
|
|
|
750
|
+ setGear(target, gearVal);
|
|
|
751
|
+ clearInterval(target["int_" + target.id]);
|
|
|
752
|
+ }
|
|
|
753
|
+ break;
|
|
|
754
|
+ case "time_mm":
|
|
|
755
|
+ if (pos < -110) {
|
|
|
756
|
+ pos = -110;
|
|
|
757
|
+ stopGear = true;
|
|
|
758
|
+ }
|
|
|
759
|
+ if (stopGear) {
|
|
|
760
|
+ var gearVal = Math.abs(pos - 8) / 2;
|
|
|
761
|
+ setGear(target, gearVal);
|
|
|
762
|
+ clearInterval(target["int_" + target.id]);
|
|
|
763
|
+ }
|
|
|
764
|
+ break;
|
|
|
765
|
+ default:
|
|
|
766
|
+ }
|
|
|
767
|
+ target["pos_" + target.id] = pos;
|
|
|
768
|
+ target.style["-webkit-transform"] = 'translate3d(0,' + pos + 'em,0)';
|
|
|
769
|
+ target.setAttribute('top', pos + 'em');
|
|
|
770
|
+ d++;
|
|
|
771
|
+ }, 30);
|
|
|
772
|
+ }
|
|
|
773
|
+ //控制插件滚动后停留的值
|
|
|
774
|
+ function setGear(target, val) {
|
|
|
775
|
+ val = Math.round(val);
|
|
|
776
|
+ target.setAttribute("val", val);
|
|
|
777
|
+ if (/date/.test(target.dataset.datetype)) {
|
|
|
778
|
+ setDateGearTooth();
|
|
|
779
|
+ } else {
|
|
|
780
|
+ setTimeGearTooth();
|
|
|
781
|
+ }
|
|
|
782
|
+ }
|
|
|
783
|
+ //取消
|
|
|
784
|
+ function closeMobileCalendar(e) {
|
|
|
785
|
+ e.preventDefault();
|
|
|
786
|
+ isTouched = isMoved = false;
|
|
|
787
|
+ if(_self.onClose) _self.onClose();
|
|
|
788
|
+ var evt = new CustomEvent('input');
|
|
|
789
|
+ _self.trigger.dispatchEvent(evt);
|
|
|
790
|
+ document.body.removeChild(_self.gearDate);
|
|
|
791
|
+ }
|
|
|
792
|
+ //日期确认
|
|
|
793
|
+ function finishMobileDate(e) {
|
|
|
794
|
+ var passY = _self.maxY - _self.minY + 1;
|
|
|
795
|
+ var date_yy = parseInt(Math.round(_self.gearDate.querySelector(".date_yy").getAttribute("val")));
|
|
|
796
|
+ var date_mm = parseInt(Math.round(_self.gearDate.querySelector(".date_mm").getAttribute("val"))) + 1;
|
|
|
797
|
+ date_mm = date_mm > 9 ? date_mm : '0' + date_mm;
|
|
|
798
|
+ var date_dd = parseInt(Math.round(_self.gearDate.querySelector(".date_dd").getAttribute("val"))) + 1;
|
|
|
799
|
+ date_dd = date_dd > 9 ? date_dd : '0' + date_dd;
|
|
|
800
|
+ _self.trigger.value = (date_yy % passY + _self.minY) + "-" + date_mm + "-" + date_dd;
|
|
|
801
|
+ _self.value = _self.trigger.value;
|
|
|
802
|
+ if(_self.onSubmit) _self.onSubmit();
|
|
|
803
|
+ closeMobileCalendar(e);
|
|
|
804
|
+ }
|
|
|
805
|
+ //年月确认
|
|
|
806
|
+ function finishMobileYM(e) {
|
|
|
807
|
+ var passY = _self.maxY - _self.minY + 1;
|
|
|
808
|
+ var date_yy = parseInt(Math.round(_self.gearDate.querySelector(".date_yy").getAttribute("val")));
|
|
|
809
|
+ var date_mm = parseInt(Math.round(_self.gearDate.querySelector(".date_mm").getAttribute("val"))) + 1;
|
|
|
810
|
+ date_mm = date_mm > 9 ? date_mm : '0' + date_mm;
|
|
|
811
|
+ _self.trigger.value = (date_yy % passY + _self.minY) + "-" + date_mm;
|
|
|
812
|
+ _self.value = _self.trigger.value;
|
|
|
813
|
+ if(_self.onSubmit) _self.onSubmit();
|
|
|
814
|
+ closeMobileCalendar(e);
|
|
|
815
|
+ }
|
|
|
816
|
+ //日期时间确认
|
|
|
817
|
+ function finishMobileDateTime(e) {
|
|
|
818
|
+ var passY = _self.maxY - _self.minY + 1;
|
|
|
819
|
+ var date_yy = parseInt(Math.round(_self.gearDate.querySelector(".date_yy").getAttribute("val")));
|
|
|
820
|
+ var date_mm = parseInt(Math.round(_self.gearDate.querySelector(".date_mm").getAttribute("val"))) + 1;
|
|
|
821
|
+ date_mm = date_mm > 9 ? date_mm : '0' + date_mm;
|
|
|
822
|
+ var date_dd = parseInt(Math.round(_self.gearDate.querySelector(".date_dd").getAttribute("val"))) + 1;
|
|
|
823
|
+ date_dd = date_dd > 9 ? date_dd : '0' + date_dd;
|
|
|
824
|
+ var time_hh = parseInt(Math.round(_self.gearDate.querySelector(".time_hh").getAttribute("val")));
|
|
|
825
|
+ time_hh = time_hh > 9 ? time_hh : '0' + time_hh;
|
|
|
826
|
+ var time_mm = parseInt(Math.round(_self.gearDate.querySelector(".time_mm").getAttribute("val")));
|
|
|
827
|
+ time_mm = time_mm > 9 ? time_mm : '0' + time_mm;
|
|
|
828
|
+ _self.trigger.value = (date_yy % passY + _self.minY) + "-" + date_mm + "-" + date_dd + " " + (time_hh.length < 2 ? "0" : "") + time_hh + (time_mm.length < 2 ? ":0" : ":") + time_mm;
|
|
|
829
|
+ _self.value = _self.trigger.value;
|
|
|
830
|
+ if(_self.onSubmit) _self.onSubmit();
|
|
|
831
|
+ closeMobileCalendar(e);
|
|
|
832
|
+ }
|
|
|
833
|
+ //时间确认
|
|
|
834
|
+ function finishMobileTime(e) {
|
|
|
835
|
+ var time_hh = parseInt(Math.round(_self.gearDate.querySelector(".time_hh").getAttribute("val")));
|
|
|
836
|
+ time_hh = time_hh > 9 ? time_hh : '0' + time_hh;
|
|
|
837
|
+ var time_mm = parseInt(Math.round(_self.gearDate.querySelector(".time_mm").getAttribute("val")));
|
|
|
838
|
+ time_mm = time_mm > 9 ? time_mm : '0' + time_mm;
|
|
|
839
|
+ _self.trigger.value = (time_hh.length < 2 ? "0" : "") + time_hh + (time_mm.length < 2 ? ":0" : ":") + time_mm;
|
|
|
840
|
+ _self.value = _self.trigger.value;
|
|
|
841
|
+ if(_self.onSubmit) _self.onSubmit();
|
|
|
842
|
+ closeMobileCalendar(e);
|
|
|
843
|
+ }
|
|
|
844
|
+ _self.trigger.addEventListener('click', {
|
|
|
845
|
+ "ym": popupYM,
|
|
|
846
|
+ "date": popupDate,
|
|
|
847
|
+ "datetime": popupDateTime,
|
|
|
848
|
+ "time": popupTime
|
|
|
849
|
+ }[type]);
|
|
|
850
|
+ }
|
|
|
851
|
+ }
|
|
|
852
|
+ return MobileCalendar;
|
|
|
853
|
+})(); |