|
// 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 ); |
|
}; |
|
} |
See: http://github.com/jamuhl/i18next/issues/29
Tests in the jsFiddle: http://jsfiddle.net/jlgrall/BzD3C