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/templates/yuuno/settings/appearance/_preview.twig
2016-04-03 23:29:46 +02:00

35 lines
1.1 KiB
Twig

<script type="text/javascript">
var parser = new 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(HTTPMethods.POST);
}
}
</script>