btouellette / concarneau

Multiplayer web game using the same rules as Carcassone
MIT License
65 stars 10 forks source link

Edit Games button click gives ReferenceError: event is not defined #8

Closed Ud71p closed 7 years ago

Ud71p commented 7 years ago

When I click on Edit Games button (svg.fa-edit), nothing happens and in console I get: ReferenceError: event is not defined

I can see it calls enableGamesEdit(event). If I just call myself enableGamesEdit() in console, I also get an error: TypeError: e is undefined but this time, it actually has an effect - the delete game icons appear on all games, so I can delete old games.

btouellette commented 7 years ago

Should just get passed to the onclick, standard usage really so it is unclear why it would be failing.

<svg class="fa-edit" onclick="enableGamesEdit(event)">

function enableGamesEdit(e) { ... e.stopPropagation(); }
Ud71p commented 7 years ago

Weird indeed. Some guru here figured it out: https://stackoverflow.com/questions/15857214/event-object-on-firefox/15863498#15863498

For HTML the spec says one has 'event' available, but for SVG, it's 'evt'. Now it's a bit confusing which spec shall be followed when SVG is embedded in HTML. :-) So FFish browsers use 'evt', others may use 'event'... :-(

Something that should work in all browsers is setting it from JS rather than as SVG attribute. $('svg.fa-edit').click(enableGamesEdit);

Or one could wrap svg in a div and define onclick attribute on that, then it's a HTML attribute instead of an SVG attribute and it is called 'event' for sure in all (hopefully) browsers.

btouellette commented 7 years ago

Thanks for finding that. Should be handled in 5f131244fec860460bba9b06fb5c503b2331db40