Last active
May 17, 2021 14:09
-
-
Save badvision/36753e9a167d676b46be to your computer and use it in GitHub Desktop.
AEM 6.x: Reload the page when the user switches layers
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
// This must be in a client library with the category cq.authoring.editor.hook | |
/* global Granite, jQuery, document */ | |
(function ($, channel) { | |
'use strict'; | |
$(function () { | |
var loadedTime = new Date(); | |
channel.on('cq-layer-activated', function (event) { | |
if (event.prevLayer && event.layer !== event.prevLayer) { | |
var eventTime = new Date(); | |
if (event.prevLayer !== 'Annotate' && event.layer !== 'Annotate' && (eventTime - loadedTime) > 1500) { | |
location.reload(); | |
} | |
} | |
}); | |
}); | |
})(Granite.$, jQuery(document)); |
Awesome, thank you for this!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added logic to not refresh if page recently loaded -- this prevents refresh-of-death scenarios