mirror of
https://github.com/beestat/app.git
synced 2025-05-23 18:04:14 -04:00
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
/**
|
|
* A button-shaped component with text, an icon, and a background color.
|
|
*/
|
|
beestat.component.button_group = function() {
|
|
this.buttons_ = [];
|
|
beestat.component.apply(this, arguments);
|
|
};
|
|
beestat.extend(beestat.component.button_group, beestat.component);
|
|
|
|
/**
|
|
* Decorate
|
|
*
|
|
* @param {rocket.Elements} parent
|
|
*/
|
|
beestat.component.button_group.prototype.decorate_ = function(parent) {
|
|
var self = this;
|
|
|
|
// Only exists so that there can be spacing between wrapped elements.
|
|
var outer_container = $.createElement('div')
|
|
.style({
|
|
'margin-top': (beestat.style.size.gutter / -2)
|
|
});
|
|
parent.appendChild(outer_container);
|
|
|
|
this.buttons_.forEach(function(button, i) {
|
|
var container = $.createElement('div').style({
|
|
'display': 'inline-block',
|
|
'margin-right': (i < self.buttons_.length) ? (beestat.style.size.gutter / 2) : 0,
|
|
'margin-top': (beestat.style.size.gutter / 2)
|
|
});
|
|
button.render(container);
|
|
outer_container.appendChild(container);
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Add a button to this group.
|
|
*
|
|
* @param {beestat.component.button} button The button to add.
|
|
*/
|
|
beestat.component.button_group.prototype.add_button = function(button) {
|
|
this.buttons_.push(button);
|
|
if (this.rendered_ === true) {
|
|
this.rerender();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Get all of the buttons in this button group.
|
|
*
|
|
* @return {[beestat.component.button]} The buttons in this group.
|
|
*/
|
|
beestat.component.button_group.prototype.get_buttons = function() {
|
|
return this.buttons_;
|
|
};
|
|
|
|
/**
|
|
* Remove this component from the page. Disposes the buttons first.
|
|
*/
|
|
beestat.component.button_group.prototype.dispose = function() {
|
|
this.buttons_.forEach(function(button) {
|
|
button.dispose();
|
|
});
|
|
beestat.component.prototype.dispose.apply(this, arguments);
|
|
};
|