Closed (fixed)
Project:
CoffeeScript
Version:
7.x-1.x-dev
Component:
Documentation
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
10 Sep 2012 at 23:58 UTC
Updated:
7 Feb 2013 at 00:40 UTC
I'm trying to use CoffeeScript to write behaviors, but the top-level function wrapper that the coffeescript compiler does by default seems to prevent the modification of the Drupal.behaviors object.
Off the cuff, the only thing I came up with that worked was to precompile this with coffee -cb myfile.js:
`(function($) {
`
Drupal.behaviors.myStuff =
attach: (context, settings) ->
# Do stuff....
`})(jQuery);`
I'm sure it wouldn't be too hard to get the 'bare' option to be used by coffeescript-php, but the back-tick insert of raw javascript is ugly and seems to break the spirit of it.
Is there a reason not just just have this module also provide (function ($) {...})(jQuery); as an alternate top-level wrapper?
Comments
Comment #1
matt2000 commentedOk, I discovered a technique that avoids the back-ticks and doesn't require the 'bare' option:
Maybe this should be documented on the project page?
Comment #2
maedi commentedIs #1 similar to putting this at the top of the file?
$ = @jQueryWhy does calling Drupal from within an anonymous function let you access Drupal.behaviors? I would have thought this is the same wrapper bubble problem.
Could we try
@Drupal.behaviors?Comment #3
maedi commentedSo how'd you go? @Drupal.behaviors worked?