Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Can be placed on a template page in edit mode to listen for mutations that affect DOM nodes which are associated with editable properties in episerver. Loading of this script should be deferred.
var publishEvent = function () {
if (window.epi && window.epi.publish) {
// Publishing the "beta/domUpdated" event will tell episerver UI that the dom has changed
// and that it needs to remap its overlays.
var observeEpiProperties = function (target) {
const ignoreList = ["#text", "#comment"];
if (ignoreList.includes(target.nodeName)) {
var nodes;
if (target.attributes["data-epi-property-name"]) {
nodes = [target];
} else {
nodes = target.querySelectorAll("[data-epi-property-name]");
nodes.forEach(function (node) {
var observer = new MutationObserver(publishEvent);
observer.observe(node, {
attributes: true,
attributeFilter: ["data-epi-property-name"]
var onNodeAdded = function(mutations) {
mutations.forEach(function (mutation) {
var observer = new MutationObserver(onNodeAdded);
observer.observe(document.body, {
childList: true,
subtree: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.