"use strict"; class AdventuresBooksList { static _getDateStr (advBook) { if (!advBook.published) return "\u2014"; const date = new Date(advBook.published); return DatetimeUtil.getDateStr({date, isShort: true, isPad: true}); } static _getGroupStr (advBook) { const group = advBook.group || "other"; const entry = SourceUtil.ADV_BOOK_GROUPS.find(it => it.group === group); return entry.displayName; } static _sortAdventuresBooks (dataList, a, b, o) { a = dataList[a.ix]; b = dataList[b.ix]; if (o.sortBy === "name") return this._sortAdventuresBooks_byName(a, b, o); if (o.sortBy === "storyline") return this._sortAdventuresBooks_orFallback(SortUtil.ascSort, "storyline", a, b, o); if (o.sortBy === "level") return this._sortAdventuresBooks_orFallback(SortUtil.ascSort, "_startLevel", a, b, o); if (o.sortBy === "group") return SortUtil.ascSortSourceGroup(a, b) || this._sortAdventuresBooks_byPublished(a, b, o); if (o.sortBy === "published") return this._sortAdventuresBooks_byPublished(a, b, o); } static _sortAdventuresBooks_byPublished (a, b, o) { return SortUtil.ascSortDate(b._pubDate, a._pubDate) || SortUtil.ascSort(a.publishedOrder || 0, b.publishedOrder || 0) || this._sortAdventuresBooks_byName(a, b, o); } static _sortAdventuresBooks_byName (a, b, o) { return SortUtil.ascSort(a.name, b.name); } static _sortAdventuresBooks_orFallback (func, prop, a, b, o) { const initial = func(a[prop] || "", b[prop] || ""); return initial || this._sortAdventuresBooks_byName(a, b, o); } constructor (options) { this._contentsUrl = options.contentsUrl; this._fnSort = options.fnSort; this._sortByInitial = options.sortByInitial; this._sortDirInitial = options.sortDirInitial; this._dataProp = options.dataProp; this._enhanceRowDataFn = options.enhanceRowDataFn; this._rootPage = options.rootPage; this._rowBuilderFn = options.rowBuilderFn; this._list = null; this._listAlt = null; this._dataIx = 0; this._dataList = []; } async pOnPageLoad () { await Promise.all([ PrereleaseUtil.pInit(), BrewUtil2.pInit(), ]); const [data] = await Promise.all([ await DataUtil.loadJSON(`${Renderer.get().baseUrl}${this._contentsUrl}`), await ExcludeUtil.pInitialise(), ]); const $iptSearch = $(`#search`); const fnSort = (a, b, o) => this._fnSort(this._dataList, a, b, o); this._list = new List({ $wrpList: $(".books"), $iptSearch, fnSort, sortByInitial: this._sortByInitial, sortDirInitial: this._sortDirInitial, isUseJquery: true, }); SortUtil.initBtnSortHandlers($(`#filtertools`), this._list); const $wrpBookshelf = $(".books--alt"); this._listAlt = new List({ $wrpList: $wrpBookshelf, $iptSearch, fnSort, sortByInitial: this._sortByInitial, sortDirInitial: this._sortDirInitial, }); $("#reset").click(() => { this._list.reset(); this._listAlt.reset(); this._list.items.forEach(li => { if (li.data.$btnToggleExpand.text() === "[\u2012]") li.data.$btnToggleExpand.click(); }); }); this.addData(data); await handleBrew(await PrereleaseUtil.pGetBrewProcessed()); await handleBrew(await BrewUtil2.pGetBrewProcessed()); // TODO(MODULES) refactor import("./utils-brew/utils-brew-ui-manage.js") .then(({ManageBrewUi}) => { ManageBrewUi.bindBtngroupManager(e_({id: "btngroup-manager"})); }); this._list.init(); this._listAlt.init(); if (ExcludeUtil.isAllContentExcluded(this._dataList)) $wrpBookshelf.append(ExcludeUtil.getAllContentBlocklistedHtml()); window.dispatchEvent(new Event("toolsLoaded")); } addData (data) { if (!data[this._dataProp] || !data[this._dataProp].length) return; this._dataList.push(...data[this._dataProp]); for (; this._dataIx < this._dataList.length; this._dataIx++) { const it = this._dataList[this._dataIx]; if (this._enhanceRowDataFn) this._enhanceRowDataFn(it); const isExcluded = ExcludeUtil.isExcluded(UrlUtil.URL_TO_HASH_BUILDER[this._rootPage](it), this._dataProp, it.source); const $elesContents = []; it.contents.map((chapter, ixChapter) => { const $lnkChapter = $$` ${Parser.bookOrdinalToAbv(chapter.ordinal)}${chapter.name} `; $elesContents.push($lnkChapter); if (!chapter.headers) return; const headerCounts = {}; chapter.headers.forEach(header => { const headerText = BookUtil.getHeaderText(header); const headerTextClean = headerText.toLowerCase().trim(); const headerPos = headerCounts[headerTextClean] || 0; headerCounts[headerTextClean] = (headerCounts[headerTextClean] || 0) + 1; const $lnk = $$` 0 ? `,${headerPos}` : ""}" class="lst__row lst--border lst__row-inner lst__wrp-cells bklist__row-section ve-flex w-100"> ${BookUtil.getContentsSectionHeader(header)} `; $elesContents.push($lnk); }); }); const $wrpContents = $$`