-
Notifications
You must be signed in to change notification settings - Fork 0
/
email_designer.html
217 lines (176 loc) · 9.45 KB
/
email_designer.html
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email Designer</title>
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800;900&family=Poppins:wght@400;500;600;700;800;900&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="./css/base.css">
<link rel="stylesheet" href="./css/email.css">
<link rel="stylesheet" href="./css/code_editing.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<!-- Include Prism CSS -->
<!-- <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism.min.css" rel="stylesheet" /> -->
<link href="./node_modules/prismjs/themes/prism.css" rel="stylesheet" />
<!-- load jquery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-4">
<!-- controls panel -->
<h1>Control panel.</h1>
<div id="control-panel">
<div class="text-center">
<div class="spinner-border" style="width: 3rem; height: 3rem;" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</div>
</div>
<div class="col-sm">
<!-- design window -->
<h5>Designer.</h5>
<div id="main-body">
<div class="text-center">
<div class="spinner-border" style="width: 3rem; height: 3rem;" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- ./ .container-fluid -->
<script>
// jquery on document ready
$(document).ready(function () {
function editorUpdate(input, language, outputid) {
console.log(`editorUpdate(${input}, ${language}, ${outputid})`); // debug
// Handle final newlines (see article)
if (input[input.length - 1] == "\n") { // If the last character is a newline character
input += " "; // Add a placeholder space character to the final line
}
// Get the HTML code
var htmlCode = input //document.getElementById('html-editing-input').value;
var indentedHtmlCode;
result_element = document.getElementById(outputid);
switch (language) {
case "html":
// Indent and add syntax highlighting
indentedHtmlCode = Prism.highlight(htmlCode, Prism.languages.markup, 'markup');
break;
case "js":
// Indent and add syntax highlighting
indentedHtmlCode = Prism.highlight(htmlCode, Prism.languages.javascript, 'javascript');
break;
default:
// Indent and add syntax highlighting
indentedHtmlCode = Prism.highlight(htmlCode, Prism.languages.markup, 'markup');
break;
}
// Add the indented and highlighted code to the preview container
// result_element.innerHTML = indentedHtmlCode;
result_element.innerHTML = indentedHtmlCode.replace(new RegExp("&", "g"), "&").replace(new RegExp("<", "g"), "<"); /* Global RegExp */
// Syntax Highlight
Prism.highlightElement(result_element);
}
$.compilePrismOutputHTML = function (input) {
console.log('$.compilePrismOutputHTML'); // debug
//*** copilot chat:
// Get the HTML code
var htmlCode = input //document.getElementById('html-output').value;
// Indent and add syntax highlighting
var indentedHtmlCode = Prism.highlight(htmlCode, Prism.languages.markup, 'markup');
// Add the indented and highlighted code to the text editot
document.getElementById('html-output').innerHTML = indentedHtmlCode;
// Add the indented and highlighted code to the text editing container
editorUpdate(htmlCode, "html", "html-editing-highlighting");
}
function sync_scroll(element, target) {
var $element = $(element);
var $target = $(target);
var element_scrollTop = $element.scrollTop();
var target_scrollTop = element_scrollTop / ($element[0].scrollHeight - $element.height()) * ($target[0].scrollHeight - $target.height());
$target.scrollTop(target_scrollTop);
}
// ajax call to get the email template
$.ajax({
url: 'http://localhost:8081/db_form_html_generator/scripts/php/email_designer/get_email_template.php',
type: 'GET',
success: function (data) {
// console.log(data); // debug
console.log("data.length: ", data.length); // debug
// append the main mail body to the main body
$('#main-body').html(data);
$('#control-panel').html(`
<div>
<div style="min-height:100px;">
<h5>Stuff...</h5>
</div>
<div>
<h5>Code.</h5>
<div class="d-grid" style="height: 400px;position: relative;">
<!-- html code editor -->
<pre id="html-editing" class="highlighting" aria-hidden="true">
<code id="html-editing-highlighting" class="language-html"></code>
</pre>
<textarea class="editing" id="html-output" spellcheck="false"></textarea>
<!-- oninput="sync_scroll(this,'#html-editing');"
onscroll="sync_scroll(this,'#html-editing');" -->
<!-- oninput="editorUpdate(this.value);" -->
<!-- ./ html code editor -->
</div>
</div>
</div>
`);
// set #html-editing-highlighting to the width and height of #html-output persistently
$("#html-editing-highlighting").css("width", $("#html-output").css("width"));
$("#html-editing-highlighting").css("height", $("#html-output").css("height"));
// event listener for #html-output on input
$("#html-output").on("input", function () {
// sync scroll
sync_scroll(this, '#html-editing');
});
// event listener for #html-output on scroll
$("#html-output").on("scroll", function () {
// sync scroll
sync_scroll(this, '#html-editing');
});
// event listener for #html-output on keyup
$("#html-output").keyup(function () {
// get the html output
var htmlOutput = $("#html-output").val();
// set the html preview
// $("#html-preview").text(htmlOutput);
// update html text editor inputs content
editorUpdate(htmlOutput, "html", "html-editing-highlighting");
// compile prism
Prism.highlightAll();
// update #design-utput with the html output
// $("#design-output").html(htmlOutput);
});
$.compilePrismOutputHTML(data);
},
error: function (err) {
console.error(err);
}
});
});
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
<!-- Include Prism JS -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/components/prism-markup.min.js"></script> -->
<script src="./node_modules/prismjs/prism.js"></script>
</body>
</html>