Skip to content Skip to sidebar Skip to footer

Event.ctrlKey Works In IE And Chrome But Not Firefox On LegendItemClick

Built a feature that deselects all but the ctrl-clicked item. It works fine in IE and Chrome, but not in Firefox. Try the jsfiddle at http://jsfiddle.net/PJVK3/ Tried to capture t

Solution 1:

If you take a look the source code you'll see that it stores the event on event.browserEvent.
It's a fixed bug: https://github.com/highslide-software/highcharts.com/pull/992

So, why you have to use event.browserEvent instead of window.event ?
Simple, because window.event doesn't exist in Firefox.

legendItemClick: function(e) {
    var visibility = this.visible ? 'visible' : 'hidden';

    if (!e.browserEvent.ctrlKey) {
        if (!confirm('The series is currently '+ 
            visibility +'. Do you want to change that?')) {
            return false;
        }
    }
}

demo

Source code - relevant code:

.on('click', function (event) {
    var strLegendItemClick = 'legendItemClick',
        fnLegendItemClick = function () {
            item.setVisible();
        };

    // Pass over the click/touch event. #4.
    event = {
        browserEvent: event                  // < -- here is the magic
    };

    // click the name or symbol
    if (item.firePointEvent) { // point
        item.firePointEvent(strLegendItemClick, event, fnLegendItemClick);
    } else {
        fireEvent(item, strLegendItemClick, event, fnLegendItemClick);
    }
});

Solution 2:

you can use something like this:

                var evtobj = window.event ? event : e;
                if (evtobj.shiftKey) {
                    //do something
                } else {
                   //other things
                }

This will work in Chrome, IE and firefox.


Post a Comment for "Event.ctrlKey Works In IE And Chrome But Not Firefox On LegendItemClick"