MonthView.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* A month view with day cells running in rows (one-per-week) and columns
  2. ----------------------------------------------------------------------------------------------------------------------*/
  3. setDefaults({
  4. fixedWeekCount: true,
  5. eventLimit: false,
  6. eventLimitText: 'more',
  7. eventLimitClick: 'popover',
  8. dayPopoverFormat: 'LL'
  9. });
  10. fcViews.month = MonthView; // register the view
  11. function MonthView(calendar) {
  12. BasicView.call(this, calendar); // call the super-constructor
  13. }
  14. MonthView.prototype = createObject(BasicView.prototype); // define the super-class
  15. $.extend(MonthView.prototype, {
  16. name: 'month',
  17. incrementDate: function(date, delta) {
  18. return date.clone().stripTime().add(delta, 'months').startOf('month');
  19. },
  20. render: function(date) {
  21. var rowCnt;
  22. this.intervalStart = date.clone().stripTime().startOf('month');
  23. this.intervalEnd = this.intervalStart.clone().add(1, 'months');
  24. this.start = this.intervalStart.clone();
  25. this.start = this.skipHiddenDays(this.start); // move past the first week if no visible days
  26. this.start.startOf('week');
  27. this.start = this.skipHiddenDays(this.start); // move past the first invisible days of the week
  28. this.end = this.intervalEnd.clone();
  29. this.end = this.skipHiddenDays(this.end, -1, true); // move in from the last week if no visible days
  30. this.end.add((7 - this.end.weekday()) % 7, 'days'); // move to end of week if not already
  31. this.end = this.skipHiddenDays(this.end, -1, true); // move in from the last invisible days of the week
  32. rowCnt = Math.ceil( // need to ceil in case there are hidden days
  33. this.end.diff(this.start, 'weeks', true) // returnfloat=true
  34. );
  35. if (this.isFixedWeeks()) {
  36. this.end.add(6 - rowCnt, 'weeks');
  37. rowCnt = 6;
  38. }
  39. this.title = this.calendar.formatDate(this.intervalStart, this.opt('titleFormat'));
  40. BasicView.prototype.render.call(this, rowCnt, this.getCellsPerWeek(), true); // call the super-method
  41. },
  42. // Overrides the default BasicView behavior to have special multi-week auto-height logic
  43. setGridHeight: function(height, isAuto) {
  44. var eventLimit = this.opt('eventLimit');
  45. isAuto = isAuto || this.opt('weekMode') === 'variable'; // LEGACY: weekMode is deprecated
  46. // if auto, make the height of each row the height that it would be if there were 6 weeks
  47. if (isAuto) {
  48. height *= this.rowCnt / 6;
  49. }
  50. this.dayGrid.destroySegPopover(); // kill the "more" popover if displayed
  51. // is the event limit a constant level number?
  52. if (eventLimit && typeof eventLimit === 'number') {
  53. this.dayGrid.limitRows(eventLimit); // limit the levels first so the height can redistribute after
  54. }
  55. distributeHeight(this.dayGrid.rowEls, height, !isAuto); // if auto, don't compensate for height-hogging rows
  56. // is the event limit dynamically calculated?
  57. if (eventLimit && typeof eventLimit !== 'number') {
  58. this.dayGrid.limitRows(eventLimit); // limit the levels after the grid's row heights have been set
  59. }
  60. },
  61. isFixedWeeks: function() {
  62. var weekMode = this.opt('weekMode'); // LEGACY: weekMode is deprecated
  63. if (weekMode) {
  64. return weekMode === 'fixed'; // if any other type of weekMode, assume NOT fixed
  65. }
  66. return this.opt('fixedWeekCount');
  67. },
  68. // If dynamically limiting events, signals that all rows need to be a constant height.
  69. hasRigidRows: function() {
  70. var eventLimit = this.opt('eventLimit');
  71. return eventLimit && typeof eventLimit !== 'number';
  72. }
  73. });