mirror of
https://gitee.com/openharmony/applications_notes
synced 2024-11-27 01:30:27 +00:00
备忘录告警处理
Signed-off-by: zwx1126739 <zhanghong121@huawei.com>
This commit is contained in:
parent
c7d1b56716
commit
0b417127a9
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var RICH_EDITOR = {};
|
let RICH_EDITOR = {};
|
||||||
let storage = window.localStorage;
|
let storage = window.localStorage;
|
||||||
RICH_EDITOR.editor = document.getElementById('editorjs_box');
|
RICH_EDITOR.editor = document.getElementById('editorjs_box');
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ RICH_EDITOR.setHtml = function (contents) {
|
|||||||
if (contents) {
|
if (contents) {
|
||||||
RICH_EDITOR.editor.style.paddingLeft = paddingLeft + 'px';
|
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)) {
|
if (base64regex.test(contents)) {
|
||||||
RICH_EDITOR.editor.innerHTML = decodeURIComponent(escape(atob(contents)));
|
RICH_EDITOR.editor.innerHTML = decodeURIComponent(escape(atob(contents)));
|
||||||
} else {
|
} else {
|
||||||
@ -67,18 +67,18 @@ RICH_EDITOR.setUnderline = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RICH_EDITOR.getListStyle = function () {
|
RICH_EDITOR.getListStyle = function () {
|
||||||
var selection;
|
let selection;
|
||||||
var type;
|
let type;
|
||||||
if (window.getSelection) {
|
if (window.getSelection) {
|
||||||
selection = getSelection();
|
selection = getSelection();
|
||||||
}
|
}
|
||||||
if (!selection) {
|
if (!selection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
|
let range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
|
||||||
try {
|
try {
|
||||||
var child = range.commonAncestorContainer;
|
let child = range.commonAncestorContainer;
|
||||||
for (var i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
if (child.nodeName === 'OL') {
|
if (child.nodeName === 'OL') {
|
||||||
console.info('insertOrderedList');
|
console.info('insertOrderedList');
|
||||||
document.execCommand('insertOrderedList', false, null);
|
document.execCommand('insertOrderedList', false, null);
|
||||||
@ -107,18 +107,18 @@ RICH_EDITOR.setNumbers = function () {
|
|||||||
let fontSize = document.queryCommandValue('fontSize');
|
let fontSize = document.queryCommandValue('fontSize');
|
||||||
document.execCommand('insertOrderedList', false, null);
|
document.execCommand('insertOrderedList', false, null);
|
||||||
document.execCommand('fontSize', false, fontSize);
|
document.execCommand('fontSize', false, fontSize);
|
||||||
var selection;
|
let selection;
|
||||||
var type;
|
let type;
|
||||||
if (window.getSelection) {
|
if (window.getSelection) {
|
||||||
selection = getSelection();
|
selection = getSelection();
|
||||||
}
|
}
|
||||||
if (!selection) {
|
if (!selection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
|
let range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
|
||||||
try {
|
try {
|
||||||
var child = range.commonAncestorContainer;
|
let child = range.commonAncestorContainer;
|
||||||
for (var i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
if (child.nodeName === 'OL') {
|
if (child.nodeName === 'OL') {
|
||||||
child.style['list-style'] = 'decimal';
|
child.style['list-style'] = 'decimal';
|
||||||
break;
|
break;
|
||||||
@ -140,18 +140,18 @@ RICH_EDITOR.setABC = function () {
|
|||||||
let fontSize = document.queryCommandValue('fontSize');
|
let fontSize = document.queryCommandValue('fontSize');
|
||||||
document.execCommand('insertOrderedList', false, null);
|
document.execCommand('insertOrderedList', false, null);
|
||||||
document.execCommand('fontSize', false, fontSize);
|
document.execCommand('fontSize', false, fontSize);
|
||||||
var selection;
|
let selection;
|
||||||
var type;
|
let type;
|
||||||
if (window.getSelection) {
|
if (window.getSelection) {
|
||||||
selection = getSelection();
|
selection = getSelection();
|
||||||
}
|
}
|
||||||
if (!selection) {
|
if (!selection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
|
let range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
|
||||||
try {
|
try {
|
||||||
var child = range.commonAncestorContainer;
|
let child = range.commonAncestorContainer;
|
||||||
for (var i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
if (child.nodeName === 'OL') {
|
if (child.nodeName === 'OL') {
|
||||||
child.style['list-style'] = 'lower-alpha';
|
child.style['list-style'] = 'lower-alpha';
|
||||||
break;
|
break;
|
||||||
@ -173,18 +173,18 @@ RICH_EDITOR.setBullets = function () {
|
|||||||
let fontSize = document.queryCommandValue('fontSize');
|
let fontSize = document.queryCommandValue('fontSize');
|
||||||
document.execCommand('insertUnorderedList', false, null);
|
document.execCommand('insertUnorderedList', false, null);
|
||||||
document.execCommand('fontSize', false, fontSize);
|
document.execCommand('fontSize', false, fontSize);
|
||||||
var selection;
|
let selection;
|
||||||
var type;
|
let type;
|
||||||
if (window.getSelection) {
|
if (window.getSelection) {
|
||||||
selection = getSelection();
|
selection = getSelection();
|
||||||
}
|
}
|
||||||
if (!selection) {
|
if (!selection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
|
let range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
|
||||||
try {
|
try {
|
||||||
var child = range.commonAncestorContainer;
|
let child = range.commonAncestorContainer;
|
||||||
for (var i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
if (child.nodeName === 'UL') {
|
if (child.nodeName === 'UL') {
|
||||||
child.style['list-style'] = 'disc';
|
child.style['list-style'] = 'disc';
|
||||||
break;
|
break;
|
||||||
@ -206,18 +206,18 @@ RICH_EDITOR.setSquare = function () {
|
|||||||
let fontSize = document.queryCommandValue('fontSize');
|
let fontSize = document.queryCommandValue('fontSize');
|
||||||
document.execCommand('insertUnorderedList', false, null);
|
document.execCommand('insertUnorderedList', false, null);
|
||||||
document.execCommand('fontSize', false, fontSize);
|
document.execCommand('fontSize', false, fontSize);
|
||||||
var selection;
|
let selection;
|
||||||
var type;
|
let type;
|
||||||
if (window.getSelection) {
|
if (window.getSelection) {
|
||||||
selection = getSelection();
|
selection = getSelection();
|
||||||
}
|
}
|
||||||
if (!selection) {
|
if (!selection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
|
let range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
|
||||||
try {
|
try {
|
||||||
var child = range.commonAncestorContainer;
|
let child = range.commonAncestorContainer;
|
||||||
for (var i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
if (child.nodeName === 'UL') {
|
if (child.nodeName === 'UL') {
|
||||||
child.style['list-style'] = 'square';
|
child.style['list-style'] = 'square';
|
||||||
break;
|
break;
|
||||||
@ -253,9 +253,9 @@ RICH_EDITOR.execFontSize = function (size, unit) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var pad = 24;
|
let pad = 24;
|
||||||
RICH_EDITOR.setIndent = function () {
|
RICH_EDITOR.setIndent = function () {
|
||||||
var parents = document.getElementById('editorjs_box');
|
let parents = document.getElementById('editorjs_box');
|
||||||
parents.removeAttribute('padding-left');
|
parents.removeAttribute('padding-left');
|
||||||
if (pad >= 408) {
|
if (pad >= 408) {
|
||||||
return;
|
return;
|
||||||
@ -269,7 +269,7 @@ RICH_EDITOR.setIndent = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RICH_EDITOR.setOutdent = function () {
|
RICH_EDITOR.setOutdent = function () {
|
||||||
var parents = document.getElementById('editorjs_box');
|
let parents = document.getElementById('editorjs_box');
|
||||||
parents.removeAttribute('padding-left');
|
parents.removeAttribute('padding-left');
|
||||||
if (pad === 24) {
|
if (pad === 24) {
|
||||||
parents.style.paddingLeft = 24 + 'px';
|
parents.style.paddingLeft = 24 + 'px';
|
||||||
@ -306,7 +306,7 @@ RICH_EDITOR.setJustifyRight = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RICH_EDITOR.insertImage = function (url) {
|
RICH_EDITOR.insertImage = function (url) {
|
||||||
var html = '<br></br><img src="' + url +
|
let html = '<br></br><img src="' + url +
|
||||||
'" alt="picvision" style="margin:0px auto;width:90%;display:table-cell;' +
|
'" alt="picvision" style="margin:0px auto;width:90%;display:table-cell;' +
|
||||||
'vertical-align:middle;border-radius:10px;max-width:90%" /><br></br>';
|
'vertical-align:middle;border-radius:10px;max-width:90%" /><br></br>';
|
||||||
document.getElementById('editorjs_box').innerHTML += html;
|
document.getElementById('editorjs_box').innerHTML += html;
|
||||||
@ -318,15 +318,15 @@ RICH_EDITOR.insertHTML = function (html) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RICH_EDITOR.setDone = function () {
|
RICH_EDITOR.setDone = function () {
|
||||||
var html = '<input type="checkbox" checked="checked"/> ';
|
let html = '<input type="checkbox" checked="checked"/> ';
|
||||||
document.execCommand('insertHTML', false, html);
|
document.execCommand('insertHTML', false, html);
|
||||||
};
|
};
|
||||||
|
|
||||||
RICH_EDITOR.addTodo = function (e) {
|
RICH_EDITOR.addTodo = function (e) {
|
||||||
var KEY_ENTER;
|
let KEY_ENTER;
|
||||||
KEY_ENTER = 13;
|
KEY_ENTER = 13;
|
||||||
if (e.which === KEY_ENTER) {
|
if (e.which === KEY_ENTER) {
|
||||||
var node = RICH_EDITOR.getSelectedAnchorNode();
|
let node = RICH_EDITOR.getSelectedAnchorNode();
|
||||||
if (node && node.nodeName === '#text') {
|
if (node && node.nodeName === '#text') {
|
||||||
node = node.parentElement;
|
node = node.parentElement;
|
||||||
}
|
}
|
||||||
@ -339,9 +339,9 @@ RICH_EDITOR.addTodo = function (e) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RICH_EDITOR.setTodo = function () {
|
RICH_EDITOR.setTodo = function () {
|
||||||
var parent = document.getElementById('editorjs_box');
|
let parent = document.getElementById('editorjs_box');
|
||||||
var isContentEmpty = parent.innerHTML.trim().length === 0 || parent.innerHTML === '<br>';
|
let isContentEmpty = parent.innerHTML.trim().length === 0 || parent.innerHTML === '<br>';
|
||||||
var html = (isContentEmpty ? '' : '<br/>') +
|
let html = (isContentEmpty ? '' : '<br/>') +
|
||||||
'<span> </span>' +
|
'<span> </span>' +
|
||||||
'<input name="checkbox" type="checkbox" onclick="onCheckChange(this)" class="note-checkbox">' +
|
'<input name="checkbox" type="checkbox" onclick="onCheckChange(this)" class="note-checkbox">' +
|
||||||
'<span class="note-checkbox-txt"> </span>';
|
'<span class="note-checkbox-txt"> </span>';
|
||||||
@ -357,9 +357,9 @@ function onCheckChange(checkbox) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RICH_EDITOR.restorerange = function () {
|
RICH_EDITOR.restorerange = function () {
|
||||||
var selection = window.getSelection();
|
let selection = window.getSelection();
|
||||||
selection.removeAllRanges();
|
selection.removeAllRanges();
|
||||||
var range = document.createRange();
|
let range = document.createRange();
|
||||||
range.setStart(RICH_EDITOR.currentSelection.startContainer, RICH_EDITOR.currentSelection.startOffset);
|
range.setStart(RICH_EDITOR.currentSelection.startContainer, RICH_EDITOR.currentSelection.startOffset);
|
||||||
range.setEnd(RICH_EDITOR.currentSelection.endContainer, RICH_EDITOR.currentSelection.endOffset);
|
range.setEnd(RICH_EDITOR.currentSelection.endContainer, RICH_EDITOR.currentSelection.endOffset);
|
||||||
selection.addRange(range);
|
selection.addRange(range);
|
||||||
@ -368,15 +368,15 @@ RICH_EDITOR.restorerange = function () {
|
|||||||
// 获取光标开始位置归属节点
|
// 获取光标开始位置归属节点
|
||||||
|
|
||||||
RICH_EDITOR.getSelectedAnchorNode = function () {
|
RICH_EDITOR.getSelectedAnchorNode = function () {
|
||||||
var node;
|
let node;
|
||||||
var selection;
|
let selection;
|
||||||
if (window.getSelection) {
|
if (window.getSelection) {
|
||||||
selection = getSelection();
|
selection = getSelection();
|
||||||
node = selection.anchorNode;
|
node = selection.anchorNode;
|
||||||
}
|
}
|
||||||
if (!node && document.selection) {
|
if (!node && document.selection) {
|
||||||
selection = 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
|
node = range.commonAncestorContainer ? range.commonAncestorContainer : range.parentElement
|
||||||
? range.parentElement() : range.item(0);
|
? range.parentElement() : range.item(0);
|
||||||
}
|
}
|
||||||
@ -384,30 +384,30 @@ RICH_EDITOR.getSelectedAnchorNode = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RICH_EDITOR.cancelSelection = function () {
|
RICH_EDITOR.cancelSelection = function () {
|
||||||
var selection = window.getSelection();
|
let selection = window.getSelection();
|
||||||
selection.removeAllRanges();
|
selection.removeAllRanges();
|
||||||
};
|
};
|
||||||
|
|
||||||
var callBackToApp;
|
let callBackToApp = window.callBackToApp;
|
||||||
|
|
||||||
function getHtmlContent() {
|
function getHtmlContent() {
|
||||||
console.log('getHtmlContent');
|
console.log('getHtmlContent');
|
||||||
var htmlString = RICH_EDITOR.getHtml();
|
let htmlString = RICH_EDITOR.getHtml();
|
||||||
let imgName = getImagePathFromContent(htmlString);
|
let imgName = getImagePathFromContent(htmlString);
|
||||||
htmlString = window.btoa(unescape(encodeURIComponent(htmlString)));
|
htmlString = window.btoa(unescape(encodeURIComponent(htmlString)));
|
||||||
callBackToApp.callbackImagePath(imgName);
|
callBackToApp.callbackImagePath(imgName);
|
||||||
var str = callBackToApp.callbackhtml(htmlString);
|
let str = callBackToApp.callbackhtml(htmlString);
|
||||||
console.log('getHtmlContent end');
|
console.log('getHtmlContent end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveHtmlContent() {
|
function saveHtmlContent() {
|
||||||
console.log('saveHtmlContent');
|
console.log('saveHtmlContent');
|
||||||
var htmlString = RICH_EDITOR.getHtml();
|
let htmlString = RICH_EDITOR.getHtml();
|
||||||
let imgName = getImagePathFromContent(htmlString);
|
let imgName = getImagePathFromContent(htmlString);
|
||||||
htmlString = window.btoa(unescape(encodeURIComponent(htmlString)));
|
htmlString = window.btoa(unescape(encodeURIComponent(htmlString)));
|
||||||
|
|
||||||
callBackToApp.callbackImagePath(imgName);
|
callBackToApp.callbackImagePath(imgName);
|
||||||
var str = callBackToApp.callbackhtmlSave(htmlString);
|
let str = callBackToApp.callbackhtmlSave(htmlString);
|
||||||
console.log('saveHtmlContent end');
|
console.log('saveHtmlContent end');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,11 +432,11 @@ function getImagePathFromContent(contentInfo) {
|
|||||||
function scheduledSaveContent() {
|
function scheduledSaveContent() {
|
||||||
if (callBackToApp !== undefined) {
|
if (callBackToApp !== undefined) {
|
||||||
console.info('scheduledSaveContent');
|
console.info('scheduledSaveContent');
|
||||||
var htmlString = RICH_EDITOR.getHtml();
|
let htmlString = RICH_EDITOR.getHtml();
|
||||||
let imgName = getImagePathFromContent(htmlString);
|
let imgName = getImagePathFromContent(htmlString);
|
||||||
htmlString = window.btoa(unescape(encodeURIComponent(htmlString)));
|
htmlString = window.btoa(unescape(encodeURIComponent(htmlString)));
|
||||||
callBackToApp.callbackImagePath(imgName);
|
callBackToApp.callbackImagePath(imgName);
|
||||||
var str = callBackToApp.callbackScheduledSave(htmlString);
|
let str = callBackToApp.callbackScheduledSave(htmlString);
|
||||||
console.info('scheduledSaveContent end');
|
console.info('scheduledSaveContent end');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -456,9 +456,9 @@ document.body.addEventListener('paste', (event) => {
|
|||||||
|
|
||||||
RICH_EDITOR.getFontSizes = function () {
|
RICH_EDITOR.getFontSizes = function () {
|
||||||
document.execCommand('fontSize', false, null);
|
document.execCommand('fontSize', false, null);
|
||||||
var fontElements = window.getSelection().anchorNode.parentNode;
|
let fontElements = window.getSelection().anchorNode.parentNode;
|
||||||
var getSize = parseInt(window.getComputedStyle(fontElements, null).fontSize);
|
let getSize = parseInt(window.getComputedStyle(fontElements, null).fontSize);
|
||||||
var str = callBackToApp.callbackGetSize(getSize);
|
let str = callBackToApp.callbackGetSize(getSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
RICH_EDITOR.insertImageHtml = function (contents) {
|
RICH_EDITOR.insertImageHtml = function (contents) {
|
||||||
@ -470,11 +470,12 @@ RICH_EDITOR.insertImageHtml = function (contents) {
|
|||||||
let img = document.createElement('img');
|
let img = document.createElement('img');
|
||||||
img.src = contents;
|
img.src = contents;
|
||||||
selection.getRangeAt(0).insertNode(img);
|
selection.getRangeAt(0).insertNode(img);
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener('click', (e) => {
|
document.addEventListener('click', (e) => {
|
||||||
console.info(`lsq: e is ${JSON.stringify(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') {
|
if (parent.id !== 'editorjs_box') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user