Skip to content

Commit

Permalink
Add keys to components.toggle.
Browse files Browse the repository at this point in the history
This adds keys — unique non-human identifiers to the toggle component.
  • Loading branch information
brockwhittaker authored and timabbott committed Feb 10, 2017
1 parent 5fbf7de commit 2ea6eda
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions static/js/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports.toggle = (function () {
opts.values.forEach(function (value, i) {
// create a tab with a tab-id so they don't have to be referenced
// by text value which can be inconsistent.
var tab = $("<div class='ind-tab' data-tab-id='" + i + "'>" + value.label + "</div>");
var tab = $("<div class='ind-tab' data-tab-key='" + value.key + "' data-tab-id='" + i + "'>" + value.label + "</div>");

// add proper classes for styling in CSS.
if (i === 0) {
Expand Down Expand Up @@ -54,7 +54,7 @@ exports.toggle = (function () {
var id = +$(this).data("tab-id");
if (last_value !== opts.values[id].label) {
last_value = opts.values[id].label;
opts.callback(last_value);
opts.callback(last_value, opts.values[id].key);
}
}
});
Expand All @@ -81,7 +81,7 @@ exports.toggle = (function () {
// and when found, select that one and provide the proper callback.
goto: function (name) {
var value = _.find(opts.values, function (o) {
return o.label === name;
return o.label === name || o.key === name;
});

var idx = opts.values.indexOf(value);
Expand All @@ -90,8 +90,7 @@ exports.toggle = (function () {
meta.$ind_tab.removeClass("selected");
meta.$ind_tab.filter("[data-tab-id='" + idx + "']").addClass("selected");

value.label = name;
opts.callback(name);
opts.callback(value.label, value.key);
}
},
};
Expand Down

0 comments on commit 2ea6eda

Please sign in to comment.