Last active
November 12, 2018 19:31
-
-
Save keslo/0fc7f7b5ae9487947d8ef2e30747466d to your computer and use it in GitHub Desktop.
LiveReload in MODX Evo (Evo CMS)
This file contains hidden or 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
global $modx; | |
// проверяем авторизацию менеджера | |
if ($_SESSION['mgrInternalKey'] == 1) { | |
// вешаем запись в localStorage при сохранении чанка | |
$e = $modx->Event; | |
if ($e->name == "OnChunkFormRender" || $e->name == "OnTempFormRender") { | |
$script = '<script> | |
var btn = document.getElementById("Button1"); | |
btn.addEventListener("click", function() { | |
localStorage["evo-reload"] = "true"; | |
}); | |
</script>'; | |
$e->output($script); | |
} | |
// на страницу фронта добавляем скрипт отслеживания изменений localStorage | |
if ($e->name == "OnWebPagePrerender") { | |
// скрипт для страницы | |
$script = " | |
<script> | |
window.addEventListener('storage', function(events) { | |
if (localStorage['evo-reload'] === 'true') { | |
localStorage['evo-reload'] = 'false'; | |
setTimeout(function() { location.reload() }, 100); | |
} | |
}); | |
</script></body> | |
"; | |
$output = $modx->documentOutput; | |
$output = str_replace('</body>', $script, $output); | |
$modx->documentOutput = $output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment