0

This is my rooms.js.coffee.

allowDrop = (ev) ->
 ev.preventDefault()
drag = (ev) ->
 ev.dataTransfer.setData("image", ev.target.id)
drop = (ev) ->
 ev.preventDefault()
 data = ev.dataTransfer.getData("image")
 ev.target.appendChild(document.getElementById(data))

When I run server and debug using firefox (pressing F12), there are two errors.

ReferenceError: drag is not defined 
ReferenceError: allowDrop is not defined

The generated Javascript is as follows.

(function() {
 var allowDrop, drag, drop;
 allowDrop = function(ev) {
 return ev.preventDefault();
 };
 drag = function(ev) {
 return ev.dataTransfer.setData("image", ev.target.id);
 };
 drop = function(ev) {
 var data;
 ev.preventDefault();
 data = ev.dataTransfer.getData("image");
 return ev.target.appendChild(document.getElementById(data));
 };
}).call(this);

I think this is elementary problem, but I can't solve this. Could you tell me how to fix them?

asked Jul 16, 2015 at 14:42
0

1 Answer 1

0

This happens because the functions are contextualized.

If you want to declare global functions, use:

window.allowDrop = (ev) ->
 ev.preventDefault()
answered Jul 16, 2015 at 15:04
Sign up to request clarification or add additional context in comments.

Comments