CoffeeScript
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Downloads
Component created
Component changed
Component body
For now I'd recommend using a preprocessor such as Atom or CodeKit until CoffeeScript PHP is made current.
CoffeeScript is a simple and elegant version of JavaScript.
This module provides CoffeeScript integration with Drupal, allowing you to write CoffeeScript code, which is automatically converted into JavaScript for use by the browser. CoffeeScript can also be used in combination with jQuery and some examples are below.
Usage
Add CoffeeScripts to your Drupal site by using one of the following:<?php print drupal_add_js('script.coffee') ?> in your theme's html.tpl.phpscripts[] = script.coffee in your theme's .info file
Installation
Requires the Libraries and Prepro APIs.
- Download the CoffeeScript PHP library from GitHub.
- Place the extracted folder in your sites/all/libraries folder
- Download and enable this module
Examples
In CoffeeScript, the function keyword is replaced by the -> symbol, and indentation is used instead of curly braces.
A Drupal 7 jQuery before and after:
(function ($) {
Drupal.behaviors.myCode = {
attach: function (context, settings) {
$('.button', context).click(function () {
$(this).next('ul').toggle('show');
});
}
};
})(jQuery);
$ = @jQuery
@Drupal.behaviors.myCode =
attach: (context, settings) ->
$(".button", context).click ->
$(this).next("ul").toggle "show"
