Skip to content

Commit

Permalink
fix section buttons when switch group library
Browse files Browse the repository at this point in the history
  • Loading branch information
volatile-static committed Sep 18, 2024
1 parent 5fc7d70 commit f98c469
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/bootstrap/modules/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ export function registerPanels() {
type: tab,
l10nID: `chartero-dashboard-${tab}`,
icon: `resource://${config.addonName}/icons/${tab}.svg`,
onClick(e) {
post(e.body, { tab });
for (const t of tabs)
e.setSectionButtonStatus(t, { disabled: t === tab });
onClick(args) {
post(args.body, { tab });
args.setSectionButtonStatus(tab, { disabled: true });
args.setSectionButtonStatus(args.body.dataset.tab!, { disabled: false });
args.body.dataset.tab = tab;
}
})),
onInit: args => {
Expand All @@ -55,21 +56,30 @@ export function registerPanels() {
styles: { height: '100%', width: '100%' },
enableElementRecord: false,
}, args.body) as HTMLIFrameElement,
ResizeObserver = G('ResizeObserver'),
ResizeObserver = G('ResizeObserver'), // 切换页面时自动调整高度
observer = new ResizeObserver(
([entry]) => args.body.style.height = `${entry.contentRect.height}px`
);
(iframe.contentWindow as any).wrappedJSObject.addon = addon;
iframe.addEventListener('load', ({ target }) => {
observer.observe((target as Document).documentElement);
}, true);
},
onRender: args => {
if (args.item.libraryID == Zotero.Libraries.userLibraryID)
args.setSectionButtonStatus('group', { hidden: true });

// 默认第一页
args.setSectionButtonStatus('progress', { disabled: true });
args.body.dataset.tab = 'progress';
},
onItemChange: args => {
const hidden = args.item.libraryID == Zotero.Libraries.userLibraryID;
args.setSectionButtonStatus('group', { hidden });
if (hidden && args.body.dataset.tab == 'group') {
args.setSectionButtonStatus('progress', { disabled: true });
args.setSectionButtonStatus('group', { disabled: false });
args.body.dataset.tab = 'progress';
post(args.body, { tab: 'progress' });
}
post(args.body, { id: args.item.id });
},
onItemChange: args => post(args.body, { id: args.item.id }),
});
}

Expand Down

0 comments on commit f98c469

Please sign in to comment.