📄 editor.js
字号:
if(this.btnOutdent)this.arrElm[27]=this.getElm("btnOutdent");
if(this.btnLTR)this.arrElm[28]=this.getElm("btnLTR");
if(this.btnRTL)this.arrElm[29]=this.getElm("btnRTL");
if(this.btnForeColor)this.arrElm[30]=this.getElm("btnForeColor");
if(this.btnBackColor)this.arrElm[31]=this.getElm("btnBackColor");
if(this.btnLine)this.arrElm[32]=this.getElm("btnLine");
}
function iwe_getElm(s)
{
return document.getElementById(s+this.oName)
}
/*********************
COLOR PICKER
**********************/
var arrColorPickerObjects=[];
function ColorPicker(sName,sParent)
{
this.oParent=sParent;
if(sParent)
{
this.oName=sParent+"."+sName;
this.oRenderName=sName+sParent;
}
else
{
this.oName=sName;
this.oRenderName=sName;
}
arrColorPickerObjects.push(this.oName);
this.url="color_picker.htm";
this.onShow=function(){return true;};
this.onHide=function(){return true;};
this.onPickColor=function(){return true;};
this.onRemoveColor=function(){return true;};
this.onMoreColor=function(){return true;};
this.show=showColorPicker;
this.hide=hideColorPicker;
this.hideAll=hideColorPickerAll;
this.color;
this.customColors=[];
this.refreshCustomColor=refreshCustomColor;
this.isActive=false;
this.txtCustomColors="Custom Colors";
this.txtMoreColors="More Colors...";
this.align="left";
this.currColor="#ffffff";//default current color
this.RENDER=drawColorPicker;
}
function drawColorPicker()
{
var arrColors=[["#800000","#8b4513","#006400","#2f4f4f","#000080","#4b0082","#800080","#000000"],
["#ff0000","#daa520","#6b8e23","#708090","#0000cd","#483d8b","#c71585","#696969"],
["#ff4500","#ffa500","#808000","#4682b4","#1e90ff","#9400d3","#ff1493","#a9a9a9"],
["#ff6347","#ffd700","#32cd32","#87ceeb","#00bfff","#9370db","#ff69b4","#dcdcdc"],
["#ffdab9","#ffffe0","#98fb98","#e0ffff","#87cefa","#e6e6fa","#dda0dd","#ffffff"]];
var sHTMLColor="<table id=dropColor"+this.oRenderName+" style=\"z-index:1;display:none;position:absolute;border:#716F64 1px solid;cursor:default;background-color:#f3f3f3;padding:2px\" unselectable=on cellpadding=0 cellspacing=0 width=143 height=109><tr><td unselectable=on>";
sHTMLColor+="<table align=center cellpadding=0 cellspacing=0 border=0 unselectable=on>";
for(var i=0;i<arrColors.length;i++)
{
sHTMLColor+="<tr>";
for(var j=0;j<arrColors[i].length;j++)
sHTMLColor+="<td onclick=\""+this.oName+".color='"+arrColors[i][j]+"';"+this.oName+".onPickColor();"+this.oName+".currColor='"+arrColors[i][j]+"';"+this.oName+".hideAll()\" onmouseover=\"this.style.border='#777777 1px solid'\" onmouseout=\"this.style.border='#efefef 1px solid'\" style=\"cursor:default;padding:1px;border:#efefef 1px solid;\" unselectable=on>"+
"<table style='margin:0;width:13px;height:13px;background:"+arrColors[i][j]+";border:white 1px solid' cellpadding=0 cellspacing=0 unselectable=on>"+
"<tr><td unselectable=on></td></tr>"+
"</table></td>";
sHTMLColor+="</tr>";
}
//~~~ custom colors ~~~~
sHTMLColor+="<tr><td colspan=8 id=idCustomColor"+this.oRenderName+"></td></tr>";
//~~~ remove color & more colors ~~~~
sHTMLColor+= "<tr>";
sHTMLColor+= "<td unselectable=on>"+
"<table style='margin-left:1px;width:14px;height:14px;background:#f3f3f3;' cellpadding=0 cellspacing=0 unselectable=on>"+
"<tr><td onclick=\""+this.oName+".onRemoveColor();"+this.oName+".currColor='';"+this.oName+".hideAll()\" onmouseover=\"this.style.border='#777777 1px solid'\" onmouseout=\"this.style.border='white 1px solid'\" style=\"cursor:default;padding:1px;border:white 1px solid;font-family:verdana;font-size:10px;font-color:black;line-height:9px;\" align=center valign=top unselectable=on>x</td></tr>"+
"</table></td>";
sHTMLColor+= "<td colspan=7 unselectable=on>"+
"<table style='margin:1px;width:117px;height:16px;background:#f3f3f3;border:#f3f3f3 1px solid' cellpadding=0 cellspacing=0 unselectable=on>"+
"<tr><td onclick=\""+this.oName+".onMoreColor();"+this.oName+".hideAll();window.showModelessDialog('"+this.url+"',[window,'"+this.oName+"'],'dialogWidth:432px;dialogHeight:427px;edge:Raised;center:1;help:0;resizable:1;')\" onmouseover=\"this.style.border='#777777 1px solid';this.style.background='#8d9aa7';this.style.color='#ffffff'\" onmouseout=\"this.style.border='#efefef 1px solid';this.style.background='#f3f3f3';this.style.color='#000000'\" style=\"cursor:default;padding:1px;border:#efefef 1px solid\" style=\"font-family:verdana;font-size:9px;font-color:black;line-height:9px;padding:1px\" align=center valign=top nowrap unselectable=on>"+this.txtMoreColors+"</td></tr>"+
"</table></td>";
sHTMLColor+= "</tr>";
sHTMLColor+= "</table>";
sHTMLColor+="</td></tr></table>";
document.write(sHTMLColor);
}
function refreshCustomColor()
{
this.customColors=eval(this.oParent).customColors;//[CUSTOM] (Get from public definition)
if(this.customColors.length==0)
{
eval("idCustomColor"+this.oRenderName).innerHTML="";
return;
}
sHTML="<table cellpadding=0 cellspacing=0 width=100%><tr><td colspan=8 style=\"font-family:verdana;font-size:9px;font-color:black;line-height:9px;padding:1\">"+this.txtCustomColors+":</td></tr></table>";
sHTML+="<table cellpadding=0 cellspacing=0><tr>";
for(var i=0;i<this.customColors.length;i++)
{
if(i<22)
{
if(i==8||i==16||i==24||i==32)sHTML+="</tr></table><table cellpadding=0 cellspacing=0><tr>";
sHTML+="<td onclick=\""+this.oName+".color='"+this.customColors[i]+"';"+this.oName+".onPickColor()\" onmouseover=\"this.style.border='#777777 1px solid'\" onmouseout=\"this.style.border='#efefef 1px solid'\" style=\"cursor:default;padding:1px;border:#efefef 1px solid;\" unselectable=on>"+
" <table style='margin:0;width:13;height:13;background:"+this.customColors[i]+";border:white 1px solid' cellpadding=0 cellspacing=0 unselectable=on>"+
" <tr><td unselectable=on></td></tr>"+
" </table>"+
"</td>";
}
}
sHTML+="</tr></table>";
eval("idCustomColor"+this.oRenderName).innerHTML=sHTML;
}
function showColorPicker(oEl)
{
this.onShow();
this.hideAll();
var box=eval("dropColor"+this.oRenderName);
box.style.display="block";
var nTop=0;
var nLeft=0;
oElTmp=oEl;
while(oElTmp.tagName!="BODY" && oElTmp.tagName!="HTML")
{
if(oElTmp.style.top!="")
nTop+=oElTmp.style.top.substring(1,oElTmp.style.top.length-2)*1;
else nTop+=oElTmp.offsetTop;
oElTmp = oElTmp.offsetParent;
}
oElTmp=oEl;
while(oElTmp.tagName!="BODY" && oElTmp.tagName!="HTML")
{
if(oElTmp.style.left!="")
nLeft+=oElTmp.style.left.substring(1,oElTmp.style.left.length-2)*1;
else nLeft+=oElTmp.offsetLeft;
oElTmp=oElTmp.offsetParent;
}
if(this.align=="left") box.style.left=nLeft;
else box.style.left=nLeft-143+oEl.offsetWidth;
box.style.top=nTop+1+oUtil.obj.dropTopAdjustment;//[CUSTOM]
//box.style.top=nTop+1+oEl.offsetHeight;//[CUSTOM]
this.isActive=true;
this.refreshCustomColor();
}
function hideColorPicker()
{
this.onHide();
var box=eval("dropColor"+this.oRenderName);
box.style.display="none";
this.isActive=false;
}
function hideColorPickerAll()
{
for(var i=0;i<arrColorPickerObjects.length;i++)
{
var box=eval("dropColor"+eval(arrColorPickerObjects[i]).oRenderName);
box.style.display="none";
eval(arrColorPickerObjects[i]).isActive=false;
}
}
/*********************
CONTENT
**********************/
function loadHTML(sHTML)//hanya utk first load.
{
var oEditor=eval("idContent"+this.oName);
var oDoc=oEditor.document.open("text/html","replace");
if(this.publishingPath!="")
{
var arrA = String(this.preloadHTML).match(/<base[^>]*>/ig);
if(!arrA)
{//if no <base> found
sHTML=this.docType+"<HTML><HEAD><BASE HREF=\""+this.publishingPath+"\"/>"+this.headContent+"</HEAD><BODY contentEditable=true>" + sHTML + "</BODY></HTML>";
//kalau cuma tambah <HTML><HEAD></HEAD><BODY.. tdk apa2.
}
}
else
{
sHTML=this.docType+"<HTML><HEAD>"+this.headContent+"</HEAD><BODY contentEditable=true>"+sHTML+"</BODY></HTML>";
}
oDoc.write(sHTML);
oDoc.close();
oEditor.document.body.contentEditable=true;
oEditor.document.execCommand("2D-Position", true, true);//make focus
oEditor.document.execCommand("MultipleSelection", true, true);//make focus
oEditor.document.execCommand("LiveResize", true, true);//make focus
//RealTime
oEditor.document.body.onkeydown = new Function("editorDoc_onkeydown('"+this.oName+"')");
oEditor.document.body.onkeyup = new Function("editorDoc_onkeyup('"+this.oName+"')");
oEditor.document.body.onmouseup = new Function("editorDoc_onmouseup('"+this.oName+"')");
//Save for Undo
oEditor.document.body.onpaste = new Function(this.oName+".doOnPaste()");
oEditor.document.body.oncut = new Function(this.oName+".saveForUndo()");
//Styles
if(this.arrStyle.length>0)
{
var oElement=oEditor.document.createElement("<STYLE>");
oEditor.document.documentElement.childNodes[0].appendChild(oElement);
for(var i=0;i<this.arrStyle.length;i++)
{
selector=this.arrStyle[i][0];
style=this.arrStyle[i][3];
oEditor.document.styleSheets(0).addRule(selector,style);
}
}
//*** RUNTIME STYLES ***
this.runtimeBorder(false);
this.runtimeStyles();
//***********************
//fix undisplayed content
if(this.initialRefresh)
{
oEditor.document.execCommand("SelectAll");
window.setTimeout("eval('idContentWord"+this.oName+"').document.execCommand('SelectAll');",0);
}
oEditor.document.body.style.width=50;
oEditor.document.body.style.height=50;
oEditor.document.body.style.width="";
oEditor.document.body.style.height="";
//oEditor.document.body.style.cssText="overflow-x:scroll;overflow-y:scroll";
if(this.css!="")
{
eval("myStyle"+this.oName).document.open("text/html","replace");
eval("myStyle"+this.oName).document.write("<html><head><link href=\""+this.css+"\" rel=\"stylesheet\" type=\"text/css\"></head><body onload=\"parent.ApplyExternalStyle('"+this.oName+"')\"></body></html>");
eval("myStyle"+this.oName).document.close();
try{ApplyExternalStyle(this.oName)}
catch(e){;}
}
//<br> or <p>
oEditor.document.body.onkeydown=new Function("doKeyPress(eval('idContent"+this.oName+"').event,'"+this.oName+"')");
}
function doOnPaste()
{
this.isAfterPaste=true;
eval(this.oName).saveForUndo();//Save for Undo
}
function putHTML(sHTML)//used by source editor
{
var oEditor=eval("idContent"+this.oName);
//save doctype (if any/if not body only)
var arrA=String(sHTML).match(/<!DOCTYPE[^>]*>/ig);
if(arrA)
for(var i=0;i<arrA.length;i++)
{
this.docType=arrA[i];
}
else this.docType="";//back to default value
//save html (if any/if not body only)
var arrB=String(sHTML).match(/<HTML[^>]*>/ig);
if(arrB)
for(var i=0;i<arrB.length;i++)
{
s=arrB[i];
s=s.replace(/\"[^\"]*\"/ig,function(x){
x=x.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'").replace(/[\s+]/ig,"#_#");
return x});
s=s.replace(/<([^ >]*)/ig,function(x){return x.toLowerCase()});
s=s.replace(/ ([^=]+)=([^" >]+)/ig," $1=\"$2\"");
s=s.replace(/ ([^=]+)=/ig,function(x){return x.toLowerCase()});
s=s.replace(/#_#/ig," ");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -