blob: a1dac7bb98342054105cb87d6e5fd89f2ed4422e [file] [log] [blame]
Akrondefa5e82018-07-10 12:09:46 +02001define(['util'], function () {
2 return {
3 /**
4 * Create button group
5 */
6 create : function (classes) {
7 return Object.create(this)._init(classes);
8 },
9
10 // Initialize button group
11 _init : function (classes) {
12 var e = document.createElement('div');
13 var cl = e.classList;
14 if (classes !== undefined) {
15 cl.add.apply(cl,classes);
16 };
17 cl.add('button-group');
18 this._element = e;
19 return this;
20 },
21
22 /**
23 * Return main element
24 */
25 element : function () {
26 return this._element;
27 },
28
29 /**
30 * Add button in order
31 */
32 add : function (title, classes, cb) {
33 var b = this._element.addE('span');
Akrondefa5e82018-07-10 12:09:46 +020034 b.setAttribute('title',title);
35 if (classes !== undefined) {
36 b.classList.add.apply(b.classList, classes);
37 };
Akronbec4a6a2018-07-10 14:45:15 +020038 b.addE('span').addT(title);
Akrondefa5e82018-07-10 12:09:46 +020039
40 var that = this;
41 b.addEventListener('click', function (e) {
42
43 // Do not bubble
44 e.halt();
45
46 // Call callback
47 cb.apply(that._bind || this, e)
48 });
49 },
50
51 /**
52 * Bind an object to all callbacks of the button group
53 */
54 bind : function (obj) {
55 if (obj !== undefined) {
56 this._bind = obj;
57 };
58 return this._bind || this;
59 }
60 }
61});