As the title says, how can I active the sort by 'data-title' on load? I tried to active it in the HTML but it didn't work. I'm no Javascript expert but my gut tells me this is easy - sadly I cant figure it out.
https://vestride.github.io/Shuffle/
emo.prototype._handleSortChange = function (evt) {
// Add and remove `active` class from buttons.
var wrapper = evt.currentTarget;
var buttons = Array.from(evt.currentTarget.children);
buttons.forEach(function (button) {
if (button.querySelector("input").value === evt.target.value) {
button.classList.add("active");
} else {
button.classList.remove("active");
}
});
// Create the sort options to give to Shuffle.
var value = evt.target.value;
var options = {};
function sortByDate(element) {
return element.getAttribute("data-title");
}
function sortByTitle(element) {
return element.getAttribute("data-title").toLowerCase();
}
if (value === "date-created") {
options = {
reverse: true,
by: sortByDate,
};
} else if (value === "title") {
options = {
by: sortByTitle,
};
}
this.shuffle.sort(options);
};