diff --git a/lib/zin/wg/docapp/js/v1.js b/lib/zin/wg/docapp/js/v1.js index 148373a8c7..fac84448e7 100644 --- a/lib/zin/wg/docapp/js/v1.js +++ b/lib/zin/wg/docapp/js/v1.js @@ -1784,6 +1784,21 @@ function getApiID(id) return +id.replace('api.', ''); } +/** + * 获取列表类型。 + * Get the list type. + * + * @param {object} docApp + * @returns {string} + */ +function getListType(docApp) +{ + docApp = docApp || getDocApp(); + if(docApp.mode !== 'list' || docApp.module) return ''; + const listType = docApp.signals.listType.value; + return listType; +} + /** * 定义页面上的自定义渲染器。 * Define the custom renderers on the page. @@ -1843,7 +1858,7 @@ const customRenders = list: function() { if(!isApiLib()) return; - const listType = this.signals.listType.value; + const listType = getListType(this); const libID = getApiID(this.libID); const releaseID = this.signals.libReleaseMap.value[libID] || 0; if(listType === 'structs') return {fetcher: $.createLink('api', 'struct', `libID=${this.libID}&releaseID=${releaseID}`), loadingText: getDocAppLang('loading'), className: 'api-struct-list'}; @@ -1857,7 +1872,7 @@ const customRenders = filters: function() { if(!isApiLib(null, this)) return; - const listType = this.signals.listType.value; + const listType = getListType(this); if(this.mode !== 'list' || !listType) return; return null; }, @@ -1869,7 +1884,7 @@ const customRenders = toolbar: function() { if(!isApiLib()) return; - const listType = this.signals.listType.value; + const listType = getListType(this); if(this.mode === 'list' && listType) { const libID = getApiID(this.libID); @@ -1920,7 +1935,7 @@ const customRenders = items[viewIndex] = ['lib', [libView, versionPicker]]; } } - const listType = this.signals.listType.value; + const listType = getListType(this); if(this.mode !== 'list' || !listType) return items; if(listType === 'structs') items.push([listType, zui.renderCustomContent({className: 'mx-2', content: getDocAppLang('struct')})]); if(listType === 'releases') items.push([listType, zui.renderCustomContent({className: 'mx-2', content: getDocAppLang('releases')})]); @@ -1940,7 +1955,7 @@ const customRenders = const isListMode = this.mode === 'list'; const lang = getDocAppLang(); - const listType = this.signals.listType.value; + const listType = getListType(this); const items = []; if(canViewStructs) items.push({text: lang.struct, selected: listType === 'structs' && isListMode, icon: 'treemap muted', command: 'showStructs'}, {type: 'divider', className: 'my-1'}); if(canViewReleases) items.push({text: lang.releases, selected: listType === 'releases' && isListMode, icon: 'version muted', command: 'showReleases'}, {type: 'divider', className: 'my-1'}); diff --git a/module/api/js/index.ui.js b/module/api/js/index.ui.js index 3161ac7abf..5baa771047 100644 --- a/module/api/js/index.ui.js +++ b/module/api/js/index.ui.js @@ -1,3 +1,18 @@ +/** + * 获取列表类型。 + * Get the list type. + * + * @param {object} docApp + * @returns {string} + */ +function getListType(docApp) +{ + docApp = docApp || getDocApp(); + if(docApp.mode !== 'list' || docApp.module) return ''; + const listType = docApp.signals.listType.value; + return listType; +} + /** * 定义页面上的自定义渲染器。 * Define the custom renderers on the page. @@ -49,7 +64,7 @@ const customRenders = */ list: function() { - const listType = this.signals.listType.value; + const listType = getListType(this); const libID = this.libID; const releaseID = this.signals.libReleaseMap.value[libID] || 0; if(listType === 'structs') return {fetcher: $.createLink('api', 'struct', `libID=${this.libID}&releaseID=${releaseID}`), loadingText: getDocAppLang('loading'), className: 'api-struct-list'}; @@ -62,7 +77,7 @@ const customRenders = */ filters: function() { - const listType = this.signals.listType.value; + const listType = getListType(this); if(this.mode !== 'list' || !listType) return; return null; }, @@ -73,7 +88,7 @@ const customRenders = */ toolbar: function() { - const listType = this.signals.listType.value; + const listType = getListType(this); if(this.mode === 'list' && listType) { const items = []; @@ -123,7 +138,7 @@ const customRenders = items[viewIndex] = ['lib', [libView, versionPicker]]; } } - const listType = this.signals.listType.value; + const listType = getListType(this); if(this.mode !== 'list' || !listType) return items; if(listType === 'structs') items.push([listType, zui.renderCustomContent({className: 'mx-2', content: getDocAppLang('struct')})]); if(listType === 'releases') items.push([listType, zui.renderCustomContent({className: 'mx-2', content: getDocAppLang('releases')})]); @@ -144,7 +159,7 @@ const customRenders = const isListMode = this.mode === 'list'; const lang = getDocAppLang(); - const listType = this.signals.listType.value; + const listType = getListType(this); const items = []; if(canViewStructs) items.push({text: lang.struct, selected: listType === 'structs' && isListMode, icon: 'treemap muted', command: 'showStructs'}, {type: 'divider', className: 'my-1'}); if(canViewReleases) items.push({text: lang.releases, selected: listType === 'releases' && isListMode, icon: 'version muted', command: 'showReleases'}, {type: 'divider', className: 'my-1'});