_jquery-connector.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8' />
  5. <link href='../packages/bundle/main.css' rel='stylesheet' />
  6. <script src='../packages/bundle/main.js'></script>
  7. <script src='../node_modules/jquery/dist/jquery.min.js'></script>
  8. <script>
  9. // The jQuery Connector
  10. // ----------------------------------------------------------------------------------------------------
  11. $.fn.fullCalendar = function(options) {
  12. var args = Array.prototype.slice.call(arguments, 1) // for a possible method call
  13. var res = this // what this function will return (the current jQuery object by default)
  14. this.each(function(i, el) { // loop each DOM element involved
  15. var $el = $(el)
  16. var calendar = $el.data('fullCalendar') // get the existing calendar object (if any)
  17. var singleRes // the returned value of this single method call
  18. // a method call
  19. if (typeof options === 'string') {
  20. if (options === 'getCalendar') {
  21. if (!i) { // first element only
  22. res = calendar
  23. }
  24. } else if (options === 'destroy') { // don't warn if no calendar object
  25. if (calendar) {
  26. calendar.destroy()
  27. $el.removeData('fullCalendar')
  28. }
  29. } else if (!calendar) {
  30. console.warn('Attempting to call a FullCalendar method on an element with no calendar.')
  31. } else if ($.isFunction(calendar[options])) {
  32. singleRes = calendar[options].apply(calendar, args)
  33. if (!i) {
  34. res = singleRes // record the first method call result
  35. }
  36. } else {
  37. console.warn("'" + options + "' is an unknown FullCalendar method.")
  38. }
  39. // an initialization
  40. } else {
  41. if (calendar) {
  42. console.warn('Can\'t initialize another calendar on the same element.')
  43. } else {
  44. calendar = new FullCalendar.Calendar(el, options)
  45. $el.data('fullCalendar', calendar)
  46. calendar.render()
  47. }
  48. }
  49. })
  50. return res
  51. }
  52. // The Actual Example
  53. // ----------------------------------------------------------------------------------------------------
  54. $(document).ready(function() {
  55. var $calendar = $('#calendar')
  56. $calendar.fullCalendar({
  57. headerToolbar: {
  58. left: 'prev,next today',
  59. center: 'title',
  60. right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
  61. },
  62. initialDate: '2020-09-12',
  63. navLinks: true, // can click day/week names to navigate views
  64. editable: true,
  65. dayMaxEvents: true, // allow "more" link when too many events
  66. events: [
  67. {
  68. title: 'All Day Event',
  69. start: '2020-09-01',
  70. },
  71. {
  72. title: 'Long Event',
  73. start: '2020-09-07',
  74. end: '2020-09-10'
  75. },
  76. {
  77. groupId: 999,
  78. title: 'Repeating Event',
  79. start: '2020-09-09T16:00:00'
  80. },
  81. {
  82. groupId: 999,
  83. title: 'Repeating Event',
  84. start: '2020-09-16T16:00:00'
  85. },
  86. {
  87. title: 'Conference',
  88. start: '2020-09-11',
  89. end: '2020-09-13'
  90. },
  91. {
  92. title: 'Meeting',
  93. start: '2020-09-12T10:30:00',
  94. end: '2020-09-12T12:30:00'
  95. },
  96. {
  97. title: 'Lunch',
  98. start: '2020-09-12T12:00:00'
  99. },
  100. {
  101. title: 'Meeting',
  102. start: '2020-09-12T14:30:00'
  103. },
  104. {
  105. title: 'Happy Hour',
  106. start: '2020-09-12T17:30:00'
  107. },
  108. {
  109. title: 'Dinner',
  110. start: '2020-09-12T20:00:00'
  111. },
  112. {
  113. title: 'Birthday Party',
  114. start: '2020-09-13T07:00:00'
  115. },
  116. {
  117. title: 'Click for Google',
  118. url: 'http://google.com/',
  119. start: '2020-09-28'
  120. }
  121. ]
  122. })
  123. $('#prev-button').on('click', function() {
  124. $calendar.fullCalendar('prev')
  125. })
  126. $('#next-button').on('click', function() {
  127. $calendar.fullCalendar('next')
  128. })
  129. $('#gotoDate-button').on('click', function() {
  130. $calendar.fullCalendar('gotoDate', '2020-09-01')
  131. })
  132. })
  133. </script>
  134. <style>
  135. body {
  136. margin: 40px 10px;
  137. padding: 0;
  138. font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
  139. font-size: 14px;
  140. }
  141. #calendar {
  142. max-width: 1100px;
  143. margin: 0 auto;
  144. }
  145. </style>
  146. </head>
  147. <body>
  148. <button id='prev-button'>prev</button>
  149. <button id='next-button'>next</button>
  150. <button id='gotoDate-button'>goto year 2000</button>
  151. <div id='calendar'></div>
  152. </body>
  153. </html>