Skip to content

Instantly share code, notes, and snippets.

@andrewnicols
Forked from bmbrands/gist:5354265
Last active December 16, 2015 01:19
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/5354539 to your computer and use it in GitHub Desktop.
Save andrewnicols/5354539 to your computer and use it in GitHub Desktop.
YUI.add('moodle-block_codex_about-toggler', function(Y) {
// Define a name space to call
M.block_codex_about = M.block_codex_about || {};
M.block_codex_about.toggler = {
init: function() {
// Delegate adds a single event listener rather than one per .codex_about_link
// There's no need to loop through and get the IDs and then pass them to the eventHandler as the targetted
// Node is available to the eventHandler in any case.
Y.delegate('click', this.toggleShow, Y.config.doc, '.codex_about_link', this);
},
toggleShow: function (e) {
// this = M.block_codex_about.toggler
// e = the EventFacade
// e.currentTarget is the Node which was targetted in the Y.delegate (the .codex_about_link)
// e.currentTarget.get('id') is the id of that node
console.log(e.currentTarget.get('id'));
// e.currentTarget is *only* available when the context (5th argument to Y.delegate) is supplied.
// If no context is supplied, the 'this' variable is the targetted Node.
// http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_delegate
};
};
}, '@VERSION@', {
requires: ['node']
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment