Skip to content

Commit 3a890de

Browse files
new feature: Getting the current language
1 parent 5bdcc6b commit 3a890de

16 files changed

+48
-42
lines changed

browser/js/code_editor.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const CopyCode = {
7777
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
7878
</svg>
7979
</div>
80-
`,
80+
`
8181
};
8282

8383
// Dropdown
@@ -159,14 +159,14 @@ const Dropdown = {
159159
<slot></slot>
160160
</div>
161161
</transition>
162-
</div>`,
162+
</div>`
163163
};
164164

165165
// CodeEditor
166166
const CodeEditor = {
167167
components: {
168-
"copy-code": CopyCode,
169-
dropdown: Dropdown,
168+
'copy-code': CopyCode,
169+
'dropdown': Dropdown
170170
},
171171
props: {
172172
modelValue: {
@@ -266,31 +266,31 @@ const CodeEditor = {
266266
highlight: {
267267
//vue2
268268
bind(el, binding) {
269-
el.textContent = binding.value;
270-
hljs.highlightElement(el);
269+
el.textContent = binding.value
270+
hljs.highlightElement(el)
271271
},
272272
componentUpdated(el, binding) {
273-
el.textContent = binding.value;
274-
hljs.highlightElement(el);
273+
el.textContent = binding.value
274+
hljs.highlightElement(el)
275275
},
276276
//vue3
277277
created(el, binding) {
278-
el.textContent = binding.value;
279-
hljs.highlightElement(el);
278+
el.textContent = binding.value
279+
hljs.highlightElement(el)
280280
},
281281
updated(el, binding) {
282-
el.textContent = binding.value;
283-
hljs.highlightElement(el);
284-
},
285-
},
282+
el.textContent = binding.value
283+
hljs.highlightElement(el)
284+
}
285+
}
286286
},
287287
data() {
288288
return {
289289
containerWidth: 0,
290290
staticValue: this.value,
291291
top: 0,
292292
left: 0,
293-
languageClass: "hljs language-" + this.languages[0][0],
293+
languageClass: 'hljs language-' + this.languages[0][0],
294294
mark:
295295
this.languages[0][1] === undefined
296296
? this.languages[0][0]
@@ -302,16 +302,14 @@ const CodeEditor = {
302302
},
303303
watch: {
304304
value(value) {
305-
this.staticValue = value;
306-
},
305+
this.staticValue = value
306+
}
307307
},
308308
computed: {
309309
contentValue() {
310-
return this.read_only
311-
? this.value
312-
: this.modelValue === undefined
313-
? this.staticValue + "\n"
314-
: this.modelValue + "\n";
310+
return this.read_only ?
311+
this.value : this.modelValue === undefined ?
312+
this.staticValue + '\n' : this.modelValue + '\n'
315313
},
316314
canScroll() {
317315
return this.height == "auto" ? false : true;
@@ -329,7 +327,8 @@ const CodeEditor = {
329327
methods: {
330328
changeLang(lang) {
331329
this.mark = lang[1] === undefined ? lang[0] : lang[1];
332-
this.languageClass = "language-" + lang[0];
330+
this.languageClass = 'language-' + lang[0];
331+
this.$emit('lang', lang[0]);
333332
},
334333
calcContainerWidth(event) {
335334
// calculating the textarea's width while typing for syncing the width between textarea and highlight area
@@ -344,27 +343,28 @@ const CodeEditor = {
344343
},
345344
resize() {
346345
// listen to the change of the textarea's width to resize the highlight area
347-
const resize = new ResizeObserver((entries) => {
346+
const resize = new ResizeObserver(entries => {
348347
for (let entry of entries) {
349348
const obj = entry.contentRect;
350-
this.containerWidth = obj.width + 40; // 40 is the padding
349+
this.containerWidth = obj.width + 40 // 40 is the padding
351350
}
352351
});
353352
// only the textarea is rendered the listener will run
354353
if (this.$refs.textarea) {
355354
resize.observe(this.$refs.textarea);
356355
}
357-
},
356+
}
358357
},
359358
mounted() {
359+
this.$emit('lang', lang[0]);
360360
this.$nextTick(function () {
361361
this.content =
362362
this.modelValue === undefined ? this.staticValue : this.modelValue;
363363
});
364-
this.resize();
364+
this.resize()
365365
},
366366
updated() {
367-
this.$emit("input", this.staticValue);
367+
this.$emit('input', this.staticValue)
368368
this.$nextTick(function () {
369369
this.content =
370370
this.modelValue === undefined ? this.staticValue : this.modelValue;
@@ -466,5 +466,5 @@ const CodeEditor = {
466466
</pre>
467467
</div>
468468
</div>
469-
`,
470-
};
469+
`
470+
}

browser/js/dist/code_editor.prod.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"><link rel="icon" href="/favicon.ico"><title>simple-code-editor-website</title><link href="/css/app.aa120c08.css" rel="preload" as="style"><link href="/js/app.21049e79.js" rel="preload" as="script"><link href="/js/chunk-vendors.0d6d9bd9.js" rel="preload" as="script"><link href="/css/app.aa120c08.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but simple-code-editor-website doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.0d6d9bd9.js"></script><script src="/js/app.21049e79.js"></script></body></html>
1+
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"><link rel="icon" href="/favicon.ico"><title>simple-code-editor-website</title><link href="/css/app.4a63a2ad.css" rel="preload" as="style"><link href="/js/app.829be612.js" rel="preload" as="script"><link href="/js/chunk-vendors.27c4acf8.js" rel="preload" as="script"><link href="/css/app.4a63a2ad.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but simple-code-editor-website doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.27c4acf8.js"></script><script src="/js/app.829be612.js"></script></body></html>

dist/js/app.21049e79.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

dist/js/app.21049e79.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/js/app.829be612.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/app.829be612.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/chunk-vendors.0d6d9bd9.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

dist/js/chunk-vendors.0d6d9bd9.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)