Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

click event in jQuery and right mouse clicking

Does click trigger when right mouse button was clicked? I want to implement a right click kind of menu with full calendar, but it only has dayClick event, which I think is triggered only when left mouse button is clicked. I was thinking something like

dayClick: function(date, allDay, jsEvent){
    if (jsEvent.button === 1){
         //show menu
    }else{
        //do something with day
    }
}

but dayClick isn't triggered when right mouse is clicked....Any other ideas?

like image 719
Apostolos Avatar asked Dec 16 '13 12:12

Apostolos


2 Answers

Try binding mousedown to each FullCalndar event in your eventRender event:

var events_array = [{
    title: 'Test1',
    start: new Date(2013, 11, 20)
}, {
    title: 'Test2',
    start: new Date(2013, 11, 21)
}];

$('#mycalendar:not(".fc-event")').on('contextmenu', function (e) {
    e.preventDefault()
})

$('#mycalendar').fullCalendar({
    events: events_array,
    header: {
        left: 'prevYear,prev,next,nextYear today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    eventRender: function (event, element) {
        element.bind('mousedown', function (e) {
            if (e.which == 3) {
                alert('Right mouse button pressed');
            }
        });
    }
});

You can disable right click on page and let it act only on events using:

$('#mycalendar:not(".fc-event")').on('contextmenu', function(e){ e.preventDefault() })

Demo: http://jsfiddle.net/IrvinDominin/3bukS/

like image 166
Irvin Dominin Avatar answered Sep 21 '22 23:09

Irvin Dominin


Your answer is No, click doesn't trigger when right mouse button is clicked, but you can try mousedown event, check this out:

jQuery(document.body).on("mousedown", function(event){
    if(event.button==2){
        //do what you want
    }
});
like image 26
Mehran Hatami Avatar answered Sep 23 '22 23:09

Mehran Hatami