Created
March 7, 2016 09:32
-
-
Save Sebobo/4bc04dc17206000d1d98 to your computer and use it in GitHub Desktop.
Detect backendlayout in Neos and reload page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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