jquery-connector.html 4.5 KB

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