4

I'm using Adam Shaw's FullCalendar control along with jQuery. I would like to add a context menu to events and days. I was able to achieve so by using Martin Wendt's Context Menu control. My code for registering the menu on events looks like this:

$('#calendar').fullCalendar({
        // Other arguments
        eventRender: function (event, element) {
            var originalClass = element[0].className;
            element[0].className = originalClass + ' hasmenu';
        },
        dayRender: function (day, cell) {
            var originalClass = cell[0].className;
            cell[0].className = originalClass + ' hasmenu';
    });
});

I'm essentially adding a class called hasmenu to each event and day in the calendar.

$(document).contextmenu({
    delegate: ".hasmenu",
    preventContextMenuForPopup: true,
    preventSelect: true,
    menu: [
            {title: "Cut", cmd: "cut", uiIcon: "ui-icon-scissors"},
            {title: "Copy", cmd: "copy", uiIcon: "ui-icon-copy"},
            {title: "Paste", cmd: "paste", uiIcon: "ui-icon-clipboard", disabled: true },
        ],
    select: function(event, ui) {
            // Logic for handing the selected option
    },
    beforeOpen: function(event, ui) {
            // Things to happen right before the menu pops up
    }
});

The problem with this is that the menu appears behind the calendar control. I believe this is because calendar events have a few other classes assigned to them and adding a hasmenu class is messing with those. When I set a breakpoint in VS, it says the event has these classes:

"fc-event fc-event-hori fc-event-draggable fc-event-start fc-event-end hasmenu"

And this is how it looks on the page:

enter image description here

I tried temporarily setting the event class to just hasmenu while the popup was open but that obviously changed the view entirely. Is there a way to force the menu to be on top of all other elements? Is there a "bring to front" method? Any help is appreciated.

mar10
  • 14,320
  • 5
  • 39
  • 64
user2872534
  • 163
  • 1
  • 10

3 Answers3

5

Adjusting the z-index will probably be your best bet.

feitla
  • 1,334
  • 1
  • 7
  • 12
5

Adjust the z-index in the beforeOpen event

beforeOpen: function (event, ui) {      
    ui.menu.zIndex($(event.target).zIndex() + 1);
}

please see: https://github.com/mar10/jquery-ui-contextmenu/issues/55

t3chb0t
  • 16,340
  • 13
  • 78
  • 118
Sandra Patta
  • 153
  • 3
  • 7
1

This helps to get resolve your issue:

beforeOpen: function (event, ui) {
            var $menu = ui.menu,
                $target = ui.target;
            ui.menu.css('z-index', '10000000');
            // Things to happen right before the menu pops up
        }