简体   繁体   English

如何在全日历中防止外部事件的突出显示(灰色背景)

[英]How to prevent highlight (gray background) of an external event in fullcalendar

I already have start and end time for an external event but is there any correct way to set the end time on highlight (gray background) of the same external event. 我已经有了外部事件的开始时间和结束时间,但是有什么正确的方法可以在同一外部事件的突出显示(灰色背景)上设置结束时间。

Or if there is no way to set the end time on highlight then can we remove the fc-highlight completely from external/draggable events. 或者,如果无法设置高光显示的结束时间,那么我们可以完全从外部/可拖动事件中删除fc-highlight吗?

By the way, I already asked this question but didn't get correct response, so that's why I'm asking again 顺便说一句,我已经问了这个问题,但是没有得到正确的答复,所以这就是为什么我再次问

For more detail, please visit my another question here: Disable highlight of an external event in fullcalendar 有关更多详细信息,请在此处访问我的另一个问题: 在全日历中禁用外部事件的突出显示

Starting from your CodePen ... 您的CodePen开始...
I managed to customise the draggable event in order to have a defined duration to be used as time calculation. 我设法自定义了可拖动事件,以便将定义的持续时间用作时间计算。

I added data-duration-hour and data-duration-minute attributes to the draggable event. 我将data-duration-hourdata-duration-minute属性添加到了可拖动事件。

Those "data" attributes ares used to determine the ending time of the event, on drop. 这些“数据”属性用于确定事件的结束时间。

NOW about the hightlight which occurs on drag (before drop ) in the calendar... 现在,关于日历中drag (在drop之前)发生的突出显示...
It still hightlights 2 hours. 仍然要亮2个小时。

You'll have to to look at a function to add on drag in fullCalendar options. 您必须查看在fullCalendar选项中添加drag的函数。
I have no idea for the moment. 我暂时不知道。

So ... I may not have answered the right question (about the hightlight effect on drag). 所以 ...我可能未回答正确的问题(关于拖动的高光效果)。
But this is still an improvement for your project. 但这仍然是您项目的一个改进。

See in this CodePen 参见此CodePen

HTML modified: 修改HTML:

<div class='fc-event' data-duration-hour="3" data-duration-minute="30">My Event 1</div>

JS modified: JS修改为:

function external_event_dropped(date, external_event) {

  var event_object;
  var copied_event_object;
  var tempDate = new Date(date);

  event_object = $(external_event).data('eventObject');

  copied_event_object = $.extend({}, event_object);
  copied_event_object.start =  date;

  // This is the dropped date object
  console.log(date);

  // This is the drop time in clear.
  console.log( "dropped at: "+date.hour()+":"+date.minute() );


  // Retreive the data-duration from the dragged element.
  var durationHour = parseInt(external_event.data("duration-hour"));
  var durationMinute = parseInt(external_event.data("duration-minute"));
  console.log("DATA: "+durationHour+":"+durationMinute);


  // Clone the time object to modify it in order to create de end time.
  var dateEnd = date.clone();

  dateEnd = dateEnd.hour(dateEnd.hour()+durationHour);
  dateEnd = dateEnd.minute(dateEnd.minute()+durationMinute);

  // This is the end time object.
  console.log(dateEnd);

  // This is the drop end time in clear.
  console.log( "dropped at: "+dateEnd.hour()+":"+dateEnd.minute() );

  // Now set it to the FullCalendar object.
  copied_event_object.end = dateEnd;

  copied_event_object.allDay =  false;
  copied_event_object.title =  'ADEEL';

  external_event.remove();

  $('#exampleCalendar').fullCalendar('renderEvent', copied_event_object, true);

}

For the complete solution check this out: Fullcalendar External/Draggable Events Highlight Effect 要获取完整的解决方案,请查看以下内容: 完整的日历外部/可拖动事件突出显示效果

Well after reading the fullcalendar documentation and spent a lot of time on this issue, I come up with a solution and I hope it might help others as well. 在阅读了完整的日历文档并在此问题上花了很多时间之后,我想出了一个解决方案,希望它也能对其他人有所帮助。

So, the solution is: 因此,解决方案是:

  • I've added an option defaultTimedEventDuration which is a default duration of an external/draggable event, if there is no duration set on event. 我添加了一个defaultTimedEventDuration选项,如果没有在事件上设置持续时间,则它是外部/可拖动事件的默认持续时间。

    eg: defaultTimedEventDuration: '01:00:00' 例如: defaultTimedEventDuration: '01:00:00'

  • Also added data-duration in html to get dynamic duration and highlighted effect. 还在html中添加了data-duration ,以获取动态持续时间和突出显示的效果。

    eg: <div class='fc-event' data-duration='03:00'>My Event 1</div> 例如: <div class='fc-event' data-duration='03:00'>My Event 1</div>

NB: Also possibility to set duration attribute in js data 注意:还可以在js data设置duration属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM