性能优化

This commit is contained in:
alvis
2020-06-22 21:35:16 +08:00
parent e64c9c17c2
commit f11530bc96
69 changed files with 66 additions and 126458 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,81 +1 @@
(function () {
var parent = window.parent;
//dialog对象
dialog = parent.$EDITORUI[window.frameElement.id.replace( /_iframe$/, '' )];
//当前打开dialog的编辑器实例
editor = dialog.editor;
UE = parent.UE;
domUtils = UE.dom.domUtils;
utils = UE.utils;
browser = UE.browser;
ajax = UE.ajax;
$G = function ( id ) {
return document.getElementById( id )
};
//focus元素
$focus = function ( node ) {
setTimeout( function () {
if ( browser.ie ) {
var r = node.createTextRange();
r.collapse( false );
r.select();
} else {
node.focus()
}
}, 0 )
};
utils.loadFile(document,{
href: "../themes/default/dialogbase.css?cache="+Math.random(),//xlz原来的路径写错了去掉了一个../
tag:"link",
type:"text/css",
// rel:"stylesheet"
});
lang = editor.getLang(dialog.className.split( "-" )[2]);
if(lang){
domUtils.on(window,'load',function () {
var langImgPath = editor.options.langPath + editor.options.lang + "/images/";
//针对静态资源
for ( var i in lang["static"] ) {
var dom = $G( i );
if(!dom) continue;
var tagName = dom.tagName,
content = lang["static"][i];
if(content.src){
//clone
content = utils.extend({},content,false);
content.src = langImgPath + content.src;
}
if(content.style){
content = utils.extend({},content,false);
content.style = content.style.replace(/url\s*\(/g,"url(" + langImgPath)
}
switch ( tagName.toLowerCase() ) {
case "var":
dom.parentNode.replaceChild( document.createTextNode( content ), dom );
break;
case "select":
var ops = dom.options;
for ( var j = 0, oj; oj = ops[j]; ) {
oj.innerHTML = content.options[j++];
}
for ( var p in content ) {
p != "options" && dom.setAttribute( p, content[p] );
}
break;
default :
domUtils.setAttributes( dom, content);
}
}
} );
}
})();
!function(){var e=window.parent;dialog=e.$EDITORUI[window.frameElement.id.replace(/_iframe$/,"")],editor=dialog.editor,UE=e.UE,domUtils=UE.dom.domUtils,utils=UE.utils,browser=UE.browser,ajax=UE.ajax,$G=function(e){return document.getElementById(e)},$focus=function(t){setTimeout(function(){if(browser.ie){var e=t.createTextRange();e.collapse(!1),e.select()}else t.focus()},0)},utils.loadFile(document,{href:"../themes/default/dialogbase.css?cache="+Math.random(),tag:"link",type:"text/css"}),lang=editor.getLang(dialog.className.split("-")[2]),lang&&domUtils.on(window,"load",function(){var e=editor.options.langPath+editor.options.lang+"/images/";for(var t in lang.static){var a=$G(t);if(a){var o=a.tagName,i=lang.static[t];switch(i.src&&((i=utils.extend({},i,!1)).src=e+i.src),i.style&&((i=utils.extend({},i,!1)).style=i.style.replace(/url\s*\(/g,"url("+e)),o.toLowerCase()){case"var":a.parentNode.replaceChild(document.createTextNode(i),a);break;case"select":for(var s,r=a.options,l=0;s=r[l];)s.innerHTML=i.options[l++];for(var n in i)"options"!=n&&a.setAttribute(n,i[n]);break;default:domUtils.setAttributes(a,i)}}}})}();

View File

@@ -1,84 +1 @@
body{
overflow: hidden;
width: 540px;
}
.wrapper {
margin: 10px auto 0;
font-size: 12px;
overflow: hidden;
width: 520px;
height: 315px;
}
.clear {
clear: both;
}
.wrapper .left {
float: left;
margin-left: 10px;;
}
.wrapper .right {
float: right;
border-left: 2px dotted #EDEDED;
padding-left: 15px;
}
.section {
margin-bottom: 15px;
width: 240px;
overflow: hidden;
}
.section h3 {
font-weight: bold;
padding: 5px 0;
margin-bottom: 10px;
border-bottom: 1px solid #EDEDED;
font-size: 12px;
}
.section ul {
list-style: none;
overflow: hidden;
clear: both;
}
.section li {
float: left;
width: 120px;;
}
.section .tone {
width: 80px;;
}
.section .preview {
width: 220px;
}
.section .preview table {
text-align: center;
vertical-align: middle;
color: #666;
}
.section .preview caption {
font-weight: bold;
}
.section .preview td {
border-width: 1px;
border-style: solid;
height: 22px;
}
.section .preview th {
border-style: solid;
border-color: #DDD;
border-width: 2px 1px 1px 1px;
height: 22px;
background-color: #F7F7F7;
}
body{overflow:hidden;width:540px}.wrapper{margin:10px auto 0;font-size:12px;overflow:hidden;width:520px;height:315px}.clear{clear:both}.wrapper .left{float:left;margin-left:10px}.wrapper .right{float:right;border-left:2px dotted #ededed;padding-left:15px}.section{margin-bottom:15px;width:240px;overflow:hidden}.section h3{font-weight:bold;padding:5px 0;margin-bottom:10px;border-bottom:1px solid #ededed;font-size:12px}.section ul{list-style:none;overflow:hidden;clear:both}.section li{float:left;width:120px}.section .tone{width:80px}.section .preview{width:220px}.section .preview table{text-align:center;vertical-align:middle;color:#666}.section .preview caption{font-weight:bold}.section .preview td{border-width:1px;border-style:solid;height:22px}.section .preview th{border-style:solid;border-color:#DDD;border-width:2px 1px 1px 1px;height:22px;background-color:#f7f7f7}

View File

@@ -1,237 +1 @@
/**
* Created with JetBrains PhpStorm.
* User: xuheng
* Date: 12-12-19
* Time: 下午4:55
* To change this template use File | Settings | File Templates.
*/
(function () {
var title = $G("J_title"),
titleCol = $G("J_titleCol"),
caption = $G("J_caption"),
sorttable = $G("J_sorttable"),
autoSizeContent = $G("J_autoSizeContent"),
autoSizePage = $G("J_autoSizePage"),
tone = $G("J_tone"),
me,
preview = $G("J_preview");
var editTable = function () {
me = this;
me.init();
};
editTable.prototype = {
init:function () {
var colorPiker = new UE.ui.ColorPicker({
editor:editor
}),
colorPop = new UE.ui.Popup({
editor:editor,
content:colorPiker
});
title.checked = editor.queryCommandState("inserttitle") == -1;
titleCol.checked = editor.queryCommandState("inserttitlecol") == -1;
caption.checked = editor.queryCommandState("insertcaption") == -1;
sorttable.checked = editor.queryCommandState("enablesort") == 1;
var enablesortState = editor.queryCommandState("enablesort"),
disablesortState = editor.queryCommandState("disablesort");
sorttable.checked = !!(enablesortState < 0 && disablesortState >=0);
sorttable.disabled = !!(enablesortState < 0 && disablesortState < 0);
sorttable.title = enablesortState < 0 && disablesortState < 0 ? lang.errorMsg:'';
me.createTable(title.checked, titleCol.checked, caption.checked);
me.setAutoSize();
me.setColor(me.getColor());
domUtils.on(title, "click", me.titleHanler);
domUtils.on(titleCol, "click", me.titleColHanler);
domUtils.on(caption, "click", me.captionHanler);
domUtils.on(sorttable, "click", me.sorttableHanler);
domUtils.on(autoSizeContent, "click", me.autoSizeContentHanler);
domUtils.on(autoSizePage, "click", me.autoSizePageHanler);
domUtils.on(tone, "click", function () {
colorPop.showAnchor(tone);
});
domUtils.on(document, 'mousedown', function () {
colorPop.hide();
});
colorPiker.addListener("pickcolor", function () {
me.setColor(arguments[1]);
colorPop.hide();
});
colorPiker.addListener("picknocolor", function () {
me.setColor("");
colorPop.hide();
});
},
createTable:function (hasTitle, hasTitleCol, hasCaption) {
var arr = [],
sortSpan = '<span>^</span>';
arr.push("<table id='J_example'>");
if (hasCaption) {
arr.push("<caption>" + lang.captionName + "</caption>")
}
if (hasTitle) {
arr.push("<tr>");
if(hasTitleCol) { arr.push("<th>" + lang.titleName + "</th>"); }
for (var j = 0; j < 5; j++) {
arr.push("<th>" + lang.titleName + "</th>");
}
arr.push("</tr>");
}
for (var i = 0; i < 6; i++) {
arr.push("<tr>");
if(hasTitleCol) { arr.push("<th>" + lang.titleName + "</th>") }
for (var k = 0; k < 5; k++) {
arr.push("<td>" + lang.cellsName + "</td>")
}
arr.push("</tr>");
}
arr.push("</table>");
preview.innerHTML = arr.join("");
this.updateSortSpan();
},
titleHanler:function () {
var example = $G("J_example"),
frg=document.createDocumentFragment(),
color = domUtils.getComputedStyle(domUtils.getElementsByTagName(example, "td")[0], "border-color"),
colCount = example.rows[0].children.length;
if (title.checked) {
example.insertRow(0);
for (var i = 0, node; i < colCount; i++) {
node = document.createElement("th");
node.innerHTML = lang.titleName;
frg.appendChild(node);
}
example.rows[0].appendChild(frg);
} else {
domUtils.remove(example.rows[0]);
}
me.setColor(color);
me.updateSortSpan();
},
titleColHanler:function () {
var example = $G("J_example"),
color = domUtils.getComputedStyle(domUtils.getElementsByTagName(example, "td")[0], "border-color"),
colArr = example.rows,
colCount = colArr.length;
if (titleCol.checked) {
for (var i = 0, node; i < colCount; i++) {
node = document.createElement("th");
node.innerHTML = lang.titleName;
colArr[i].insertBefore(node, colArr[i].children[0]);
}
} else {
for (var i = 0; i < colCount; i++) {
domUtils.remove(colArr[i].children[0]);
}
}
me.setColor(color);
me.updateSortSpan();
},
captionHanler:function () {
var example = $G("J_example");
if (caption.checked) {
var row = document.createElement('caption');
row.innerHTML = lang.captionName;
example.insertBefore(row, example.firstChild);
} else {
domUtils.remove(domUtils.getElementsByTagName(example, 'caption')[0]);
}
},
sorttableHanler:function(){
me.updateSortSpan();
},
autoSizeContentHanler:function () {
var example = $G("J_example");
example.removeAttribute("width");
},
autoSizePageHanler:function () {
var example = $G("J_example");
var tds = example.getElementsByTagName(example, "td");
utils.each(tds, function (td) {
td.removeAttribute("width");
});
example.setAttribute('width', '100%');
},
updateSortSpan: function(){
var example = $G("J_example"),
row = example.rows[0];
var spans = domUtils.getElementsByTagName(example,"span");
utils.each(spans,function(span){
span.parentNode.removeChild(span);
});
if (sorttable.checked) {
utils.each(row.cells, function(cell, i){
var span = document.createElement("span");
span.innerHTML = "^";
cell.appendChild(span);
});
}
},
getColor:function () {
var start = editor.selection.getStart(), color,
cell = domUtils.findParentByTagName(start, ["td", "th", "caption"], true);
color = cell && domUtils.getComputedStyle(cell, "border-color");
if (!color) color = "#DDDDDD";
return color;
},
setColor:function (color) {
var example = $G("J_example"),
arr = domUtils.getElementsByTagName(example, "td").concat(
domUtils.getElementsByTagName(example, "th"),
domUtils.getElementsByTagName(example, "caption")
);
tone.value = color;
utils.each(arr, function (node) {
node.style.borderColor = color;
});
},
setAutoSize:function () {
var me = this;
autoSizePage.checked = true;
me.autoSizePageHanler();
}
};
new editTable;
dialog.onok = function () {
editor.__hasEnterExecCommand = true;
var checks = {
title:"inserttitle deletetitle",
titleCol:"inserttitlecol deletetitlecol",
caption:"insertcaption deletecaption",
sorttable:"enablesort disablesort"
};
editor.fireEvent('saveScene');
for(var i in checks){
var cmds = checks[i].split(" "),
input = $G("J_" + i);
if(input["checked"]){
editor.queryCommandState(cmds[0])!=-1 &&editor.execCommand(cmds[0]);
}else{
editor.queryCommandState(cmds[1])!=-1 &&editor.execCommand(cmds[1]);
}
}
editor.execCommand("edittable", tone.value);
autoSizeContent.checked ?editor.execCommand('adaptbytext') : "";
autoSizePage.checked ? editor.execCommand("adaptbywindow") : "";
editor.fireEvent('saveScene');
editor.__hasEnterExecCommand = false;
};
})();
!function(){function e(){(r=this).init()}var r,l=$G("J_title"),d=$G("J_titleCol"),i=$G("J_caption"),a=$G("J_sorttable"),c=$G("J_autoSizeContent"),m=$G("J_autoSizePage"),s=$G("J_tone"),u=$G("J_preview");e.prototype={init:function(){var e=new UE.ui.ColorPicker({editor:editor}),t=new UE.ui.Popup({editor:editor,content:e});l.checked=-1==editor.queryCommandState("inserttitle"),d.checked=-1==editor.queryCommandState("inserttitlecol"),i.checked=-1==editor.queryCommandState("insertcaption"),a.checked=1==editor.queryCommandState("enablesort");var o=editor.queryCommandState("enablesort"),n=editor.queryCommandState("disablesort");a.checked=!!(o<0&&0<=n),a.disabled=!!(o<0&&n<0),a.title=o<0&&n<0?lang.errorMsg:"",r.createTable(l.checked,d.checked,i.checked),r.setAutoSize(),r.setColor(r.getColor()),domUtils.on(l,"click",r.titleHanler),domUtils.on(d,"click",r.titleColHanler),domUtils.on(i,"click",r.captionHanler),domUtils.on(a,"click",r.sorttableHanler),domUtils.on(c,"click",r.autoSizeContentHanler),domUtils.on(m,"click",r.autoSizePageHanler),domUtils.on(s,"click",function(){t.showAnchor(s)}),domUtils.on(document,"mousedown",function(){t.hide()}),e.addListener("pickcolor",function(){r.setColor(arguments[1]),t.hide()}),e.addListener("picknocolor",function(){r.setColor(""),t.hide()})},createTable:function(e,t,o){var n=[];if(n.push("<table id='J_example'>"),o&&n.push("<caption>"+lang.captionName+"</caption>"),e){n.push("<tr>"),t&&n.push("<th>"+lang.titleName+"</th>");for(var i=0;i<5;i++)n.push("<th>"+lang.titleName+"</th>");n.push("</tr>")}for(var a=0;a<6;a++){n.push("<tr>"),t&&n.push("<th>"+lang.titleName+"</th>");for(var r=0;r<5;r++)n.push("<td>"+lang.cellsName+"</td>");n.push("</tr>")}n.push("</table>"),u.innerHTML=n.join(""),this.updateSortSpan()},titleHanler:function(){var e=$G("J_example"),t=document.createDocumentFragment(),o=domUtils.getComputedStyle(domUtils.getElementsByTagName(e,"td")[0],"border-color"),n=e.rows[0].children.length;if(l.checked){e.insertRow(0);for(var i,a=0;a<n;a++)(i=document.createElement("th")).innerHTML=lang.titleName,t.appendChild(i);e.rows[0].appendChild(t)}else domUtils.remove(e.rows[0]);r.setColor(o),r.updateSortSpan()},titleColHanler:function(){var e=$G("J_example"),t=domUtils.getComputedStyle(domUtils.getElementsByTagName(e,"td")[0],"border-color"),o=e.rows,n=o.length;if(d.checked)for(var i,a=0;a<n;a++)(i=document.createElement("th")).innerHTML=lang.titleName,o[a].insertBefore(i,o[a].children[0]);else for(a=0;a<n;a++)domUtils.remove(o[a].children[0]);r.setColor(t),r.updateSortSpan()},captionHanler:function(){var e=$G("J_example");if(i.checked){var t=document.createElement("caption");t.innerHTML=lang.captionName,e.insertBefore(t,e.firstChild)}else domUtils.remove(domUtils.getElementsByTagName(e,"caption")[0])},sorttableHanler:function(){r.updateSortSpan()},autoSizeContentHanler:function(){$G("J_example").removeAttribute("width")},autoSizePageHanler:function(){var e=$G("J_example"),t=e.getElementsByTagName(e,"td");utils.each(t,function(e){e.removeAttribute("width")}),e.setAttribute("width","100%")},updateSortSpan:function(){var e=$G("J_example"),t=e.rows[0],o=domUtils.getElementsByTagName(e,"span");utils.each(o,function(e){e.parentNode.removeChild(e)}),a.checked&&utils.each(t.cells,function(e,t){var o=document.createElement("span");o.innerHTML="^",e.appendChild(o)})},getColor:function(){var e=editor.selection.getStart(),t=domUtils.findParentByTagName(e,["td","th","caption"],!0);return t&&domUtils.getComputedStyle(t,"border-color")||"#DDDDDD"},setColor:function(t){var e=$G("J_example"),o=domUtils.getElementsByTagName(e,"td").concat(domUtils.getElementsByTagName(e,"th"),domUtils.getElementsByTagName(e,"caption"));s.value=t,utils.each(o,function(e){e.style.borderColor=t})},setAutoSize:function(){m.checked=!0,this.autoSizePageHanler()}},new e,dialog.onok=function(){editor.__hasEnterExecCommand=!0;var e={title:"inserttitle deletetitle",titleCol:"inserttitlecol deletetitlecol",caption:"insertcaption deletecaption",sorttable:"enablesort disablesort"};for(var t in editor.fireEvent("saveScene"),e){var o=e[t].split(" ");$G("J_"+t).checked?-1!=editor.queryCommandState(o[0])&&editor.execCommand(o[0]):-1!=editor.queryCommandState(o[1])&&editor.execCommand(o[1])}editor.execCommand("edittable",s.value),c.checked&&editor.execCommand("adaptbytext"),m.checked&&editor.execCommand("adaptbywindow"),editor.fireEvent("saveScene"),editor.__hasEnterExecCommand=!1}}();