Skip to content

Commit

Permalink
IBX-8011: Refine bookmarking in Content Tree
Browse files Browse the repository at this point in the history
  • Loading branch information
tischsoic committed Apr 11, 2024
1 parent b99be41 commit c077b33
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/bundle/Resources/public/js/scripts/admin.location.bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@

return response.status;
};
const onBookmarkUpdated = (isBookmarked) => {
const handleBookmarkUpdated = (isBookmarked) => {
ibexa.helpers.tooltips.hideAll();
toggleBookmarkIconState(isBookmarked);
isUpdatingBookmark = false;

doc.body.dispatchEvent(
new CustomEvent('ibexa-bookmark-change', {
detail: {
bookmarked: isBookmarked,
locationId: currentLocationId,
},
}),
);
};
const updateBookmark = (addBookmark) => {
if (isUpdatingBookmark) {
Expand All @@ -43,7 +51,7 @@
credentials: 'same-origin',
});

fetch(request).then(getResponseStatus).then(onBookmarkUpdated.bind(null, addBookmark)).catch(handleUpdateError);
fetch(request).then(getResponseStatus).then(handleBookmarkUpdated.bind(null, addBookmark)).catch(handleUpdateError);
};
const isCurrentLocation = (locationId) => {
return parseInt(locationId, 10) === currentLocationId;
Expand All @@ -58,18 +66,15 @@
toggleBookmarkIconState(bookmarked);
}
};
const checkIsBookmarked = () => {
return bookmarkWrapper.classList.contains(CLASS_BOOKMARK_CHECKED);
};
const onBookmarkChange = () => {
const addBookmark = !checkIsBookmarked();
const handleBookmarkClick = () => {
const isBookmarked = bookmarkWrapper.classList.contains(CLASS_BOOKMARK_CHECKED);

updateBookmark(addBookmark);
updateBookmark(!isBookmarked);
};

doc.body.addEventListener('ibexa-bookmark-change', updateBookmarkIconState, false);

if (bookmarkWrapper) {
bookmarkWrapper.addEventListener('click', onBookmarkChange, false);
bookmarkWrapper.addEventListener('click', handleBookmarkClick, false);
}
})(window, window.document, window.ibexa);

0 comments on commit c077b33

Please sign in to comment.