Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
i18next: Adds support for data-i18n and data-i18n-options to jQuery UI Buttons
// Adds support for data-i18n and data-i18n-options to jQuery UI Buttons:
if( $.fn.button ) { // Checks the presence of the button component of jQuery UI
// Keep a reference to the original _create function:
var button_create_orig = $.ui.button.prototype._create;
$.ui.button.prototype._create = function( ) {
button_create_orig.apply( this, arguments );
if( this.type === "button" ) { // Not needed for input, radio or checkbox
var data_i18n = this.buttonElement.attr( "data-i18n" ),
i18n_options = this.buttonElement.data( "i18n-options" );
// If found, apply the attribute and datas to the button label:
if( data_i18n || i18n_options ) {
var elementButtonText = this.buttonElement.find( ".ui-button-text" );
this.buttonElement.removeAttr( "data-i18n" ).removeData( "i18n-options" );
if( data_i18n ) elementButtonText.attr( "data-i18n", data_i18n );
if( i18n_options ) elementButtonText.data( "i18n-options", i18n_options );
}
}
};
// Keep a reference to the original destroy function:
var button_destroy_orig = $.ui.button.prototype.destroy;
$.ui.button.prototype.destroy = function( ) {
if( this.type === "button" ) {
var elementButtonText = this.buttonElement.find( ".ui-button-text" ),
data_i18n = elementButtonText.attr( "data-i18n" ),
i18n_options = elementButtonText.data( "i18n-options" );
// If found, apply the attribute and datas to the button element:
if( data_i18n ) this.buttonElement.attr( "data-i18n", data_i18n );
if( i18n_options ) this.buttonElement.data( "i18n-options", i18n_options );
}
button_destroy_orig.apply( this, arguments );
};
}
@jlgrall

This comment has been minimized.

Copy link
Owner Author

commented Aug 14, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.