Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions apps/tup-cms/src/taccsite_cms/templates/snippets/js-move-to.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script id="js-move-to" type="module">
function processMoveToElements() {
const alerts = document.querySelectorAll('[data-move-to]');

[ ...alerts ].forEach(function(alert) {
const targetSelector = alert.dataset.moveTo;
const requiredPath = alert.dataset.moveIf;
const shouldMove = ( !requiredPath || window.location.pathname.includes(requiredPath) );
const targetElement = document.querySelector(targetSelector);

console.debug('[data-move-to]', {shouldMove, requiredPath, alert, targetElement});

if (shouldMove) {
targetElement?.prepend(alert);

if (alert.style.display === 'none') {
alert.style.removeProperty('display');
}
} else {
alert.style.setProperty('display', 'none');
}
});
}
processMoveToElements();

// To trigger on React navigation
const originalPushState = history.pushState;
const originalReplaceState = history.replaceState;
history.pushState = function() {
originalPushState.apply(this, arguments);
processMoveToElements();
};
</script>