Created
January 21, 2011 00:52
-
-
Save andypearson/789050 to your computer and use it in GitHub Desktop.
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
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