You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.2 KiB
36 lines
1.2 KiB
extends ./template
|
|
block content
|
|
if errors
|
|
each error in errors
|
|
p(style='color: red; font-weight: bold;') #{error}
|
|
if (!readonly)
|
|
form#snippet_form(method='post' enctype='multipart/form-data')
|
|
label(for='snippet_name') Snippet Title:
|
|
input#snippet_name(type='text' name='title' autofocus required)
|
|
input#snippet_value(type='hidden' name='data' required)
|
|
pre#editor #{ snippet ? snippet.data : '' }
|
|
if (!readonly)
|
|
button(onclick='submitSnippet()') #{ snippet ? 'Update Snippet' : 'Create Snippet' }
|
|
|
|
block scripts
|
|
script(src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.5/ace.js")
|
|
script.
|
|
const editor = ace.edit('editor');
|
|
editor.setTheme('ace/theme/cobalt');
|
|
//- editor.session.setMode('ace/mode/javascript');
|
|
|
|
function trim(s){
|
|
return ( s || '' ).replace( /^\s+|\s+$/g, '' );
|
|
}
|
|
|
|
function submitSnippet(){
|
|
const form = document.getElementById('snippet_form');
|
|
const value = document.getElementById('snippet_value');
|
|
const name = document.getElementById('snippet_name');
|
|
value.value = editor.getValue();
|
|
|
|
if ( trim(value.value) && trim(name.value) ) form.submit();
|
|
}
|
|
if readonly
|
|
script.
|
|
editor.setOption('readOnly', true) |