123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- /** appendbase 追加内容到基本元素中
- * **/
- UE.plugins["appendbase"] = function() {
- let me = this;
- me.commands["appendbase"] = {
- execCommand: function(cmd,text) {
- let range = me.selection.getRange();
- //判断是否在基本元素中
- let startNode = range.startContainer;
- let endNode = range.endContainer;
- let startA = UE.dom.domUtils.findParentByTagName(startNode, "a", true);
- let endA = UE.dom.domUtils.findParentByTagName(endNode, "a", true);
- if(!startA || startA.getAttribute("class").indexOf("input") == -1){
- return false;
- }
- if(!endA || endA.getAttribute("class").indexOf("input") == -1){
- return false;
- }
- //在同一个元素内才插入
- if(startA == endA){
- let dataType = startA.getAttribute("dataType");
- //文本02 多行文本03 数字04
- if(dataType == "02"){
- // startA.innerHTML = startA.innerHTML+text;
- // insertAfterText(startA, text)
- let value = startA.innerHTML;
- let newValue = value.substring(0, range.startOffset) + text + value.substring(range.endOffset, value.length);
- startA.innerHTML = newValue;
- } else if(dataType == "03"){
- let textarea = $(startA).find("textarea");
- textarea.insertAtCaret(text);
- }
- }
- }
- }
- };
- //end UE.plugins["appendbase"]
- /** amendment 修订
- * **/
- UE.plugins["amendment"] = function() {
- let me = this;
- // emrRemark.init(me);
- function getValue(ele){
- let value = "";
- if(ele){
- if(ele.nodeName == "TEXTAREA"){
- value = ele.textContent;
- } else if(ele.nodeName == "INPUT"){
- value = ele.value;
- } else {
- value = ele.textContent;
- }
- }
- return value;
- }
- function beforeInputEvent(e){
- // console.log("beforeInputEvent")
- // console.log(e)
- let ele = e.target;
- // console.log(ele)
- // console.log(util)
- if(ele){
- // 获取到a标签
- let inputA = emrRemark.getParentA(ele);
- if(inputA){
- let value = getValue(ele);
- emrRemark.setData(inputA,value);
- }
- }
- }
-
- function inputEvent(e){
- // console.log("amendment.inputEvent")
- let ele = e.target;
- // console.log(ele)
- // showEleRemark(ele);
- if(ele){
- let inputA = emrRemark.getParentA(ele);
- if(inputA){
- emrRemark.showAllRemark();
- }
- }
- }
- me.commands["amendment"] = {
- execCommand: function(cmd,ui) {
- me.options.amendment = !me.options.amendment;
- // console.log(me.options.amendment)
- if(ui.target){
- if(me.options.amendment){
- me.document.addEventListener("beforeinput", beforeInputEvent),
- me.document.addEventListener("input", inputEvent);
- ui.target.classList.add("edui-active");
- } else {
- me.document.removeEventListener("beforeinput", beforeInputEvent),
- me.document.removeEventListener("input", inputEvent);
- ui.target.classList.remove("edui-active");
- }
- emrRemark.showAllRemark();
- }
- }
- }
- };
- //end UE.plugins["amendment"]
- /** annotations 批注
- * **/
- UE.plugins["annotations"] = function() {
- let me = this;
- me.commands["annotations"] = {
- execCommand: function(cmd,ui) {
- me.options.annotations = !me.options.annotations;
- // console.log(me.options.annotations)
- if(ui.target){
- if(me.options.annotations){
- ui.target.classList.add("edui-active");
- me.document.addEventListener("input", emrRemark.annotationsInput);
- } else {
- ui.target.classList.remove("edui-active");
- me.document.removeEventListener("input", emrRemark.annotationsInput);
- }
- emrRemark.showAllRemark();
- }
- }
- }
- };
- //end UE.plugins["annotations"]
- /** addannotations 添加批注
- * **/
- UE.plugins["addannotations"] = function() {
- let me = this;
- function createSpan(){
- let span = me.document.createElement("label");
- span.classList.add("note");
- span.setAttribute("note","true");
- span.setAttribute("data-original","");
- span.setAttribute("data-create-time", util.formatDate(new Date()));
- span.setAttribute("data-creator", me.options.userName);
- // span.setAttribute("data-id", dataId);
- return span;
- }
- function setAndShowRemark(){
- if(!me.options.annotations){
- me.options.annotations = !me.options.annotations;
- me.document.addEventListener("input", emrRemark.annotationsInput);
- // 设置批注为选中状态
- let toolbar = document.querySelector(".edui-for-annotations");
- if(toolbar && toolbar.firstChild){
- toolbar.firstChild.classList.add("edui-active");
- }
- }
- emrRemark.showAllRemark();
- }
- me.commands["addannotations"] = {
- execCommand: function(cmd,ui) {
- // console.log("addannotations")
- let range = me.selection.getRange().adjustmentBoundary();
- // console.log(range.startContainer)
- // 处理牙位
- let startA = emrRemark.getParentA(range.startContainer);
- let endA = emrRemark.getParentA(range.endContainer);
- // console.log(startA);
- // console.log(endA);
- // 同一个牙位
- if(startA && endA && startA == endA && startA.getAttribute("datatype") == "tooth"){
- let tooth = startA.querySelector(".tooth-all");
- tooth.innerHTML = '<label class="note" note="true" data-create-time="'+util.formatDate(new Date())
- +'" data-creator="'+me.options.userName+'" data-original="">'+tooth.innerHTML+'</label>';
- setAndShowRemark();
- return false;
- }
- // 处理牙位 end
- // 处理图片
- if(startA && endA && startA == endA && startA.getAttribute("datatype") == "imgUpload"){
- let note = me.document.createElement("label");
- note.className = "note";
- note.style.position="absolute";
- // 是否可以单独remove而不需要其他处理
- note.setAttribute("remove","true");
- note.setAttribute("note","true");
- note.setAttribute("data-create-time", util.formatDate(new Date()));
- note.setAttribute("data-creator", me.options.userName);
- note.setAttribute("data-original", "");
- let cupload = startA.querySelector(".Cupload")
- cupload.prepend(note);
-
- setAndShowRemark();
- // startA.innerHTML = '<label class="note" note="true" data-create-time="'+util.formatDate(new Date())
- // +'" data-creator="'+me.options.userName+'" data-original="">'+startA.innerHTML+'</label>';
- return false;
- }
- // 处理图片 end
- //若是未选择,就在当前位置插入节点
- if(range.endOffset == range.startOffset){
- range.insertNode(createSpan());
- setAndShowRemark();
- return;
- }
- //若是已经选择,走以下流程
- // let endOffset = range.endOffset;
- // console.log(range);
- // 起始节点若是空的,跳过
- let rangeNode = null;
- range.traversal(function(node){
- let content = node.textContent;
- if(content && content.trim() && !rangeNode){
- rangeNode = node;
- return false;
- }
- });
- range.setStart(rangeNode,0);
- // console.log(rangeNode);
- // console.log(range);
- range.applyInlineStyle("label",{
- "class":"note",
- "note":"true",
- "data-original":"",
- "data-create-time": util.formatDate(new Date()),
- "data-creator": me.options.userName
- }, null, true);
- // let text = startNode.textContent;
- // let selectText = "";
- // let preText = text.substring(0,range.startOffset);
- // let suffText = "";
- // // 若是选择同一个元素,则按位移量获取文本,若不是同一个元素,则以起始元素为准,结束位移量就是起始元素的结束位置
- // if(range.startContainer == range.endContainer){
- // selectText = text.substring(range.startOffset,endOffset);
- // suffText = text.substring(endOffset,text.length);
- // } else {
- // selectText = text.substring(range.startOffset,text.length);
- // }
-
- // let resultText = '<span class="note" note="true" data-create-time="'+datetime
- // +'" data-creator="'+me.options.userName+'" data-id="'+remarkId+'">'+selectText+'</span>';
- // console.log("preText=="+preText);
- // console.log("selectText=="+selectText);
- // console.log("suffText=="+suffText);
- // console.log("resultText=="+resultText);
- // startNode.parentNode.innerHTML = startNode.parentNode.innerHTML.replace(selectText,resultText);
- // console.log(me.selection)
- me.selection.clearRange();
- // debugger
- setAndShowRemark();
- }
- }
- };
- //end UE.plugins["addannotations"]
- /** 签名
- * **/
- UE.plugins["sign"] = function() {
- let me = this;
- me.commands["sign"] = {
- execCommand: function(cmd) {
- sign(me);
- }
- }
- };
|