1

how can I bind a right click event in CanJS?

I've attempted the following, but I guess click only captures left clicks (as ev.which doesn't log 3 on right clicks).

'.btn click': function (el, ev) {
    console.log(ev.which);
    switch(ev.which) {
        case 1:
            var val = 1;
            break;
        case 3:
            ev.preventDefault();
            var val = -1;
            break;
    }
    var item = can.data(el.closest('tr'), 'item');
    item.attr('rel', item.rel + val);
}
ramblinjan
  • 6,578
  • 3
  • 30
  • 38
veksen
  • 6,863
  • 5
  • 20
  • 33

2 Answers2

3

I don't know what CanJS is, but I would use oncontextmenu:

elem.oncontextmenu = function(e) {
    e = e || window.event;

    if(e.preventDefault) e.preventDefault();
    e.returnValue = false;

    // Your code
};
Oriol
  • 274,082
  • 63
  • 437
  • 513
  • 2
    Thank you for putting me on the right path! a CanJS oncontextmenu search got me to this page of the docs : [http://canjs.com/docs/can.Control.processors.html](http://canjs.com/docs/can.Control.processors.html). So the way to record a right click would be `'.btn contextmenu'` :) – veksen Oct 06 '13 at 16:32
0

I think you were looking for contextmenu event: https://developer.mozilla.org/en/docs/Web/Events/contextmenu

You can use this in CanJS events:

'.btn contextmenu': function (el, ev) {
     // your code
}
Jry9972
  • 463
  • 7
  • 16