diff --git a/common/component/src/main/ets/components/NoteContent.ets b/common/component/src/main/ets/components/NoteContent.ets
index e5e97a67a3722f81f952d6dbcb336c20db48afc0..b3a8ad8bba439fe2666fdc3fc1495263b970caf8 100644
--- a/common/component/src/main/ets/components/NoteContent.ets
+++ b/common/component/src/main/ets/components/NoteContent.ets
@@ -117,9 +117,11 @@ export struct NoteContent {
.width(StyleConstants.PERCENTAGE_100)
.onClick(() => {
// 添加定时器:3s自动保存
- timeID = setInterval(() => {
- this.controllerShow.runJavaScript({ script: "scheduled_save_content()" })
- }, 3000)
+ if (timeID == undefined) {
+ timeID = setInterval(() => {
+ this.controllerShow.runJavaScript({ script: "scheduledSaveContent()" })
+ }, 3000)
+ }
LogUtil.info(TAG, "setInterval timeID : " + timeID)
this.issave = 0
this.editModel = true
@@ -167,7 +169,7 @@ export struct ToolBarComp {
.width(24)
.onClick(() => {
this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setInputEnabled(false)" })
- this.controllerShow.runJavaScript({ script: "get_html_content()" })
+ this.controllerShow.runJavaScript({ script: "getHtmlContent()" })
// 清除定时器
if (timeID != undefined) {
LogUtil.info(TAG, "zoom, clearInterval timeID : " + timeID)
@@ -300,7 +302,7 @@ export struct ToolBarComp {
.onClick(() => {
this.issave = 1
// 保存笔记信息到数据库
- this.controllerShow.runJavaScript({ script: "get_html_content()" })
+ this.controllerShow.runJavaScript({ script: "getHtmlContent()" })
})
}.width(42)
.height(42)
diff --git a/common/component/src/main/ets/components/NoteContentComp.ets b/common/component/src/main/ets/components/NoteContentComp.ets
index 1e5c51727f6834646e8bff470895a7f3ec07e966..a805d36947df96b340950bd2d9ee6715d675b493 100644
--- a/common/component/src/main/ets/components/NoteContentComp.ets
+++ b/common/component/src/main/ets/components/NoteContentComp.ets
@@ -164,7 +164,7 @@ export struct NoteContentComp {
this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setInputEnabled(true)" })
// 添加定时器:3s自动保存
timeId = setInterval(() => {
- this.controllerShow.runJavaScript({ script: "scheduled_save_content()" })
+ this.controllerShow.runJavaScript({ script: "scheduledSaveContent()" })
}, 3000)
LogUtil.info(TAG, "setInterval timeId : " + timeId)
// save continue data
@@ -376,7 +376,7 @@ export struct ToolBarComp {
this.sectionStatus = this.lastSectionStatus
// 退出全屏时存库
LogUtil.info(TAG, "close note" + this.selectedNoteData.uuid)
- this.controllerShow.runJavaScript({ script: "save_html_content()" })
+ this.controllerShow.runJavaScript({ script: "saveHtmlContent()" })
//退出键盘
inputMethod.getInputMethodController().stopInput();
// 清除定时器
@@ -532,7 +532,7 @@ export struct ToolBarComp {
.fillColor(this.issave == 0 ? Color.Black : Color.Grey)
.onClick(() => {
// 保存笔记信息到数据库
- this.controllerShow.runJavaScript({ script: "get_html_content()" })
+ this.controllerShow.runJavaScript({ script: "getHtmlContent()" })
if (this.selectedNoteData.title == "标题" && this.selectedNoteData.content_text == "") {
LogUtil.info(TAG, "note is empty,save note failed")
}
diff --git a/common/component/src/main/ets/components/NoteContentCompPortrait.ets b/common/component/src/main/ets/components/NoteContentCompPortrait.ets
index c73e6dece506668f344b7775fbb91ffb83ecd667..a3bef8299f850a2a75890248f95622a471fcf8f1 100644
--- a/common/component/src/main/ets/components/NoteContentCompPortrait.ets
+++ b/common/component/src/main/ets/components/NoteContentCompPortrait.ets
@@ -122,7 +122,7 @@ export struct NoteContentCompPortrait {
.onClick(() => {
// 添加定时器:3s自动保存
time_id = setInterval(() => {
- this.controllerShow.runJavaScript({ script: "scheduled_save_content()" })
+ this.controllerShow.runJavaScript({ script: "scheduledSaveContent()" })
}, 3000)
LogUtil.info(TAG, "setInterval time_id : " + time_id)
this.editModel = true
@@ -296,7 +296,7 @@ export struct ToolBarComp {
.width(24)
.responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 })
.onClick(() => {
- this.controllerShow.runJavaScript({ script: "get_html_content()" })
+ this.controllerShow.runJavaScript({ script: "getHtmlContent()" })
// 清除定时器
if (time_id != undefined) {
LogUtil.info(TAG, "back, clearInterval time_id : " + time_id)
@@ -359,7 +359,7 @@ export struct ToolBarComp {
Image($r('app.media.tick_thin')).height(24).width(24)
.onClick(() => {
// 保存笔记信息到数据库
- this.controllerShow.runJavaScript({ script: "get_html_content()" })
+ this.controllerShow.runJavaScript({ script: "getHtmlContent()" })
this.editModel = false
})
}.width(42)
diff --git a/common/component/src/main/ets/components/NoteListComp.ets b/common/component/src/main/ets/components/NoteListComp.ets
index d773587b83aa0a91d90d1c6d4bdb3fb20f88d80d..7b0ef222225a4f83895c324ccc7d3ce75df994d9 100644
--- a/common/component/src/main/ets/components/NoteListComp.ets
+++ b/common/component/src/main/ets/components/NoteListComp.ets
@@ -733,7 +733,7 @@ export struct OperateNoteCompForPortrait {
})
opacityChange() {
- if (this.CheckedNoteArray.length == 0) {
+ if (this.CheckedNoteArray.length == 0 && this.longpress == true) {
this.greyOpacity = true
LogUtil.info(TAG, "none checked array")
} else {
@@ -787,8 +787,8 @@ export struct OperateNoteCompForPortrait {
})
}
NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
- this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
this.longpress = false
+ this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)
// save continue data
let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
diff --git a/common/resources/src/main/resources/rawfile/rich_editor.js b/common/resources/src/main/resources/rawfile/rich_editor.js
index c8bc40b553ddf06de60bfbf115672fad8aba27fa..1b0c41e86cd704c8ca993f45fcdfa0352c0b8c6b 100644
--- a/common/resources/src/main/resources/rawfile/rich_editor.js
+++ b/common/resources/src/main/resources/rawfile/rich_editor.js
@@ -1,4 +1,4 @@
-/*
+/* @file
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,48 +17,54 @@ var RICH_EDITOR = {};
RICH_EDITOR.editor = document.getElementById('editorjs');
-RICH_EDITOR.setHtml = function(contents) {
- RICH_EDITOR.editor.innerHTML = contents.replace(/'/g, "'");
-}
+RICH_EDITOR.setHtml = function (contents) {
+ var 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 {
+ RICH_EDITOR.editor.innerHTML = contents;
+ }
+};
-RICH_EDITOR.getHtml = function() {
+RICH_EDITOR.getHtml = function () {
return RICH_EDITOR.editor.innerHTML;
-}
+};
-RICH_EDITOR.undo = function() {
+RICH_EDITOR.undo = function () {
document.execCommand('undo', false, null);
-}
+};
-RICH_EDITOR.redo = function() {
+RICH_EDITOR.redo = function () {
document.execCommand('redo', false, null);
-}
+};
-RICH_EDITOR.setBold = function() {
+RICH_EDITOR.setBold = function () {
document.execCommand('bold');
-}
+};
-RICH_EDITOR.setItalic = function() {
+RICH_EDITOR.setItalic = function () {
document.execCommand('italic', false, null);
-}
+};
-RICH_EDITOR.setSubscript = function() {
+RICH_EDITOR.setSubscript = function () {
document.execCommand('subscript', false, null);
-}
+};
-RICH_EDITOR.setSuperscript = function() {
+RICH_EDITOR.setSuperscript = function () {
document.execCommand('superscript', false, null);
-}
+};
-RICH_EDITOR.setStrikeThrough = function() {
+RICH_EDITOR.setStrikeThrough = function () {
document.execCommand('strikeThrough', false, null);
-}
+};
-RICH_EDITOR.setUnderline = function() {
+RICH_EDITOR.setUnderline = function () {
document.execCommand('underline', false, null);
-}
+};
RICH_EDITOR.getListStyle = function () {
- var selection, type;
+ var selection;
+ var type;
if (window.getSelection) {
selection = getSelection();
}
@@ -67,34 +73,35 @@ RICH_EDITOR.getListStyle = function () {
try {
var child = range.commonAncestorContainer.parentNode;
for (var i = 0; i < 10; i++) {
- if (child.nodeName == "OL") {
- console.info('insertOrderedList')
+ if (child.nodeName === 'OL') {
+ console.info('insertOrderedList');
document.execCommand('insertOrderedList', false, null);
- return child.style["list-style"]
+ return child.style['list-style'];
}
- if (child.nodeName == "UL") {
- console.info('insertUnorderedList')
+ if (child.nodeName === 'UL') {
+ console.info('insertUnorderedList');
document.execCommand('insertUnorderedList', false, null);
- return child.style["list-style"]
+ return child.style['list-style'];
}
if (child.parentNode) {
- child = child.parentNode
+ child = child.parentNode;
}
}
} catch (err) {
- console.error(err)
+ console.error(err);
}
}
-}
+};
RICH_EDITOR.setNumbers = function () {
- let listStyle = RICH_EDITOR.getListStyle()
- if(listStyle == "decimal") {
- return
+ let listStyle = RICH_EDITOR.getListStyle();
+ if (listStyle === 'decimal') {
+ return;
}
document.execCommand('insertOrderedList', false, null);
- var selection, type;
+ var selection;
+ var type;
if (window.getSelection) {
selection = getSelection();
}
@@ -103,27 +110,28 @@ RICH_EDITOR.setNumbers = function () {
try {
var child = range.commonAncestorContainer.parentNode;
for (var i = 0; i < 10; i++) {
- if (child.nodeName == "OL") {
- child.style["list-style"] = "decimal";
+ if (child.nodeName === 'OL') {
+ child.style['list-style'] = 'decimal';
break;
}
if (child.parentNode) {
- child = child.parentNode
+ child = child.parentNode;
}
}
} catch (err) {
- console.error(err)
+ console.error(err);
}
}
-}
+};
RICH_EDITOR.setABC = function () {
- let listStyle = RICH_EDITOR.getListStyle()
- if(listStyle == "lower-alpha") {
- return
+ let listStyle = RICH_EDITOR.getListStyle();
+ if (listStyle === 'lower-alpha') {
+ return;
}
document.execCommand('insertOrderedList', false, null);
- var selection, type;
+ var selection;
+ var type;
if (window.getSelection) {
selection = getSelection();
}
@@ -132,27 +140,28 @@ RICH_EDITOR.setABC = function () {
try {
var child = range.commonAncestorContainer.parentNode;
for (var i = 0; i < 10; i++) {
- if (child.nodeName == "OL") {
- child.style["list-style"] = "lower-alpha";
+ if (child.nodeName === 'OL') {
+ child.style['list-style'] = 'lower-alpha';
break;
}
if (child.parentNode) {
- child = child.parentNode
+ child = child.parentNode;
}
}
} catch (err) {
- console.error(err)
+ console.error(err);
}
}
-}
+};
RICH_EDITOR.setBullets = function () {
- let listStyle = RICH_EDITOR.getListStyle()
- if(listStyle == "disc") {
- return
+ let listStyle = RICH_EDITOR.getListStyle();
+ if (listStyle === 'disc') {
+ return;
}
document.execCommand('insertUnorderedList', false, null);
- var selection, type;
+ var selection;
+ var type;
if (window.getSelection) {
selection = getSelection();
}
@@ -161,27 +170,28 @@ RICH_EDITOR.setBullets = function () {
try {
var child = range.commonAncestorContainer.parentNode;
for (var i = 0; i < 10; i++) {
- if (child.nodeName == "UL") {
- child.style["list-style"] = "disc";
+ if (child.nodeName === 'UL') {
+ child.style['list-style'] = 'disc';
break;
}
if (child.parentNode) {
- child = child.parentNode
+ child = child.parentNode;
}
}
} catch (err) {
- console.error(err)
+ console.error(err);
}
}
-}
+};
RICH_EDITOR.setSquare = function () {
- let listStyle = RICH_EDITOR.getListStyle()
- if(listStyle == "square") {
- return
+ let listStyle = RICH_EDITOR.getListStyle();
+ if (listStyle === 'square') {
+ return;
}
document.execCommand('insertUnorderedList', false, null);
- var selection, type;
+ var selection;
+ var type;
if (window.getSelection) {
selection = getSelection();
}
@@ -190,161 +200,169 @@ RICH_EDITOR.setSquare = function () {
try {
var child = range.commonAncestorContainer.parentNode;
for (var i = 0; i < 10; i++) {
- if (child.nodeName == "UL") {
- child.style["list-style"] = "square";
+ if (child.nodeName === 'UL') {
+ child.style['list-style'] = 'square';
break;
}
if (child.parentNode) {
- child = child.parentNode
+ child = child.parentNode;
}
}
} catch (err) {
- console.error(err)
+ console.error(err);
}
}
-}
+};
RICH_EDITOR.setTextColor = function (color) {
document.execCommand('foreColor', false, color);
-}
+};
-RICH_EDITOR.setFontSize = function(fontSize){
- document.execCommand("fontSize", false, fontSize);
-}
+RICH_EDITOR.setFontSize = function (fontSize) {
+ document.execCommand('fontSize', false, fontSize);
+};
RICH_EDITOR.execFontSize = function (size, unit) {
- document.execCommand("fontSize", false, "7");
- var fontElements = window.getSelection().anchorNode.parentNode
- fontElements.removeAttribute("size");
- fontElements.style.fontSize = size + 'px'
+ document.execCommand('fontSize', false, '7');
+ var fontElements = window.getSelection().anchorNode.parentNode;
+ fontElements.removeAttribute('size');
+ fontElements.style.fontSize = size + 'px';
};
-var pad = 24
-RICH_EDITOR.setIndent = function() {
- var parents = document.getElementById('editorjs')
+var pad = 24;
+RICH_EDITOR.setIndent = function () {
+ var parents = document.getElementById('editorjs');
parents.removeAttribute('padding-left');
- pad = pad + 24
- parents.style.paddingLeft = pad + 'px'
-}
+ pad = pad + 24;
+ parents.style.paddingLeft = pad + 'px';
+};
-RICH_EDITOR.setOutdent = function() {
- var parents = document.getElementById('editorjs')
+RICH_EDITOR.setOutdent = function () {
+ var parents = document.getElementById('editorjs');
parents.removeAttribute('padding-left');
- if (pad == 24) {
- parents.style.paddingLeft = 24 + 'px'
+ if (pad === 24) {
+ parents.style.paddingLeft = 24 + 'px';
} else {
- pad = pad - 24
- parents.style.paddingLeft = pad + 'px'
+ pad = pad - 24;
+ parents.style.paddingLeft = pad + 'px';
}
-}
+};
-RICH_EDITOR.setJustifyLeft = function() {
+RICH_EDITOR.setJustifyLeft = function () {
document.execCommand('justifyLeft', false, null);
-}
+};
-RICH_EDITOR.setJustifyCenter = function() {
+RICH_EDITOR.setJustifyCenter = function () {
document.execCommand('justifyCenter', false, null);
-}
+};
-RICH_EDITOR.setJustifyRight = function() {
+RICH_EDITOR.setJustifyRight = function () {
document.execCommand('justifyRight', false, null);
-}
+};
-RICH_EDITOR.insertImage = function(url) {
- var html = '

';
+RICH_EDITOR.insertImage = function (url) {
+ var html = '

';
RICH_EDITOR.insertHTML(html);
- RICH_EDITOR.editor.scrollIntoView(false)
-}
+ RICH_EDITOR.editor.scrollIntoView(false);
+};
-RICH_EDITOR.insertHTML = function(html) {
+RICH_EDITOR.insertHTML = function (html) {
document.execCommand('insertHTML', false, html);
-}
+};
-RICH_EDITOR.setDone = function() {
+RICH_EDITOR.setDone = function () {
var html = ' ';
document.execCommand('insertHTML', false, html);
-}
+};
-RICH_EDITOR.addTodo=function(e){
- KEY_ENTER=13;
- if(e.which == KEY_ENTER){
- var node=RICH_EDITOR.getSelectedAnchorNode();
- if(node&&node.nodeName=="#text"){
- node=node.parentElement;
+RICH_EDITOR.addTodo = function (e) {
+ var KEY_ENTER;
+ KEY_ENTER = 13;
+ if (e.which === KEY_ENTER) {
+ var node = RICH_EDITOR.getSelectedAnchorNode();
+ if (node && node.nodeName === '#text') {
+ node = node.parentElement;
}
- if(node&&node.nodeName=="SPAN"&&node.previousElementSibling&&node.previousElementSibling.className=='note-checkbox'){
+ if (node && node.nodeName === 'SPAN' && node.previousElementSibling
+ && node.previousElementSibling.className === 'note-checkbox') {
RICH_EDITOR.setTodo();
e.preventDefault();
}
}
-}
+};
RICH_EDITOR.setTodo = function () {
- var parent = document.getElementById('editorjs')
- var isContentEmpty = parent.innerHTML.trim().length == 0 || parent.innerHTML == '
';
- var html = (isContentEmpty ? '' : '
') + ' ';
+ var parent = document.getElementById('editorjs');
+ var isContentEmpty = parent.innerHTML.trim().length === 0 || parent.innerHTML === '
';
+ var html = (isContentEmpty ? '' : '
')
+ + ''
+ + ' ';
document.execCommand('insertHTML', false, html);
-}
+};
function onCheckChange(checkbox) {
- if (checkbox.checked == true) {
- checkbox.setAttribute("checked", "checked");
+ if (checkbox.checked === true) {
+ checkbox.setAttribute('checked', 'checked');
} else {
- checkbox.removeAttribute("checked");
+ checkbox.removeAttribute('checked');
}
}
-RICH_EDITOR.restorerange = function(){
+RICH_EDITOR.restorerange = function () {
var selection = window.getSelection();
selection.removeAllRanges();
var 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);
-}
+};
-//获取光标开始位置归属节点
-RICH_EDITOR.getSelectedAnchorNode=function(){
- var node,selection;
+// 获取光标开始位置归属节点
+
+RICH_EDITOR.getSelectedAnchorNode = function () {
+ var node;
+ var selection;
if (window.getSelection) {
selection = getSelection();
node = selection.anchorNode;
}
if (!node && document.selection) {
- selection = document.selection
+ selection = document.selection;
var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
- node = range.commonAncestorContainer ? range.commonAncestorContainer :
- range.parentElement ? range.parentElement() : range.item(0);
+ node = range.commonAncestorContainer ? range.commonAncestorContainer : range.parentElement
+ ? range.parentElement() : range.item(0);
}
return node;
-}
-
-function get_html_content() {
- console.log('get_html_content');
- var htmlString = RICH_EDITOR.getHtml()
- htmlString = htmlString.replace(/'/g, ''')
- var str = callBackToApp.callbackhtml(htmlString)
- console.log('get_html_content end');
-}
-
-function save_html_content() {
- console.log('save_html_content');
- var htmlString = RICH_EDITOR.getHtml()
- htmlString = htmlString.replace(/'/g, ''')
- var str = callBackToApp.callbackhtmlSave(htmlString)
- console.log('save_html_content end');
-}
-
-function scheduled_save_content() {
- console.info('scheduled_save_content')
- var htmlString = RICH_EDITOR.getHtml()
- var str = callBackToApp.callbackScheduledSave(htmlString)
- console.info('scheduled_save_content end')
-}
-
-RICH_EDITOR.getFontSizes = function(){
- document.execCommand("fontSize", false, null);
- var fontElements = window.getSelection().anchorNode.parentNode
- var getSize = fontElements.style.fontSize
- var str = callBackToApp.callbackGetSize(getSize)
-}
\ No newline at end of file
+};
+var callBackToApp;
+function getHtmlContent() {
+ console.log('getHtmlContent');
+ var htmlString = RICH_EDITOR.getHtml();
+ htmlString = window.btoa(unescape(encodeURIComponent(htmlString)));
+ var str = callBackToApp.callbackhtml(htmlString);
+ console.log('getHtmlContent end');
+}
+
+function saveHtmlContent() {
+ console.log('saveHtmlContent');
+ var htmlString = RICH_EDITOR.getHtml();
+ htmlString = window.btoa(unescape(encodeURIComponent(htmlString)));
+ var str = callBackToApp.callbackhtmlSave(htmlString);
+ console.log('saveHtmlContent end');
+}
+
+function scheduledSaveContent() {
+ console.info('scheduledSaveContent');
+ var htmlString = RICH_EDITOR.getHtml();
+ var str = callBackToApp.callbackScheduledSave(htmlString);
+ console.info('scheduledSaveContent end');
+}
+
+RICH_EDITOR.getFontSizes = function () {
+ document.execCommand('fontSize', false, null);
+ var fontElements = window.getSelection().anchorNode.parentNode;
+ var getSize = fontElements.style.fontSize;
+ var str = callBackToApp.callbackGetSize(getSize);
+};
\ No newline at end of file
diff --git a/product/phone/src/main/ets/pages/NoteContentHome.ets b/product/phone/src/main/ets/pages/NoteContentHome.ets
index 89a4853742ff94431491ebb3e76cc2f9b088e030..d12a18e7e3b30b5279bf2ca495530af7b4afb458 100644
--- a/product/phone/src/main/ets/pages/NoteContentHome.ets
+++ b/product/phone/src/main/ets/pages/NoteContentHome.ets
@@ -40,7 +40,7 @@ struct NoteContentHome {
onBackPress():void{
LogUtil.info(this.TAG, "onBackPress")
this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setInputEnabled(false)" })
- this.controllerShow.runJavaScript({ script: "get_html_content()" })
+ this.controllerShow.runJavaScript({ script: "getHtmlContent()" })
}
aboutToAppear(): void{
diff --git a/product/tablet/src/main/ets/pages/NoteContentHome.ets b/product/tablet/src/main/ets/pages/NoteContentHome.ets
index 2dc330564514435523e4b83b0fbe20b69ae7e874..861a478de1924427aad179e9701440caf97ac0d0 100644
--- a/product/tablet/src/main/ets/pages/NoteContentHome.ets
+++ b/product/tablet/src/main/ets/pages/NoteContentHome.ets
@@ -40,7 +40,7 @@ struct NoteContentHome {
onBackPress():void{
LogUtil.info(this.TAG, "onBackPress")
this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setInputEnabled(false)" })
- this.controllerShow.runJavaScript({ script: "get_html_content()" })
+ this.controllerShow.runJavaScript({ script: "getHtmlContent()" })
inputMethod.getInputMethodController().stopInput()
}