From 0b417127a9a18c7e2c88e492996471bd5bc4c788 Mon Sep 17 00:00:00 2001 From: zwx1126739 Date: Tue, 15 Oct 2024 09:14:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E5=BF=98=E5=BD=95=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zwx1126739 --- .../src/main/resources/rawfile/rich_editor.js | 109 +++++++++--------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/common/resources/src/main/resources/rawfile/rich_editor.js b/common/resources/src/main/resources/rawfile/rich_editor.js index 9f803fb..5bb655f 100644 --- a/common/resources/src/main/resources/rawfile/rich_editor.js +++ b/common/resources/src/main/resources/rawfile/rich_editor.js @@ -13,7 +13,7 @@ * limitations under the License. */ -var RICH_EDITOR = {}; +let RICH_EDITOR = {}; let storage = window.localStorage; RICH_EDITOR.editor = document.getElementById('editorjs_box'); @@ -22,7 +22,7 @@ RICH_EDITOR.setHtml = function (contents) { if (contents) { RICH_EDITOR.editor.style.paddingLeft = paddingLeft + 'px'; } - var base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/; + let base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/; if (base64regex.test(contents)) { RICH_EDITOR.editor.innerHTML = decodeURIComponent(escape(atob(contents))); } else { @@ -67,18 +67,18 @@ RICH_EDITOR.setUnderline = function () { }; RICH_EDITOR.getListStyle = function () { - var selection; - var type; + let selection; + let type; if (window.getSelection) { selection = getSelection(); } if (!selection) { return; } - var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange(); + let range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange(); try { - var child = range.commonAncestorContainer; - for (var i = 0; i < 10; i++) { + let child = range.commonAncestorContainer; + for (let i = 0; i < 10; i++) { if (child.nodeName === 'OL') { console.info('insertOrderedList'); document.execCommand('insertOrderedList', false, null); @@ -107,18 +107,18 @@ RICH_EDITOR.setNumbers = function () { let fontSize = document.queryCommandValue('fontSize'); document.execCommand('insertOrderedList', false, null); document.execCommand('fontSize', false, fontSize); - var selection; - var type; + let selection; + let type; if (window.getSelection) { selection = getSelection(); } if (!selection) { return; } - var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange(); + let range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange(); try { - var child = range.commonAncestorContainer; - for (var i = 0; i < 10; i++) { + let child = range.commonAncestorContainer; + for (let i = 0; i < 10; i++) { if (child.nodeName === 'OL') { child.style['list-style'] = 'decimal'; break; @@ -140,18 +140,18 @@ RICH_EDITOR.setABC = function () { let fontSize = document.queryCommandValue('fontSize'); document.execCommand('insertOrderedList', false, null); document.execCommand('fontSize', false, fontSize); - var selection; - var type; + let selection; + let type; if (window.getSelection) { selection = getSelection(); } if (!selection) { return; } - var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange(); + let range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange(); try { - var child = range.commonAncestorContainer; - for (var i = 0; i < 10; i++) { + let child = range.commonAncestorContainer; + for (let i = 0; i < 10; i++) { if (child.nodeName === 'OL') { child.style['list-style'] = 'lower-alpha'; break; @@ -173,18 +173,18 @@ RICH_EDITOR.setBullets = function () { let fontSize = document.queryCommandValue('fontSize'); document.execCommand('insertUnorderedList', false, null); document.execCommand('fontSize', false, fontSize); - var selection; - var type; + let selection; + let type; if (window.getSelection) { selection = getSelection(); } if (!selection) { return; } - var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange(); + let range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange(); try { - var child = range.commonAncestorContainer; - for (var i = 0; i < 10; i++) { + let child = range.commonAncestorContainer; + for (let i = 0; i < 10; i++) { if (child.nodeName === 'UL') { child.style['list-style'] = 'disc'; break; @@ -206,18 +206,18 @@ RICH_EDITOR.setSquare = function () { let fontSize = document.queryCommandValue('fontSize'); document.execCommand('insertUnorderedList', false, null); document.execCommand('fontSize', false, fontSize); - var selection; - var type; + let selection; + let type; if (window.getSelection) { selection = getSelection(); } if (!selection) { return; } - var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange(); + let range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange(); try { - var child = range.commonAncestorContainer; - for (var i = 0; i < 10; i++) { + let child = range.commonAncestorContainer; + for (let i = 0; i < 10; i++) { if (child.nodeName === 'UL') { child.style['list-style'] = 'square'; break; @@ -253,9 +253,9 @@ RICH_EDITOR.execFontSize = function (size, unit) { } }; -var pad = 24; +let pad = 24; RICH_EDITOR.setIndent = function () { - var parents = document.getElementById('editorjs_box'); + let parents = document.getElementById('editorjs_box'); parents.removeAttribute('padding-left'); if (pad >= 408) { return; @@ -269,7 +269,7 @@ RICH_EDITOR.setIndent = function () { }; RICH_EDITOR.setOutdent = function () { - var parents = document.getElementById('editorjs_box'); + let parents = document.getElementById('editorjs_box'); parents.removeAttribute('padding-left'); if (pad === 24) { parents.style.paddingLeft = 24 + 'px'; @@ -306,7 +306,7 @@ RICH_EDITOR.setJustifyRight = function () { }; RICH_EDITOR.insertImage = function (url) { - var html = '

picvision

'; document.getElementById('editorjs_box').innerHTML += html; @@ -318,15 +318,15 @@ RICH_EDITOR.insertHTML = function (html) { }; RICH_EDITOR.setDone = function () { - var html = '  '; + let html = '  '; document.execCommand('insertHTML', false, html); }; RICH_EDITOR.addTodo = function (e) { - var KEY_ENTER; + let KEY_ENTER; KEY_ENTER = 13; if (e.which === KEY_ENTER) { - var node = RICH_EDITOR.getSelectedAnchorNode(); + let node = RICH_EDITOR.getSelectedAnchorNode(); if (node && node.nodeName === '#text') { node = node.parentElement; } @@ -339,9 +339,9 @@ RICH_EDITOR.addTodo = function (e) { }; RICH_EDITOR.setTodo = function () { - var parent = document.getElementById('editorjs_box'); - var isContentEmpty = parent.innerHTML.trim().length === 0 || parent.innerHTML === '
'; - var html = (isContentEmpty ? '' : '
') + + let parent = document.getElementById('editorjs_box'); + let isContentEmpty = parent.innerHTML.trim().length === 0 || parent.innerHTML === '
'; + let html = (isContentEmpty ? '' : '
') + ' ' + '' + ' '; @@ -357,9 +357,9 @@ function onCheckChange(checkbox) { } RICH_EDITOR.restorerange = function () { - var selection = window.getSelection(); + let selection = window.getSelection(); selection.removeAllRanges(); - var range = document.createRange(); + let range = document.createRange(); range.setStart(RICH_EDITOR.currentSelection.startContainer, RICH_EDITOR.currentSelection.startOffset); range.setEnd(RICH_EDITOR.currentSelection.endContainer, RICH_EDITOR.currentSelection.endOffset); selection.addRange(range); @@ -368,15 +368,15 @@ RICH_EDITOR.restorerange = function () { // 获取光标开始位置归属节点 RICH_EDITOR.getSelectedAnchorNode = function () { - var node; - var selection; + let node; + let selection; if (window.getSelection) { selection = getSelection(); node = selection.anchorNode; } if (!node && document.selection) { selection = document.selection; - var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange(); + let range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange(); node = range.commonAncestorContainer ? range.commonAncestorContainer : range.parentElement ? range.parentElement() : range.item(0); } @@ -384,30 +384,30 @@ RICH_EDITOR.getSelectedAnchorNode = function () { }; RICH_EDITOR.cancelSelection = function () { - var selection = window.getSelection(); + let selection = window.getSelection(); selection.removeAllRanges(); }; -var callBackToApp; +let callBackToApp = window.callBackToApp; function getHtmlContent() { console.log('getHtmlContent'); - var htmlString = RICH_EDITOR.getHtml(); + let htmlString = RICH_EDITOR.getHtml(); let imgName = getImagePathFromContent(htmlString); htmlString = window.btoa(unescape(encodeURIComponent(htmlString))); callBackToApp.callbackImagePath(imgName); - var str = callBackToApp.callbackhtml(htmlString); + let str = callBackToApp.callbackhtml(htmlString); console.log('getHtmlContent end'); } function saveHtmlContent() { console.log('saveHtmlContent'); - var htmlString = RICH_EDITOR.getHtml(); + let htmlString = RICH_EDITOR.getHtml(); let imgName = getImagePathFromContent(htmlString); htmlString = window.btoa(unescape(encodeURIComponent(htmlString))); callBackToApp.callbackImagePath(imgName); - var str = callBackToApp.callbackhtmlSave(htmlString); + let str = callBackToApp.callbackhtmlSave(htmlString); console.log('saveHtmlContent end'); } @@ -432,11 +432,11 @@ function getImagePathFromContent(contentInfo) { function scheduledSaveContent() { if (callBackToApp !== undefined) { console.info('scheduledSaveContent'); - var htmlString = RICH_EDITOR.getHtml(); + let htmlString = RICH_EDITOR.getHtml(); let imgName = getImagePathFromContent(htmlString); htmlString = window.btoa(unescape(encodeURIComponent(htmlString))); callBackToApp.callbackImagePath(imgName); - var str = callBackToApp.callbackScheduledSave(htmlString); + let str = callBackToApp.callbackScheduledSave(htmlString); console.info('scheduledSaveContent end'); } } @@ -456,9 +456,9 @@ document.body.addEventListener('paste', (event) => { RICH_EDITOR.getFontSizes = function () { document.execCommand('fontSize', false, null); - var fontElements = window.getSelection().anchorNode.parentNode; - var getSize = parseInt(window.getComputedStyle(fontElements, null).fontSize); - var str = callBackToApp.callbackGetSize(getSize); + let fontElements = window.getSelection().anchorNode.parentNode; + let getSize = parseInt(window.getComputedStyle(fontElements, null).fontSize); + let str = callBackToApp.callbackGetSize(getSize); }; RICH_EDITOR.insertImageHtml = function (contents) { @@ -470,11 +470,12 @@ RICH_EDITOR.insertImageHtml = function (contents) { let img = document.createElement('img'); img.src = contents; selection.getRangeAt(0).insertNode(img); + return true; }; document.addEventListener('click', (e) => { console.info(`lsq: e is ${JSON.stringify(e)}`); - var parent = document.getElementById('editorjs_box'); + let parent = document.getElementById('editorjs_box'); if (parent.id !== 'editorjs_box') { e.preventDefault(); }