QQ邮箱的一个文本编辑器代码

时间:2021-05-26

edt_color_slt.js
复制代码 代码如下:
var_r="";
varcolor_table=[
['000000','993300','333300','003300','003366','000080','333399','333333'],
['800000','FF6600','808000','008000','008080','0000FF','666699','808080'],
['FF0000','FF9900','99CC00','339966','33CCCC','3366FF','800080','999999'],
['FF00FF','FFCC00','FFFF00','00FF00','00FFFF','00CCFF','993366','C0C0C0'],
['FF99CC','FFCC99','FFFF99','CCFFCC','CCFFFF','99CCFF','CC99FF','FFFFFF']
];
functiona1(obj)
{
obj.style.border='1pxsolid#000080';
obj.style.background='#FFEEC2';
}
functiona2(obj)
{
obj.style.border='1pxsolid#F6F6F6';
obj.style.background='#F6F6F6';
}
functionpaintCell(color)
{
//_r+='<TDBGCOLOR="'+color+'"style="height:12px;width:12px;">';
_r+='<TDstyle="padding:2px;background:#f6f6f6;border:1pxsolid#f6f6f6"onmouseover="a1(this)"onmouseout="a2(this)">';
_r+="<IMGsrc='/htmledition/images/spacer.gif'HEIGHT=12WIDTH=12style='border:1pxsolid#ccc;background:#"+color+"'></TD>";
}
functionpaintRow(color_row)//一行
{
_r+='<TR>';
for(vari=0,l=color_row.length;i<l;++i)
{
paintCell(color_row[i]);
}
_r+='</TR>';
}
functionpaintTable(b)//表格
{
_r+='<TABLECELLPADDING=0CELLSPACING=0style="border:5pxsolid#F6F6F6">';
for(vari=0,l=b.length;i<l;++i){
paintRow(b[i]);
}
_r+='</TABLE>';
}
functionpaintCube(){//大边框
_r+='<TABLECELLPADDING=0CELLSPACING=0style="border:1pxsolid#888;"><TR>';
_r+='<TDBGCOLOR="#FFFFFF">';
paintTable(color_table);
_r+=('</TD>');
_r+='</TR></TR></TABLE>';
return_r;
}

edt_main.js
复制代码 代码如下:
//html输出
functionoutput(dat,templ,b)
{
for(vari=0;i<dat.length;i++)
{
vard=dat[i];
if(d.join)
{
for(varj=0;j<d.length;j++)
if(templ[j*2+1])
templ[j*2+1]=d[j];
if(b)alert(templ.join(""));
document.write(templ.join(""));
}
elsedocument.write(d);
}
}
//BIU
varcommFunc="onmousedown=OnTBMouseDown(this)onmouseover=OnTBMouseOver(this)onmouseout=OnTBMouseOut(this)";
varcommAttr='style="position:absolute;clip:rect($rect$);margin:$margin$;"title="$title$"';
varcommHead='<imgsrc="./images/editoricon.gif"'+commAttr;
varcommHeadMask='<imgsrc="./images/editoricon_mask.gif"'+commAttr;
varsComm=commHead+commFunc;



//模块结构:1.基础函数2.接口定义3.事件函数4.HTML编辑框5.全局事件绑定6.全局变量声明
//基础函数
functionGetDoc(win){return(win?win:window).document;}
functionS(i,win){returnGetDoc(win).getElementById(i);}
functionF(sID,win)//sunnyforfirefox
{
if(sID==""||sID==null)returnnull;
varframe=S(sID,win);
if(!frame)returnnull;
returnframe.contentWindow?frame.contentWindow:(win?win:window).frames[sID];
}
functionDisp(obj,flag)//0隐藏,1显示
{
if(obj){obj.style.display=flag?"":"none";}
}
functiongetPosX(e)
{
varl=e.offsetLeft;
while(e=e.offsetParent){
l+=e.offsetLeft;
}
returnl;
}
functiongetPosY(e)
{
vart=e.offsetTop;
while(e=e.offsetParent){
t+=e.offsetTop;
}
returnt;
}
String.prototype.trim=function(){
returnthis.replace(/(^\s*)|(\s*$)/g,"");
};

functionExecCmd(type,para){
LoadPos();
varf=F("HtmlEditor");
varsAlert="";
if(!gIsIE)
{
switch(type){
case"Cut":
sAlert="你的浏览器安全设置不允许编辑器自动执行剪切操作,请使用键盘快捷键(Ctrl+X)来完成";
break;
case"Copy":
sAlert="你的浏览器安全设置不允许编辑器自动执行拷贝操作,请使用键盘快捷键(Ctrl+C)来完成";
break;
case"Paste":
sAlert="你的浏览器安全设置不允许编辑器自动执行粘贴操作,请使用键盘快捷键(Ctrl+V)来完成";
break;
}
}
if(sAlert!=""){
alert(sAlert);
return;
}
f.focus();
vardoc=f.document;
if(!para)
{
gIsIE?doc.execCommand(type):doc.execCommand(type,false,false);
}
else
{
//为了图片插入后把焦点放到图片后面
if(type=="InsertImage"&&gIsIE){
varr=doc.selection.createRange();
}

doc.execCommand(type,false,para);

//为了图片插入后把焦点放到图片后面
if(type=="InsertImage"&&gIsIE){
r.move("character");
r.select();
}
}
f.focus();
}
functionIsValidURL(str)
{
return((str.indexOf("://")>1)||(str.indexOf(":\\")>1));
}
functionaddHyperLink(){
varf=F("HtmlEditor");
//哈哈,终于找到兼容mf噶方法
varsel=f.document.selection!=null?f.document.selection.createRange().text:f.document.getSelection();
if(sel.length>0)
{
varsURL=window.prompt("请输入链接的目标地址(e.g.http://mObjectCheck(document.activeElement,event.srcElement)){
setTimeout("LoadPos();HideMenu();",10);
}
}
}


