Skip to content

Instantly share code, notes, and snippets.

@badvision
Last active May 17, 2021 14:09
Show Gist options
  • Save badvision/36753e9a167d676b46be to your computer and use it in GitHub Desktop.
Save badvision/36753e9a167d676b46be to your computer and use it in GitHub Desktop.
AEM 6.x: Reload the page when the user switches layers
// 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));
@badvision
Copy link
Author

Updated to not refresh when going in/out of annotation mode (it was more annoying than it was useful)

@badvision
Copy link
Author

Added logic to not refresh if page recently loaded -- this prevents refresh-of-death scenarios

@HitmanInWis
Copy link

Awesome, thank you for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment