2013-08-27 23:28:29 +00:00
|
|
|
/*!
|
2013-10-09 20:09:59 +00:00
|
|
|
* ObjectOriented UserInterface IconedElement class.
|
2013-08-27 23:28:29 +00:00
|
|
|
*
|
2013-10-09 20:09:59 +00:00
|
|
|
* @copyright 2011-2013 OOJS Team and others; see AUTHORS.txt
|
2013-08-27 23:28:29 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-10-09 20:09:59 +00:00
|
|
|
* Element containing an icon.
|
2013-08-27 23:28:29 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
|
|
|
*
|
|
|
|
* @constructor
|
2013-10-09 20:09:59 +00:00
|
|
|
* @param {jQuery} $icon Icon node, assigned to #$icon
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-08-27 23:28:29 +00:00
|
|
|
* @cfg {Object|string} [icon=''] Symbolic icon name, or map of icon names keyed by language ID
|
|
|
|
*/
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.IconedElement = function OoUiIconedElement( $icon, config ) {
|
2013-08-27 23:28:29 +00:00
|
|
|
// Config intialization
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.$icon = $icon;
|
|
|
|
this.icon = null;
|
|
|
|
|
|
|
|
// Initialization
|
2013-10-09 20:09:59 +00:00
|
|
|
this.$icon.addClass( 'oo-ui-iconedElement-icon' );
|
2013-08-27 23:28:29 +00:00
|
|
|
this.setIcon( config.icon );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the icon.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} [value] Symbolic name of icon to use
|
|
|
|
* @chainable
|
|
|
|
*/
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.IconedElement.prototype.setIcon = function ( value ) {
|
2013-08-27 23:28:29 +00:00
|
|
|
var i, len, icon, lang,
|
2013-10-09 20:09:59 +00:00
|
|
|
langs = OO.ui.getUserLanguages();
|
2013-08-27 23:28:29 +00:00
|
|
|
|
2013-10-09 20:09:59 +00:00
|
|
|
if ( OO.isPlainObject( value ) ) {
|
2013-08-27 23:28:29 +00:00
|
|
|
icon = value['default'];
|
|
|
|
for ( i = 0, len = langs.length; i < len; i++ ) {
|
|
|
|
lang = langs[i];
|
|
|
|
if ( value[lang] ) {
|
|
|
|
icon = value[lang];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
icon = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.icon ) {
|
2013-10-09 20:09:59 +00:00
|
|
|
this.$icon.removeClass( 'oo-ui-icon-' + this.icon );
|
2013-08-27 23:28:29 +00:00
|
|
|
}
|
|
|
|
if ( typeof icon === 'string' ) {
|
|
|
|
icon = icon.trim();
|
|
|
|
if ( icon.length ) {
|
2013-10-09 20:09:59 +00:00
|
|
|
this.$icon.addClass( 'oo-ui-icon-' + icon );
|
2013-08-27 23:28:29 +00:00
|
|
|
this.icon = icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|