@@ -65,10 +65,12 @@ $themeList = $helperData->getThemes();
65
65
preElm.style.top = codeInputElm.offsetTop+'px';
66
66
preElm.style.left = codeInputElm.offsetLeft+'px';
67
67
preElm.style.height = codeInputElm.offsetHeight+'px';
68
- preElm.style.width = codeInputElm.offsetWidth+'px';
68
+ preElm.style.width = (codeInputElm.offsetWidth+15)+'px';
69
+ preElm.style.resize = 'both';
69
70
70
71
parentElm.appendChild(preElm);
71
72
updateSyntax(textArea);
73
+ updateTheme();
72
74
73
75
textArea.addEventListener('scroll', function() {
74
76
syncScroll(textArea);
@@ -84,13 +86,61 @@ $themeList = $helperData->getThemes();
84
86
syncScroll(textArea);
85
87
});
86
88
87
- textArea.addEventListener('mousemove', function () {
89
+ textArea.addEventListener('mousemove', function() {
88
90
hoverBraces(textArea, event);
89
91
});
90
92
91
- textArea.addEventListener('click', function () {
93
+ textArea.addEventListener('click', function() {
92
94
hoverBraces(textArea, event);
93
95
});
96
+
97
+ //resize function
98
+ let isResize = 0;
99
+ preElm.addEventListener('mousedown', function() {
100
+ if (event.which !== 1) {
101
+ return;
102
+ }
103
+
104
+ let elementPosition = preElm.getBoundingClientRect();
105
+ let elementX = elementPosition.width + elementPosition.left;
106
+ let elementY = elementPosition.height + elementPosition.top;
107
+
108
+ let currentPointX = event.x;
109
+ let currentPointY = event.y;
110
+
111
+ if ((elementX-16 <= currentPointX)
112
+ && (currentPointX <= elementX)
113
+ && (elementY-16 <= currentPointY)
114
+ && (currentPointY <= elementY)
115
+ ) {
116
+ textArea.style.display = 'none';
117
+ isResize = 1;
118
+ }
119
+ });
120
+
121
+ window.addEventListener('mousemove', function() {
122
+ if (!isResize) {
123
+ return;
124
+ }
125
+
126
+ codeInputElm.style.width = (preElm.offsetWidth - 15)+'px';
127
+ codeInputElm.style.height = preElm.offsetHeight+'px';
128
+ textArea.style.width = preElm.offsetWidth+'px';
129
+ textArea.style.height = preElm.offsetHeight+'px';
130
+ });
131
+
132
+ preElm.addEventListener('mouseup', function() {
133
+ if (!isResize) {
134
+ return;
135
+ }
136
+
137
+ isResize = 0;
138
+ textArea.style.display = 'block';
139
+ codeInputElm.style.width = (preElm.offsetWidth - 15)+'px';
140
+ codeInputElm.style.height = preElm.offsetHeight+'px';
141
+ textArea.style.width = preElm.offsetWidth+'px';
142
+ textArea.style.height = preElm.offsetHeight+'px';
143
+ });
94
144
}
95
145
96
146
function updateSyntax(element) {
@@ -106,8 +156,6 @@ $themeList = $helperData->getThemes();
106
156
return;
107
157
}
108
158
109
- this.updateTheme();
110
-
111
159
let codes = preElement.getElementsByTagName('code');
112
160
if (codes.length) {
113
161
let result_element = codes[0];
@@ -120,20 +168,10 @@ $themeList = $helperData->getThemes();
120
168
}
121
169
}
122
170
123
- function updateTheme() {
124
- let theme = window.syntaxHighlighter.theme;
125
- let links = document.querySelectorAll('link');
126
- for (let i = 0; i < links.length; i++) {
127
- let link = links[i];
128
- let href = link.href;
129
- if (href.includes('Jajuma_SyntaxHighlighter/css/themes/')) {
130
- let hrefArr = href.split('/');
131
- let currentTheme = hrefArr[hrefArr.length - 1];
132
- let newTheme = theme + '.css';
133
- link.href = href.replace('/css/themes/' + currentTheme, '/css/themes/' + newTheme);
134
- return;
135
- }
136
- }
171
+ function updateSyntaxOnChange(element)
172
+ {
173
+ updateSyntax(element);
174
+ syncScroll(element);
137
175
}
138
176
139
177
function syncScroll(element) {
@@ -146,9 +184,12 @@ $themeList = $helperData->getThemes();
146
184
if (preElement.classList.contains('jajuma-syntax-highlighter-highlighting') === false) {
147
185
return;
148
186
}
149
- let result_element = preElement;
150
- result_element.scrollTop = element.scrollTop;
151
- result_element.scrollLeft = element.scrollLeft;
187
+
188
+ if (preElement.scrollHeight <= preElement.clientHeight) {
189
+ element.style.width = (preElement.offsetWidth - 15)+'px';
190
+ }
191
+ preElement.scrollTop = element.scrollTop;
192
+ preElement.scrollLeft = element.scrollLeft;
152
193
}
153
194
154
195
function checkTab(element, event) {
@@ -206,45 +247,6 @@ $themeList = $helperData->getThemes();
206
247
updateSyntax(input_element);
207
248
}
208
249
209
- function changeTheme(element) {
210
- let theme = element.value;
211
- let links = document.querySelectorAll('link');
212
- for (let i = 0; i < links.length; i++) {
213
- let link = links[i];
214
- let href = link.href;
215
- if (href.includes('Jajuma_SyntaxHighlighter/css/themes/')) {
216
- let hrefArr = href.split('/');
217
- let currentTheme = hrefArr[hrefArr.length - 1];
218
- let newTheme = theme + '.css';
219
- link.href = href.replace('/css/themes/' + currentTheme, '/css/themes/' + newTheme);
220
- return;
221
- }
222
- }
223
- }
224
-
225
- function addPlugin(element, plugin) {
226
- let toolbarElement = element.parentElement.parentElement;
227
- let nextElement = toolbarElement.nextElementSibling;
228
- if (nextElement.classList.contains('jajuma-highlight-editor') === false) {
229
- return;
230
- }
231
-
232
- let parentElm = nextElement.parentElement;
233
- let preElement = parentElm.querySelector('pre');
234
- if (!preElement) {
235
- return;
236
- }
237
-
238
- if (element.checked === false) {
239
- preElement.classList.remove(plugin);
240
- } else {
241
- if (preElement.classList.contains(plugin)) {
242
- return;
243
- }
244
- preElement.classList.add(plugin);
245
- }
246
- }
247
-
248
250
var curElem = null;
249
251
function hoverBraces(element, event) {
250
252
let x, y;
@@ -297,6 +299,61 @@ $themeList = $helperData->getThemes();
297
299
element.dispatchEvent(event);
298
300
}
299
301
302
+ function updateTheme() {
303
+ let theme = window.syntaxHighlighter.theme;
304
+ let links = document.querySelectorAll('link');
305
+ for (let i = 0; i < links.length; i++) {
306
+ let link = links[i];
307
+ let href = link.href;
308
+ if (href.includes('Jajuma_SyntaxHighlighter/css/themes/')) {
309
+ let hrefArr = href.split('/');
310
+ let currentTheme = hrefArr[hrefArr.length - 1];
311
+ let newTheme = theme + '.css';
312
+ link.href = href.replace('/css/themes/' + currentTheme, '/css/themes/' + newTheme);
313
+ return;
314
+ }
315
+ }
316
+ }
317
+
318
+ function addPlugin(element, plugin) {
319
+ let toolbarElement = element.parentElement.parentElement;
320
+ let nextElement = toolbarElement.nextElementSibling;
321
+ if (nextElement.classList.contains('jajuma-highlight-editor') === false) {
322
+ return;
323
+ }
324
+
325
+ let parentElm = nextElement.parentElement;
326
+ let preElement = parentElm.querySelector('pre');
327
+ if (!preElement) {
328
+ return;
329
+ }
330
+
331
+ if (element.checked === false) {
332
+ preElement.classList.remove(plugin);
333
+ } else {
334
+ if (preElement.classList.contains(plugin)) {
335
+ return;
336
+ }
337
+ preElement.classList.add(plugin);
338
+ }
339
+ }
340
+
341
+ function changeTheme(element) {
342
+ let theme = element.value;
343
+ let links = document.querySelectorAll('link');
344
+ for (let i = 0; i < links.length; i++) {
345
+ let link = links[i];
346
+ let href = link.href;
347
+ if (href.includes('Jajuma_SyntaxHighlighter/css/themes/')) {
348
+ let hrefArr = href.split('/');
349
+ let currentTheme = hrefArr[hrefArr.length - 1];
350
+ let newTheme = theme + '.css';
351
+ link.href = href.replace('/css/themes/' + currentTheme, '/css/themes/' + newTheme);
352
+ return;
353
+ }
354
+ }
355
+ }
356
+
300
357
window.openThemeListModal = () => {
301
358
require([
302
359
"jquery",
0 commit comments