|
157 | 157 | } |
158 | 158 |
|
159 | 159 | // invalid offset |
160 | | - if (!/^-?\d+$/.test(val)) { return; } |
| 160 | + if ( !(/^-?\d+$/).test(val) ) { return; } |
161 | 161 |
|
162 | 162 | // convert to integer |
163 | 163 | val = integer(val); |
|
339 | 339 |
|
340 | 340 |
|
341 | 341 | if (index > 41) { |
342 | | - showNextMonth(); |
| 342 | + self.addMonth(); |
343 | 343 | el = $("#" + css.weeks + " a:eq(" + (index-42) + ")"); |
344 | 344 | } else if (index < 0) { |
345 | | - showPreviousMonth(); |
| 345 | + self.addMonth(-1); |
346 | 346 | el = $("#" + css.weeks + " a:eq(" + (index+42) + ")"); |
347 | 347 | } else { |
348 | 348 | el = days.eq(index); |
|
354 | 354 | } |
355 | 355 |
|
356 | 356 | // pageUp / pageDown |
357 | | - if (key == 34) { return showNextMonth(); } |
358 | | - if (key == 33) { return showPreviousMonth(); } |
| 357 | + if (key == 34) { return self.addMonth(); } |
| 358 | + if (key == 33) { return self.addMonth(-1); } |
359 | 359 |
|
360 | 360 | // home |
361 | 361 | if (key == 36) { return self.today(); } |
|
384 | 384 | //}}} |
385 | 385 |
|
386 | 386 |
|
387 | | - /** |
388 | | - * @private |
389 | | - * |
390 | | - * Calculates the days in the next month to properly switch months |
391 | | - * |
392 | | - */ |
393 | | - function showNextMonth() { |
394 | | - |
395 | | - var daysNextMonth = dayAm(currYear, currMonth + 1); |
396 | | - |
397 | | - /* |
398 | | - * If next month has less days than the current date |
399 | | - * add number of days in the next month, otherwise add |
400 | | - * number of days in the current month |
401 | | - */ |
402 | | - return self.addDay(currDay > daysNextMonth ? daysNextMonth : dayAm(currYear, currMonth)); |
403 | | - } |
404 | | - |
405 | | - /** |
406 | | - * @private |
407 | | - * |
408 | | - * Return to previous month |
409 | | - */ |
410 | | - function showPreviousMonth() { |
411 | | - return self.addDay(-dayAm(currYear, currMonth)); |
412 | | - } |
413 | | - |
414 | 387 | $.extend(self, { |
415 | 388 |
|
416 | 389 |
|
|
447 | 420 | // prev / next month |
448 | 421 | pm = root.find("#" + css.prev).unbind("click").click(function(e) { |
449 | 422 | if (!pm.hasClass(css.disabled)) { |
450 | | - showPreviousMonth(); |
| 423 | + self.addMonth(-1); |
451 | 424 | } |
452 | 425 | return false; |
453 | 426 | }); |
454 | 427 |
|
455 | 428 | nm = root.find("#" + css.next).unbind("click").click(function(e) { |
456 | 429 | if (!nm.hasClass(css.disabled)) { |
457 | | - showNextMonth(); |
| 430 | + self.addMonth(); |
458 | 431 | } |
459 | 432 | return false; |
460 | 433 | }); |
|
657 | 630 | }, |
658 | 631 |
|
659 | 632 | addMonth: function(amount) { |
660 | | - return this.setValue(currYear, currMonth + (amount || 1), currDay); |
| 633 | + var targetMonth = currMonth + (amount || 1), |
| 634 | + daysInTargetMonth = dayAm(currYear, targetMonth), |
| 635 | + targetDay = currDay <= daysInTargetMonth ? currDay : daysInTargetMonth; |
| 636 | + |
| 637 | + return this.setValue(currYear, targetMonth, targetDay); |
661 | 638 | }, |
662 | 639 |
|
663 | 640 | addYear: function(amount) { |
|
0 commit comments