欢迎来到福编程网,本站提供各种互联网专业知识!

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

发布时间:2007-03-14 作者: 来源:转载
edt_color_slt.js复制代码代码如下:var_r="";varcolor_table=[['000000','993300','333300','003300','003366','000080','333399','333333'],['800000','FF6600','808000','008000','008080','0000FF','666699','808080'],
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+='';
_r+='';
_r+="";
}
functionpaintRow(color_row)//一行
{
_r+='';
for(vari=0,l=color_row.length;i{
paintCell(color_row[i]);
}
_r+='';
}
functionpaintTable(b)//表格
{
_r+='';
for(vari=0,l=b.length;ipaintRow(b[i]);
}
_r+='';
}
functionpaintCube(){//大边框
_r+='';
_r+='';
paintTable(color_table);
_r+=('');
_r+='';
return_r;
}

edt_main.js
复制代码 代码如下:
//html输出
functionoutput(dat,templ,b)
{
for(vari=0;i{
vard=dat[i];
if(d.join)
{
for(varj=0;jif(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='varcommHeadMask='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://www.qq.com/):","http://");
if(sURL!=null)
{
if(!IsValidURL(sURL))
{
sURL="http://"+sURL;
}
F("HtmlEditor").document.execCommand("CreateLink",false,sURL);
}
}
else
{
alert("请先选择要连接的文字。");
}
}
functionaddImage()
{
varwidth="380px",height="150px";
//modifybyangusdu2006-10-13
//showModalDialog("uploadImg.htm",window,vfeature);
varurl="uploadImg.htm";
if(gIsIE)//IE
{
window.showModalDialog(url,window,"dialogWidth:"+width+";dialogHeight:"+height+";center:Yes;help:off;status:no;scroll:no");
}
else
{
window.open(url,window,"width="+width+",height="+height+",menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes");
}
}
functiongetIEVer(){
vars=navigator.userAgent;
if(s.indexOf("MSIE")>-1)
returnparseFloat(s.split(";")[1].replace("MSIE",""));
}
//接口定义
functioneditor()
{
this.get_contents=GetContents;
this.get_plaincontents=GetPlainContents;
this.put_contents=PutContents;
this.put_plaincontents=PutPlainContents;
this.put_firstline=PutFirstLine;
}
functionPutFirstLine(s)
{
return;
}
functionGetContents(){
if(curEditor=="source")
returnS("sourceEditor").value;
returnHtmlEditor.document.body.innerHTML;
}
functionGetPlainContents(){
//modifybyangusdu2006-10-11
varbc=HtmlEditor.document.body;
if(curEditor=="source")
bc.innerHTML=S("sourceEditor").value;
if(bc.innerText!=null){
returnbc.innerText;
}
else{
returnbc.textContent;
}
}
functionPutContents(contents)
{
HtmlEditor.document.designMode="on";
HtmlEditor.document.body.innerHTML=contents;
SetDiv();
S("sourceEditor").value=HtmlEditor.document.body.innerHTML;
}

functionPutPlainContents(contents)
{
HtmlEditor.document.designMode="on";
//modifybyangusdu2006-10-12
varbc=HtmlEditor.document.body;
if(bc.innerText!=null){
bc.innerText=contents;
}
else{
bc.textContent=contents;
}
S("sourceEditor").value=HtmlEditor.document.body.innerHTML;
}
//==========
//事件函数
functionOnLoad(){
try
{
if(!window.top.isFireFox)
{
F("HtmlEditor").document.designMode="on";
}
gLoaded=true;
SetEditable();
SetFrameClick();
document.parentWindow.onclick=HideMenu();
}catch(e){
}
setTimeout(SetColor,100);//--sunny一开始就画颜色表,那么第一次就不会慢了
}
vareditorTxtRange=null;
functionSavePos(){
if(document.selection){
editorTxtRange=F("HtmlEditor").document.selection.createRange();
}
}
functionLoadPos(){
if(editorTxtRange){
editorTxtRange.select();
editorTxtRange=null;
}
}
//sunny:foreColor与backColor只是负责弹出ColorBoard,不需要ExecCmd(此时ExecCmd会导致白色)
functionOnForeColor(e){
SavePos();
HideMenu();
varsColor=DispColorBrd(e);
gSetColorType="foreColor";
if(gIsIE&&gIEVer<6)
{
ExecCmd(gSetColorType,sColor);
}
return;
}
functionOnBackColor(e){
SavePos();
HideMenu();
varsColor=DispColorBrd(e,1);
gSetColorType=(gIsIE)?"backColor":"hilitecolor";
if(gIsIE&&gIEVer<6)
{
ExecCmd(gSetColorType,sColor);
}
return
}

functionOnMo(e){
SavePos();
HideMenu();
varsMo=DispMoBrd(e);
if(gIsIE&&gIEVer<6&&sMo!=null)
{
ExecCmd("InsertImage",sMo);
}
return;
}
functionOnTBMouseOver(obj){
SetBorderMouse(obj,0);
}
functionOnTBMouseDown(obj){
SetBorderMouse(obj,1);
}
functionOnTBMouseOut(obj){
obj.style.border="none";
}
//HTML编辑框
functionSetEditable(){
vardoc=window.frames["HtmlEditor"].document;
doc.designMode="on";
if(!gIsIE){
//angus:难怪,察看ff的文档发现,如此说明:usefalsetouseCSS,truetouseHTML
doc.execCommand("useCSS",false,false);
}
}
functionSetFrameClick(){
varfrm=window.frames["HtmlEditor"];
vardoc=frm.document;
doc.onmousemove=function(){
window.onblur();
};
doc.onclick=function(){
//alert("aa")
HideMenu();
};
doc.onkeydown=function()
{
if(frm.event.keyCode==13&&frm.event.ctrlKey)
{
if(parent.DoCtrlEnter)parent.DoCtrlEnter();
}
//top.frames["jsFrame"].gIsEdited=true;
};
}
functionSetDiv()
{

varloc=""+window.parent.location;
if(loc.indexOf("setting")>0)
{
Disp(document.getElementById("add_pic_id"),0);
/*removedbyangusdu2006-11-17
if(!/^

/.test(HtmlEditor.document.body.innerHTML))
{
HtmlEditor.document.body.innerHTML=HtmlEditor.document.body.innerHTML+"
";
}
*/S("HtmlEditor").style.height=gIsIE?"182px":"188px";
S("sourceEditor").style.height="184px";
S("sourceEditor").style.width="100%";
S("htmlbtn").style.marginLeft="393px";
}
elseif(loc.indexOf("compose_card")>0)
{
Disp(document.getElementById("add_pic_id"),0);
S("HtmlEditor").style.height="181px";
S("sourceEditor").style.height="183px";
S("sourceEditor").style.width="100%";
}
elseif(loc.indexOf("compose")>0)
{
if(GetSetting())
{
if(HtmlEditor.document.getElementById("QQMail_signature"))
{
HtmlEditor.document.getElementById("QQMail_signature").innerHTML=GetSetting().nSignature;
}

}
}

vardoc=F("HtmlEditor").document;
doc.designMode="on";

//HtmlEditor.document.body.innerHTML="

"+HtmlEditor.document.body.innerHTML;
if(doc.body)
{
doc.body.style.background='#ffffff';
doc.body.style.fontSize='12px';
doc.body.style.fontFamily='verdana';
try
{
if(HtmlEditor.document.body.innerHTML.indexOf("")>-1)
{
doc.body.style.margin='0.5%000';
doc.body.style.background='#fff';
doc.body.style.fontSize='12px';
return;
}

}catch(e)
{}
doc.body.style.margin='4px';
}
}
functionSetColor(){
vardvForeColor=S("dvForeColor");
if(dvForeColor.getElementsByTagName("TABLE").length==1){
dvForeColor.innerHTML=paintCube();//+dvForeColor.innerHTML;
//window.top.document.write(dvForeColor.innerHTML);
}
}
functionSetMo(){
vardvMo=S("dvMo");
dvMo.innerHTML=moCube();
}
//工具栏
//addbyangusdu2006-10-13
functionshowDialog(url,type,feature)
{
if(gIsIE)//IE
{
returnwindow.showModalDialog(url,type,feature);
}
else
{
//modelessDialog可以将modal换成dialog=yes
feature="width=300,height=200,menubar=no,toolbar=no,location=no,";
feature+="scrollbars=no,status=no,modal=yes";
window.open(url,type,feature);
}
}
functionDispColorBrd(e,isBC){
if(gIEVer<6&&gIsIE){
vararr=showModalDialog("color_slt.html","","font-family:Verdana;font-size:12;status:no;dialogWidth:17em;dialogHeight:14em");
if(arr!=null)returnarr;
return;
}
vardvForeColor=S("dvForeColor");
SetColor();
Disp(dvForeColor,1);
dvForeColor.style.left=(isBC?bcL:fcL)+"px";
dvForeColor.style.top=33+"px";
dvForeColor.focus();
e.cancelBubble=true;
returntrue;
}
functionDispMoBrd(e){
if(gIEVer<6&&gIsIE){
vararr=showModalDialog("mo_slt.html","","font-family:Verdana;font-size:12;status:no;dialogWidth:265px;dialogHeight:190px");
if(arr!=null)returnarr;
return;
}
vardvMo=S("dvMo");
SetMo();
Disp(dvMo,1);
dvMo.focus();
e.cancelBubble=true;
returntrue;
}
functionCommCheck(obj,str,func)
{
if(obj.id==str){
returntrue;
}
if(obj.parentNode){
returnfunc(obj.parentNode);
}
returnfalse;
}
functionCommObjectCheck(obj,inObj)
{
if(obj==inObj)
{
returntrue;
}
if(obj.parentNode){
returnCommObjectCheck(obj.parentNode,inObj);
}
returnfalse;
}
functionHideMenu()
{
varelementTable=["fontface","fontsize","dvForeColor","dvPortrait","divAlign","divList","dvMo"];
for(vari=0;iDisp(S(elementTable[i]),0);
}
functionIsInColorBrd(obj){
returnCommCheck(obj,"dvForeColor",IsInColorBrd);
}
functionIsInFontFaceBrd(obj){
returnCommCheck(obj,"fontface",IsInFontFaceBrd);
}
functionIsInFontSizeBrd(obj){
returnCommCheck(obj,"fontsize",IsInFontSizeBrd);
}
functionIsInMoBrd(obj){
returnCommCheck(obj,"dvMo",IsInMoBrd);
}
functionSetBorderMouse(obj,flag)//flag:0over1out
{
vard=[
["1pxsolid#fff","1pxsolid#fff","1pxsolid#F3F8FC","1pxsolid#F3F8FC"]
,["1pxsolid#ccc","1pxsolid#ccc","1pxsolid#F3F8FC","1pxsolid#ccc"]][flag];
obj.style.borderTop=d[0];
obj.style.borderRight=d[1];
obj.style.borderBottom=d[2];
obj.style.borderLeft=d[3];
}
functionDispBoard(element,displayValue,nLeft){
if(gIEVer<=5.01&&gIsIE){
if(element=="fontface"){
varsReturnValue=showModalDialog("fontface_slt.html","","font-family:Verdana;font-size:12;status:no;unadorned:yes;scroll:no;resizable:yes;dialogWidth:112px;dialogHeight:271px");;
ExecCmd("fontname",sReturnValue);
}elseif(element=="fontsize"){
varsReturnValue=showModalDialog("fontsize_slt.html","","font-family:Verdana;font-size:12;status:no;unadorned:yes;scroll:no;resizable:yes;dialogWidth:130px;dialogHeight:250px");;
ExecCmd("fontsize",sReturnValue);
}
return;
}
HideMenu();
if(typeofelement=="string")
element=S(element);
if(element==null)return;
element.style.display=displayValue;
SavePos();
if(gIsIE){
vare=event;
}else{
vare=ev;
}
variX=e.clientX;
variY=e.clientY;
Disp(element,1);
element.style.left=((null==nLeft)?(iX-30):nLeft)+"px";
element.style.top=33+"px";
setTimeout("document.getElementById('"+element.id+"').focus();",500);
returntrue;
}
functionSaveEvent(e){
ev=e;
}
//qqmail增加的函数

functionfSetReplyContent(){
try{
win.fSetComposeContent(win.gReplyContent);
window.frames["HtmlEditor"].focus();
}catch(exp){
window.setTimeout('fSetReplyContent()',1000);
}
win.gReplyContent=null;
}

functionsetContentType(ContentType)
{
alert("setContentType");
if(ContentType=="text")
{
PutContents(GetPlainContents());
}
window.parent.contenttype.value=ContentType;

}

functionGetSetting()
{
try
{
returnwindow.top.GetApp().setting;
}catch(e)
{}
returnnull;
}

functionBrdBlur(){
if(gIsIE)
{
if(!CommObjectCheck(document.activeElement,event.srcElement)){
setTimeout("LoadPos();HideMenu();",10);
}
}
}


//全局事件绑定
window.onblur=function(){
if(!gIsIE){
HideMenu();
}
};
window.onerror=function(){
returntrue;
};
document.onmousemove=function(e){
/*if(gIsIE)varel=event.srcElement;
elsevarel=e.target;
vartdView=S("tdView");
vartdColorCode=S("tdColorCode");
vardvForeColor=S("dvForeColor");
vardvPortrait=S("dvPortrait");
varfontsize=S("fontsize");
varfontface=S("fontface");
if(el.tagName=="IMG"){
try{
if(IsInColorBrd(el)){
//tdView.bgColor=el.parentNode.bgColor;
//tdColorCode.innerHTML=el.parentNode.bgColor
}
}catch(e){}
}else{
return;
Disp(dvForeColor,0);
if(!IsInFontFaceBrd(el))Disp(fontface,0);
if(!IsInFontSizeBrd(el))Disp(fontsize,0);
}
*/
};
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;iif(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="<普通模式>";
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="";
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;
}
}
}


本地下载

相关推荐