-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.html
More file actions
229 lines (174 loc) · 7.57 KB
/
Copy patheditor.html
File metadata and controls
229 lines (174 loc) · 7.57 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>basic HTML editor</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- AlpineJS support -->
<script defer src="https://unpkg.com/alpinejs"></script>
<!-- TailwindCSS -->
<!-- <script src="https://cdn.tailwindcss.com"></script> -->
<script>
// TailwindCSS
// pairs of css selectors and classes to apply
let cssSelectorsClassesPairs = [
// ['button , input[type=button] , input[type=submit]', 'bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded'],
['button , input[type=button] , input[type=submit] , a[href^="javascript:"] ', 'btn btn-blue'],
['.btn', 'font-bold py-2 px-4 rounded'],
['.btn-blue', 'bg-blue-500 text-white'],
//['.btn-blue:hover', 'bg-blue-700'],
['.btn-blue', 'hover:bg-blue-700'],
['.btn-red', 'bg-red-500 text-white hover:bg-red-700'],
['textarea , input[type=text] , input:not([type])', 'border border-gray-300'],
]
// cssSelectorsClassesPairs = [] // disable default pairs
// apply classes to selectors
function cssSelectorsClassesPairApply(pair) {
// add classes to element
function cssAddClasses(element, classes) {
element.classList.add(...classes.split(' '));
}
// apply classes to all elements matching selector
const [selector, classes] = pair;
document.querySelectorAll(selector).forEach(element => cssAddClasses(element, classes));
}
function initCSSPairs(cssPairs) {
// apply all pairs
cssPairs.forEach(pair => cssSelectorsClassesPairApply(pair));
}
function initCSS() {
initCSSPairs(cssSelectorsClassesPairs);
}
function init() {
// initCSS();
}
init();
</script>
<script src="https://unpkg.com/ractive"></script>
<!-- VueJS + PiniaJS -->
<!-- VueJS 3 -->
<script src="https://unpkg.com/vue@3.4.30/dist/vue.global.js"></script>
<!-- PiniaJS 2 -->
<!-- vue-demi required by pinia 2 -->
<!-- <script src="https://unpkg.com/vue-demi@0.14.8/lib/index.iife.js"></script>
<script src="https://unpkg.com/pinia@2.1.7/dist/pinia.iife.js"></script> -->
<!-- BootstrapCSS + BootstrapJS + PopperJS -->
<!-- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"
integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r"
crossorigin="anonymous"></script> -->
</head>
<body>
<script type="text/javascript">
// show sources
function showSources() {
document.getElementById("sources").classList.toggle("hidden");
}
</script>
<style>
.hidden {
display: none;
}
</style>
Editor for DHTML <button type="button" onclick="showSources()">show sources (toggle)</button>
<div id="sources" class="hidden">
<script src="show-source.js" data-href="editor.js"></script>
<button type="button" onclick="showSources()">show sources (toggle)</button>
<script src="show-source.js" data-href="editor.html"></script>
<button type="button" onclick="showSources()">show sources (toggle)</button>
<script src="show-source.js" data-href="editor.css"></script>
<button type="button" onclick="showSources()">show sources (toggle)</button>
</div>
<hr>
<button type="button" onclick="syncContent()">sync</button>
<label><input type="checkbox" id="autoSync" checked="">auto-sync</label>
<button type="button" onclick="location.reload()">reload</button>
<button type="button" onclick="displayToggle(panel_load)">
load …</button>
<script>
function displayToggle(element) {
element.style.display = element.style.display === '' ? 'none' : ''
}
</script>
<div id="panel_load" style="display: none;">
load example:
<button type="button" onclick="loadExampleFromURL('alpine')">Alpine-JS</button>
<button type="button" onclick="loadExampleFromURL('blank')">blank</button>
<button type="button" onclick="loadExampleFromURL('counters')">counters</button>
<button type="button" onclick="loadExampleFromURL('markdown')">markdown</button>
<button type="button" onclick="loadExampleFromURL('vue')">Vue-JS</button>
<button type="button" onclick="loadExampleFromURL('ractive')">Ractive-JS</button>
<button type="button" onclick="loadExampleFromURL('ht-persist')">HT-Persist</button>
<button type="button" onclick="loadExampleFromURL('tailwind')">Tailwind-CSS</button>
</div>
<hr>
<div id="page"></div>
<hr>
<pre id="html_console" contenteditable="" class="html_console border"></pre>
<button type="button" onclick="html_console.innerHTML = ''">clear console</button>
<script>
function html_write(html) {
html_console.innerHTML += html
}
function html_write_line(html) {
html_write(html + "\n")
}
</script>
<hr>
<div class="relative">
<div id="editor" class="border" spellcheck="false" translate="no"></div>
<textarea id="textarea" class="border" spellcheck="false" translate="no" title="textarea for html code editor"
placeholder="write some HTML code here"></textarea>
</div>
<script>
function bind() {
// Get computed styles for accurate measurements
const textareaStyles = getComputedStyle(textarea);
// Copy exact dimensions
editor.style.width = textareaStyles.width;
editor.style.height = textareaStyles.height;
// Sync scrolling
editor.scrollTop = textarea.scrollTop;
editor.scrollLeft = textarea.scrollLeft;
}
// Use requestAnimationFrame instead of setInterval for better performance
function startSyncing() {
function sync() {
bind();
requestAnimationFrame(sync);
}
requestAnimationFrame(sync);
}
// Start the syncing
startSyncing();
</script>
<script src="code-decorations.js"></script>
<script src="editor.js"></script>
<link rel="stylesheet" href="editor.css">
<link rel="stylesheet" href="code-decorations.css">
<script>
// save & restore
// [vue] save and restore vue.$data
function save() {
saved_data = {}
if (typeof vue != "undefined") {
for (const name of Object.keys(vue.$data)) {
saved_data[name] = vue.$data[name]
}
}
} // end of: save()
function restore() {
if (typeof vue != "undefined") {
for (const name of Object.keys(saved_data)) {
vue.$data[name] = saved_data[name]
}
}
} // end of: restore()
// end of: save & restore
</script>
</body>
</html>