57f83a083364e45641be9d104f1fc29347ced2ef
[ccsdk/features.git] /
1 (function( $, joey, app ) {
2
3         var ui = app.ns("ui");
4
5         ui.Button = ui.AbstractWidget.extend({
6                 defaults : {
7                         label: "",                 // the label text
8                         disabled: false,           // create a disabled button
9                         autoDisable: false         // automatically disable the button when clicked
10                 },
11
12                 _baseCls: "uiButton",
13
14                 init: function(parent) {
15                         this._super();
16                         this.el = $.joey(this.button_template())
17                                 .bind("click", this.click_handler);
18                         this.config.disabled && this.disable();
19                         this.attach( parent );
20                 },
21
22                 click_handler: function(jEv) {
23                         if(! this.disabled) {
24                                 this.fire("click", jEv, this);
25                                 this.config.autoDisable && this.disable();
26                         }
27                 },
28
29                 enable: function() {
30                         this.el.removeClass("disabled");
31                         this.disabled = false;
32                         return this;
33                 },
34
35                 disable: function(disable) {
36                         if(disable === false) {
37                                         return this.enable();
38                         }
39                         this.el.addClass("disabled");
40                         this.disabled = true;
41                         return this;
42                 },
43
44                 button_template: function() { return (
45                         { tag: 'BUTTON', type: 'button', id: this.id(), cls: this._baseCls, children: [
46                                 { tag: 'DIV', cls: 'uiButton-content', children: [
47                                         { tag: 'DIV', cls: 'uiButton-label', text: this.config.label }
48                                 ] }
49                         ] }
50                 ); }
51         });
52
53 })( this.jQuery, this.joey, this.app );