Skip to content

Commit

Permalink
feat: add compendium document ids
Browse files Browse the repository at this point in the history
  • Loading branch information
akrigline committed Jan 23, 2022
1 parent e8322bc commit 80f2a89
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
"Name": "Show Sidebar Directory Ids?",
"Hint": "Places a clickable chip on sidebar directory entries to copy the id or print the document to the console. Requires Reload"
},
"show-compendium-ids": {
"Name": "Show Compendium Document Ids?",
"Hint": "Places a clickable chip on compendium directory entries to copy the id or print the document to the console."
},
"suppress-too-small": {
"Name": "Suppress Window Size Warning",
"Hint": "Suppresses the window size warning on startup."
Expand Down
1 change: 1 addition & 0 deletions module/classes/DevMode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class DevMode {
packageSpecificDebug: 'package-specific-debug',
suppressTooSmall: 'suppress-too-small',
showDirectoryIds: 'show-directory-ids',
showCompendiumIds: 'show-compendium-ids',
appHeaderButton: 'app-header-button',
showChatIds: 'show-chat-ids',
disableTemplateCache: 'disable-template-cache',
Expand Down
4 changes: 4 additions & 0 deletions module/classes/DevModeSettings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export class DevModeSettings {
return;
},
},
{
key: DevMode.SETTINGS.showCompendiumIds,
default: true,
},
{
key: DevMode.SETTINGS.appHeaderButton,
default: true,
Expand Down
23 changes: 21 additions & 2 deletions module/hooks/dev-mode-anchor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ export default function setupDevModeAnchor() {
const devModeTag = (relevantId, collection) => `
<div class="dev-mode-tag">
${relevantId}
<div class="dev-mode-tag-actions" ${idAttribute}="${relevantId}" data-collection="${collection}">
<div class="dev-mode-tag-actions"
${idAttribute}="${relevantId}"
${collection ? `data-collection="${collection}"` : ''}>
<button class="dev-mode-copy" title=""><i class="far fa-copy"></i></button>
<button class="dev-mode-print" title=""><i class="fa fa-terminal"></i></button>
${collection ? '<button class="dev-mode-print" title=""><i class="fa fa-terminal"></i></button>' : ''}
</div>
</div>
`;
Expand Down Expand Up @@ -50,6 +52,23 @@ export default function setupDevModeAnchor() {
html.addClass('dev-mode-anchor');
});

Hooks.on('renderCompendium', async (compendium, html) => {
if (!game.settings.get(DevMode.MODULE_ID, DevMode.SETTINGS.showCompendiumIds)) {
return;
}

DevMode.log(false, 'renderCompendium', compendium, {
idAttribute,
});

html.find(`.directory-item[${idAttribute}]`).each(function () {
const relevantId = $(this).data()?.[idKey];

$(this).addClass('dev-mode-anchor');
$(this).append(devModeTag(relevantId));
});
});

/**
* Any DOM element with the `.dev-mode-copy` class will look up the tree for an element
* with `${idAttribute}` attribute and copy that attribute's value when clicked.
Expand Down

0 comments on commit 80f2a89

Please sign in to comment.