happydatepicker 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +32 -0
- data/app/assets/images/happydatepicker/datepicker_b.png +0 -0
- data/app/assets/images/happydatepicker/datepicker_bl.png +0 -0
- data/app/assets/images/happydatepicker/datepicker_br.png +0 -0
- data/app/assets/images/happydatepicker/datepicker_l.png +0 -0
- data/app/assets/images/happydatepicker/datepicker_r.png +0 -0
- data/app/assets/images/happydatepicker/datepicker_t.png +0 -0
- data/app/assets/images/happydatepicker/datepicker_tl.png +0 -0
- data/app/assets/images/happydatepicker/datepicker_tr.png +0 -0
- data/app/assets/javascripts/happydatepicker/datepicker.js +891 -0
- data/app/assets/javascripts/happydatepicker/happydatepicker.js +20 -0
- data/app/assets/javascripts/happydatepicker/index.js +2 -0
- data/app/assets/stylesheets/happydatepicker/datepicker.css +192 -0
- data/app/assets/stylesheets/happydatepicker/index.css +3 -0
- data/lib/happydatepicker/engine.rb +4 -0
- data/lib/happydatepicker/version.rb +3 -0
- data/lib/happydatepicker.rb +2 -0
- metadata +64 -0
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Happydatepicker
|
2
|
+
|
3
|
+
A simple but ready-made datepicker for rails. Based upon http://www.eyecon.ro/datepicker
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'happydatepicker'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install happydatepicker
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
From within your coffeescript file just do as follows:
|
22
|
+
|
23
|
+
new HappyDatePicker($("#your_element"))
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
32
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,891 @@
|
|
1
|
+
/**
|
2
|
+
*
|
3
|
+
* Date picker
|
4
|
+
* Author: Stefan Petre www.eyecon.ro
|
5
|
+
*
|
6
|
+
* Dual licensed under the MIT and GPL licenses
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
(function ($) {
|
10
|
+
var DatePicker = function () {
|
11
|
+
var ids = {},
|
12
|
+
views = {
|
13
|
+
years: 'datepickerViewYears',
|
14
|
+
moths: 'datepickerViewMonths',
|
15
|
+
days: 'datepickerViewDays'
|
16
|
+
},
|
17
|
+
tpl = {
|
18
|
+
wrapper: '<div class="datepicker"><div class="datepickerBorderT" /><div class="datepickerBorderB" /><div class="datepickerBorderL" /><div class="datepickerBorderR" /><div class="datepickerBorderTL" /><div class="datepickerBorderTR" /><div class="datepickerBorderBL" /><div class="datepickerBorderBR" /><div class="datepickerContainer"><table cellspacing="0" cellpadding="0"><tbody><tr></tr></tbody></table></div></div>',
|
19
|
+
head: [
|
20
|
+
'<td>',
|
21
|
+
'<table cellspacing="0" cellpadding="0">',
|
22
|
+
'<thead>',
|
23
|
+
'<tr>',
|
24
|
+
'<th class="datepickerGoPrev"><a href="#"><span><%=prev%></span></a></th>',
|
25
|
+
'<th colspan="6" class="datepickerMonth"><a href="#"><span></span></a></th>',
|
26
|
+
'<th class="datepickerGoNext"><a href="#"><span><%=next%></span></a></th>',
|
27
|
+
'</tr>',
|
28
|
+
'<tr class="datepickerDoW">',
|
29
|
+
'<th><span><%=week%></span></th>',
|
30
|
+
'<th><span><%=day1%></span></th>',
|
31
|
+
'<th><span><%=day2%></span></th>',
|
32
|
+
'<th><span><%=day3%></span></th>',
|
33
|
+
'<th><span><%=day4%></span></th>',
|
34
|
+
'<th><span><%=day5%></span></th>',
|
35
|
+
'<th><span><%=day6%></span></th>',
|
36
|
+
'<th><span><%=day7%></span></th>',
|
37
|
+
'</tr>',
|
38
|
+
'</thead>',
|
39
|
+
'</table></td>'
|
40
|
+
],
|
41
|
+
space : '<td class="datepickerSpace"><div></div></td>',
|
42
|
+
days: [
|
43
|
+
'<tbody class="datepickerDays">',
|
44
|
+
'<tr>',
|
45
|
+
'<th class="datepickerWeek"><a href="#"><span><%=weeks[0].week%></span></a></th>',
|
46
|
+
'<td class="<%=weeks[0].days[0].classname%>"><a href="#"><span><%=weeks[0].days[0].text%></span></a></td>',
|
47
|
+
'<td class="<%=weeks[0].days[1].classname%>"><a href="#"><span><%=weeks[0].days[1].text%></span></a></td>',
|
48
|
+
'<td class="<%=weeks[0].days[2].classname%>"><a href="#"><span><%=weeks[0].days[2].text%></span></a></td>',
|
49
|
+
'<td class="<%=weeks[0].days[3].classname%>"><a href="#"><span><%=weeks[0].days[3].text%></span></a></td>',
|
50
|
+
'<td class="<%=weeks[0].days[4].classname%>"><a href="#"><span><%=weeks[0].days[4].text%></span></a></td>',
|
51
|
+
'<td class="<%=weeks[0].days[5].classname%>"><a href="#"><span><%=weeks[0].days[5].text%></span></a></td>',
|
52
|
+
'<td class="<%=weeks[0].days[6].classname%>"><a href="#"><span><%=weeks[0].days[6].text%></span></a></td>',
|
53
|
+
'</tr>',
|
54
|
+
'<tr>',
|
55
|
+
'<th class="datepickerWeek"><a href="#"><span><%=weeks[1].week%></span></a></th>',
|
56
|
+
'<td class="<%=weeks[1].days[0].classname%>"><a href="#"><span><%=weeks[1].days[0].text%></span></a></td>',
|
57
|
+
'<td class="<%=weeks[1].days[1].classname%>"><a href="#"><span><%=weeks[1].days[1].text%></span></a></td>',
|
58
|
+
'<td class="<%=weeks[1].days[2].classname%>"><a href="#"><span><%=weeks[1].days[2].text%></span></a></td>',
|
59
|
+
'<td class="<%=weeks[1].days[3].classname%>"><a href="#"><span><%=weeks[1].days[3].text%></span></a></td>',
|
60
|
+
'<td class="<%=weeks[1].days[4].classname%>"><a href="#"><span><%=weeks[1].days[4].text%></span></a></td>',
|
61
|
+
'<td class="<%=weeks[1].days[5].classname%>"><a href="#"><span><%=weeks[1].days[5].text%></span></a></td>',
|
62
|
+
'<td class="<%=weeks[1].days[6].classname%>"><a href="#"><span><%=weeks[1].days[6].text%></span></a></td>',
|
63
|
+
'</tr>',
|
64
|
+
'<tr>',
|
65
|
+
'<th class="datepickerWeek"><a href="#"><span><%=weeks[2].week%></span></a></th>',
|
66
|
+
'<td class="<%=weeks[2].days[0].classname%>"><a href="#"><span><%=weeks[2].days[0].text%></span></a></td>',
|
67
|
+
'<td class="<%=weeks[2].days[1].classname%>"><a href="#"><span><%=weeks[2].days[1].text%></span></a></td>',
|
68
|
+
'<td class="<%=weeks[2].days[2].classname%>"><a href="#"><span><%=weeks[2].days[2].text%></span></a></td>',
|
69
|
+
'<td class="<%=weeks[2].days[3].classname%>"><a href="#"><span><%=weeks[2].days[3].text%></span></a></td>',
|
70
|
+
'<td class="<%=weeks[2].days[4].classname%>"><a href="#"><span><%=weeks[2].days[4].text%></span></a></td>',
|
71
|
+
'<td class="<%=weeks[2].days[5].classname%>"><a href="#"><span><%=weeks[2].days[5].text%></span></a></td>',
|
72
|
+
'<td class="<%=weeks[2].days[6].classname%>"><a href="#"><span><%=weeks[2].days[6].text%></span></a></td>',
|
73
|
+
'</tr>',
|
74
|
+
'<tr>',
|
75
|
+
'<th class="datepickerWeek"><a href="#"><span><%=weeks[3].week%></span></a></th>',
|
76
|
+
'<td class="<%=weeks[3].days[0].classname%>"><a href="#"><span><%=weeks[3].days[0].text%></span></a></td>',
|
77
|
+
'<td class="<%=weeks[3].days[1].classname%>"><a href="#"><span><%=weeks[3].days[1].text%></span></a></td>',
|
78
|
+
'<td class="<%=weeks[3].days[2].classname%>"><a href="#"><span><%=weeks[3].days[2].text%></span></a></td>',
|
79
|
+
'<td class="<%=weeks[3].days[3].classname%>"><a href="#"><span><%=weeks[3].days[3].text%></span></a></td>',
|
80
|
+
'<td class="<%=weeks[3].days[4].classname%>"><a href="#"><span><%=weeks[3].days[4].text%></span></a></td>',
|
81
|
+
'<td class="<%=weeks[3].days[5].classname%>"><a href="#"><span><%=weeks[3].days[5].text%></span></a></td>',
|
82
|
+
'<td class="<%=weeks[3].days[6].classname%>"><a href="#"><span><%=weeks[3].days[6].text%></span></a></td>',
|
83
|
+
'</tr>',
|
84
|
+
'<tr>',
|
85
|
+
'<th class="datepickerWeek"><a href="#"><span><%=weeks[4].week%></span></a></th>',
|
86
|
+
'<td class="<%=weeks[4].days[0].classname%>"><a href="#"><span><%=weeks[4].days[0].text%></span></a></td>',
|
87
|
+
'<td class="<%=weeks[4].days[1].classname%>"><a href="#"><span><%=weeks[4].days[1].text%></span></a></td>',
|
88
|
+
'<td class="<%=weeks[4].days[2].classname%>"><a href="#"><span><%=weeks[4].days[2].text%></span></a></td>',
|
89
|
+
'<td class="<%=weeks[4].days[3].classname%>"><a href="#"><span><%=weeks[4].days[3].text%></span></a></td>',
|
90
|
+
'<td class="<%=weeks[4].days[4].classname%>"><a href="#"><span><%=weeks[4].days[4].text%></span></a></td>',
|
91
|
+
'<td class="<%=weeks[4].days[5].classname%>"><a href="#"><span><%=weeks[4].days[5].text%></span></a></td>',
|
92
|
+
'<td class="<%=weeks[4].days[6].classname%>"><a href="#"><span><%=weeks[4].days[6].text%></span></a></td>',
|
93
|
+
'</tr>',
|
94
|
+
'<tr>',
|
95
|
+
'<th class="datepickerWeek"><a href="#"><span><%=weeks[5].week%></span></a></th>',
|
96
|
+
'<td class="<%=weeks[5].days[0].classname%>"><a href="#"><span><%=weeks[5].days[0].text%></span></a></td>',
|
97
|
+
'<td class="<%=weeks[5].days[1].classname%>"><a href="#"><span><%=weeks[5].days[1].text%></span></a></td>',
|
98
|
+
'<td class="<%=weeks[5].days[2].classname%>"><a href="#"><span><%=weeks[5].days[2].text%></span></a></td>',
|
99
|
+
'<td class="<%=weeks[5].days[3].classname%>"><a href="#"><span><%=weeks[5].days[3].text%></span></a></td>',
|
100
|
+
'<td class="<%=weeks[5].days[4].classname%>"><a href="#"><span><%=weeks[5].days[4].text%></span></a></td>',
|
101
|
+
'<td class="<%=weeks[5].days[5].classname%>"><a href="#"><span><%=weeks[5].days[5].text%></span></a></td>',
|
102
|
+
'<td class="<%=weeks[5].days[6].classname%>"><a href="#"><span><%=weeks[5].days[6].text%></span></a></td>',
|
103
|
+
'</tr>',
|
104
|
+
'</tbody>'
|
105
|
+
],
|
106
|
+
months: [
|
107
|
+
'<tbody class="<%=className%>">',
|
108
|
+
'<tr>',
|
109
|
+
'<td colspan="2"><a href="#"><span><%=data[0]%></span></a></td>',
|
110
|
+
'<td colspan="2"><a href="#"><span><%=data[1]%></span></a></td>',
|
111
|
+
'<td colspan="2"><a href="#"><span><%=data[2]%></span></a></td>',
|
112
|
+
'<td colspan="2"><a href="#"><span><%=data[3]%></span></a></td>',
|
113
|
+
'</tr>',
|
114
|
+
'<tr>',
|
115
|
+
'<td colspan="2"><a href="#"><span><%=data[4]%></span></a></td>',
|
116
|
+
'<td colspan="2"><a href="#"><span><%=data[5]%></span></a></td>',
|
117
|
+
'<td colspan="2"><a href="#"><span><%=data[6]%></span></a></td>',
|
118
|
+
'<td colspan="2"><a href="#"><span><%=data[7]%></span></a></td>',
|
119
|
+
'</tr>',
|
120
|
+
'<tr>',
|
121
|
+
'<td colspan="2"><a href="#"><span><%=data[8]%></span></a></td>',
|
122
|
+
'<td colspan="2"><a href="#"><span><%=data[9]%></span></a></td>',
|
123
|
+
'<td colspan="2"><a href="#"><span><%=data[10]%></span></a></td>',
|
124
|
+
'<td colspan="2"><a href="#"><span><%=data[11]%></span></a></td>',
|
125
|
+
'</tr>',
|
126
|
+
'</tbody>'
|
127
|
+
]
|
128
|
+
},
|
129
|
+
defaults = {
|
130
|
+
flat: false,
|
131
|
+
starts: 1,
|
132
|
+
prev: '◀',
|
133
|
+
next: '▶',
|
134
|
+
lastSel: false,
|
135
|
+
mode: 'single',
|
136
|
+
view: 'days',
|
137
|
+
calendars: 1,
|
138
|
+
format: 'Y-m-d',
|
139
|
+
position: 'bottom',
|
140
|
+
eventName: 'click',
|
141
|
+
onRender: function(){return {};},
|
142
|
+
onChange: function(){return true;},
|
143
|
+
onShow: function(){return true;},
|
144
|
+
onBeforeShow: function(){return true;},
|
145
|
+
onHide: function(){return true;},
|
146
|
+
locale: {
|
147
|
+
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
148
|
+
daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
|
149
|
+
daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
|
150
|
+
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
151
|
+
monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
|
152
|
+
weekMin: 'wk'
|
153
|
+
}
|
154
|
+
},
|
155
|
+
fill = function(el) {
|
156
|
+
var options = $(el).data('datepicker');
|
157
|
+
var cal = $(el);
|
158
|
+
var currentCal = Math.floor(options.calendars/2), date, data, dow, month, cnt = 0, week, days, indic, indic2, html, tblCal;
|
159
|
+
cal.find('td>table tbody').remove();
|
160
|
+
for (var i = 0; i < options.calendars; i++) {
|
161
|
+
date = new Date(options.current);
|
162
|
+
date.addMonths(-currentCal + i);
|
163
|
+
tblCal = cal.find('table').eq(i+1);
|
164
|
+
switch (tblCal[0].className) {
|
165
|
+
case 'datepickerViewDays':
|
166
|
+
dow = formatDate(date, 'B, Y');
|
167
|
+
break;
|
168
|
+
case 'datepickerViewMonths':
|
169
|
+
dow = date.getFullYear();
|
170
|
+
break;
|
171
|
+
case 'datepickerViewYears':
|
172
|
+
dow = (date.getFullYear()-6) + ' - ' + (date.getFullYear()+5);
|
173
|
+
break;
|
174
|
+
}
|
175
|
+
tblCal.find('thead tr:first th:eq(1) span').text(dow);
|
176
|
+
dow = date.getFullYear()-6;
|
177
|
+
data = {
|
178
|
+
data: [],
|
179
|
+
className: 'datepickerYears'
|
180
|
+
}
|
181
|
+
for ( var j = 0; j < 12; j++) {
|
182
|
+
data.data.push(dow + j);
|
183
|
+
}
|
184
|
+
html = tmpl(tpl.months.join(''), data);
|
185
|
+
date.setDate(1);
|
186
|
+
data = {weeks:[], test: 10};
|
187
|
+
month = date.getMonth();
|
188
|
+
var dow = (date.getDay() - options.starts) % 7;
|
189
|
+
date.addDays(-(dow + (dow < 0 ? 7 : 0)));
|
190
|
+
week = -1;
|
191
|
+
cnt = 0;
|
192
|
+
while (cnt < 42) {
|
193
|
+
indic = parseInt(cnt/7,10);
|
194
|
+
indic2 = cnt%7;
|
195
|
+
if (!data.weeks[indic]) {
|
196
|
+
week = date.getWeekNumber();
|
197
|
+
data.weeks[indic] = {
|
198
|
+
week: week,
|
199
|
+
days: []
|
200
|
+
};
|
201
|
+
}
|
202
|
+
data.weeks[indic].days[indic2] = {
|
203
|
+
text: date.getDate(),
|
204
|
+
classname: []
|
205
|
+
};
|
206
|
+
if (month != date.getMonth()) {
|
207
|
+
data.weeks[indic].days[indic2].classname.push('datepickerNotInMonth');
|
208
|
+
}
|
209
|
+
if (date.getDay() == 0) {
|
210
|
+
data.weeks[indic].days[indic2].classname.push('datepickerSunday');
|
211
|
+
}
|
212
|
+
if (date.getDay() == 6) {
|
213
|
+
data.weeks[indic].days[indic2].classname.push('datepickerSaturday');
|
214
|
+
}
|
215
|
+
var fromUser = options.onRender(date);
|
216
|
+
var val = date.valueOf();
|
217
|
+
if (fromUser.selected || options.date == val || $.inArray(val, options.date) > -1 || (options.mode == 'range' && val >= options.date[0] && val <= options.date[1])) {
|
218
|
+
data.weeks[indic].days[indic2].classname.push('datepickerSelected');
|
219
|
+
}
|
220
|
+
if (fromUser.disabled) {
|
221
|
+
data.weeks[indic].days[indic2].classname.push('datepickerDisabled');
|
222
|
+
}
|
223
|
+
if (fromUser.className) {
|
224
|
+
data.weeks[indic].days[indic2].classname.push(fromUser.className);
|
225
|
+
}
|
226
|
+
data.weeks[indic].days[indic2].classname = data.weeks[indic].days[indic2].classname.join(' ');
|
227
|
+
cnt++;
|
228
|
+
date.addDays(1);
|
229
|
+
}
|
230
|
+
html = tmpl(tpl.days.join(''), data) + html;
|
231
|
+
data = {
|
232
|
+
data: options.locale.monthsShort,
|
233
|
+
className: 'datepickerMonths'
|
234
|
+
};
|
235
|
+
html = tmpl(tpl.months.join(''), data) + html;
|
236
|
+
tblCal.append(html);
|
237
|
+
}
|
238
|
+
},
|
239
|
+
parseDate = function (date, format) {
|
240
|
+
if (date.constructor == Date) {
|
241
|
+
return new Date(date);
|
242
|
+
}
|
243
|
+
var parts = date.split(/\W+/);
|
244
|
+
var against = format.split(/\W+/), d, m, y, h, min, now = new Date();
|
245
|
+
for (var i = 0; i < parts.length; i++) {
|
246
|
+
switch (against[i]) {
|
247
|
+
case 'd':
|
248
|
+
case 'e':
|
249
|
+
d = parseInt(parts[i],10);
|
250
|
+
break;
|
251
|
+
case 'm':
|
252
|
+
m = parseInt(parts[i], 10)-1;
|
253
|
+
break;
|
254
|
+
case 'Y':
|
255
|
+
case 'y':
|
256
|
+
y = parseInt(parts[i], 10);
|
257
|
+
y += y > 100 ? 0 : (y < 29 ? 2000 : 1900);
|
258
|
+
break;
|
259
|
+
case 'H':
|
260
|
+
case 'I':
|
261
|
+
case 'k':
|
262
|
+
case 'l':
|
263
|
+
h = parseInt(parts[i], 10);
|
264
|
+
break;
|
265
|
+
case 'P':
|
266
|
+
case 'p':
|
267
|
+
if (/pm/i.test(parts[i]) && h < 12) {
|
268
|
+
h += 12;
|
269
|
+
} else if (/am/i.test(parts[i]) && h >= 12) {
|
270
|
+
h -= 12;
|
271
|
+
}
|
272
|
+
break;
|
273
|
+
case 'M':
|
274
|
+
min = parseInt(parts[i], 10);
|
275
|
+
break;
|
276
|
+
}
|
277
|
+
}
|
278
|
+
return new Date(
|
279
|
+
y === undefined ? now.getFullYear() : y,
|
280
|
+
m === undefined ? now.getMonth() : m,
|
281
|
+
d === undefined ? now.getDate() : d,
|
282
|
+
h === undefined ? now.getHours() : h,
|
283
|
+
min === undefined ? now.getMinutes() : min,
|
284
|
+
0
|
285
|
+
);
|
286
|
+
},
|
287
|
+
formatDate = function(date, format) {
|
288
|
+
var m = date.getMonth();
|
289
|
+
var d = date.getDate();
|
290
|
+
var y = date.getFullYear();
|
291
|
+
var wn = date.getWeekNumber();
|
292
|
+
var w = date.getDay();
|
293
|
+
var s = {};
|
294
|
+
var hr = date.getHours();
|
295
|
+
var pm = (hr >= 12);
|
296
|
+
var ir = (pm) ? (hr - 12) : hr;
|
297
|
+
var dy = date.getDayOfYear();
|
298
|
+
if (ir == 0) {
|
299
|
+
ir = 12;
|
300
|
+
}
|
301
|
+
var min = date.getMinutes();
|
302
|
+
var sec = date.getSeconds();
|
303
|
+
var parts = format.split(''), part;
|
304
|
+
for ( var i = 0; i < parts.length; i++ ) {
|
305
|
+
part = parts[i];
|
306
|
+
switch (parts[i]) {
|
307
|
+
case 'a':
|
308
|
+
part = date.getDayName();
|
309
|
+
break;
|
310
|
+
case 'A':
|
311
|
+
part = date.getDayName(true);
|
312
|
+
break;
|
313
|
+
case 'b':
|
314
|
+
part = date.getMonthName();
|
315
|
+
break;
|
316
|
+
case 'B':
|
317
|
+
part = date.getMonthName(true);
|
318
|
+
break;
|
319
|
+
case 'C':
|
320
|
+
part = 1 + Math.floor(y / 100);
|
321
|
+
break;
|
322
|
+
case 'd':
|
323
|
+
part = (d < 10) ? ("0" + d) : d;
|
324
|
+
break;
|
325
|
+
case 'e':
|
326
|
+
part = d;
|
327
|
+
break;
|
328
|
+
case 'H':
|
329
|
+
part = (hr < 10) ? ("0" + hr) : hr;
|
330
|
+
break;
|
331
|
+
case 'I':
|
332
|
+
part = (ir < 10) ? ("0" + ir) : ir;
|
333
|
+
break;
|
334
|
+
case 'j':
|
335
|
+
part = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy;
|
336
|
+
break;
|
337
|
+
case 'k':
|
338
|
+
part = hr;
|
339
|
+
break;
|
340
|
+
case 'l':
|
341
|
+
part = ir;
|
342
|
+
break;
|
343
|
+
case 'm':
|
344
|
+
part = (m < 9) ? ("0" + (1+m)) : (1+m);
|
345
|
+
break;
|
346
|
+
case 'M':
|
347
|
+
part = (min < 10) ? ("0" + min) : min;
|
348
|
+
break;
|
349
|
+
case 'p':
|
350
|
+
case 'P':
|
351
|
+
part = pm ? "PM" : "AM";
|
352
|
+
break;
|
353
|
+
case 's':
|
354
|
+
part = Math.floor(date.getTime() / 1000);
|
355
|
+
break;
|
356
|
+
case 'S':
|
357
|
+
part = (sec < 10) ? ("0" + sec) : sec;
|
358
|
+
break;
|
359
|
+
case 'u':
|
360
|
+
part = w + 1;
|
361
|
+
break;
|
362
|
+
case 'w':
|
363
|
+
part = w;
|
364
|
+
break;
|
365
|
+
case 'y':
|
366
|
+
part = ('' + y).substr(2, 2);
|
367
|
+
break;
|
368
|
+
case 'Y':
|
369
|
+
part = y;
|
370
|
+
break;
|
371
|
+
}
|
372
|
+
parts[i] = part;
|
373
|
+
}
|
374
|
+
return parts.join('');
|
375
|
+
},
|
376
|
+
extendDate = function(options) {
|
377
|
+
if (Date.prototype.tempDate) {
|
378
|
+
return;
|
379
|
+
}
|
380
|
+
Date.prototype.tempDate = null;
|
381
|
+
Date.prototype.months = options.months;
|
382
|
+
Date.prototype.monthsShort = options.monthsShort;
|
383
|
+
Date.prototype.days = options.days;
|
384
|
+
Date.prototype.daysShort = options.daysShort;
|
385
|
+
Date.prototype.getMonthName = function(fullName) {
|
386
|
+
return this[fullName ? 'months' : 'monthsShort'][this.getMonth()];
|
387
|
+
};
|
388
|
+
Date.prototype.getDayName = function(fullName) {
|
389
|
+
return this[fullName ? 'days' : 'daysShort'][this.getDay()];
|
390
|
+
};
|
391
|
+
Date.prototype.addDays = function (n) {
|
392
|
+
this.setDate(this.getDate() + n);
|
393
|
+
this.tempDate = this.getDate();
|
394
|
+
};
|
395
|
+
Date.prototype.addMonths = function (n) {
|
396
|
+
if (this.tempDate == null) {
|
397
|
+
this.tempDate = this.getDate();
|
398
|
+
}
|
399
|
+
this.setDate(1);
|
400
|
+
this.setMonth(this.getMonth() + n);
|
401
|
+
this.setDate(Math.min(this.tempDate, this.getMaxDays()));
|
402
|
+
};
|
403
|
+
Date.prototype.addYears = function (n) {
|
404
|
+
if (this.tempDate == null) {
|
405
|
+
this.tempDate = this.getDate();
|
406
|
+
}
|
407
|
+
this.setDate(1);
|
408
|
+
this.setFullYear(this.getFullYear() + n);
|
409
|
+
this.setDate(Math.min(this.tempDate, this.getMaxDays()));
|
410
|
+
};
|
411
|
+
Date.prototype.getMaxDays = function() {
|
412
|
+
var tmpDate = new Date(Date.parse(this)),
|
413
|
+
d = 28, m;
|
414
|
+
m = tmpDate.getMonth();
|
415
|
+
d = 28;
|
416
|
+
while (tmpDate.getMonth() == m) {
|
417
|
+
d ++;
|
418
|
+
tmpDate.setDate(d);
|
419
|
+
}
|
420
|
+
return d - 1;
|
421
|
+
};
|
422
|
+
Date.prototype.getFirstDay = function() {
|
423
|
+
var tmpDate = new Date(Date.parse(this));
|
424
|
+
tmpDate.setDate(1);
|
425
|
+
return tmpDate.getDay();
|
426
|
+
};
|
427
|
+
Date.prototype.getWeekNumber = function() {
|
428
|
+
var tempDate = new Date(this);
|
429
|
+
tempDate.setDate(tempDate.getDate() - (tempDate.getDay() + 6) % 7 + 3);
|
430
|
+
var dms = tempDate.valueOf();
|
431
|
+
tempDate.setMonth(0);
|
432
|
+
tempDate.setDate(4);
|
433
|
+
return Math.round((dms - tempDate.valueOf()) / (604800000)) + 1;
|
434
|
+
};
|
435
|
+
Date.prototype.getDayOfYear = function() {
|
436
|
+
var now = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
|
437
|
+
var then = new Date(this.getFullYear(), 0, 0, 0, 0, 0);
|
438
|
+
var time = now - then;
|
439
|
+
return Math.floor(time / 24*60*60*1000);
|
440
|
+
};
|
441
|
+
},
|
442
|
+
layout = function (el) {
|
443
|
+
var options = $(el).data('datepicker');
|
444
|
+
var cal = $('#' + options.id);
|
445
|
+
if (!options.extraHeight) {
|
446
|
+
var divs = $(el).find('div');
|
447
|
+
options.extraHeight = divs.get(0).offsetHeight + divs.get(1).offsetHeight;
|
448
|
+
options.extraWidth = divs.get(2).offsetWidth + divs.get(3).offsetWidth;
|
449
|
+
}
|
450
|
+
var tbl = cal.find('table:first').get(0);
|
451
|
+
var width = tbl.offsetWidth;
|
452
|
+
var height = tbl.offsetHeight;
|
453
|
+
cal.css({
|
454
|
+
width: width + options.extraWidth + 'px',
|
455
|
+
height: height + options.extraHeight + 'px'
|
456
|
+
}).find('div.datepickerContainer').css({
|
457
|
+
width: width + 'px',
|
458
|
+
height: height + 'px'
|
459
|
+
});
|
460
|
+
},
|
461
|
+
click = function(ev) {
|
462
|
+
if ($(ev.target).is('span')) {
|
463
|
+
ev.target = ev.target.parentNode;
|
464
|
+
}
|
465
|
+
var el = $(ev.target);
|
466
|
+
if (el.is('a')) {
|
467
|
+
ev.target.blur();
|
468
|
+
if (el.hasClass('datepickerDisabled')) {
|
469
|
+
return false;
|
470
|
+
}
|
471
|
+
var options = $(this).data('datepicker');
|
472
|
+
var parentEl = el.parent();
|
473
|
+
var tblEl = parentEl.parent().parent().parent();
|
474
|
+
var tblIndex = $('table', this).index(tblEl.get(0)) - 1;
|
475
|
+
var tmp = new Date(options.current);
|
476
|
+
var changed = false;
|
477
|
+
var fillIt = false;
|
478
|
+
if (parentEl.is('th')) {
|
479
|
+
if (parentEl.hasClass('datepickerWeek') && options.mode == 'range' && !parentEl.next().hasClass('datepickerDisabled')) {
|
480
|
+
var val = parseInt(parentEl.next().text(), 10);
|
481
|
+
tmp.addMonths(tblIndex - Math.floor(options.calendars/2));
|
482
|
+
if (parentEl.next().hasClass('datepickerNotInMonth')) {
|
483
|
+
tmp.addMonths(val > 15 ? -1 : 1);
|
484
|
+
}
|
485
|
+
tmp.setDate(val);
|
486
|
+
options.date[0] = (tmp.setHours(0,0,0,0)).valueOf();
|
487
|
+
tmp.setHours(23,59,59,0);
|
488
|
+
tmp.addDays(6);
|
489
|
+
options.date[1] = tmp.valueOf();
|
490
|
+
fillIt = true;
|
491
|
+
changed = true;
|
492
|
+
options.lastSel = false;
|
493
|
+
} else if (parentEl.hasClass('datepickerMonth')) {
|
494
|
+
tmp.addMonths(tblIndex - Math.floor(options.calendars/2));
|
495
|
+
switch (tblEl.get(0).className) {
|
496
|
+
case 'datepickerViewDays':
|
497
|
+
tblEl.get(0).className = 'datepickerViewMonths';
|
498
|
+
el.find('span').text(tmp.getFullYear());
|
499
|
+
break;
|
500
|
+
case 'datepickerViewMonths':
|
501
|
+
tblEl.get(0).className = 'datepickerViewYears';
|
502
|
+
el.find('span').text((tmp.getFullYear()-6) + ' - ' + (tmp.getFullYear()+5));
|
503
|
+
break;
|
504
|
+
case 'datepickerViewYears':
|
505
|
+
tblEl.get(0).className = 'datepickerViewDays';
|
506
|
+
el.find('span').text(formatDate(tmp, 'B, Y'));
|
507
|
+
break;
|
508
|
+
}
|
509
|
+
} else if (parentEl.parent().parent().is('thead')) {
|
510
|
+
switch (tblEl.get(0).className) {
|
511
|
+
case 'datepickerViewDays':
|
512
|
+
options.current.addMonths(parentEl.hasClass('datepickerGoPrev') ? -1 : 1);
|
513
|
+
break;
|
514
|
+
case 'datepickerViewMonths':
|
515
|
+
options.current.addYears(parentEl.hasClass('datepickerGoPrev') ? -1 : 1);
|
516
|
+
break;
|
517
|
+
case 'datepickerViewYears':
|
518
|
+
options.current.addYears(parentEl.hasClass('datepickerGoPrev') ? -12 : 12);
|
519
|
+
break;
|
520
|
+
}
|
521
|
+
fillIt = true;
|
522
|
+
}
|
523
|
+
} else if (parentEl.is('td') && !parentEl.hasClass('datepickerDisabled')) {
|
524
|
+
switch (tblEl.get(0).className) {
|
525
|
+
case 'datepickerViewMonths':
|
526
|
+
options.current.setMonth(tblEl.find('tbody.datepickerMonths td').index(parentEl));
|
527
|
+
options.current.setFullYear(parseInt(tblEl.find('thead th.datepickerMonth span').text(), 10));
|
528
|
+
options.current.addMonths(Math.floor(options.calendars/2) - tblIndex);
|
529
|
+
tblEl.get(0).className = 'datepickerViewDays';
|
530
|
+
break;
|
531
|
+
case 'datepickerViewYears':
|
532
|
+
options.current.setFullYear(parseInt(el.text(), 10));
|
533
|
+
tblEl.get(0).className = 'datepickerViewMonths';
|
534
|
+
break;
|
535
|
+
default:
|
536
|
+
var val = parseInt(el.text(), 10);
|
537
|
+
tmp.addMonths(tblIndex - Math.floor(options.calendars/2));
|
538
|
+
if (parentEl.hasClass('datepickerNotInMonth')) {
|
539
|
+
tmp.addMonths(val > 15 ? -1 : 1);
|
540
|
+
}
|
541
|
+
tmp.setDate(val);
|
542
|
+
switch (options.mode) {
|
543
|
+
case 'multiple':
|
544
|
+
val = (tmp.setHours(0,0,0,0)).valueOf();
|
545
|
+
if ($.inArray(val, options.date) > -1) {
|
546
|
+
$.each(options.date, function(nr, dat){
|
547
|
+
if (dat == val) {
|
548
|
+
options.date.splice(nr,1);
|
549
|
+
return false;
|
550
|
+
}
|
551
|
+
});
|
552
|
+
} else {
|
553
|
+
options.date.push(val);
|
554
|
+
}
|
555
|
+
break;
|
556
|
+
case 'range':
|
557
|
+
if (!options.lastSel) {
|
558
|
+
options.date[0] = (tmp.setHours(0,0,0,0)).valueOf();
|
559
|
+
}
|
560
|
+
val = (tmp.setHours(23,59,59,0)).valueOf();
|
561
|
+
if (val < options.date[0]) {
|
562
|
+
options.date[1] = options.date[0] + 86399000;
|
563
|
+
options.date[0] = val - 86399000;
|
564
|
+
} else {
|
565
|
+
options.date[1] = val;
|
566
|
+
}
|
567
|
+
options.lastSel = !options.lastSel;
|
568
|
+
break;
|
569
|
+
default:
|
570
|
+
options.date = tmp.valueOf();
|
571
|
+
break;
|
572
|
+
}
|
573
|
+
break;
|
574
|
+
}
|
575
|
+
fillIt = true;
|
576
|
+
changed = true;
|
577
|
+
}
|
578
|
+
if (fillIt) {
|
579
|
+
fill(this);
|
580
|
+
}
|
581
|
+
if (changed) {
|
582
|
+
options.onChange.apply(this, prepareDate(options));
|
583
|
+
}
|
584
|
+
}
|
585
|
+
return false;
|
586
|
+
},
|
587
|
+
prepareDate = function (options) {
|
588
|
+
var tmp;
|
589
|
+
if (options.mode == 'single') {
|
590
|
+
tmp = new Date(options.date);
|
591
|
+
return [formatDate(tmp, options.format), tmp, options.el];
|
592
|
+
} else {
|
593
|
+
tmp = [[],[], options.el];
|
594
|
+
$.each(options.date, function(nr, val){
|
595
|
+
var date = new Date(val);
|
596
|
+
tmp[0].push(formatDate(date, options.format));
|
597
|
+
tmp[1].push(date);
|
598
|
+
});
|
599
|
+
return tmp;
|
600
|
+
}
|
601
|
+
},
|
602
|
+
getViewport = function () {
|
603
|
+
var m = document.compatMode == 'CSS1Compat';
|
604
|
+
return {
|
605
|
+
l : window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft),
|
606
|
+
t : window.pageYOffset || (m ? document.documentElement.scrollTop : document.body.scrollTop),
|
607
|
+
w : window.innerWidth || (m ? document.documentElement.clientWidth : document.body.clientWidth),
|
608
|
+
h : window.innerHeight || (m ? document.documentElement.clientHeight : document.body.clientHeight)
|
609
|
+
};
|
610
|
+
},
|
611
|
+
isChildOf = function(parentEl, el, container) {
|
612
|
+
if (parentEl == el) {
|
613
|
+
return true;
|
614
|
+
}
|
615
|
+
if (parentEl.contains) {
|
616
|
+
return parentEl.contains(el);
|
617
|
+
}
|
618
|
+
if ( parentEl.compareDocumentPosition ) {
|
619
|
+
return !!(parentEl.compareDocumentPosition(el) & 16);
|
620
|
+
}
|
621
|
+
var prEl = el.parentNode;
|
622
|
+
while(prEl && prEl != container) {
|
623
|
+
if (prEl == parentEl)
|
624
|
+
return true;
|
625
|
+
prEl = prEl.parentNode;
|
626
|
+
}
|
627
|
+
return false;
|
628
|
+
},
|
629
|
+
show = function (ev) {
|
630
|
+
var cal = $('#' + $(this).data('datepickerId'));
|
631
|
+
if (!cal.is(':visible')) {
|
632
|
+
var calEl = cal.get(0);
|
633
|
+
fill(calEl);
|
634
|
+
var options = cal.data('datepicker');
|
635
|
+
options.onBeforeShow.apply(this, [cal.get(0)]);
|
636
|
+
var pos = $(this).offset();
|
637
|
+
var viewPort = getViewport();
|
638
|
+
var top = pos.top;
|
639
|
+
var left = pos.left;
|
640
|
+
var oldDisplay = $.curCSS(calEl, 'display');
|
641
|
+
cal.css({
|
642
|
+
visibility: 'hidden',
|
643
|
+
display: 'block'
|
644
|
+
});
|
645
|
+
layout(calEl);
|
646
|
+
switch (options.position){
|
647
|
+
case 'top':
|
648
|
+
top -= calEl.offsetHeight;
|
649
|
+
break;
|
650
|
+
case 'left':
|
651
|
+
left -= calEl.offsetWidth;
|
652
|
+
break;
|
653
|
+
case 'right':
|
654
|
+
left += this.offsetWidth;
|
655
|
+
break;
|
656
|
+
case 'bottom':
|
657
|
+
top += this.offsetHeight;
|
658
|
+
break;
|
659
|
+
}
|
660
|
+
if (top + calEl.offsetHeight > viewPort.t + viewPort.h) {
|
661
|
+
top = pos.top - calEl.offsetHeight;
|
662
|
+
}
|
663
|
+
if (top < viewPort.t) {
|
664
|
+
top = pos.top + this.offsetHeight + calEl.offsetHeight;
|
665
|
+
}
|
666
|
+
if (left + calEl.offsetWidth > viewPort.l + viewPort.w) {
|
667
|
+
left = pos.left - calEl.offsetWidth;
|
668
|
+
}
|
669
|
+
if (left < viewPort.l) {
|
670
|
+
left = pos.left + this.offsetWidth
|
671
|
+
}
|
672
|
+
cal.css({
|
673
|
+
visibility: 'visible',
|
674
|
+
display: 'block',
|
675
|
+
top: top + 'px',
|
676
|
+
left: left + 'px'
|
677
|
+
});
|
678
|
+
if (options.onShow.apply(this, [cal.get(0)]) != false) {
|
679
|
+
cal.show();
|
680
|
+
}
|
681
|
+
$(document).bind('mousedown', {cal: cal, trigger: this}, hide);
|
682
|
+
}
|
683
|
+
return false;
|
684
|
+
},
|
685
|
+
hide = function (ev) {
|
686
|
+
if (ev.target != ev.data.trigger && !isChildOf(ev.data.cal.get(0), ev.target, ev.data.cal.get(0))) {
|
687
|
+
if (ev.data.cal.data('datepicker').onHide.apply(this, [ev.data.cal.get(0)]) != false) {
|
688
|
+
ev.data.cal.hide();
|
689
|
+
}
|
690
|
+
$(document).unbind('mousedown', hide);
|
691
|
+
}
|
692
|
+
};
|
693
|
+
return {
|
694
|
+
init: function(options){
|
695
|
+
options = $.extend({}, defaults, options||{});
|
696
|
+
extendDate(options.locale);
|
697
|
+
options.calendars = Math.max(1, parseInt(options.calendars,10)||1);
|
698
|
+
options.mode = /single|multiple|range/.test(options.mode) ? options.mode : 'single';
|
699
|
+
return this.each(function(){
|
700
|
+
if (!$(this).data('datepicker')) {
|
701
|
+
options.el = this;
|
702
|
+
if (options.date.constructor == String) {
|
703
|
+
options.date = parseDate(options.date, options.format);
|
704
|
+
options.date.setHours(0,0,0,0);
|
705
|
+
}
|
706
|
+
if (options.mode != 'single') {
|
707
|
+
if (options.date.constructor != Array) {
|
708
|
+
options.date = [options.date.valueOf()];
|
709
|
+
if (options.mode == 'range') {
|
710
|
+
options.date.push(((new Date(options.date[0])).setHours(23,59,59,0)).valueOf());
|
711
|
+
}
|
712
|
+
} else {
|
713
|
+
for (var i = 0; i < options.date.length; i++) {
|
714
|
+
options.date[i] = (parseDate(options.date[i], options.format).setHours(0,0,0,0)).valueOf();
|
715
|
+
}
|
716
|
+
if (options.mode == 'range') {
|
717
|
+
options.date[1] = ((new Date(options.date[1])).setHours(23,59,59,0)).valueOf();
|
718
|
+
}
|
719
|
+
}
|
720
|
+
} else {
|
721
|
+
options.date = options.date.valueOf();
|
722
|
+
}
|
723
|
+
if (!options.current) {
|
724
|
+
options.current = new Date();
|
725
|
+
} else {
|
726
|
+
options.current = parseDate(options.current, options.format);
|
727
|
+
}
|
728
|
+
options.current.setDate(1);
|
729
|
+
options.current.setHours(0,0,0,0);
|
730
|
+
var id = 'datepicker_' + parseInt(Math.random() * 1000), cnt;
|
731
|
+
options.id = id;
|
732
|
+
$(this).data('datepickerId', options.id);
|
733
|
+
var cal = $(tpl.wrapper).attr('id', id).bind('click', click).data('datepicker', options);
|
734
|
+
if (options.className) {
|
735
|
+
cal.addClass(options.className);
|
736
|
+
}
|
737
|
+
var html = '';
|
738
|
+
for (var i = 0; i < options.calendars; i++) {
|
739
|
+
cnt = options.starts;
|
740
|
+
if (i > 0) {
|
741
|
+
html += tpl.space;
|
742
|
+
}
|
743
|
+
html += tmpl(tpl.head.join(''), {
|
744
|
+
week: options.locale.weekMin,
|
745
|
+
prev: options.prev,
|
746
|
+
next: options.next,
|
747
|
+
day1: options.locale.daysMin[(cnt++)%7],
|
748
|
+
day2: options.locale.daysMin[(cnt++)%7],
|
749
|
+
day3: options.locale.daysMin[(cnt++)%7],
|
750
|
+
day4: options.locale.daysMin[(cnt++)%7],
|
751
|
+
day5: options.locale.daysMin[(cnt++)%7],
|
752
|
+
day6: options.locale.daysMin[(cnt++)%7],
|
753
|
+
day7: options.locale.daysMin[(cnt++)%7]
|
754
|
+
});
|
755
|
+
}
|
756
|
+
cal
|
757
|
+
.find('tr:first').append(html)
|
758
|
+
.find('table').addClass(views[options.view]);
|
759
|
+
fill(cal.get(0));
|
760
|
+
if (options.flat) {
|
761
|
+
cal.appendTo(this).show().css('position', 'relative');
|
762
|
+
layout(cal.get(0));
|
763
|
+
} else {
|
764
|
+
cal.appendTo(document.body);
|
765
|
+
$(this).bind(options.eventName, show);
|
766
|
+
}
|
767
|
+
}
|
768
|
+
});
|
769
|
+
},
|
770
|
+
showPicker: function() {
|
771
|
+
return this.each( function () {
|
772
|
+
if ($(this).data('datepickerId')) {
|
773
|
+
show.apply(this);
|
774
|
+
}
|
775
|
+
});
|
776
|
+
},
|
777
|
+
hidePicker: function() {
|
778
|
+
return this.each( function () {
|
779
|
+
if ($(this).data('datepickerId')) {
|
780
|
+
$('#' + $(this).data('datepickerId')).hide();
|
781
|
+
}
|
782
|
+
});
|
783
|
+
},
|
784
|
+
setDate: function(date, shiftTo){
|
785
|
+
return this.each(function(){
|
786
|
+
if ($(this).data('datepickerId')) {
|
787
|
+
var cal = $('#' + $(this).data('datepickerId'));
|
788
|
+
var options = cal.data('datepicker');
|
789
|
+
options.date = date;
|
790
|
+
if (options.date.constructor == String) {
|
791
|
+
options.date = parseDate(options.date, options.format);
|
792
|
+
options.date.setHours(0,0,0,0);
|
793
|
+
}
|
794
|
+
if (options.mode != 'single') {
|
795
|
+
if (options.date.constructor != Array) {
|
796
|
+
options.date = [options.date.valueOf()];
|
797
|
+
if (options.mode == 'range') {
|
798
|
+
options.date.push(((new Date(options.date[0])).setHours(23,59,59,0)).valueOf());
|
799
|
+
}
|
800
|
+
} else {
|
801
|
+
for (var i = 0; i < options.date.length; i++) {
|
802
|
+
options.date[i] = (parseDate(options.date[i], options.format).setHours(0,0,0,0)).valueOf();
|
803
|
+
}
|
804
|
+
if (options.mode == 'range') {
|
805
|
+
options.date[1] = ((new Date(options.date[1])).setHours(23,59,59,0)).valueOf();
|
806
|
+
}
|
807
|
+
}
|
808
|
+
} else {
|
809
|
+
options.date = options.date.valueOf();
|
810
|
+
}
|
811
|
+
if (shiftTo) {
|
812
|
+
options.current = new Date (options.mode != 'single' ? options.date[0] : options.date);
|
813
|
+
}
|
814
|
+
fill(cal.get(0));
|
815
|
+
}
|
816
|
+
});
|
817
|
+
},
|
818
|
+
getDate: function(formated) {
|
819
|
+
if (this.size() > 0) {
|
820
|
+
return prepareDate($('#' + $(this).data('datepickerId')).data('datepicker'))[formated ? 0 : 1];
|
821
|
+
}
|
822
|
+
},
|
823
|
+
clear: function(){
|
824
|
+
return this.each(function(){
|
825
|
+
if ($(this).data('datepickerId')) {
|
826
|
+
var cal = $('#' + $(this).data('datepickerId'));
|
827
|
+
var options = cal.data('datepicker');
|
828
|
+
if (options.mode != 'single') {
|
829
|
+
options.date = [];
|
830
|
+
fill(cal.get(0));
|
831
|
+
}
|
832
|
+
}
|
833
|
+
});
|
834
|
+
},
|
835
|
+
fixLayout: function(){
|
836
|
+
return this.each(function(){
|
837
|
+
if ($(this).data('datepickerId')) {
|
838
|
+
var cal = $('#' + $(this).data('datepickerId'));
|
839
|
+
var options = cal.data('datepicker');
|
840
|
+
if (options.flat) {
|
841
|
+
layout(cal.get(0));
|
842
|
+
}
|
843
|
+
}
|
844
|
+
});
|
845
|
+
}
|
846
|
+
};
|
847
|
+
}();
|
848
|
+
$.fn.extend({
|
849
|
+
DatePicker: DatePicker.init,
|
850
|
+
DatePickerHide: DatePicker.hidePicker,
|
851
|
+
DatePickerShow: DatePicker.showPicker,
|
852
|
+
DatePickerSetDate: DatePicker.setDate,
|
853
|
+
DatePickerGetDate: DatePicker.getDate,
|
854
|
+
DatePickerClear: DatePicker.clear,
|
855
|
+
DatePickerLayout: DatePicker.fixLayout
|
856
|
+
});
|
857
|
+
})(jQuery);
|
858
|
+
|
859
|
+
(function(){
|
860
|
+
var cache = {};
|
861
|
+
|
862
|
+
this.tmpl = function tmpl(str, data){
|
863
|
+
// Figure out if we're getting a template, or if we need to
|
864
|
+
// load the template - and be sure to cache the result.
|
865
|
+
var fn = !/\W/.test(str) ?
|
866
|
+
cache[str] = cache[str] ||
|
867
|
+
tmpl(document.getElementById(str).innerHTML) :
|
868
|
+
|
869
|
+
// Generate a reusable function that will serve as a template
|
870
|
+
// generator (and which will be cached).
|
871
|
+
new Function("obj",
|
872
|
+
"var p=[],print=function(){p.push.apply(p,arguments);};" +
|
873
|
+
|
874
|
+
// Introduce the data as local variables using with(){}
|
875
|
+
"with(obj){p.push('" +
|
876
|
+
|
877
|
+
// Convert the template into pure JavaScript
|
878
|
+
str
|
879
|
+
.replace(/[\r\t\n]/g, " ")
|
880
|
+
.split("<%").join("\t")
|
881
|
+
.replace(/((^|%>)[^\t]*)'/g, "$1\r")
|
882
|
+
.replace(/\t=(.*?)%>/g, "',$1,'")
|
883
|
+
.split("\t").join("');")
|
884
|
+
.split("%>").join("p.push('")
|
885
|
+
.split("\r").join("\\'")
|
886
|
+
+ "');}return p.join('');");
|
887
|
+
|
888
|
+
// Provide some basic currying to the user
|
889
|
+
return data ? fn( data ) : fn;
|
890
|
+
};
|
891
|
+
})();
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
this.HappyDatePicker = (function() {
|
3
|
+
|
4
|
+
function HappyDatePicker(element) {
|
5
|
+
$(element).DatePicker({
|
6
|
+
flat: false,
|
7
|
+
date: new Date(),
|
8
|
+
current: new Date(),
|
9
|
+
calendars: 1,
|
10
|
+
starts: 1,
|
11
|
+
onChange: function(formated, dates) {
|
12
|
+
$(element).val(formated);
|
13
|
+
return $(element).DatePickerHide();
|
14
|
+
}
|
15
|
+
});
|
16
|
+
}
|
17
|
+
|
18
|
+
return HappyDatePicker;
|
19
|
+
|
20
|
+
})();
|
@@ -0,0 +1,192 @@
|
|
1
|
+
div.datepicker {
|
2
|
+
position: relative;
|
3
|
+
font-family: Arial, Helvetica, sans-serif;
|
4
|
+
font-size: 12px;
|
5
|
+
width: 196px;
|
6
|
+
height: 147px;
|
7
|
+
position: absolute;
|
8
|
+
cursor: default;
|
9
|
+
top: 0;
|
10
|
+
left: 0;
|
11
|
+
display: none;
|
12
|
+
z-index: 1011;
|
13
|
+
}
|
14
|
+
.datepickerContainer {
|
15
|
+
background: #121212;
|
16
|
+
position: absolute;
|
17
|
+
top: 10px;
|
18
|
+
left: 10px;
|
19
|
+
}
|
20
|
+
.datepickerBorderT {
|
21
|
+
position: absolute;
|
22
|
+
left: 10px;
|
23
|
+
top: 0;
|
24
|
+
right: 10px;
|
25
|
+
height: 10px;
|
26
|
+
background: url(/assets/happydatepicker/datepicker_t.png);
|
27
|
+
}
|
28
|
+
.datepickerBorderB {
|
29
|
+
position: absolute;
|
30
|
+
left: 10px;
|
31
|
+
bottom: 0;
|
32
|
+
right: 10px;
|
33
|
+
height: 10px;
|
34
|
+
background: url(/assets/happydatepicker/datepicker_b.png);
|
35
|
+
}
|
36
|
+
.datepickerBorderL {
|
37
|
+
position: absolute;
|
38
|
+
left: 0;
|
39
|
+
bottom: 10px;
|
40
|
+
top: 10px;
|
41
|
+
width: 10px;
|
42
|
+
background: url(/assets/happydatepicker/datepicker_l.png);
|
43
|
+
}
|
44
|
+
.datepickerBorderR {
|
45
|
+
position: absolute;
|
46
|
+
right: 0;
|
47
|
+
bottom: 10px;
|
48
|
+
top: 10px;
|
49
|
+
width: 10px;
|
50
|
+
background: url(/assets/happydatepicker/datepicker_r.png);
|
51
|
+
}
|
52
|
+
.datepickerBorderTL {
|
53
|
+
position: absolute;
|
54
|
+
top: 0;
|
55
|
+
left: 0;
|
56
|
+
width: 10px;
|
57
|
+
height: 10px;
|
58
|
+
background: url(/assets/happydatepicker/datepicker_tl.png);
|
59
|
+
}
|
60
|
+
.datepickerBorderTR {
|
61
|
+
position: absolute;
|
62
|
+
top: 0;
|
63
|
+
right: 0;
|
64
|
+
width: 10px;
|
65
|
+
height: 10px;
|
66
|
+
background: url(/assets/happydatepicker/datepicker_tr.png);
|
67
|
+
}
|
68
|
+
.datepickerBorderBL {
|
69
|
+
position: absolute;
|
70
|
+
bottom: 0;
|
71
|
+
left: 0;
|
72
|
+
width: 10px;
|
73
|
+
height: 10px;
|
74
|
+
background: url(/assets/happydatepicker/datepicker_bl.png);
|
75
|
+
}
|
76
|
+
.datepickerBorderBR {
|
77
|
+
position: absolute;
|
78
|
+
bottom: 0;
|
79
|
+
right: 0;
|
80
|
+
width: 10px;
|
81
|
+
height: 10px;
|
82
|
+
background: url(/assets/happydatepicker/datepicker_br.png);
|
83
|
+
}
|
84
|
+
.datepickerHidden {
|
85
|
+
display: none;
|
86
|
+
}
|
87
|
+
div.datepicker table {
|
88
|
+
border-collapse:collapse;
|
89
|
+
}
|
90
|
+
div.datepicker a {
|
91
|
+
color: #eee;
|
92
|
+
text-decoration: none;
|
93
|
+
cursor: default;
|
94
|
+
outline: none;
|
95
|
+
}
|
96
|
+
div.datepicker table td {
|
97
|
+
text-align: right;
|
98
|
+
padding: 0;
|
99
|
+
margin: 0;
|
100
|
+
}
|
101
|
+
div.datepicker th {
|
102
|
+
text-align: center;
|
103
|
+
color: #999;
|
104
|
+
font-weight: normal;
|
105
|
+
}
|
106
|
+
div.datepicker tbody th {
|
107
|
+
text-align: left;
|
108
|
+
}
|
109
|
+
div.datepicker tbody a {
|
110
|
+
display: block;
|
111
|
+
}
|
112
|
+
.datepickerDays a {
|
113
|
+
width: 20px;
|
114
|
+
line-height: 16px;
|
115
|
+
height: 16px;
|
116
|
+
padding-right: 2px;
|
117
|
+
}
|
118
|
+
.datepickerYears a,
|
119
|
+
.datepickerMonths a{
|
120
|
+
width: 44px;
|
121
|
+
line-height: 36px;
|
122
|
+
height: 36px;
|
123
|
+
text-align: center;
|
124
|
+
}
|
125
|
+
td.datepickerNotInMonth a {
|
126
|
+
color: #666;
|
127
|
+
}
|
128
|
+
tbody.datepickerDays td.datepickerSelected{
|
129
|
+
background: #136A9F;
|
130
|
+
}
|
131
|
+
tbody.datepickerDays td.datepickerNotInMonth.datepickerSelected {
|
132
|
+
background: #17384d;
|
133
|
+
}
|
134
|
+
tbody.datepickerYears td.datepickerSelected,
|
135
|
+
tbody.datepickerMonths td.datepickerSelected{
|
136
|
+
background: #17384d;
|
137
|
+
}
|
138
|
+
div.datepicker a:hover,
|
139
|
+
div.datepicker a:hover {
|
140
|
+
color: #88c5eb;
|
141
|
+
}
|
142
|
+
div.datepicker td.datepickerNotInMonth a:hover {
|
143
|
+
color: #999;
|
144
|
+
}
|
145
|
+
div.datepicker tbody th {
|
146
|
+
text-align: left;
|
147
|
+
}
|
148
|
+
.datepickerSpace div {
|
149
|
+
width: 20px;
|
150
|
+
}
|
151
|
+
.datepickerGoNext a,
|
152
|
+
.datepickerGoPrev a,
|
153
|
+
.datepickerMonth a {
|
154
|
+
text-align: center;
|
155
|
+
height: 20px;
|
156
|
+
line-height: 20px;
|
157
|
+
}
|
158
|
+
.datepickerGoNext a {
|
159
|
+
float: right;
|
160
|
+
width: 20px;
|
161
|
+
}
|
162
|
+
.datepickerGoPrev a {
|
163
|
+
float: left;
|
164
|
+
width: 20px;
|
165
|
+
}
|
166
|
+
table.datepickerViewDays tbody.datepickerMonths,
|
167
|
+
table.datepickerViewDays tbody.datepickerYears {
|
168
|
+
display: none;
|
169
|
+
}
|
170
|
+
table.datepickerViewMonths tbody.datepickerDays,
|
171
|
+
table.datepickerViewMonths tbody.datepickerYears,
|
172
|
+
table.datepickerViewMonths tr.datepickerDoW {
|
173
|
+
display: none;
|
174
|
+
}
|
175
|
+
table.datepickerViewYears tbody.datepickerDays,
|
176
|
+
table.datepickerViewYears tbody.datepickerMonths,
|
177
|
+
table.datepickerViewYears tr.datepickerDoW {
|
178
|
+
display: none;
|
179
|
+
}
|
180
|
+
td.datepickerDisabled a,
|
181
|
+
td.datepickerDisabled.datepickerNotInMonth a{
|
182
|
+
color: #333;
|
183
|
+
}
|
184
|
+
td.datepickerDisabled a:hover {
|
185
|
+
color: #333;
|
186
|
+
}
|
187
|
+
td.datepickerSpecial a {
|
188
|
+
background: #700;
|
189
|
+
}
|
190
|
+
td.datepickerSpecial.datepickerSelected a {
|
191
|
+
background: #a00;
|
192
|
+
}
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: happydatepicker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Fabio Russo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-24 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A simple datepicker ready for rails
|
15
|
+
email:
|
16
|
+
- fabio@objectivesheep.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/happydatepicker/engine.rb
|
22
|
+
- lib/happydatepicker/version.rb
|
23
|
+
- lib/happydatepicker.rb
|
24
|
+
- app/assets/images/happydatepicker/datepicker_b.png
|
25
|
+
- app/assets/images/happydatepicker/datepicker_bl.png
|
26
|
+
- app/assets/images/happydatepicker/datepicker_br.png
|
27
|
+
- app/assets/images/happydatepicker/datepicker_l.png
|
28
|
+
- app/assets/images/happydatepicker/datepicker_r.png
|
29
|
+
- app/assets/images/happydatepicker/datepicker_t.png
|
30
|
+
- app/assets/images/happydatepicker/datepicker_tl.png
|
31
|
+
- app/assets/images/happydatepicker/datepicker_tr.png
|
32
|
+
- app/assets/javascripts/happydatepicker/datepicker.js
|
33
|
+
- app/assets/javascripts/happydatepicker/happydatepicker.js
|
34
|
+
- app/assets/javascripts/happydatepicker/index.js
|
35
|
+
- app/assets/stylesheets/happydatepicker/datepicker.css
|
36
|
+
- app/assets/stylesheets/happydatepicker/index.css
|
37
|
+
- README.md
|
38
|
+
homepage: http://objectivesheep.com
|
39
|
+
licenses: []
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.8.24
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: ! 'Based upon http://www.eyecon.ro/datepicker and nicely packaged. From your
|
62
|
+
coffeescript files just do: my_datepicker = new HappyDatePicker($("#you_input"))
|
63
|
+
and watch the magic happen.'
|
64
|
+
test_files: []
|