Skip to content

Instantly share code, notes, and snippets.

@lantius
Created December 20, 2011 02:47
Show Gist options
  • Save lantius/1500003 to your computer and use it in GitHub Desktop.
Save lantius/1500003 to your computer and use it in GitHub Desktop.
Simple response to simple coding exercise.
// blocks class; targets a container and specifies a highlight color for the blocks when they are clicked.
// constructor arguments 'args' is a JSON object:
// {
// container: "#container", //Container element content blocks should be added to
// clickColor: "#ff9" //Color to be applied to a block after clicking it
// }
function blocks(args) {
this.container = args['container'];
this.clickColor = args['clickColor'];
// event bubbling
$(this.container).on('click', 'div.block', { col: this.clickColor }, function(event) {
$(this).css('background-color', event.data.col);
})
}
blocks.prototype.add = function(text) {
var newBlock = $('<div>' + text + '</div>');
newBlock.addClass('block');
$(this.container).append(newBlock)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment