Created
December 20, 2011 02:47
-
-
Save lantius/1500003 to your computer and use it in GitHub Desktop.
Simple response to simple coding exercise.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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