8000 Button: backcompat for old button widget · ashishkummar/jquery-ui@259f8aa · GitHub
[go: up one dir, main page]

Skip to content

Commit 259f8aa

Browse files
committed
Button: backcompat for old button widget
1 parent 3d65007 commit 259f8aa

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

ui/button.js

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,84 @@ $.widget( "ui.button", {
223223

224224
this._updateTooltip();
225225
}
226-
227226
});
228227

228+
// DEPRECATED
229+
if ( $.uiBackCompat ) {
230+
231+
// Text and Icons options
232+
$.widget( "ui.button", $.ui.button, {
233+
options: {
234+
text: true,
235+
icons: {
236+
primary: null,
237+
secondary: null
238+
}
239+
},
240+
241+
_create: function() {
242+
if ( this.options.showLabel && !this.options.text ) {
243+
this.options.showLabel = this.options.text;
244+
}
245+
if ( !this.options.icon && ( this.options.icons.primary ||
246+
this.options.icons.secondary ) ) {
247+
if ( this.options.icons.primary ) {
248+
this.options.icon = this.options.icons.primary;
249+
} else {
250+
this.options.icon = this.options.icons.secondary;
251+
this.options.iconPosition = "end";
252+
}
253+
}
254+
this._super();
255+
},
256+
257+
_setOption: function( key, value ) {
258+
if ( key === "text" ) {
259+
this._setOption( "showLabel", value );
260+
}
261+
if ( key === "icons" ) {
262+
this._setOption( "icon", value );
263+
if ( value.primary ) {
264+
this._setOption( "icon", value );
265+
this._setOption( "iconPosition", "beginning" );
266+
} else if ( value.secondary ) {
267+
this._setOption( "icon", value );
268+
this._setOption( "iconPosition", "end" );
269+
}
270+
}
271+
this._superApply( arguments );
272+
}
273+
});
274+
$.fn.button = (function( orig ) {
275+
return function() {
276+
if ( this[ 0 ].tagName === "input" && ( this.attr( "type") === "checkbox" ||
277+
this.attr( "type" ) === "radio" ) ) {
278+
if ( $.ui.checkboxradio ) {
279+
if ( arguments.length === 0 ) {
280+
return this.checkboxradio({
281+
"icon": false
282+
});
283+
} else {
284+
return this.checkboxradio.apply( arguments );
285+
}
286+
} else {
287+
$.error( "Checkboxradio widget missing" );
288+
}
289+
} else {
290+
return orig.apply( this, arguments );
291+
}
292+
};
293+
})( $.fn.button );
294+
$.fn.buttonset = function( method, key, value ) {
295+
if ( method === "option" && key === "items" ) {
296+
value = {
297+
"button": value
298+
};
299+
}
300+
this.controlgroup.call( method, key, value );
301+
};
302+
}
303+
229304
return $.ui.button;
230305

231306
}));

0 commit comments

Comments
 (0)
0