Skip to content

Commit

Permalink
Merge branch 'main' of github.com:adobe/assets-distribution-portal
Browse files Browse the repository at this point in the history
  • Loading branch information
synox committed Dec 4, 2023
2 parents f3457f3 + d8701ac commit 779f0c0
Showing 1 changed file with 53 additions and 54 deletions.
107 changes: 53 additions & 54 deletions blocks/adp-header/adp-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export default async function decorate(block) {
if (!isPublicPage()) {
loadSearchField(nav);
await createUserInfo(nav);
initQuickLinks(nav);
}
}

Expand Down Expand Up @@ -287,8 +288,59 @@ async function createUserInfo(nav) {
},
);
});
}

async function handleRemoveMultiSelectedAssetsFromCollection() {
const collectionId = getCollectionIdFromURL();
const collectionJSON = await getCollection(collectionId);
const collectionIndexes = {};
collectionJSON.items.forEach((item, index) => {
collectionIndexes[item.id] = index;
});
const selectedAssets = getSelectedAssetsFromInfiniteResultsBlock();
const selectedAssetIds = selectedAssets.map((asset) => asset.getAttribute('data-item-id'));

const deleteOperation = selectedAssetIds.map((assetId) => ({
value: collectionJSON.items[collectionIndexes[assetId]],
path: `/items/${collectionIndexes[assetId]}`,
}));

await patchCollection(collectionId, collectionJSON?.etag, null, deleteOperation);
// Refresh the page
window.location.reload();
}

function initQuickLinks(nav) {
if (document.querySelector('head meta[name="hide-quicklinks"]')?.getAttribute('content') === 'true') {
return;
}

const quickLinks = document.querySelector('.adp-header .nav-bottom .quick-links');
// decorate quick links
quickLinksConfig.forEach((item) => {
const itemEl = document.createElement('div');
itemEl.className = 'item';
const itemLinkEl = document.createElement('a');
if (item.page.startsWith('/') && isUrlPathNonRoot()) {
itemLinkEl.href = getBaseConfigPath() + item.page;
} else {
itemLinkEl.href = item.page;
}
if (item.page.startsWith('http')) {
itemLinkEl.target = '_blank';
itemLinkEl.rel = 'noopener';
}
itemLinkEl.textContent = item.title;
itemEl.append(itemLinkEl);
quickLinks.append(itemEl);
});

initQuickLinks();
// set aria-selected on quick links
quickLinks.querySelectorAll('.item').forEach((item) => {
if (item.querySelector('a')?.getAttribute('href') === window.location.pathname) {
item.setAttribute('aria-selected', 'true');
}
});

const closeBanner = nav.querySelector('.banner .action-close');
closeBanner.addEventListener('click', () => {
Expand Down Expand Up @@ -347,59 +399,6 @@ async function createUserInfo(nav) {
});
}

async function handleRemoveMultiSelectedAssetsFromCollection() {
const collectionId = getCollectionIdFromURL();
const collectionJSON = await getCollection(collectionId);
const collectionIndexes = {};
collectionJSON.items.forEach((item, index) => {
collectionIndexes[item.id] = index;
});
const selectedAssets = getSelectedAssetsFromInfiniteResultsBlock();
const selectedAssetIds = selectedAssets.map((asset) => asset.getAttribute('data-item-id'));

const deleteOperation = selectedAssetIds.map((assetId) => ({
value: collectionJSON.items[collectionIndexes[assetId]],
path: `/items/${collectionIndexes[assetId]}`,
}));

await patchCollection(collectionId, collectionJSON?.etag, null, deleteOperation);
// Refresh the page
window.location.reload();
}

function initQuickLinks() {
if (document.querySelector('head meta[name="hide-quicklinks"]')?.getAttribute('content') === 'true') {
return;
}

const quickLinks = document.querySelector('.adp-header .nav-bottom .quick-links');
// decorate quick links
quickLinksConfig.forEach((item) => {
const itemEl = document.createElement('div');
itemEl.className = 'item';
const itemLinkEl = document.createElement('a');
if (item.page.startsWith('/') && isUrlPathNonRoot()) {
itemLinkEl.href = getBaseConfigPath() + item.page;
} else {
itemLinkEl.href = item.page;
}
if (item.page.startsWith('http')) {
itemLinkEl.target = '_blank';
itemLinkEl.rel = 'noopener';
}
itemLinkEl.textContent = item.title;
itemEl.append(itemLinkEl);
quickLinks.append(itemEl);
});

// set aria-selected on quick links
quickLinks.querySelectorAll('.item').forEach((item) => {
if (item.querySelector('a')?.getAttribute('href') === window.location.pathname) {
item.setAttribute('aria-selected', 'true');
}
});
}

export function getNavHeight() {
return document.querySelector('.nav-wrapper').getBoundingClientRect().height;
}

0 comments on commit 779f0c0

Please sign in to comment.