Guest User

Untitled

a guest
Jul 21st, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. <template>
  2. <div class="calendar">
  3. <div class="calendar-nav">
  4. <div class="calendar-nav-previous-month">
  5. <button class="button is-small is-text" @click='prevMonth'>
  6. <b-icon icon-pack="fas" icon="long-arrow-alt-left"></b-icon>
  7. </button>
  8. </div>
  9. <div class="calendar-month">{{ monthInString[month] }} {{ year }}</div>
  10. <div class="calendar-nav-next-month">
  11. <button class="button is-small is-text" @click='nextMonth'>
  12. <b-icon icon-pack="fas" icon="long-arrow-alt-right"></b-icon>
  13. </button>
  14. </div>
  15. </div>
  16. <div class="calendar-container">
  17. <div class="calendar-header">
  18. <div class="calendar-date">Sun</div>
  19. <div class="calendar-date">Mon</div>
  20. <div class="calendar-date">Tue</div>
  21. <div class="calendar-date">Wed</div>
  22. <div class="calendar-date">Thu</div>
  23. <div class="calendar-date">Fri</div>
  24. <div class="calendar-date">Sat</div>
  25. </div>
  26. <div class="calendar-body">
  27. <v-html="content"></v-html>
  28. </div>
  29. </div>
  30. </div>
  31. </template>
  32.  
  33. <script>
  34. export default {
  35. data: function () {
  36. return {
  37. monthInString : ['January','February','March','April','May','June','July','August','September','October','November','December'],
  38. date: null,
  39. month: 0,
  40. year: 0
  41. }
  42. },
  43.  
  44. created () {
  45. let today = new Date()
  46. this.date = today
  47. this.month = today.getMonth()
  48. this.year = today.getFullYear()
  49. },
  50.  
  51. computed: {
  52. // oh, this is killing me!
  53. calendarContent: function () {
  54. let content = ''
  55. // get first day in current month
  56. let day = new Date(this.year,this.month,1).getDay()
  57. // if it doesn't start in Sunday, generate previous date from previous month
  58. if (day !== 0) {
  59. let daysInPreviousMonth = getDaysInMonth(this.month-1,year)
  60. for (let i = daysInPreviousMonth-day+1; i <= daysInPreviousMonth; i++) {
  61. content += `<div class="calendar-date is-disabled"><button class="date-item">${ i }</button></div>\n`
  62. }
  63. }
  64. // now, handle the actual calendar
  65. // yes, the calendar here is still static
  66. // attaching an event will require new data, get it in created hook
  67. for (let i = 1; i <= getDaysInMonth(this.year,this.month); i++) {
  68. let realContent = `<button class="date-item ${ this.date.getDate() === i ? ' is-today' : '' }">${ i }</button>`
  69. // if there's an event in the current date, add calendar-events class
  70. // the event(s) will be added ONLY IF the event(s)
  71. // ADD IT HERE!
  72. content += `<div class="calendar-date">${ realContent }</div>`
  73. day++
  74. if (day>6) {
  75. day = 0
  76. }
  77. }
  78. // now, fill the remaining calendar with days from next month
  79. for (let i = 1; day <= 6; day++, i++) {
  80. content += `<div class="calendar-date is-disabled"><button class="date-item">${ i }</button></div>\n`
  81. }
  82. return content
  83. }
  84. },
  85.  
  86. methods: {
  87. prevMonth: function () {
  88. if (month === 0) {
  89. month = 11
  90. year -= 1
  91. } else {
  92. month = date.getMonth()-1
  93. }
  94. },
  95.  
  96. nextMonth: function () {
  97. if(month === 11) {
  98. month = 0
  99. year += 1
  100. } else {
  101. month = date.getMonth()+1
  102. }
  103. },
  104.  
  105. getDaysInMonth: function (month, year) {
  106. return new Date(year, month+1, 0).getDate()
  107. }
  108. }
  109. }
  110. </script>
  111.  
  112. <style lang="scss" scoped>
  113. @import '~bulma-calendar';
  114. </style>
Add Comment
Please, Sign In to add comment