Paste - Chief Tools Utilities
`;
const blob = new Blob([s], {type: 'text/html; charset=utf-8'});
preview.src = URL.createObjectURL(blob);
}
function updatePreviewFrameVisibility() {
const current = renderPreview;
const newValue = syntaxId.endsWith('+preview');
if (current === newValue) {
return;
}
if (!newValue) {
previewContainer.classList.add('hidden');
return;
}
previewContainer.classList.remove('hidden');
editor.refresh();
renderPreview = newValue;
}
const previewUpdater = _.debounce((editor) => {
updatePreviewFrame(editor.doc.getValue());
updatePreviewFrameVisibility();
}, 500, {maxWait: 5000});
editor.on('change', previewUpdater);
function updateQueryParam(key, value) {
if (history.pushState) {
const params = new URLSearchParams(window.location.search);
params.set(key, value);
const newUrl = window.location.origin
+ window.location.pathname
+ '?' + params.toString();
window.history.replaceState({path: newUrl}, '', newUrl);
}
}
jQuery('#code').removeClass('hidden');
jQuery('[data-syntax]').click(function(event) {
event.preventDefault();
syntaxId = jQuery(this).data('syntax-id');
editor.setOption('mode', jQuery(this).data('syntax'));
jQuery('input[name="syntax"]').val(syntaxId);
updateQueryParam('syntax', syntaxId);
previewUpdater(editor);
});
previewUpdater(editor);
});