jquery.calendar.js
10.5 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/**
* jQuery EasyUI 1.5
*
* Copyright (c) 2009-2016 www.jeasyui.com. All rights reserved.
*
* Licensed under the freeware license: http://www.jeasyui.com/license_freeware.php
* To use it on other terms please contact us: info@jeasyui.com
*
*/
(function($){
function _1(_2,_3){
var _4=$.data(_2,"calendar").options;
var t=$(_2);
if(_3){
$.extend(_4,{width:_3.width,height:_3.height});
}
t._size(_4,t.parent());
t.find(".calendar-body")._outerHeight(t.height()-t.find(".calendar-header")._outerHeight());
if(t.find(".calendar-menu").is(":visible")){
_5(_2);
}
};
function _6(_7){
$(_7).addClass("calendar").html("<div class=\"calendar-header\">"+"<div class=\"calendar-nav calendar-prevmonth\"></div>"+"<div class=\"calendar-nav calendar-nextmonth\"></div>"+"<div class=\"calendar-nav calendar-prevyear\"></div>"+"<div class=\"calendar-nav calendar-nextyear\"></div>"+"<div class=\"calendar-title\">"+"<span class=\"calendar-text\"></span>"+"</div>"+"</div>"+"<div class=\"calendar-body\">"+"<div class=\"calendar-menu\">"+"<div class=\"calendar-menu-year-inner\">"+"<span class=\"calendar-nav calendar-menu-prev\"></span>"+"<span><input class=\"calendar-menu-year\" type=\"text\"></input></span>"+"<span class=\"calendar-nav calendar-menu-next\"></span>"+"</div>"+"<div class=\"calendar-menu-month-inner\">"+"</div>"+"</div>"+"</div>");
$(_7).bind("_resize",function(e,_8){
if($(this).hasClass("easyui-fluid")||_8){
_1(_7);
}
return false;
});
};
function _9(_a){
var _b=$.data(_a,"calendar").options;
var _c=$(_a).find(".calendar-menu");
_c.find(".calendar-menu-year").unbind(".calendar").bind("keypress.calendar",function(e){
if(e.keyCode==13){
_d(true);
}
});
$(_a).unbind(".calendar").bind("mouseover.calendar",function(e){
var t=_e(e.target);
if(t.hasClass("calendar-nav")||t.hasClass("calendar-text")||(t.hasClass("calendar-day")&&!t.hasClass("calendar-disabled"))){
t.addClass("calendar-nav-hover");
}
}).bind("mouseout.calendar",function(e){
var t=_e(e.target);
if(t.hasClass("calendar-nav")||t.hasClass("calendar-text")||(t.hasClass("calendar-day")&&!t.hasClass("calendar-disabled"))){
t.removeClass("calendar-nav-hover");
}
}).bind("click.calendar",function(e){
var t=_e(e.target);
if(t.hasClass("calendar-menu-next")||t.hasClass("calendar-nextyear")){
_f(1);
}else{
if(t.hasClass("calendar-menu-prev")||t.hasClass("calendar-prevyear")){
_f(-1);
}else{
if(t.hasClass("calendar-menu-month")){
_c.find(".calendar-selected").removeClass("calendar-selected");
t.addClass("calendar-selected");
_d(true);
}else{
if(t.hasClass("calendar-prevmonth")){
_10(-1);
}else{
if(t.hasClass("calendar-nextmonth")){
_10(1);
}else{
if(t.hasClass("calendar-text")){
if(_c.is(":visible")){
_c.hide();
}else{
_5(_a);
}
}else{
if(t.hasClass("calendar-day")){
if(t.hasClass("calendar-disabled")){
return;
}
var _11=_b.current;
t.closest("div.calendar-body").find(".calendar-selected").removeClass("calendar-selected");
t.addClass("calendar-selected");
var _12=t.attr("abbr").split(",");
var y=parseInt(_12[0]);
var m=parseInt(_12[1]);
var d=parseInt(_12[2]);
_b.current=new Date(y,m-1,d);
_b.onSelect.call(_a,_b.current);
if(!_11||_11.getTime()!=_b.current.getTime()){
_b.onChange.call(_a,_b.current,_11);
}
if(_b.year!=y||_b.month!=m){
_b.year=y;
_b.month=m;
_19(_a);
}
}
}
}
}
}
}
}
});
function _e(t){
var day=$(t).closest(".calendar-day");
if(day.length){
return day;
}else{
return $(t);
}
};
function _d(_13){
var _14=$(_a).find(".calendar-menu");
var _15=_14.find(".calendar-menu-year").val();
var _16=_14.find(".calendar-selected").attr("abbr");
if(!isNaN(_15)){
_b.year=parseInt(_15);
_b.month=parseInt(_16);
_19(_a);
}
if(_13){
_14.hide();
}
};
function _f(_17){
_b.year+=_17;
_19(_a);
_c.find(".calendar-menu-year").val(_b.year);
};
function _10(_18){
_b.month+=_18;
if(_b.month>12){
_b.year++;
_b.month=1;
}else{
if(_b.month<1){
_b.year--;
_b.month=12;
}
}
_19(_a);
_c.find("td.calendar-selected").removeClass("calendar-selected");
_c.find("td:eq("+(_b.month-1)+")").addClass("calendar-selected");
};
};
function _5(_1a){
var _1b=$.data(_1a,"calendar").options;
$(_1a).find(".calendar-menu").show();
if($(_1a).find(".calendar-menu-month-inner").is(":empty")){
$(_1a).find(".calendar-menu-month-inner").empty();
var t=$("<table class=\"calendar-mtable\"></table>").appendTo($(_1a).find(".calendar-menu-month-inner"));
var idx=0;
for(var i=0;i<3;i++){
var tr=$("<tr></tr>").appendTo(t);
for(var j=0;j<4;j++){
$("<td class=\"calendar-nav calendar-menu-month\"></td>").html(_1b.months[idx++]).attr("abbr",idx).appendTo(tr);
}
}
}
var _1c=$(_1a).find(".calendar-body");
var _1d=$(_1a).find(".calendar-menu");
var _1e=_1d.find(".calendar-menu-year-inner");
var _1f=_1d.find(".calendar-menu-month-inner");
_1e.find("input").val(_1b.year).focus();
_1f.find("td.calendar-selected").removeClass("calendar-selected");
_1f.find("td:eq("+(_1b.month-1)+")").addClass("calendar-selected");
_1d._outerWidth(_1c._outerWidth());
_1d._outerHeight(_1c._outerHeight());
_1f._outerHeight(_1d.height()-_1e._outerHeight());
};
function _20(_21,_22,_23){
var _24=$.data(_21,"calendar").options;
var _25=[];
var _26=new Date(_22,_23,0).getDate();
for(var i=1;i<=_26;i++){
_25.push([_22,_23,i]);
}
var _27=[],_28=[];
var _29=-1;
while(_25.length>0){
var _2a=_25.shift();
_28.push(_2a);
var day=new Date(_2a[0],_2a[1]-1,_2a[2]).getDay();
if(_29==day){
day=0;
}else{
if(day==(_24.firstDay==0?7:_24.firstDay)-1){
_27.push(_28);
_28=[];
}
}
_29=day;
}
if(_28.length){
_27.push(_28);
}
var _2b=_27[0];
if(_2b.length<7){
while(_2b.length<7){
var _2c=_2b[0];
var _2a=new Date(_2c[0],_2c[1]-1,_2c[2]-1);
_2b.unshift([_2a.getFullYear(),_2a.getMonth()+1,_2a.getDate()]);
}
}else{
var _2c=_2b[0];
var _28=[];
for(var i=1;i<=7;i++){
var _2a=new Date(_2c[0],_2c[1]-1,_2c[2]-i);
_28.unshift([_2a.getFullYear(),_2a.getMonth()+1,_2a.getDate()]);
}
_27.unshift(_28);
}
var _2d=_27[_27.length-1];
while(_2d.length<7){
var _2e=_2d[_2d.length-1];
var _2a=new Date(_2e[0],_2e[1]-1,_2e[2]+1);
_2d.push([_2a.getFullYear(),_2a.getMonth()+1,_2a.getDate()]);
}
if(_27.length<6){
var _2e=_2d[_2d.length-1];
var _28=[];
for(var i=1;i<=7;i++){
var _2a=new Date(_2e[0],_2e[1]-1,_2e[2]+i);
_28.push([_2a.getFullYear(),_2a.getMonth()+1,_2a.getDate()]);
}
_27.push(_28);
}
return _27;
};
function _19(_2f){
var _30=$.data(_2f,"calendar").options;
if(_30.current&&!_30.validator.call(_2f,_30.current)){
_30.current=null;
}
var now=new Date();
var _31=now.getFullYear()+","+(now.getMonth()+1)+","+now.getDate();
var _32=_30.current?(_30.current.getFullYear()+","+(_30.current.getMonth()+1)+","+_30.current.getDate()):"";
var _33=6-_30.firstDay;
var _34=_33+1;
if(_33>=7){
_33-=7;
}
if(_34>=7){
_34-=7;
}
$(_2f).find(".calendar-title span").html(_30.months[_30.month-1]+" "+_30.year);
var _35=$(_2f).find("div.calendar-body");
_35.children("table").remove();
var _36=["<table class=\"calendar-dtable\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">"];
_36.push("<thead><tr>");
if(_30.showWeek){
_36.push("<th class=\"calendar-week\">"+_30.weekNumberHeader+"</th>");
}
for(var i=_30.firstDay;i<_30.weeks.length;i++){
_36.push("<th>"+_30.weeks[i]+"</th>");
}
for(var i=0;i<_30.firstDay;i++){
_36.push("<th>"+_30.weeks[i]+"</th>");
}
_36.push("</tr></thead>");
_36.push("<tbody>");
var _37=_20(_2f,_30.year,_30.month);
for(var i=0;i<_37.length;i++){
var _38=_37[i];
var cls="";
if(i==0){
cls="calendar-first";
}else{
if(i==_37.length-1){
cls="calendar-last";
}
}
_36.push("<tr class=\""+cls+"\">");
if(_30.showWeek){
var _39=_30.getWeekNumber(new Date(_38[0][0],parseInt(_38[0][1])-1,_38[0][2]));
_36.push("<td class=\"calendar-week\">"+_39+"</td>");
}
for(var j=0;j<_38.length;j++){
var day=_38[j];
var s=day[0]+","+day[1]+","+day[2];
var _3a=new Date(day[0],parseInt(day[1])-1,day[2]);
var d=_30.formatter.call(_2f,_3a);
var css=_30.styler.call(_2f,_3a);
var _3b="";
var _3c="";
if(typeof css=="string"){
_3c=css;
}else{
if(css){
_3b=css["class"]||"";
_3c=css["style"]||"";
}
}
var cls="calendar-day";
if(!(_30.year==day[0]&&_30.month==day[1])){
cls+=" calendar-other-month";
}
if(s==_31){
cls+=" calendar-today";
}
if(s==_32){
cls+=" calendar-selected";
}
if(j==_33){
cls+=" calendar-saturday";
}else{
if(j==_34){
cls+=" calendar-sunday";
}
}
if(j==0){
cls+=" calendar-first";
}else{
if(j==_38.length-1){
cls+=" calendar-last";
}
}
cls+=" "+_3b;
if(!_30.validator.call(_2f,_3a)){
cls+=" calendar-disabled";
}
_36.push("<td class=\""+cls+"\" abbr=\""+s+"\" style=\""+_3c+"\">"+d+"</td>");
}
_36.push("</tr>");
}
_36.push("</tbody>");
_36.push("</table>");
_35.append(_36.join(""));
_35.children("table.calendar-dtable").prependTo(_35);
_30.onNavigate.call(_2f,_30.year,_30.month);
};
$.fn.calendar=function(_3d,_3e){
if(typeof _3d=="string"){
return $.fn.calendar.methods[_3d](this,_3e);
}
_3d=_3d||{};
return this.each(function(){
var _3f=$.data(this,"calendar");
if(_3f){
$.extend(_3f.options,_3d);
}else{
_3f=$.data(this,"calendar",{options:$.extend({},$.fn.calendar.defaults,$.fn.calendar.parseOptions(this),_3d)});
_6(this);
}
if(_3f.options.border==false){
$(this).addClass("calendar-noborder");
}
_1(this);
_9(this);
_19(this);
$(this).find("div.calendar-menu").hide();
});
};
$.fn.calendar.methods={options:function(jq){
return $.data(jq[0],"calendar").options;
},resize:function(jq,_40){
return jq.each(function(){
_1(this,_40);
});
},moveTo:function(jq,_41){
return jq.each(function(){
if(!_41){
var now=new Date();
$(this).calendar({year:now.getFullYear(),month:now.getMonth()+1,current:_41});
return;
}
var _42=$(this).calendar("options");
if(_42.validator.call(this,_41)){
var _43=_42.current;
$(this).calendar({year:_41.getFullYear(),month:_41.getMonth()+1,current:_41});
if(!_43||_43.getTime()!=_41.getTime()){
_42.onChange.call(this,_42.current,_43);
}
}
});
}};
$.fn.calendar.parseOptions=function(_44){
var t=$(_44);
return $.extend({},$.parser.parseOptions(_44,["weekNumberHeader",{firstDay:"number",fit:"boolean",border:"boolean",showWeek:"boolean"}]));
};
$.fn.calendar.defaults={width:180,height:180,fit:false,border:true,showWeek:false,firstDay:0,weeks:["S","M","T","W","T","F","S"],months:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],year:new Date().getFullYear(),month:new Date().getMonth()+1,current:(function(){
var d=new Date();
return new Date(d.getFullYear(),d.getMonth(),d.getDate());
})(),weekNumberHeader:"",getWeekNumber:function(_45){
var _46=new Date(_45.getTime());
_46.setDate(_46.getDate()+4-(_46.getDay()||7));
var _47=_46.getTime();
_46.setMonth(0);
_46.setDate(1);
return Math.floor(Math.round((_47-_46)/86400000)/7)+1;
},formatter:function(_48){
return _48.getDate();
},styler:function(_49){
return "";
},validator:function(_4a){
return true;
},onSelect:function(_4b){
},onChange:function(_4c,_4d){
},onNavigate:function(_4e,_4f){
}};
})(jQuery);