//全局事件绑定
window.onblur=function(){
if(!gIsIE){
HideMenu();
}
};
window.onerror=function(){
returntrue;
};
document.onmousemove=function(e){

};
functionDectoHex(num){
vari,j=20,str="#",N="ABCDEF";
while(j>=0){
i=(num>>j)%16;
str+=(i>9)?N.charAt(i-10):i;
j-=4;
}
returnstr;
}
functionGetColorFromBg(bg)
{
vari=bg.indexOf("("),j=bg.indexOf(")"),s=bg.substr(i+1,j-i-1).split(",");
returnDectoHex((s[0]<<16)+(s[1]<<8)+parseInt(s[2]));
}
document.onclick=function(e){
if(gIsIE)varel=event.srcElement;
elsevarel=e.target;
vardvForeColor=S("dvForeColor");
vardvPortrait=S("dvPortrait");

try{

if(IsInColorBrd(el)){
//var_bgColor=(el.tagName=="IMG")?el.parentNode.bgColor:el.bgColor;
vart=el;
if(t.tagName!="IMG"){
t=t.getElementsByTagName("IMG")[0];
}
var_bgColor=t.style.background+"";
if(_bgColor.indexOf(")")>-1)//firefox
{
_bgColor=GetColorFromBg(_bgColor);
}
ExecCmd(gSetColorType,_bgColor);
Disp(dvForeColor,0);
return;
}

if(IsInMoBrd(el)){
vart=el;
if(t.tagName=="TD"){
t=el.getElementsByTagName("IMG")[0];
}
if(t.tagName=="IMG"&&t.attributes["data"]!=null)
{
ExecCmd("InsertImage",giMoBaseUrl+t.attributes["data"].nodeValue);
Disp(S("dvMo"),0);
}
return;
}
}catch(e){}

HideMenu();
varidTable=[
"imgFontface","fontface"
,"imgFontsize","fontsize"
,"imgFontColor","fontsize"
,"imgBackColor","dvForeColor"
,"imgFace","dvPortrait"
,"imgAlign","divAlign"
,"imgList","divList"];
for(vari=0;i<idTable.length;i+=2){
if(idTable[i]==el.id)
{
varobj=S(idTable[i+1]);
obj?(obj.style.display=""):0;
break;
}
}
};
//全局变量
public_description=neweditor;
vargSetColorType="";
vargIsIE=document.all;
vargIEVer=getIEVer();
vargLoaded=false;
varev=null;

//增加源代码编辑器...
//addbyangusdu2006-11-21
varcurEditor="Html";
functionEnableToolBar(flag){
vartools=document.getElementsByName("tool_mask");
for(i=tools.length-1;i>=0;i--){
Disp(tools[i],flag);
}
if(S("add_pic_id").style.display==""){
Disp(S("add_pic_mask_id"),flag);
}
}
functionChangeEditor(){
if(curEditor=="Html"){
curEditor="source";
Disp(S("sourceEditor"),1);
Disp(S("HtmlEditor"),0);
S("sourceEditor").value=HtmlEditor.document.body.innerHTML;
S("sourceEditor").focus();
S("htmlbtn").title="图文编辑";
S("htmlbtn").innerHTML="<aclass=abtnhref=javascript:void(0);>&lt;普通模式&gt;</a>";
EnableToolBar(1);
}
else{
curEditor="Html";
Disp(S("sourceEditor"),0);
Disp(S("HtmlEditor"),1);
HtmlEditor.document.body.innerHTML=S("sourceEditor").value;
F("HtmlEditor").focus();
S("htmlbtn").title="编辑HTML源码";
S("htmlbtn").innerHTML="<aclass=abtnhref=javascript:void(0);>&lt;HTML模式&gt;</a>";
EnableToolBar(0);
}
}
functionGetEditorType(){
return(curEditor=="Html"?"Html":"source");
}

//增加对编辑器的高度修改接口
vargMinSize=0;
functionGetMinSize(){
if(!gMinSize){
gMinSize=parseInt(S("HtmlEditor").style.height);
}
returngMinSize;
}
functionAddElementHeight(el,l){
el.style.height=(parseInt(el.style.height)+l)+"px";
}
functionStretchEditor(bIsLarge,l,frameid){
//默认伸缩长度为50px
l=(l!=null?l:50);
varpw=window.parent;
varpwif=pw.document.getElementsByTagName("iframe");
for(i=pwif.length-1;i>=0;i--){
if(pwif[i].id&&(frameid?pwif[i].id==frameid:GetDoc(pw.frames[pwif[i].id]).body.innerHTML==GetDoc().body.innerHTML)){
if(parseInt(S("HtmlEditor").style.height)<=GetMinSize()&&!bIsLarge){
return;
}
l=(bIsLarge?l:(-1)*l);
AddElementHeight(pwif[i],l);
AddElementHeight(S("HtmlEditor"),l);
AddElementHeight(S("sourceEditor"),l);
return;
}
}
}


本地下载

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章