mylomen-server/static/js/testEdit.js
shaoyongjun 4c4ba596fb to:sync
2024-11-26 12:00:58 +08:00

50 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(function (utils, eventHandle) {
/**
* 输入事件
*/
utils.MyRoot.addEventListener('input', styleCmd.inputHandle);
utils.MyRoot.addEventListener('compositionstart', styleCmd.compositionstartHandle);
utils.MyRoot.addEventListener('compositionend', styleCmd.compositionendHandle);
//窗口撤销事件
window.addEventListener('keydown', styleCmd.windowsCtrZHandle, true);
// window.onkeydown = styleCmd.windowsCtrZHandle
//样式事件
document.getElementById("myPlusB").addEventListener('click', styleCmd.surroundContentsByStyle);
document.getElementById("myPlusI").addEventListener('click', styleCmd.surroundContentsByStyle);
document.getElementById("myPlusU").addEventListener('click', styleCmd.surroundContentsByStyle);
document.getElementById("myPlusDel").addEventListener('click', styleCmd.surroundContentsByStyle);
document.getElementById("myPlusC").addEventListener('click', styleCmd.surroundContentsByStyle);
//窗口初始化完成事件
window.onload = function () {//do something
// yanxuelu.style.outline = 'none'
// yanxuelu.onkeydown = fn // 注册keydown事件处理函数键盘按下
// key.onkeyup = fn // 注册keyup事件处理函数键盘松开
// key.onkeypress = fn // 注册keypress事件处理函数不推荐使用
var newParagraph = document.createElement("p")
newParagraph.setAttribute("contenteditable", "true")
let uuid = utils.uuid()
let curOrder = ++utils.num
newParagraph.setAttribute("data-id", uuid)
newParagraph.setAttribute("id", uuid)
newParagraph.setAttribute("data-order", curOrder)
newParagraph.onkeydown = styleCmd.onkeydownHandle
newParagraph.focus()
newParagraph.innerHTML = "<br>"
utils.MyRoot.appendChild(newParagraph)
// MyDocMap[curOrder] = new Map()
utils.MyDocMap.set(curOrder, new utils.MyNode(uuid))
//收起选区到一个点,光标落在一个可编辑元素上
window.getSelection().setPosition(newParagraph, 0);
}
})(utils, styleCmd)