// Generated by github.com/steida/coffee2closure 0.1.12
goog.provide('spark.components.Button');
goog.require('spark.core.View');
goog.require('spark.validation');
/**
Button component of Spark Framework.
@constructor
@export
@param {Object=} options Class options.
@param {*=} data Class data
@extends {spark.core.View}
*/
spark.components.Button = function(options, data) {
if (options == null) {
options = {};
}
options.tagName = options['tagName'] = 'button';
options.title || (options.title = options['title'] || null);
options.callback || (options.callback = options['callback'] || null);
options.iconClass || (options.iconClass = options['iconClass'] || null);
options.events || (options.events = options['events'] || {});
this.getCssClass(options, 'button');
if (spark.validation.isFunction(options.callback)) {
options.events.click = options.callback;
}
spark.components.Button.superClass_.constructor.call(this, options, data);
this.createIcon_();
this.createTitle_();
}
goog.inherits(spark.components.Button, spark.core.View);
/**
Creates the icon view.
@private
*/
spark.components.Button.prototype.createIcon_ = function() {
var iconClass;
iconClass = this.getOptions().iconClass;
this.iconView = new spark.core.View({
tagName: 'span',
renderTo: this,
cssClass: spark.utils.concatString('icon', iconClass)
});
if (!iconClass) {
return this.iconView.addClass('hidden');
}
};
/**
Creates the title view.
@private
*/
spark.components.Button.prototype.createTitle_ = function() {
var title;
title = this.getOptions().title;
this.titleView = new spark.core.View({
tagName: 'span',
renderTo: this,
template: title
});
return this.title = title;
};
/**
Returns the icon view instance.
@export
@return {spark.core.View} The icon view.
*/
spark.components.Button.prototype.getIconView = function() {
return this.iconView;
};
/**
Returns the title view instance.
@export
@return {spark.core.View} The title view.
*/
spark.components.Button.prototype.getTitleView = function() {
return this.titleView;
};
/**
Returns the current button title.
@export
@return {string} The title of the button.
*/
spark.components.Button.prototype.getTitle = function() {
return this.title;
};
/**
Updates the button title.
@export
@param {!string} title The new button title.
*/
spark.components.Button.prototype.setTitle = function(title) {
this.getTitleView().setTemplate(title);
return this.title = title;
};
/**
Shows the icon view of the button by removing the 'hidden' class.
@export
*/
spark.components.Button.prototype.showIcon = function() {
return this.getIconView().removeClass('hidden');
};
/**
Hides the icon view of the button by adding the 'hidden' class.
@export
*/
spark.components.Button.prototype.hideIcon = function() {
return this.getIconView().addClass('hidden');
};
/**
Shows the icon view and sets the given iconClass to icon element.
@export
@param {!string} iconClass The new icon class.
*/
spark.components.Button.prototype.setIcon = function(iconClass) {
this.showIcon();
return this.getIconView().addClass(iconClass);
};