I'm experimenting with the leaderboards example and I would like to unset the selected_player
when you click outside a player name. I figured for this to work, I'd need to add a listener event to the body element and prevent it from triggering other elements that are inside it. Then I would set selected_player
to 0.
However I only seem to be able to add event maps to Templates?
Template.player.events({
'click': function () {
Session.set("selected_player", this._id);
}
});
Am I missing something? How can I listen to a 'click' event for the whole page?
There is no good way to bind events to the whole body. However, you can wrap all your code in one outer template that has events, as Narven suggests.
<body>
{{> outer}}
</body>
<template name="outer">
your stuff
</template>
and
Template.outer.events({
'click': function () {
do stuff
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With