Debian Codegraph @

src/flask_debugtoolbar/templates/panels/template_editor.html

raw
1 <!doctype html>
2 <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
3 <head>
4 <base href="{{ request.path }}">
5 <meta charset="utf-8">
6 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
7 <meta http-equiv="Pragma" content="no-cache">
8 <meta name="description" content="{% block meta_description %}Description{% endblock %}">
9 <meta name="author" content="{% block meta_author %}Author{% endblock %}">
10 <meta name="viewport" content="width=device-width,initial-scale=1">
11 <title>Editing {{ templates[0].name }}</title>
12 <script src="{{ static_path }}js/jquery.js"></script>
13 <!-- Temporarily adding jquery-migrate during the Jquery upgrade process, this can be removed post-upgrade -->
14 <script src="{{ static_path }}js/jquery-migrate.js"></script>
15 <link rel="stylesheet" href="{{ static_path }}codemirror/codemirror.css">
16 <link rel="stylesheet" href="{{ static_path }}codemirror/theme/rubyblue.css">
17 <link rel="stylesheet" href="{{ static_path }}codemirror/theme/lesser-dark.css">
18 <style>
19 {% with %}
20 {% set toolbar_height = 25 %}
21 {% set editor_width = request.cookies.get('fldt_editor_size')|int(40) %}
22
23 #flDebugPanel, #flDebugEditor, #flDebugPreview, #flDebugSplitter, #flDebugToolbar {
24 box-sizing: border-box;
25 -moz-box-sizing: border-box;
26 -ms-box-sizing: border-box;
27 border: none;
28 }
29 #flDebugPanel, #flDebugPreview { position: fixed; }
30 #flDebugPanel > div { position: absolute; }
31
32 #flDebugPanel { width: {{ editor_width }}%; height: 100%; top: 0; left: 0; bottom: 0; }
33 #flDebugToolbar { top: 0; width: 100%; height: {{ toolbar_height }}px; border-bottom: 1px solid black; padding: 2px 4px; }
34 #flDebugEditor { top: {{ toolbar_height }}px; bottom: 0; width: 100%; }
35 #flDebugPreview { top: 0; bottom: 0; right: 0; height: 100%; width: {{ 100 - editor_width }}%; }
36
37 /* need a dummy element over the page so that drag events don't get captured by the preview iframe */
38 #flDebugDragHandler { display: none; position: fixed; width: 100%; height: 100%; z-index: 1000; }
39 #flDebugSplitter { width: 8px; height: 100%; top: 0; bottom: 0; right: -1px; z-index: 999; cursor: e-resize; border-right: 1px solid black; }
40
41 .CodeMirror, .CodeMirror-scroll { height: 100%; }
42 .syntax-error { background: red !important; }
43
44 #flDebugToolbar button { margin: 0; }
45 #flDebugSave { float: left; }
46 #flDebugClose { float: right; }
47 {% endwith %}
48 </style>
49 </head>
50 <body>
51 <div id="flDebugDragHandler"></div>
52 <div id="flDebugPanel">
53 <div id="flDebugToolbar">
54 <button id="flDebugSave">Save</button>
55 <button id="flDebugClose">Close</button>
56 </div>
57 <div id="flDebugEditor">
58 <textarea name="{{ templates[0].name }}" id="code">{{ templates[0].source }}</textarea>
59 </div>
60 <div id="flDebugSplitter"></div>
61 </div>
62 <iframe id="flDebugPreview"></iframe>
63
64 <script src="{{ static_path }}codemirror/codemirror.js"></script>
65 <script src="{{ static_path }}codemirror/util/closetag.js"></script>
66 <script src="{{ static_path }}codemirror/util/overlay.js"></script>
67 <script src="{{ static_path }}codemirror/mode/xml/xml.js"></script>
68 <script src="{{ static_path }}codemirror/mode/javascript/javascript.js"></script>
69 <script src="{{ static_path }}codemirror/mode/css/css.js"></script>
70 <script src="{{ static_path }}codemirror/mode/htmlmixed/htmlmixed.js"></script>
71 <script src="{{ static_path }}codemirror/mode/jinja2/jinja2.js"></script>
72 <script>{% raw %}
73 $('#flDebugDragHandler')
74 .mousemove(function(e) {
75 var size = 100 * e.pageX / $(document).width();
76 $('#flDebugPanel').css('width', size + '%');
77 $('#flDebugPreview').css('width', (100 - size) + '%');
78 return false;
79 })
80 .mouseup(function(e) {
81 $(this).hide();
82 var size = Math.round(100 * e.pageX / $(document).width());
83 document.cookie = 'fldt_editor_size=' + size;
84 return false;
85 });
86
87 $('#flDebugSplitter').mousedown(function() {
88 $('#flDebugDragHandler').show();
89 return false;
90 });
91
92 $('#flDebugSave').click(function() {
93 $.ajax({
94 type: 'POST'
95 , url: document.baseURI + '/save'
96 , data: {content: editor.getValue()}
97 });
98 });
99
100 $('#flDebugClose').click(function() {
101 document.location = document.location;
102 });
103
104 CodeMirror.defineMode("html+jinja2", function(config, parserConf) {
105 return CodeMirror.overlayParser(CodeMirror.getMode(config, "htmlmixed"), CodeMirror.getMode(config, 'jinja2'));
106 });
107 CodeMirror.defineMIME("text/html", "html+jinja2");
108
109 var delay;
110 // Initialize CodeMirror editor with a nice html5 canvas demo.
111 var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
112 mode: 'text/html'
113 , theme: 'rubyblue'
114 , lineNumbers: true
115 , tabMode: 'indent'
116 , onChange: function() {
117 clearTimeout(delay);
118 delay = setTimeout(updatePreview, 300);
119 }
120 });
121
122 var previewFrame = document.getElementById('flDebugPreview');
123 var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
124 var errorLine = null;
125
126 function updatePreview() {
127 $.ajax({
128 type: 'POST'
129 , url: ''
130 , data: {content: editor.getValue()}
131 , success: function(data, status, xhr) {
132 if (errorLine != null) {
133 editor.setLineClass(errorLine, null, null);
134 }
135 preview.open();
136 preview.write(xhr.responseText);
137 preview.close();
138 $('head', preview).append('<base target="_top">');
139 }
140 , error: function(xhr, status, error) {
141 if (status === 'error') {
142 var data = JSON.parse(xhr.responseText);
143 console.log(data);
144 if (errorLine != null) {
145 editor.setLineClass(errorLine, null, null);
146 }
147 errorLine = editor.setLineClass(data.lineno - 1, null, 'syntax-error');
148 }
149 }
150 });
151 }
152
153 setTimeout(updatePreview, 300);
154 {% endraw %}</script>
155 </body>
156 </html>