You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/assets/javascripts/views/list/list_select.js

79 lines
1.9 KiB

// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS002: Fix invalid constructor
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining
* DS206: Consider reworking classes to avoid initClass
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
const Cls = (app.views.ListSelect = class ListSelect extends app.View {
static initClass() {
1 year ago
this.activeClass = "active";
this.events = { click: "onClick" };
}
1 year ago
constructor(el) {
this.onClick = this.onClick.bind(this);
this.el = el;
super(...arguments);
}
deactivate() {
1 year ago
if (super.deactivate(...arguments)) {
this.deselect();
}
}
select(el) {
this.deselect();
if (el) {
el.classList.add(this.constructor.activeClass);
1 year ago
$.trigger(el, "select");
}
}
deselect() {
let selection;
1 year ago
if ((selection = this.getSelection())) {
selection.classList.remove(this.constructor.activeClass);
1 year ago
$.trigger(selection, "deselect");
}
}
selectByHref(href) {
1 year ago
if (
__guard__(this.getSelection(), (x) => x.getAttribute("href")) !== href
) {
this.select(this.find(`a[href='${href}']`));
}
}
selectCurrent() {
this.selectByHref(location.pathname + location.hash);
}
getSelection() {
return this.findByClass(this.constructor.activeClass);
}
onClick(event) {
1 year ago
if (event.which !== 1 || event.metaKey || event.ctrlKey) {
return;
}
const target = $.eventTarget(event);
1 year ago
if (target.tagName === "A") {
this.select(target);
}
}
});
Cls.initClass();
function __guard__(value, transform) {
1 year ago
return typeof value !== "undefined" && value !== null
? transform(value)
: undefined;
}