Skip to content

Instantly share code, notes, and snippets.

@Sebobo
Created March 7, 2016 09:32
Show Gist options
  • Save Sebobo/4bc04dc17206000d1d98 to your computer and use it in GitHub Desktop.
Save Sebobo/4bc04dc17206000d1d98 to your computer and use it in GitHub Desktop.
Detect backendlayout in Neos and reload page
(function () {
/**
* Backend specific scripts
*/
"use strict";
var lastPageLayout,
layouts = {
newsletter: 'typo3:Vendor.Package:Newsletter'
};
// Reload page on layout change
function verifyPageLayout () {
var pageMeta = document.getElementById('neos-document-metadata'),
currentLayout = pageMeta.getAttribute('typeof'),
currentLayoutIsNewsletter = currentLayout == layouts.newsletter;
// Reload page if layout has changed
if ((lastPageLayout == layouts.newsletter && !currentLayoutIsNewsletter) || (lastPageLayout != layouts.newsletter && lastPageLayout !== undefined && currentLayoutIsNewsletter)) {
location.reload();
}
lastPageLayout = currentLayout;
}
verifyPageLayout();
// Load scripts for certain events
if (typeof document.addEventListener === 'function') {
document.addEventListener('Neos.PageLoaded', function(event) {
// Reload google maps after a page has loaded
verifyPageLayout();
}, false);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment