Total Complexity | 136 |
Complexity/F | 3.78 |
Lines of Code | 759 |
Function Count | 36 |
Duplicated Lines | 57 |
Ratio | 7.51 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like framework/Web/Javascripts/source/prado/datepicker/datepicker.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | /*! PRADO TDatePicker javascript file | github.com/pradosoft/prado */ |
||
3 | Prado.WebUI.TDatePicker = jQuery.klass(Prado.WebUI.Control, |
||
1 ignored issue
–
show
|
|||
4 | { |
||
5 | MonthNames : [ "January", "February", "March", "April", |
||
6 | "May", "June", "July", "August", |
||
7 | "September", "October", "November", "December" |
||
8 | ], |
||
9 | AbbreviatedMonthNames : ["Jan", "Feb", "Mar", "Apr", "May", |
||
10 | "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], |
||
11 | |||
12 | ShortWeekDayNames : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ], |
||
13 | |||
14 | Format : "yyyy-MM-dd", |
||
15 | |||
16 | FirstDayOfWeek : 1, // 0 for sunday |
||
17 | |||
18 | ClassName : "", |
||
19 | |||
20 | CalendarStyle : "default", |
||
21 | |||
22 | FromYear : 2005, UpToYear: 2020, |
||
23 | |||
24 | View Code Duplication | onInit : function(options) |
|
25 | { |
||
26 | this.options = options || []; |
||
27 | this.control = jQuery('#'+options.ID).get(0); |
||
28 | this.dateSlot = new Array(42); |
||
29 | this.weekSlot = new Array(6); |
||
30 | this.minimalDaysInFirstWeek = 4; |
||
31 | this.positionMode = 'Bottom'; |
||
32 | |||
33 | Prado.Registry[options.ID] = this; |
||
1 ignored issue
–
show
|
|||
34 | |||
35 | //which element to trigger to show the calendar |
||
36 | if(this.options.Trigger) |
||
37 | { |
||
38 | this.trigger = jQuery('#'+this.options.Trigger).get(0); |
||
39 | var triggerEvent = this.options.TriggerEvent || "click"; |
||
40 | } |
||
41 | else |
||
42 | { |
||
43 | this.trigger = this.control; |
||
44 | var triggerEvent = this.options.TriggerEvent || "focus"; |
||
45 | } |
||
46 | |||
47 | // Popup position |
||
48 | if(this.options.PositionMode == 'Top') |
||
49 | { |
||
50 | this.positionMode = this.options.PositionMode; |
||
51 | } |
||
52 | |||
53 | jQuery.extend(this,options); |
||
54 | // generate default date _after_ extending options |
||
55 | this.selectedDate = this.newDate(); |
||
56 | |||
57 | this.observe(this.trigger, triggerEvent, jQuery.proxy(this.show,this)); |
||
58 | |||
59 | // Listen to change event if needed |
||
60 | if (typeof(this.options.OnDateChanged) == "function") |
||
61 | { |
||
62 | if(this.options.InputMode == "TextBox") |
||
63 | { |
||
64 | this.observe(this.control, "change", jQuery.proxy(this.onDateChanged,this)); |
||
65 | } |
||
66 | else |
||
67 | { |
||
68 | var day = Prado.WebUI.TDatePicker.getDayListControl(this.control); |
||
69 | var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control); |
||
70 | var year = Prado.WebUI.TDatePicker.getYearListControl(this.control); |
||
71 | this.observe (day, "change", jQuery.proxy(this.onDateChanged,this)); |
||
72 | this.observe (month, "change", jQuery.proxy(this.onDateChanged,this)); |
||
73 | this.observe (year, "change", jQuery.proxy(this.onDateChanged,this)); |
||
74 | |||
75 | } |
||
76 | |||
77 | |||
78 | } |
||
79 | |||
80 | }, |
||
81 | |||
82 | create : function() |
||
83 | { |
||
84 | if(typeof(this._calDiv) != "undefined") |
||
85 | return; |
||
1 ignored issue
–
show
|
|||
86 | |||
87 | var div; |
||
88 | var table; |
||
89 | var tbody; |
||
90 | var tr; |
||
91 | var td; |
||
92 | |||
93 | // Create the top-level div element |
||
94 | this._calDiv = document.createElement("div"); |
||
95 | this._calDiv.className = "TDatePicker_"+this.CalendarStyle+" "+this.ClassName; |
||
96 | this._calDiv.style.display = "none"; |
||
97 | this._calDiv.style.position = "absolute" |
||
98 | |||
99 | // header div |
||
100 | div = document.createElement("div"); |
||
101 | div.className = "calendarHeader"; |
||
102 | this._calDiv.appendChild(div); |
||
103 | |||
104 | table = document.createElement("table"); |
||
105 | table.style.cellSpacing = 0; |
||
106 | div.appendChild(table); |
||
107 | |||
108 | tbody = document.createElement("tbody"); |
||
109 | table.appendChild(tbody); |
||
110 | |||
111 | tr = document.createElement("tr"); |
||
112 | tbody.appendChild(tr); |
||
113 | |||
114 | // Previous Month Button |
||
115 | td = document.createElement("td"); |
||
116 | var previousMonth = document.createElement("input"); |
||
117 | previousMonth.className = "prevMonthButton button"; |
||
118 | previousMonth.type = "button" |
||
119 | previousMonth.value = "<<"; |
||
120 | td.appendChild(previousMonth); |
||
121 | tr.appendChild(td); |
||
122 | |||
123 | |||
124 | |||
125 | // |
||
126 | // Create the month drop down |
||
127 | // |
||
128 | td = document.createElement("td"); |
||
129 | tr.appendChild(td); |
||
130 | this._monthSelect = document.createElement("select"); |
||
131 | this._monthSelect.className = "months"; |
||
132 | for (var i = 0 ; i < this.MonthNames.length ; i++) { |
||
133 | var opt = document.createElement("option"); |
||
134 | opt.innerHTML = this.MonthNames[i]; |
||
135 | opt.value = i; |
||
136 | if (i == this.selectedDate.getMonth()) { |
||
137 | opt.selected = true; |
||
138 | } |
||
139 | this._monthSelect.appendChild(opt); |
||
140 | } |
||
141 | td.appendChild(this._monthSelect); |
||
142 | |||
143 | |||
144 | // |
||
145 | // Create the year drop down |
||
146 | // |
||
147 | td = document.createElement("td"); |
||
148 | td.className = "labelContainer"; |
||
149 | tr.appendChild(td); |
||
150 | this._yearSelect = document.createElement("select"); |
||
151 | for(var i=this.FromYear; i <= this.UpToYear; ++i) { |
||
152 | var opt = document.createElement("option"); |
||
153 | opt.innerHTML = i; |
||
154 | opt.value = i; |
||
155 | if (i == this.selectedDate.getFullYear()) { |
||
156 | opt.selected = false; |
||
157 | } |
||
158 | this._yearSelect.appendChild(opt); |
||
159 | } |
||
160 | td.appendChild(this._yearSelect); |
||
161 | |||
162 | |||
163 | td = document.createElement("td"); |
||
164 | var nextMonth = document.createElement("input"); |
||
165 | nextMonth.className = "nextMonthButton button"; |
||
166 | nextMonth.type = "button"; |
||
167 | nextMonth.value = ">>"; |
||
168 | td.appendChild(nextMonth); |
||
169 | tr.appendChild(td); |
||
170 | |||
171 | // Calendar body |
||
172 | div = document.createElement("div"); |
||
173 | div.className = "calendarBody"; |
||
174 | this._calDiv.appendChild(div); |
||
175 | var calendarBody = div; |
||
176 | |||
177 | // Create the inside of calendar body |
||
178 | |||
179 | var text; |
||
180 | table = document.createElement("table"); |
||
181 | table.align="center"; |
||
182 | table.className = "grid"; |
||
183 | |||
184 | div.appendChild(table); |
||
185 | var thead = document.createElement("thead"); |
||
186 | table.appendChild(thead); |
||
187 | tr = document.createElement("tr"); |
||
188 | thead.appendChild(tr); |
||
189 | |||
190 | for(i=0; i < 7; ++i) { |
||
191 | td = document.createElement("th"); |
||
192 | text = document.createTextNode(this.ShortWeekDayNames[(i+this.FirstDayOfWeek)%7]); |
||
193 | td.appendChild(text); |
||
194 | td.className = "weekDayHead"; |
||
195 | tr.appendChild(td); |
||
196 | } |
||
197 | |||
198 | // Date grid |
||
199 | tbody = document.createElement("tbody"); |
||
200 | table.appendChild(tbody); |
||
201 | |||
202 | for(var week=0; week<6; ++week) { |
||
203 | tr = document.createElement("tr"); |
||
204 | tbody.appendChild(tr); |
||
205 | |||
206 | for(var day=0; day<7; ++day) { |
||
207 | td = document.createElement("td"); |
||
208 | td.className = "calendarDate"; |
||
209 | text = document.createTextNode(String.fromCharCode(160)); |
||
210 | td.appendChild(text); |
||
211 | |||
212 | tr.appendChild(td); |
||
213 | var tmp = new Object(); |
||
214 | tmp.tag = "DATE"; |
||
215 | tmp.value = -1; |
||
216 | tmp.data = text; |
||
217 | this.dateSlot[(week*7)+day] = tmp; |
||
218 | |||
219 | this.observe(td, "mouseover", jQuery.proxy(this.hover,this)); |
||
220 | this.observe(td, "mouseout", jQuery.proxy(this.hover,this)); |
||
221 | |||
222 | } |
||
223 | } |
||
224 | |||
225 | // Calendar Footer |
||
226 | div = document.createElement("div"); |
||
227 | div.className = "calendarFooter"; |
||
228 | this._calDiv.appendChild(div); |
||
229 | |||
230 | var todayButton = document.createElement("input"); |
||
231 | todayButton.type="button"; |
||
232 | todayButton.className = "todayButton"; |
||
233 | var today = this.newDate(); |
||
234 | var buttonText = today.SimpleFormat(this.Format,this); |
||
235 | todayButton.value = buttonText; |
||
236 | div.appendChild(todayButton); |
||
237 | |||
238 | this.control.parentNode.appendChild(this._calDiv); |
||
239 | |||
240 | this.update(); |
||
241 | this.updateHeader(); |
||
242 | |||
243 | // hook up events |
||
244 | this.observe(previousMonth, "click", jQuery.proxy(this.prevMonth,this)); |
||
245 | this.observe(nextMonth, "click", jQuery.proxy(this.nextMonth,this)); |
||
246 | this.observe(todayButton, "click", jQuery.proxy(this.selectToday,this)); |
||
247 | //Event.observe(clearButton, "click", jQuery.proxy(this.clearSelection,this)); |
||
248 | this.observe(this._monthSelect, "change", jQuery.proxy(this.monthSelect,this)); |
||
249 | this.observe(this._yearSelect, "change", jQuery.proxy(this.yearSelect,this)); |
||
250 | |||
251 | // ie, opera |
||
252 | this.observe(this._calDiv, "mousewheel", jQuery.proxy(this.mouseWheelChange,this)); |
||
253 | // ff |
||
254 | this.observe(this._calDiv, "DOMMouseScroll", jQuery.proxy(this.mouseWheelChange,this)); |
||
255 | |||
256 | this.observe(calendarBody, "click", jQuery.proxy(this.selectDate,this)); |
||
257 | |||
258 | jQuery(this.control).focus(); |
||
259 | |||
260 | }, |
||
261 | |||
262 | keyPressed : function(ev) |
||
263 | { |
||
264 | if(!this.showing) return; |
||
1 ignored issue
–
show
|
|||
265 | if (!ev) ev = document.parentWindow.event; |
||
1 ignored issue
–
show
|
|||
266 | var kc = ev.keyCode != null ? ev.keyCode : ev.charCode; |
||
267 | |||
268 | // return, space, tab |
||
269 | if(kc == 13 || kc == 32 || kc == 9) |
||
270 | { |
||
271 | this.setSelectedDate(this.selectedDate); |
||
272 | ev.preventDefault(); |
||
273 | this.hide(); |
||
274 | } |
||
275 | // esc |
||
276 | if(kc == 27) |
||
277 | { |
||
278 | ev.preventDefault(); |
||
279 | this.hide(); |
||
280 | } |
||
281 | |||
282 | var getDaysPerMonth = function (nMonth, nYear) |
||
283 | { |
||
284 | nMonth = (nMonth + 12) % 12; |
||
285 | var days= [31,28,31,30,31,30,31,31,30,31,30,31]; |
||
286 | var res = days[nMonth]; |
||
287 | if (nMonth == 1) //feburary, leap years has 29 |
||
288 | res += nYear % 4 == 0 && !(nYear % 400 == 0) ? 1 : 0; |
||
1 ignored issue
–
show
|
|||
289 | return res; |
||
290 | } |
||
291 | |||
292 | if(kc < 37 || kc > 40) return true; |
||
1 ignored issue
–
show
|
|||
293 | |||
294 | var current = this.selectedDate; |
||
295 | var d = current.valueOf(); |
||
296 | if(kc == 37) // left |
||
297 | { |
||
298 | if(ev.ctrlKey || ev.shiftKey) // -1 month |
||
299 | { |
||
300 | current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth() - 1,current.getFullYear())) ); // no need to catch dec -> jan for the year |
||
301 | d = current.setMonth( current.getMonth() - 1 ); |
||
302 | } |
||
303 | else |
||
304 | d -= 86400000; //-1 day |
||
1 ignored issue
–
show
|
|||
305 | } |
||
306 | else if (kc == 39) // right |
||
307 | { |
||
308 | if(ev.ctrlKey || ev.shiftKey) // +1 month |
||
309 | { |
||
310 | current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth() + 1,current.getFullYear())) ); // no need to catch dec -> jan for the year |
||
311 | d = current.setMonth( current.getMonth() + 1 ); |
||
312 | } |
||
313 | else |
||
314 | d += 86400000; //+1 day |
||
1 ignored issue
–
show
|
|||
315 | } |
||
316 | else if (kc == 38) // up |
||
317 | { |
||
318 | if(ev.ctrlKey || ev.shiftKey) //-1 year |
||
319 | { |
||
320 | current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth(),current.getFullYear() - 1)) ); // no need to catch dec -> jan for the year |
||
321 | d = current.setFullYear( current.getFullYear() - 1 ); |
||
322 | } |
||
323 | else |
||
324 | d -= 604800000; // -7 days |
||
1 ignored issue
–
show
|
|||
325 | } |
||
326 | else if (kc == 40) // down |
||
327 | { |
||
328 | if(ev.ctrlKey || ev.shiftKey) // +1 year |
||
329 | { |
||
330 | current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth(),current.getFullYear() + 1)) ); // no need to catch dec -> jan for the year |
||
331 | d = current.setFullYear( current.getFullYear() + 1 ); |
||
332 | } |
||
333 | else |
||
334 | d += 7 * 24 * 61 * 60 * 1000; // +7 days |
||
1 ignored issue
–
show
|
|||
335 | } |
||
336 | this.setSelectedDate(d); |
||
337 | ev.preventDefault(); |
||
338 | }, |
||
339 | |||
340 | selectDate : function(ev) |
||
341 | { |
||
342 | var el = ev.target; |
||
343 | while (el.nodeType != 1) |
||
344 | el = el.parentNode; |
||
1 ignored issue
–
show
|
|||
345 | |||
346 | while (el != null && el.tagName && el.tagName.toLowerCase() != "td") |
||
347 | el = el.parentNode; |
||
1 ignored issue
–
show
|
|||
348 | |||
349 | // if no td found, return |
||
350 | if (el == null || el.tagName == null || el.tagName.toLowerCase() != "td") |
||
351 | return; |
||
1 ignored issue
–
show
|
|||
352 | |||
353 | var d = this.newDate(this.selectedDate); |
||
354 | var n = Number(el.firstChild.data); |
||
355 | if (isNaN(n) || n <= 0 || n == null) |
||
356 | return; |
||
1 ignored issue
–
show
|
|||
357 | |||
358 | d.setDate(n); |
||
359 | this.setSelectedDate(d); |
||
360 | this.hide(); |
||
361 | }, |
||
362 | |||
363 | selectToday : function() |
||
364 | { |
||
365 | if(this.selectedDate.toISODate() == this.newDate().toISODate()) |
||
366 | this.hide(); |
||
1 ignored issue
–
show
|
|||
367 | |||
368 | this.setSelectedDate(this.newDate()); |
||
369 | }, |
||
370 | |||
371 | clearSelection : function() |
||
372 | { |
||
373 | this.setSelectedDate(this.newDate()); |
||
374 | this.hide(); |
||
375 | }, |
||
376 | |||
377 | monthSelect : function(ev) |
||
378 | { |
||
379 | this.setMonth(ev.target.value); |
||
380 | }, |
||
381 | |||
382 | yearSelect : function(ev) |
||
383 | { |
||
384 | this.setYear(ev.target.value); |
||
385 | }, |
||
386 | |||
387 | mouseWheelChange : function (event) |
||
388 | { |
||
389 | var delta = 0; |
||
390 | if (!event) event = document.parentWindow.event; |
||
1 ignored issue
–
show
|
|||
391 | if (event.wheelDelta) { |
||
392 | delta = event.wheelDelta/120; |
||
393 | if (window.opera) delta = -delta; |
||
1 ignored issue
–
show
|
|||
394 | } else if (event.detail) { delta = -event.detail/3; } |
||
395 | |||
396 | var d = this.newDate(this.selectedDate); |
||
397 | var m = d.getMonth() + Math.round(delta); |
||
398 | this.setMonth(m,true); |
||
399 | return false; |
||
400 | }, |
||
401 | |||
402 | // Respond to change event on the textbox or dropdown list |
||
403 | // This method raises OnDateChanged event on client side if it has been defined |
||
404 | onDateChanged : function () |
||
405 | { |
||
406 | if (this.options.OnDateChanged) |
||
407 | { |
||
408 | var date; |
||
409 | if (this.options.InputMode == "TextBox") |
||
410 | { |
||
411 | date=this.control.value; |
||
412 | } |
||
413 | else |
||
414 | { |
||
415 | var day = Prado.WebUI.TDatePicker.getDayListControl(this.control).selectedIndex+1; |
||
1 ignored issue
–
show
|
|||
416 | var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control).selectedIndex; |
||
417 | var year = Prado.WebUI.TDatePicker.getYearListControl(this.control).value; |
||
418 | date=new Date(year, month, day, 0,0,0).SimpleFormat(this.Format, this); |
||
419 | } |
||
420 | this.options.OnDateChanged(this, date); |
||
421 | } |
||
422 | }, |
||
423 | |||
424 | fireChangeEvent: function(element, capped) |
||
425 | { |
||
426 | if (capped) |
||
427 | { |
||
428 | var obj = this; |
||
429 | |||
430 | if (typeof(obj.changeeventtimer)!="undefined") |
||
431 | { |
||
432 | clearTimeout(obj.changeeventtimer); |
||
433 | obj.changeeventtimer = null; |
||
434 | } |
||
435 | obj.changeeventtimer = setTimeout( |
||
436 | function() { obj.changeeventtimer = null; jQuery(element).trigger("change"); }, |
||
437 | 1500 |
||
438 | ); |
||
439 | } |
||
440 | else |
||
441 | jQuery(element).trigger("change"); |
||
1 ignored issue
–
show
|
|||
442 | }, |
||
443 | |||
444 | onChange : function(ref, date, capevents) |
||
445 | { |
||
446 | if(this.options.InputMode == "TextBox") |
||
447 | { |
||
448 | this.control.value = this.formatDate(); |
||
449 | this.fireChangeEvent(this.control, capevents); |
||
450 | } |
||
451 | else |
||
452 | { |
||
453 | var day = Prado.WebUI.TDatePicker.getDayListControl(this.control); |
||
1 ignored issue
–
show
|
|||
454 | var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control); |
||
455 | var year = Prado.WebUI.TDatePicker.getYearListControl(this.control); |
||
456 | var date = this.selectedDate; |
||
457 | if(day) |
||
458 | { |
||
459 | day.selectedIndex = date.getDate()-1; |
||
460 | } |
||
461 | if(month) |
||
462 | { |
||
463 | month.selectedIndex = date.getMonth(); |
||
464 | } |
||
465 | if(year) |
||
466 | { |
||
467 | var years = year.options; |
||
468 | var currentYear = date.getFullYear(); |
||
469 | for(var i = 0; i < years.length; i++) |
||
470 | years[i].selected = years[i].value.toInteger() == currentYear; |
||
1 ignored issue
–
show
|
|||
471 | } |
||
472 | |||
473 | day && this.fireChangeEvent(day, capevents); |
||
474 | month && this.fireChangeEvent(month, capevents); |
||
475 | year && this.fireChangeEvent(year, capevents); |
||
476 | } |
||
477 | }, |
||
478 | |||
479 | formatDate : function() |
||
480 | { |
||
481 | return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format,this) : ''; |
||
482 | }, |
||
483 | |||
484 | newDate : function(date) |
||
485 | { |
||
486 | if(!date) |
||
487 | date = new Date(); |
||
1 ignored issue
–
show
|
|||
488 | if(typeof(date) == "string" || typeof(date) == "number") |
||
489 | date = new Date(date); |
||
1 ignored issue
–
show
|
|||
490 | return new Date(Math.min(Math.max(date.getFullYear(),this.FromYear),this.UpToYear), date.getMonth(), date.getDate(), 0,0,0); |
||
491 | }, |
||
492 | |||
493 | setSelectedDate : function(date, capevents) |
||
494 | { |
||
495 | if (date == null) |
||
496 | return; |
||
1 ignored issue
–
show
|
|||
497 | var old=this.selectedDate; |
||
498 | this.selectedDate = this.newDate(date); |
||
499 | var dateChanged=(old - this.selectedDate != 0) || ( this.options.InputMode == "TextBox" && this.control.value != this.formatDate()); |
||
500 | |||
501 | this.updateHeader(); |
||
502 | this.update(); |
||
503 | if (dateChanged && typeof(this.onChange) == "function") |
||
504 | this.onChange(this, date, capevents); |
||
1 ignored issue
–
show
|
|||
505 | }, |
||
506 | |||
507 | getElement : function() |
||
508 | { |
||
509 | return this._calDiv; |
||
510 | }, |
||
511 | |||
512 | getSelectedDate : function () |
||
513 | { |
||
514 | return this.selectedDate == null ? null : this.newDate(this.selectedDate); |
||
515 | }, |
||
516 | |||
517 | setYear : function(year) |
||
518 | { |
||
519 | var d = this.newDate(this.selectedDate); |
||
520 | d.setFullYear(year); |
||
521 | this.setSelectedDate(d); |
||
522 | }, |
||
523 | |||
524 | setMonth : function (month, capevents) |
||
525 | { |
||
526 | var d = this.newDate(this.selectedDate); |
||
527 | d.setDate(Math.min(d.getDate(), this.getDaysPerMonth(month,d.getFullYear()))); |
||
528 | d.setMonth(month); |
||
529 | this.setSelectedDate(d,capevents); |
||
530 | }, |
||
531 | |||
532 | nextMonth : function () |
||
533 | { |
||
534 | this.setMonth(this.selectedDate.getMonth()+1); |
||
535 | }, |
||
536 | |||
537 | prevMonth : function () |
||
538 | { |
||
539 | this.setMonth(this.selectedDate.getMonth()-1); |
||
540 | }, |
||
541 | |||
542 | getDaysPerMonth : function (month, year) |
||
543 | { |
||
544 | month = (Number(month)+12) % 12; |
||
545 | var days = [31,28,31,30,31,30,31,31,30,31,30,31]; |
||
546 | var res = days[month]; |
||
547 | if (month == 1 && ((!(year % 4) && (year % 100)) || !(year % 400))) //feburary, leap years has 29 |
||
548 | res++; |
||
1 ignored issue
–
show
|
|||
549 | return res; |
||
550 | }, |
||
551 | |||
552 | getDatePickerOffsetHeight : function() |
||
553 | { |
||
554 | if(this.options.InputMode == "TextBox") |
||
555 | return this.control.offsetHeight; |
||
1 ignored issue
–
show
|
|||
556 | |||
557 | var control = Prado.WebUI.TDatePicker.getDayListControl(this.control); |
||
1 ignored issue
–
show
|
|||
558 | if(control) return control.offsetHeight; |
||
1 ignored issue
–
show
|
|||
559 | |||
560 | var control = Prado.WebUI.TDatePicker.getMonthListControl(this.control); |
||
561 | if(control) return control.offsetHeight; |
||
1 ignored issue
–
show
|
|||
562 | |||
563 | var control = Prado.WebUI.TDatePicker.getYearListControl(this.control); |
||
564 | if(control) return control.offsetHeight; |
||
1 ignored issue
–
show
|
|||
565 | return 0; |
||
566 | }, |
||
567 | |||
568 | show : function() |
||
569 | { |
||
570 | this.create(); |
||
571 | |||
572 | if(!this.showing) |
||
573 | { |
||
574 | var pos = jQuery(this.control).position(); |
||
575 | |||
576 | pos['top'] += this.getDatePickerOffsetHeight(); |
||
577 | this._calDiv.style.top = (pos['top']-1) + "px"; |
||
578 | this._calDiv.style.display = "block"; |
||
579 | this._calDiv.style.left = pos['left'] + "px"; |
||
580 | |||
581 | this.documentClickEvent = jQuery.bind(this.hideOnClick, this); |
||
582 | this.documentKeyDownEvent = jQuery.bind(this.keyPressed, this); |
||
583 | this.observe(document.body, "click", this.documentClickEvent); |
||
584 | var date = this.getDateFromInput(); |
||
585 | if(date) |
||
586 | { |
||
587 | this.selectedDate = date; |
||
588 | this.setSelectedDate(date); |
||
589 | } |
||
590 | this.observe(document,"keydown", this.documentKeyDownEvent); |
||
591 | this.showing = true; |
||
592 | |||
593 | if(this.positionMode=='Top') |
||
594 | { |
||
595 | this._calDiv.style.top = ((pos['top']-1) - this.getDatePickerOffsetHeight() - this._calDiv.offsetHeight) + 'px'; |
||
596 | } |
||
597 | } |
||
598 | }, |
||
599 | |||
600 | getDateFromInput : function() |
||
601 | { |
||
602 | if(this.options.InputMode == "TextBox") |
||
603 | return Date.SimpleParse(this.control.value, this.Format); |
||
1 ignored issue
–
show
|
|||
604 | else |
||
605 | return Prado.WebUI.TDatePicker.getDropDownDate(this.control); |
||
1 ignored issue
–
show
|
|||
606 | }, |
||
607 | |||
608 | //hide the calendar when clicked outside any calendar |
||
609 | hideOnClick : function(ev) |
||
610 | { |
||
611 | if(!this.showing) return; |
||
1 ignored issue
–
show
|
|||
612 | var el = ev.target; |
||
613 | var within = false; |
||
614 | do |
||
615 | { |
||
616 | within = within || (el.className && jQuery(el).hasClass("TDatePicker_"+this.CalendarStyle)); |
||
617 | within = within || el == this.trigger; |
||
618 | within = within || el == this.control; |
||
619 | if(within) break; |
||
1 ignored issue
–
show
|
|||
620 | el = el.parentNode; |
||
621 | } |
||
622 | while(el); |
||
623 | if(!within) this.hide(); |
||
1 ignored issue
–
show
|
|||
624 | }, |
||
625 | |||
626 | |||
627 | hide : function() |
||
628 | { |
||
629 | if(this.showing) |
||
630 | { |
||
631 | this._calDiv.style.display = "none"; |
||
632 | this.showing = false; |
||
633 | this.stopObserving(document.body, "click", this.documentClickEvent); |
||
634 | this.stopObserving(document,"keydown", this.documentKeyDownEvent); |
||
635 | } |
||
636 | }, |
||
637 | |||
638 | update : function() |
||
639 | { |
||
640 | // Calculate the number of days in the month for the selected date |
||
641 | var date = this.selectedDate; |
||
642 | var today = (this.newDate()).toISODate(); |
||
643 | |||
644 | var selected = date.toISODate(); |
||
645 | var d1 = new Date(date.getFullYear(), date.getMonth(), 1); |
||
646 | var d2 = new Date(date.getFullYear(), date.getMonth()+1, 1); |
||
647 | var monthLength = Math.round((d2 - d1) / (24 * 60 * 60 * 1000)); |
||
648 | |||
649 | // Find out the weekDay index for the first of this month |
||
650 | var firstIndex = (d1.getDay() - this.FirstDayOfWeek) % 7 ; |
||
651 | if (firstIndex < 0) |
||
652 | firstIndex += 7; |
||
1 ignored issue
–
show
|
|||
653 | |||
654 | var index = 0; |
||
655 | while (index < firstIndex) { |
||
656 | this.dateSlot[index].value = -1; |
||
657 | this.dateSlot[index].data.data = String.fromCharCode(160); |
||
658 | this.dateSlot[index].data.parentNode.className = "empty"; |
||
659 | index++; |
||
660 | } |
||
661 | |||
662 | for (var i = 1; i <= monthLength; i++, index++) { |
||
663 | var slot = this.dateSlot[index]; |
||
664 | var slotNode = slot.data.parentNode; |
||
665 | slot.value = i; |
||
666 | slot.data.data = i; |
||
667 | slotNode.className = "date"; |
||
668 | //slotNode.style.color = ""; |
||
669 | if (d1.toISODate() == today) { |
||
670 | slotNode.className += " today"; |
||
671 | } |
||
672 | if (d1.toISODate() == selected) { |
||
673 | // slotNode.style.color = "blue"; |
||
674 | slotNode.className += " selected"; |
||
675 | } |
||
676 | d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()+1); |
||
677 | } |
||
678 | |||
679 | var lastDateIndex = index; |
||
680 | |||
681 | while(index < 42) { |
||
682 | this.dateSlot[index].value = -1; |
||
683 | this.dateSlot[index].data.data = String.fromCharCode(160); |
||
684 | this.dateSlot[index].data.parentNode.className = "empty"; |
||
685 | ++index; |
||
686 | } |
||
687 | |||
688 | }, |
||
689 | |||
690 | hover : function(ev) |
||
691 | { |
||
692 | if(ev.target.tagName) |
||
693 | { |
||
694 | if(ev.type == "mouseover") |
||
695 | jQuery(ev.target).addClass("hover"); |
||
1 ignored issue
–
show
|
|||
696 | else |
||
697 | jQuery(ev.target).removeClass("hover"); |
||
698 | } |
||
699 | }, |
||
700 | |||
701 | updateHeader : function () { |
||
702 | |||
703 | var options = this._monthSelect.options; |
||
704 | var m = this.selectedDate.getMonth(); |
||
705 | for(var i=0; i < options.length; ++i) { |
||
706 | options[i].selected = false; |
||
707 | if (options[i].value == m) { |
||
708 | options[i].selected = true; |
||
709 | } |
||
710 | } |
||
711 | |||
712 | options = this._yearSelect.options; |
||
713 | var year = this.selectedDate.getFullYear(); |
||
714 | for(var i=0; i < options.length; ++i) { |
||
715 | options[i].selected = false; |
||
716 | if (options[i].value == year) { |
||
717 | options[i].selected = true; |
||
718 | } |
||
719 | } |
||
720 | |||
721 | } |
||
722 | }); |
||
723 | |||
724 | jQuery.extend(Prado.WebUI.TDatePicker, |
||
1 ignored issue
–
show
|
|||
725 | { |
||
726 | /** |
||
727 | * @return Date the date from drop down list options. |
||
728 | */ |
||
729 | getDropDownDate : function(control) |
||
730 | { |
||
731 | var now=new Date(); |
||
732 | var year=now.getFullYear(); |
||
733 | var month=now.getMonth(); |
||
734 | var day=1; |
||
735 | |||
736 | var month_list = Prado.WebUI.TDatePicker.getMonthListControl(control); |
||
1 ignored issue
–
show
|
|||
737 | var day_list = Prado.WebUI.TDatePicker.getDayListControl(control); |
||
738 | var year_list = Prado.WebUI.TDatePicker.getYearListControl(control); |
||
739 | |||
740 | var day = day_list ? day_list.value : 1; |
||
741 | var month = month_list ? month_list.value : now.getMonth(); |
||
742 | var year = year_list ? year_list.value : now.getFullYear(); |
||
743 | |||
744 | return new Date(year,month,day, 0, 0, 0); |
||
745 | }, |
||
746 | |||
747 | getYearListControl : function(control) |
||
748 | { |
||
749 | return jQuery('#'+control.id+"_year").get(0); |
||
750 | }, |
||
751 | |||
752 | getMonthListControl : function(control) |
||
753 | { |
||
754 | return jQuery('#'+control.id+"_month").get(0); |
||
755 | }, |
||
756 | |||
757 | getDayListControl : function(control) |
||
758 | { |
||
759 | return jQuery('#'+control.id+"_day").get(0); |
||
760 | } |
||
761 | }); |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.