| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- // TODO: This file was created by bulk-decaffeinate.
- // Sanity-check the conversion and remove this comment.
- /*
- * decaffeinate suggestions:
- * DS101: Remove unnecessary use of Array.from
- * 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
- * DS207: Consider shorter variations of null checks
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
- */
- app.views.DocPicker = class DocPicker extends app.View {
- static initClass() {
- this.className = "_list _list-picker";
- this.events = {
- mousedown: "onMouseDown",
- mouseup: "onMouseUp",
- };
- }
- init() {
- this.addSubview((this.listFold = new app.views.ListFold(this.el)));
- }
- activate() {
- if (super.activate(...arguments)) {
- this.render();
- this.onDOMFocus = this.onDOMFocus.bind(this);
- $.on(this.el, "focus", this.onDOMFocus, true);
- }
- }
- deactivate() {
- if (super.deactivate(...arguments)) {
- this.empty();
- $.off(this.el, "focus", this.onDOMFocus, true);
- this.focusEl = null;
- }
- }
- render() {
- let doc;
- let html = this.tmpl("docPickerHeader");
- let docs = app.docs
- .all()
- .concat(...Array.from(app.disabledDocs.all() || []));
- while ((doc = docs.shift())) {
- if (doc.version != null) {
- var versions;
- [docs, versions] = Array.from(this.extractVersions(docs, doc));
- html += this.tmpl(
- "sidebarVersionedDoc",
- doc,
- this.renderVersions(versions),
- { open: app.docs.contains(doc) },
- );
- } else {
- html += this.tmpl("sidebarLabel", doc, {
- checked: app.docs.contains(doc),
- });
- }
- }
- this.html(html + this.tmpl("docPickerNote"));
- $.requestAnimationFrame(() =>
- __guard__(this.findByTag("input"), (x) => x.focus()),
- );
- }
- renderVersions(docs) {
- let html = "";
- for (var doc of Array.from(docs)) {
- html += this.tmpl("sidebarLabel", doc, {
- checked: app.docs.contains(doc),
- });
- }
- return html;
- }
- extractVersions(originalDocs, version) {
- const docs = [];
- const versions = [version];
- for (var doc of Array.from(originalDocs)) {
- (doc.name === version.name ? versions : docs).push(doc);
- }
- return [docs, versions];
- }
- empty() {
- this.resetClass();
- super.empty(...arguments);
- }
- getSelectedDocs() {
- return Array.from(this.findAllByTag("input"))
- .filter((input) => (input != null ? input.checked : undefined))
- .map((input) => input.name);
- }
- onMouseDown() {
- this.mouseDown = Date.now();
- }
- onMouseUp() {
- this.mouseUp = Date.now();
- }
- onDOMFocus(event) {
- const { target } = event;
- if (target.tagName === "INPUT") {
- if (
- (!this.mouseDown || !(Date.now() < this.mouseDown + 100)) &&
- (!this.mouseUp || !(Date.now() < this.mouseUp + 100))
- ) {
- $.scrollTo(target.parentNode, null, "continuous");
- }
- } else if (target.classList.contains(app.views.ListFold.targetClass)) {
- target.blur();
- if (!this.mouseDown || !(Date.now() < this.mouseDown + 100)) {
- if (this.focusEl === $("input", target.nextElementSibling)) {
- if (target.classList.contains(app.views.ListFold.activeClass)) {
- this.listFold.close(target);
- }
- let prev = target.previousElementSibling;
- while (
- prev.tagName !== "LABEL" &&
- !prev.classList.contains(app.views.ListFold.targetClass)
- ) {
- prev = prev.previousElementSibling;
- }
- if (prev.classList.contains(app.views.ListFold.activeClass)) {
- prev = $.makeArray($$("input", prev.nextElementSibling)).pop();
- }
- this.delay(() => prev.focus());
- } else {
- if (!target.classList.contains(app.views.ListFold.activeClass)) {
- this.listFold.open(target);
- }
- this.delay(() => $("input", target.nextElementSibling).focus());
- }
- }
- }
- this.focusEl = target;
- }
- };
- app.views.DocPicker.initClass();
- function __guard__(value, transform) {
- return typeof value !== "undefined" && value !== null
- ? transform(value)
- : undefined;
- }
|