11155
(-- --)
1
I convert my old JS files into CoffeeScript, In my public controller I
used this functions
$('#events a').lightBox()
$(document).ready ->
$("#slider").easySlider
auto: true,
continuous: true
they load inside application.js like this
(function() {
$('#events a').lightBox();
$(document).ready(function() {
$("#slider").easySlider({
auto: true,
continuous: true
});
});
but it doesnt seems to work, also tried with an alert "hello" and doesnt
work neither, what i'm doing wrong?
Try
$ →
$(‘#events a’).lightBox()
$(“#slider”).easySlider
auto: true
continuous: true
There is an online js to coffeescript converter out there, I just can’t find the link right now too.
http://ricostacruz.com/js2coffee/
Hope this helps
Best regards
Peter De Berdt
Nopik
(Nopik)
4
they load inside application.js like this
(function() {
$('#events a').lightBox();
$(document).ready(function() {
$("#slider").easySlider({
auto: true,
continuous: true
});
});
Isn't .call(this) missing at the end? The function is not called at
all, no wonder it doesnt work.
11155
(-- --)
5
Peter De Berdt wrote in post #1012552:
11155
(-- --)
6
I found the problem, a jquery plugin isnt loading well.
Uncaught TypeError: undefined is not a function
but it was working after rails 3.1, is beeing loaded at the end of the
file so it should be ok
(bubblepopup plugin)
the problem is that coffee creates this in a private scope, so any method from inside that scope can't be called..
try
window.testFunction: (param) ->
alert param
and
testFunction2: (param) ->
alert param
and check 'compiled' code of both
the function with "window" prefix will be available globally, instead of the other one
there's a big difference between (after 'compiling')
(function () {
var testFunction2 = function(param) {
alert(param);
}
}();
and
var testFunction = function(param)
alert(param);
}
as for the first case, there's no publicly exposed part of the first testFunction2 function.
tom