-
Notifications
You must be signed in to change notification settings - Fork 24
/
edit.tpl
executable file
·98 lines (94 loc) · 3.92 KB
/
edit.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{*
* Copyright (c) 2004-2019 OIC Group, Inc.
*
* This file is part of Exponent
*
* Exponent is free software; you can redistribute
* it and/or modify it under the terms of the GNU
* General Public License as published by the Free
* Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* GPL: http://www.gnu.org/licenses/gpl.txt
*
*}
<div class="module text edit">
{if $record->id != ""}
<h1>{'Editing'|gettext}: {$record->title}</h1>
{else}
<h1>{'New Code Snippet'|gettext}</h1>
{/if}
{form action=update}
{control type=hidden name=id value=$record->id}
{control type=hidden name=rank value=$record->rank}
{control type=text name=title label="Title"|gettext value=$record->title focus=1}
{control type=textarea cols="80" rows=20 id=body name=body label="Code Snippet"|gettext value=$record->body}
{control type=buttongroup submit="Save Text"|gettext cancel="Cancel"|gettext}
{/form}
</div>
{if $smarty.const.SITE_CODE_EDITOR == 'ace'}
{script unique='aceeditor' jquery=1 src='https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.3/ace.js'}
{literal}
// Hook up ACE editor to all textareas with data-editor attribute
$(function () {
$('textarea').each(function () {
var textarea = $(this);
var editDiv = $('<div>', {
position: 'absolute',
width: textarea.width(),
height: textarea.height(),
'class': textarea.attr('class')
}).insertBefore(textarea);
textarea.css('display', 'none');
var editor = ace.edit(editDiv[0]);
editor.getSession().setValue(textarea.val());
editor.setTheme("ace/theme/{/literal}{$smarty.const.SITE_CODE_EDITOR_THEME}{literal}");
editor.getSession().setMode("ace/mode/javascript");
editor.setOptions({
maxLines: 20,
minLines: 20,
autoScrollEditorIntoView: true,
useWorker: false
});
editor.setFontSize(14);
// copy back to textarea on form submit...
textarea.closest('form').submit(function () {
textarea.val(editor.getSession().getValue());
})
});
});
{/literal}
{/script}
{elseif $smarty.const.SITE_CODE_EDITOR == 'codemirror'}
{css unique="snippet-codemirror"}
.CodeMirror {
line-height: 1.2em;
height: 24.4em!important;
}
{/css}
{literal}
{/literal}{$cdn = 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.45.0/'}{literal}
<script src="{/literal}{$cdn}{literal}codemirror.js"></script>
<link rel="stylesheet" href="{/literal}{$cdn}{literal}codemirror.css">
<link rel="stylesheet" href="{/literal}{$cdn}{literal}addon/fold/foldgutter.css">
<link rel="stylesheet" href="{/literal}{$cdn}{literal}theme/{/literal}{$smarty.const.SITE_CODE_EDITOR_THEME}{literal}.css">
<script src="{/literal}{$cdn}{literal}addon/selection/active-line.js"></script>
<script src="{/literal}{$cdn}{literal}addon/edit/matchbrackets.js"></script>
<script src="{/literal}{$cdn}{literal}addon/fold/foldcode.js"></script>
<script src="{/literal}{$cdn}{literal}addon/fold/foldgutter.js"></script>
<script src="{/literal}{$cdn}{literal}addon/fold/brace-fold.js"></script>
<script src="{/literal}{$cdn}{literal}addon/fold/comment-fold.js"></script>
<script src="{/literal}{$cdn}{literal}mode/javascript/javascript.js"></script>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("body"), {
lineNumbers: true,
theme: "{/literal}{$smarty.const.SITE_CODE_EDITOR_THEME}{literal}",
mode: "javascript",
// lineWrapping: true,
styleActiveLine: true,
foldGutter: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
});
</script>
{/literal}
{/if}