@@ -66,22 +66,19 @@ $.widget( "ui.button", {
66
66
} ,
67
67
68
68
_create : function ( ) {
69
- this . element . closest ( "form" )
70
- . unbind ( "reset" + this . eventNamespace )
71
- . bind ( "reset" + this . eventNamespace , formResetHandler ) ;
69
+ this . _off ( this . element . closest ( "form" ) , "reset" ) ;
70
+ this . _on ( this . element . closest ( "form" ) , {
71
+ "reset" : formResetHandler
72
+ } ) ;
72
73
73
74
if ( typeof this . options . disabled === "boolean" ) {
74
75
this . element . prop ( "disabled" , this . options . disabled ) ;
75
- } else {
76
- this . options . disabled = ! ! this . element . prop ( "disabled" ) ;
77
76
}
78
77
if ( this . options . disabled === true ) {
79
78
this . _setOption ( "disabled" , true ) ;
80
79
}
81
80
82
- this . element
83
- . addClass ( baseClasses )
84
- . attr ( "role" , "button" ) ;
81
+ this . element . addClass ( baseClasses ) . attr ( "role" , "button" ) ;
85
82
86
83
if ( this . options . label ) {
87
84
if ( this . isInput ) {
@@ -93,44 +90,43 @@ $.widget( "ui.button", {
93
90
94
91
if ( this . options . icon ) {
95
92
this . icon = $ ( "<span>" ) ;
96
- this . icon . addClass ( " ui-icon " + this . options . icon ) ;
93
+ this . icon . addClass ( "ui-icon " + this . options . icon ) ;
97
94
if ( this . options . iconPosition ) {
98
95
this . element . addClass ( "ui-icon-" + this . options . iconPosition ) ;
99
96
}
100
97
if ( ! this . options . showLabel ) {
101
- this . element . addClass ( " ui-button-icon-only" ) ;
98
+ this . element . addClass ( "ui-button-icon-only" ) ;
102
99
}
103
100
this . element . append ( this . icon ) ;
104
- this . _setTitle ( ) ;
101
+ this . _updateTooltip ( ) ;
105
102
}
106
103
107
104
if ( this . element . is ( "a" ) ) {
108
- this . element . keyup ( function ( event ) {
109
- if ( event . keyCode === $ . ui . keyCode . SPACE ) {
110
- // TODO pass through original event correctly (just as 2nd argument doesn't work)
111
- $ ( this ) . click ( ) ;
105
+ this . _on ( {
106
+ "keyup" : function ( event ) {
107
+ if ( event . keyCode === $ . ui . keyCode . SPACE ) {
108
+ event . type = "click" ;
109
+ this . element . trigger ( event ) ;
110
+ }
112
111
}
113
112
} ) ;
114
113
}
115
114
} ,
116
115
117
- _setTitle : function ( ) {
116
+ _updateTooltip : function ( ) {
118
117
this . title = this . element . attr ( "title" ) ;
119
118
this . hasTitle = ! ! this . title ;
120
119
121
- if ( ! this . options . showLabel ) {
122
- if ( ! this . hasTitle ) {
123
- this . element . attr ( "title" , this . title ) ;
124
- }
120
+ if ( ! this . options . showLabel && ! this . hasTitle ) {
121
+ this . element . attr ( "title" , this . title ) ;
125
122
}
126
123
} ,
127
124
128
125
_destroy : function ( ) {
129
126
this . element
130
- . removeClass ( "ui-helper-hidden-accessible " + baseClasses +
127
+ . removeClass ( baseClasses +
131
128
" ui-state-active " + typeClasses )
132
- . removeAttr ( "role" )
133
- . removeAttr ( "aria-pressed" ) ;
129
+ . removeAttr ( "role" ) ;
134
130
135
131
if ( ! this . hasTitle ) {
136
132
this . element . removeAttr ( "title" ) ;
@@ -139,13 +135,20 @@ $.widget( "ui.button", {
139
135
140
136
_setOption : function ( key , value ) {
141
137
if ( key === "icon" ) {
142
- this . icon . addClass ( " ui-icon " + value )
143
- . removeClass ( this . options . icon ) ;
138
+ if ( value !== null ) {
139
+ if ( this . icon === undefined ) {
140
+ this . icon = $ ( "<span>" ) ;
141
+ }
142
+ this . icon . addClass ( "ui-icon " + value ) . removeClass ( this . options . icon ) ;
143
+ } else {
144
+ this . icon . remove ( ) ;
145
+ this . element . removeClass ( this . options . iconPosition ) ;
146
+ }
144
147
}
145
148
if ( key === "showLabel" ) {
146
- this . element . toggleClass ( ". ui-button-icon-only" , ! ( ! ! value ) )
149
+ this . element . toggleClass ( "ui-button-icon-only" , ! value )
147
150
. toggleClass ( this . options . iconPosition , ! ! value ) ;
148
- this . _setTitle ( ) ;
151
+ this . _updateTooltip ( ) ;
149
152
}
150
153
if ( key === "iconPosition" && this . options . showLabel ) {
151
154
this . element . addClass ( value )
@@ -155,13 +158,14 @@ $.widget( "ui.button", {
155
158
if ( this . element . is ( "input" ) ) {
156
159
this . element . val ( value ) ;
157
160
} else {
158
- this . element . html ( value ) ;
161
+ console . log ( this . icon ) ;
162
+ this . element . html ( ( ( ! ! this . icon ) ? "" : this . icon ) + value ) ;
159
163
}
160
164
}
161
165
this . _super ( key , value ) ;
162
166
if ( key === "disabled" ) {
163
- this . element . toggleClass ( " ui-state-disabled" , ! ! value ) ;
164
- this . element . prop ( "disabled" , ! ! value ) . blur ( ) ;
167
+ this . element . toggleClass ( "ui-state-disabled" , value ) ;
168
+ this . element . prop ( "disabled" , value ) . blur ( ) ;
165
169
return ;
166
170
}
167
171
} ,
@@ -175,7 +179,7 @@ $.widget( "ui.button", {
175
179
this . _setOptions ( { "disabled" : isDisabled } ) ;
176
180
}
177
181
178
- this . _setTitle ( ) ;
182
+ this . _updateTooltip ( ) ;
179
183
}
180
184
181
185
} ) ;
0 commit comments