This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/resources/views/yuuno/settings/account/_preview.twig

35 lines
1.1 KiB
Twig

<script type="text/javascript">
var parser = new Sakura.AJAX(),
textMax = {{ maxLength }},
form = document.getElementById("settingsEditor"),
preview = document.getElementById("settingsPreview");
parser.SetUrl("{{ route('helper.bbcode.parse') }}");
parser.ContentType("application/x-www-form-urlencoded");
function settingsPreview() {
var text = form.value;
if (text.length == 0) {
preview.innerHTML = "";
} else if (text.length > textMax) {
preview.innerHTML = "<span style='color: red;'>Too long!</span>";
} else {
parser.SetSend({"text":text});
parser.AddCallback(200, function () {
preview.innerHTML = parser.Response();
var codeBlocks = preview.querySelectorAll("pre code");
for (var _i in codeBlocks) {
if ((typeof codeBlocks[_i]).toLowerCase() === 'object') {
hljs.highlightBlock(codeBlocks[_i]);
}
}
});
parser.Start(Sakura.HTTPMethod.POST);
}
}
</script>