在fullcalendar v3上显示节假日活动,就像easemytrip移动视图日历中一样。

huangapple go评论99阅读模式
英文:

Showing holiday events on fullcalendar v3 as in easemytrip mobile view calendar

问题

您正在使用fullcalendar v3进行项目开发。您想要在日历上显示假期,就像附带的图像中标记的红色方框所示。

它应该显示如下:

  1. 在顶部 - 它将显示每个月的总假期数。
  2. 它应该像徽章一样标有1、2、3的日期,表示每个月的假期。
  3. 在每个月底部,应该描述每个月的徽章及其假期名称。
英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

  1. $(document).ready(function () {
  2. $(&#39;#calendar&#39;).fullCalendar({
  3. header: {
  4. left: &#39;today&#39;,//&#39;month,basicWeek,basicDay&#39;,
  5. center: &#39;title&#39;,
  6. right: &#39;prev,next&#39;
  7. },
  8. views: {
  9. month: { // name of view
  10. titleFormat: &#39;MMM YYYY&#39;
  11. // other view-specific options here
  12. }
  13. },
  14. buttonText: {
  15. today: &#39;Today&#39;,
  16. },
  17. defaultDate: &#39;2023-06-09&#39;,
  18. fixedWeekCount: false,
  19. showNonCurrentDates: false,
  20. navLinks: false, // can click day/week names to navigate views
  21. editable: false,
  22. eventLimit: false, // allow &quot;more&quot; link when too many events
  23. selectable: true,
  24. selectHelper: true,
  25. dayClick: function (date) {
  26. alert(date.format() + &quot;\n&quot; + calEvent.title);
  27. },
  28. eventClick: function(calEvent) {
  29. alert(calEvent.title);
  30. },
  31. eventSources: [
  32. // your event source
  33. //&#39;/feed1.php&#39;,
  34. //&#39;/feed2.php&#39;,
  35. {
  36. events: [
  37. {
  38. title: &#39;FULL&#39;,
  39. start: &#39;2023-06-11&#39;,
  40. },
  41. //for holidays
  42. {
  43. title: &#39;1&#39;,
  44. start: &#39;2023-06-11&#39;,
  45. color: &#39;#FFE3A2&#39;,
  46. textColor: &#39;#000&#39;,
  47. className: &#39;circle_dot&#39;
  48. },
  49. {
  50. title: &#39;AVAILABLE&#39;,
  51. start: &#39;2023-06-12&#39;,
  52. color: &#39;#257e4a&#39;,
  53. textColor: &#39;#ffffff&#39;,
  54. },
  55. //for holidays
  56. {
  57. title: &#39;2&#39;,
  58. start: &#39;2023-06-12&#39;,
  59. color: &#39;#FFE3A2&#39;,
  60. textColor: &#39;#000&#39;,
  61. className: &#39;circle_dot&#39;
  62. },
  63. {
  64. title: &#39;FULL&#39;,
  65. start: &#39;2023-06-23&#39;,
  66. color: &#39;#e66d1d&#39;
  67. },
  68. {
  69. title: &#39;AVAILABLE&#39;,
  70. start: &#39;2023-06-28&#39;,
  71. }
  72. ],
  73. color: &#39;black&#39;, // an universal option!
  74. textColor: &#39;yellow&#39;, // an universal option!
  75. className: &#39;text-center&#39;
  76. }
  77. ]
  78. });
  79. });

<!-- language: lang-css -->

  1. .circle_dot {
  2. font-size: 9px;
  3. width: 12px;
  4. height: 12px;
  5. background: #FFE3A2;
  6. border-radius: 50%;
  7. color: #000;
  8. align-items: center;
  9. justify-content: center;
  10. font-weight: 500;
  11. position: absolute;
  12. top: 0px;
  13. opacity: 1;
  14. }

<!-- language: lang-html -->

  1. &lt;link href=&quot;https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.10.2/fullcalendar.min.css&quot; rel=&quot;stylesheet&quot;/&gt;
  2. &lt;script src=&quot;https://code.jquery.com/jquery-3.6.0.min.js&quot;&gt;&lt;/script&gt;
  3. &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js&quot;&gt;&lt;/script&gt;
  4. &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.10.2/fullcalendar.min.js&quot;&gt;&lt;/script&gt;
  5. &lt;div id=&quot;calendar&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

在fullcalendar v3上显示节假日活动,就像easemytrip移动视图日历中一样。

I am using fullcalendar v3 in my project. I want to show holidays on the calendar, as shown on attached image marked in red square box.

It should show following as:


  1. on the top - it will show total holidays of each month
  2. it should number 1,2,3 like badge on dates which has holidays for each month
  3. at the bottom of the month it should describe the badge with the holiday name for each month

答案1

得分: 0

After a lot of research I found an event - eventAfterAllRender and wrote a function to achieve my task

  1. eventAfterAllRender: function (view) {
  2. $('.holidaycount').html('').hide();
  3. $('#holidays-list').html('');
  4. var loop = 0;
  5. $('.circle_dot').each(function () {
  6. loop++;
  7. $('#holidays-list').append("<p class=\"holidayName\"> <span class=\"holidayNo\">" + loop + "</span>" + $(this).find('.fc-title').text() + "</p>");
  8. $(this).find('.fc-title').text(loop);
  9. $('.holidaycount').show();
  10. });
  11. $('.holidaycount').html(loop + ' Holidays');
  12. },
  13. eventSources: [
  14. '/home/getcalendar?bid=test',
  15. '/home/getholidays',
  16. ]
  1. <p class="holidaycount"></p> - This line is above calendar month
  2. <div id="holidays-list"></div> - this line is below calendar month
英文:

After a lot of research I found an event - eventAfterAllRender and wrote a function to achieve my task

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

  1. eventAfterAllRender: function (view) {
  2. $(&#39;.holidaycount&#39;).html(&#39;&#39;).hide();
  3. $(&#39;#holidays-list&#39;).html(&#39;&#39;);
  4. var loop = 0;
  5. $(&#39;.circle_dot&#39;).each(function () {
  6. loop++;
  7. $(&#39;#holidays-list&#39;).append(&quot;&lt;p class=\&quot;holidayName\&quot;&gt; &lt;span class=\&quot;holidayNo\&quot;&gt;&quot; + loop + &quot;&lt;/span&gt;&quot; + $(this).find(&#39;.fc-title&#39;).text() + &quot;&lt;/p&gt;&quot;);
  8. $(this).find(&#39;.fc-title&#39;).text(loop);
  9. $(&#39;.holidaycount&#39;).show();
  10. });
  11. $(&#39;.holidaycount&#39;).html(loop + &#39; Holidays&#39;);
  12. },
  13. eventSources: [
  14. &#39;/home/getcalendar?bid=test&#39;,
  15. &#39;/home/getholidays&#39;,
  16. ]

<!-- language: lang-html -->

  1. &lt;p class=&quot;holidaycount&quot;&gt;&lt;/p&gt; - This line is above calendar month
  2. &lt;div id=&quot;holidays-list&quot;&gt;&lt;/div&gt; - this line is below calendar month

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月8日 16:39:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76430051.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定