Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 the same event with simple javascript code and the same problem occurs. This works in Chrome(24.0.1312.57) and IE(9), but not Firefox(18.0.2):

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
if (event.ctrlKey){document.getElementById("demo").innerHTML="ctl key pressed";}
if (!event.ctrlKey){document.getElementById("demo").innerHTML="ctl key NOT pressed";}
}
</script>
</head>
<body>
<p>Click the button to trigger a function.</p>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
</body>
</html>

Whatup? anyone?

like image 789
Zoom Avatar asked Dec 06 '25 08:12

Zoom


1 Answers

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);
    }
});
like image 183
Ricardo Alvaro Lohmann Avatar answered Dec 07 '25 21:12

Ricardo Alvaro Lohmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!