How to change the color of a fullcalendar event on right click

。_饼干妹妹 提交于 2020-01-02 11:34:31

问题


In order to change the color of the jQuery event on right click using context menu , I got some assistance from here with the answer with the most votes.

Making custom right-click context menus for my web-app

However, I am trying to change the color of the even on right click so this is what I did :-

$(".custom-menu li").click(function(){

// This is the triggered action name
switch($(this).attr("data-action")) {

    // A case for each action. Your actions here
    case "red"  : 

    //alert("RED");
    $('#calendar').fullCalendar({
        editable: false,
        backgroundColor: "#800637"
    });
    break;


    case "green": 

    $('#calendar').fullCalendar({
        editable: false,
        backgroundColor: "#00ff00"
    });
    break;
}

// Hide it AFTER the action was triggered
$(".custom-menu").hide(100);
});

And the HTML for the right click custom event looks like this :-

<ul class="custom-menu">
   <li data-action="red" data-color="red">Red/Rouge</li>
   <li data-action="green" data-color="green">Green/Verg</li>    
 </ul>

And the CSS for the color change looks like this :

.red{
  background-color: red;
}

.green{
   background-color: green;
}

This is how it looks but at the moment the color does not change. Full Calendar view


回答1:


Here is a fiddle where you can right-click on an event and choose a color from the menu.

https://jsfiddle.net/uucm2c6m/

/*
    Contains modified code from
    http://stackoverflow.com/questions/4495626/making-custom-right-click-context-menus-for-my-web-app?answertab=active#tab-top
*/

$('#calendar').fullCalendar({
  defaultDate: '2016-03-29',
  events: [{
    title: 'Right-click on me!',
    start: '2016-03-29'
  }],
});

// Trigger action when the contexmenu is about to be shown
$('a.fc-event').bind("contextmenu", function(event) {
  // Avoid the real one
  event.preventDefault();
  // Show contextmenu, save the a.fc-event $(this) for access later
  $(".custom-menu").data('event', $(this)).finish().toggle(100).
    // In the right position (the mouse)
  css({
    top: event.pageY + "px",
    left: event.pageX + "px"
  });
});

// If the document is clicked somewhere
$(document).bind("mousedown", function(e) {
  // If the clicked element is not the menu
  if (!$(e.target).parents(".custom-menu").length > 0) {
    // Hide it
    $(".custom-menu").hide(100);
  }
});

// If the menu element is clicked
$("ul.custom-menu li").click(function() {
  // ul.custom-menu data has 'event'
  var $event = $(this).parent().data('event');
  // This is the triggered action name

  var color = $(this).attr('data-color') || 'lightblue'; // Default to light blue
  // Set the color for the event
  // if the event has multiple sections (spans multiple weeks/days, depending on view)
  // It will only change color of currently right-clicked section...
  // See http://stackoverflow.com/questions/36128815/highlight-fullcalendar-events-that-expands-over-multiple-rows-columns/36185661
  // for ideas on how to approach changing the color of all related sections if needed
  $event.css('background-color', color);

  // Hide it AFTER the action was triggered
  $(".custom-menu").hide(100);
});


来源:https://stackoverflow.com/questions/36284513/how-to-change-the-color-of-a-fullcalendar-event-on-right-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!