Introduce button group
Change-Id: Ic9d158e77f76aabfc92ce54093d768a0e92b3560
diff --git a/dev/js/src/buttongroup.js b/dev/js/src/buttongroup.js
new file mode 100644
index 0000000..b33c13a
--- /dev/null
+++ b/dev/js/src/buttongroup.js
@@ -0,0 +1,61 @@
+define(['util'], function () {
+ return {
+ /**
+ * Create button group
+ */
+ create : function (classes) {
+ return Object.create(this)._init(classes);
+ },
+
+ // Initialize button group
+ _init : function (classes) {
+ var e = document.createElement('div');
+ var cl = e.classList;
+ if (classes !== undefined) {
+ cl.add.apply(cl,classes);
+ };
+ cl.add('button-group');
+ this._element = e;
+ return this;
+ },
+
+ /**
+ * Return main element
+ */
+ element : function () {
+ return this._element;
+ },
+
+ /**
+ * Add button in order
+ */
+ add : function (title, classes, cb) {
+ var b = this._element.addE('span');
+ b.addT(title);
+ b.setAttribute('title',title);
+ if (classes !== undefined) {
+ b.classList.add.apply(b.classList, classes);
+ };
+
+ var that = this;
+ b.addEventListener('click', function (e) {
+
+ // Do not bubble
+ e.halt();
+
+ // Call callback
+ cb.apply(that._bind || this, e)
+ });
+ },
+
+ /**
+ * Bind an object to all callbacks of the button group
+ */
+ bind : function (obj) {
+ if (obj !== undefined) {
+ this._bind = obj;
+ };
+ return this._bind || this;
+ }
+ }
+});