Skip to content

Instantly share code, notes, and snippets.

@andypearson
Created January 21, 2011 00:52
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 andypearson/789050 to your computer and use it in GitHub Desktop.
Save andypearson/789050 to your computer and use it in GitHub Desktop.
var Interface = {
init : function()
{
$('#interface').append(new Interface.Button('Button 1', function() {
alert('Button 1 has been pressed!');
}).element());
$('#interface').append(new Interface.Button('Button 2', function() {
alert('Button 2 has been pressed!');
}).element());
button = new Interface.Button('Button 3', function() {
alert('Button 3 has been pressed!');
});
$('#interface').append(button.element());
// Output
console.log(button.element());
console.log(button.value());
button.value('THE FINAL BUTTON');
button.action(function() { alert('THIS IS THE FINAL BUTTON!!!'); });
console.log(button.value());
}
};
Interface.Button = function(value, action) {
var event = 'click';
var element = null;
var attributes = {
'value' : value,
'type' : 'submit'
};
this.value = function(value)
{
if (value) {
attributes['value'] = value;
$(element).attr('value', value);
} else {
return attributes['value'];
}
}
this.action = function(action)
{
$(element).unbind(event).bind(event, action);
}
this.element = function()
{
if (!element) {
element = $('<input />', attributes);
this.action(action);
}
return element;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment