|
1 | 1 | import ContentSEOAnalyzer from './seo-analyzer.js'
|
| 2 | + |
2 | 3 | let timeOut = null;
|
3 | 4 | window.addEventListener('load', function () {
|
4 | 5 |
|
5 |
| - let keywordInput = document.querySelector('#keyword') ; |
6 |
| - let dirx = document.querySelector('#panel-dir').value; |
7 |
| - let editors = {}; |
8 |
| - document.querySelectorAll('.ckeditorx')?.forEach(function (el) { |
9 |
| - |
10 |
| - const currentDir = el.getAttribute('dir'); |
11 |
| - let finalDir = dirx; |
12 |
| - if (currentDir != null){ |
13 |
| - finalDir = currentDir; |
14 |
| - } |
15 |
| - editors[el.getAttribute('name')] = CKEDITOR.replace(el.getAttribute('name'), { |
16 |
| - filebrowserUploadUrl: xupload, |
17 |
| - filebrowserUploadMethod: 'form', |
18 |
| - contentsLangDirection: finalDir, |
19 |
| - skin: 'moono-dark', |
20 |
| - }); |
21 |
| - |
| 6 | + try { |
22 | 7 |
|
23 |
| - CKEDITOR.addCss('.cke_editable { background-color: ' + website_bg + '; color: ' + website_text_color + ' ; font-family: ' + website_font + ' }'); |
24 |
| - editors[el.getAttribute('name')].on('change', function (evt) { |
25 |
| - const content = evt.editor.getData(); |
26 |
| - el.value = content; |
27 |
| - if (el.classList.contains('seo-analyze')){ |
28 |
| - let keyword = keywordInput?.value; |
| 8 | + let keywordInput = document.querySelector('#keyword'); |
| 9 | + let dirx = document.querySelector('#panel-dir').value; |
| 10 | + let editors = {}; |
| 11 | + document.querySelectorAll('.ckeditorx')?.forEach(function (el) { |
29 | 12 |
|
30 |
| - const analyzer = new ContentSEOAnalyzer(content, keyword); |
31 |
| - const report = analyzer.generateReport(); |
32 |
| - analyzer.displaySEOReport(report,'seo-hint') |
| 13 | + const currentDir = el.getAttribute('dir'); |
| 14 | + let finalDir = dirx; |
| 15 | + if (currentDir != null) { |
| 16 | + finalDir = currentDir; |
33 | 17 | }
|
34 |
| - }); |
| 18 | + editors[el.getAttribute('name')] = CKEDITOR.replace(el.getAttribute('name'), { |
| 19 | + filebrowserUploadUrl: xupload, |
| 20 | + filebrowserUploadMethod: 'form', |
| 21 | + contentsLangDirection: finalDir, |
| 22 | + skin: 'moono-dark', |
| 23 | + }); |
35 | 24 |
|
36 | 25 |
|
37 |
| - if (el.classList.contains('seo-analyze')){ |
38 |
| - editors[el.getAttribute('name')].fire('change'); |
39 |
| - keywordInput?.addEventListener('input',function () { |
40 |
| - editors[el.getAttribute('name')].fire('change'); |
| 26 | + CKEDITOR.addCss('.cke_editable { background-color: ' + website_bg + '; color: ' + website_text_color + ' ; font-family: ' + website_font + ' }'); |
| 27 | + editors[el.getAttribute('name')].on('change', function (evt) { |
| 28 | + const content = evt.editor.getData(); |
| 29 | + el.value = content; |
| 30 | + if (el.classList.contains('seo-analyze')) { |
| 31 | + let keyword = keywordInput?.value; |
| 32 | + |
| 33 | + const analyzer = new ContentSEOAnalyzer(content, keyword); |
| 34 | + const report = analyzer.generateReport(); |
| 35 | + analyzer.displaySEOReport(report, 'seo-hint') |
| 36 | + } |
41 | 37 | });
|
42 |
| - } |
43 | 38 |
|
44 |
| - }); |
| 39 | + |
| 40 | + if (el.classList.contains('seo-analyze')) { |
| 41 | + editors[el.getAttribute('name')].fire('change'); |
| 42 | + keywordInput?.addEventListener('input', function () { |
| 43 | + editors[el.getAttribute('name')].fire('change'); |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + }); |
| 48 | + |
| 49 | + } catch { |
| 50 | + } |
45 | 51 | });
|
0 commit comments