Support activity-toggle in otherwise non-toggle buttons
Change-Id: I263c1bad69bc7af3089b802e0cea9a3cc22835fe
diff --git a/dev/js/src/buttongroup.js b/dev/js/src/buttongroup.js
index c6a772e..da12078 100644
--- a/dev/js/src/buttongroup.js
+++ b/dev/js/src/buttongroup.js
@@ -96,6 +96,19 @@
b['state'] = data['state'];
};
+ if (data['active'] !== undefined) {
+ let active = data['active'];
+
+ let check = _addCheck(b,active);
+ check.addEventListener('click', function (e) {
+ // Do not bubble
+ e.halt();
+ // Toggle state
+ active.roll();
+ });
+ };
+
+
if (data['desc'] !== undefined) {
desc = data['desc'];
};
@@ -103,7 +116,7 @@
b.setAttribute('title', desc);
b.addE('span').addT(title);
-
+
let that = this;
b.addEventListener('click', function (e) {
@@ -174,22 +187,8 @@
};
b.setAttribute('title',desc);
-
- // Set check marker
- const check = b.addE('span');
- check.classList.add("check", "button-icon");
- check.addE('span');
- // Associate this object to state
- // Add setState method to object
- check.setState = function (value) {
- if (value) {
- this.classList.add("checked");
- } else {
- this.classList.remove("checked");
- }
- };
- state.associate(check);
+ _addCheck(b, state);
b.addE('span').addT(title);
@@ -229,3 +228,23 @@
}
}
});
+
+function _addCheck(b,state) {
+
+ // Set check marker
+ const check = b.addE('span');
+ check.classList.add("check", "button-icon");
+ check.addE('span');
+
+ // Associate this object to state
+ // Add setState method to object
+ check.setState = function (value) {
+ if (value) {
+ this.classList.add("checked");
+ } else {
+ this.classList.remove("checked");
+ }
+ };
+ state.associate(check);
+ return check;
+};