_jquery-connector.html 5.0 KB

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