Skip to content

Instantly share code, notes, and snippets.

@andrewnicols
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewnicols/8970635 to your computer and use it in GitHub Desktop.
Save andrewnicols/8970635 to your computer and use it in GitHub Desktop.
/**
* A description of the module.
*
* @module moodle-FRANKENSTYLE-YUIMODNAME
*/
/**
* A description of the class. Most of the time, this will be the same as
* the module, but it is possible to have multiple classes within a single
* module.
*
* @class M.FRANKENSTYLE.namespace
*/
var LOGNAME = 'moodle-FRANKENSTYLE-YUIMODNAME',
WRAPPER = '#somewrapper',
CLICKEDNODE = '.somebutton',
SELECTORS = {
SOMETHING: '.foo',
SOMETHINGELSE: '.bar',
},
CSS = {
SOMETHING: 'foo',
SOMETHINGELSE: 'bar',
};
// This defines the namespace.
//
// That's the 'Y.M.FRANKENSTYLE.namespace' in:
// $PAGE->requires->yui_module('moodle-FRANKENSTYLE-YUIMODNAME', 'Y.M.FRANKENSTYLE.namespace.init', array(array(
// 'someValue' => 'the new value'
// ));
//
// The 'init' in that 'Y.M.FRANKENSTYLE.namespace.init' is defined as a function in the namespae object (see below).
//
// Y.namespace created the full namespace, so specifying:
// Y.namespace('M.food.fruit.legume.bean')
// will create:
// Y.M.food.fruit.legume.bean = {}
// The alternative would be:
// M.food = M.food || {};
// M.food.fruit = M.food.fruit || {};
// M.food.fruit.legume = M.food.fruit.legume || {};
// M.food.fruit.legume.bean = M.food.fruit.legume.bean || {};
//
Y.namespace('M.FRANKENSTYLE').namespace = {
/**
* A description of a property
*
* @property propertyName
* @type String
* @default null
* @protected
*/
propertyName: null,
/**
*
* This method is called by the yui_module function
*
* @method init
*/
init: function(params) {
// This call this.doSomething when any node mapping CLICKEDNODE in WRAPPER is clicked. It passes a context of
// 'this' so that the 'this' variable refers to the current CLASS rather than the CLICKEDNODE in doSomething.
Y.delegate('click', this.doSomething, WRAPPER, CLICKEDNODE, this);
// The 'params' argument passed here contains all of the parameters
// passed in yui_module().
Y.log(params, 'debug', LOGNAME);
},
/**
* This is the doSomething function which handles whatever you're doing.
*
* @method doSomething
* @param {EventFacade} e
*/
doSomething: function(e) {
// We probably want to prevent the default browser behaviour here.
e.preventDefault();
// Do some other stuff here:
// Get a property:
this.propertyName = 'apple';
// Set a property:
Y.log(this.propertyName, 'debug', 'moodle-FRANKENSTYLE-YUIMODNAME');
// Whenever we call Y.log, we need:
// * a message;
// * a log category; and
// * the module name.
Y.log('This is my message', 'info', 'moodle-FRANKENSTYLE-YUIMODNAME');
// Other things to consider:
// You may want to store the the full modname above and use it in Y.log. When the file is minified, it will
// make the file considerably smaller:
Y.log('This is my message', 'info', LOGNAME);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment