I have a button in my views in test.html.erb as follows
<button id="Todo_full" onclick="showFullscreen(this);">Full size</button>
and its javascript is as follows:
function showFullscreen(event)
{
var elem = document.getElementById('card_' + event.id);
if (elem.requestFullscreen) {
return elem.requestFullscreen();
}
else if (elem.mozRequestFullScreen)
{
/* Firefox */
return elem.mozRequestFullScreen();
}
}
When I keep the javascript code at the below of the test.html.erb file it works fine.
And when I convert this code into coffeescript through http://js2.coffee/ and keep the code in app/assets/javascript/test.coffee which is as follows:
showFullscreen = (event) ->
elem = document.getElementById('card_' + event.id)
if elem.requestFullscreen
return elem.requestFullscreen()
else if elem.mozRequestFullScreen
### Firefox ###
return elem.mozRequestFullScreen()
return
It shows an error in console
Uncaught ReferenceError: showFullscreen is not defined
at HTMLButtonElement.onclick ((index):384)
Even when I use window.onload = -> at the top of coffeescript's code I get the same error in console.
Thank you
showFullscreenfunction whereas the CoffeeScript one is creating a localshowFullscreenfunction inside a scope wrapper. Perhaps you want to say@showFullScreen = (event) -> ...orwindow.showFullScreen = (event) -> .... Or better, don't use anonclickattribute at all, create local functions and bind them to elements.