手机
当前位置:查字典教程网 >编程开发 >网页编辑器 >一款垃圾中的极品HTML编辑器(兼容IE OR FF)
一款垃圾中的极品HTML编辑器(兼容IE OR FF)
摘要:这东东实现了一些常用的功能,今天刚完成,大家多给点建议!在FF下不完善,有些功能暂时还没实现!这也是本人写的第一个编辑器(处女作哦),做得不...

这东东实现了一些常用的功能,今天刚完成,大家多给点建议!

在FF下不完善,有些功能暂时还没实现!

这也是本人写的第一个编辑器(处女作哦),做得不好,千万别丢鸡蛋过来...

先闪人!

复制代码 代码如下:

/*******************************************

一款垃圾中的极品FreeEditor(2006-08-22)

ThisJavaScriptwaswritenbyCXP.

*******************************************/

varcolorType;

varcurrentMode="Design";//当前模式

varie=document.all?true:false;

document.onclick=function(){

}

functionformat(str,arg){

if(currentMode!="Design"){//非设计模式

return;

}

varobj=window.frames["design"];

if(!ie){

varsAlert="";

switch(str){

case"Cut":

sAlert="你的浏览器安全设置不允许编辑器自动执行剪切操作,请使用键盘快捷键(Ctrl+X)来完成";

break;

case"Copy":

sAlert="你的浏览器安全设置不允许编辑器自动执行拷贝操作,请使用键盘快捷键(Ctrl+C)来完成";

break;

case"Paste":

sAlert="你的浏览器安全设置不允许编辑器自动执行粘贴操作,请使用键盘快捷键(Ctrl+V)来完成";

break;

}

if(sAlert!=""){

alert(sAlert);

return;

}

}

obj.focus();

if(arg){

returnobj.document.execCommand(str,false,arg);

}

else{

if(ie){

obj.document.execCommand(str);

}

else{

obj.document.execCommand(str,false,false);

}

}

obj.focus();

}

//显示颜色菜单

functionshowColorMenu(obj,e){

if(currentMode!="Design"){//非设计模式

return;

}

vartarget=document.all?e.srcElement:e.target;

varcolorMode=target.getAttribute("title");

switch(colorMode){

case"背景颜色":

colorType="BodyBackColor";

break;

case"字体背景颜色":

colorType="backColor";

break;

case"字体颜色":

colorType="foreColor";

break;

default:

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

vardb=window.frames["design"].document;

varheight=125;

if(colorType=="foreColor"){

height=145;

}

varcolor=showModalDialog("dialog/color.html",window,"dialogWidth:263px;dialogHeight:"+height+"px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+top+";px");

if(color!=null){

if(colorType=="BodyBackColor"){

db.body.style.backgroundColor=color;

return;

}

elseif(colorType=="foreColor"){

vararr=color.split("|");

if(arr.length==2){

format(colorType,arr[0]);

//设置发光滤镜,IEOnly

if(db.selection.type.toLowerCase()!="none"){

varselectText=db.selection.createRange().htmlText;

selectText="<spanstyle="height:18px;filter:Glow(color="+arr[0]+",Strength=2);">"+selectText+"</span>";

insertHTML(selectText);

return;

}

}

}

format(colorType,color);

}

}

else{

if(colorType=="backColor"){

alert('待完善!');

return;

}

FFOpenWidnow("dialog/color.html",263,112,top+25,left);

}

}

//显示插入图片窗口

functionshowImageMenu(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

varpath=showModalDialog("dialog/image.html","","dialogWidth:390px;dialogHeight:120px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+top+";px");

if(path==null){

return;

}

format("insertImage",path);

}

else{

FFOpenWidnow("dialog/image.html",385,100,top+25,left);

}

}

//显示插入FLASH窗口

functionshowFlashMenu(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj);

if(document.all){

varpath=showModalDialog("dialog/FLASH.html","","dialogWidth:402px;dialogHeight:139px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+(top+138)+";px");

if(path==null){

return;

}

vararr=path.split("|");

varstr="<OBJECTcodeBase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'width='"+arr[1]+"'height='"+arr[2]+"'><PARAMNAME=movieVALUE='"+arr[0]+"'><PARAMNAME=qualityVALUE=high><embedsrc='"+arr[0]+"'quality=highpluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'type='application/x-shockwave-flash'width='"+arr[1]+"'height='"+arr[2]+"'></embed></OBJECT>";

insertHTML(str);

}

else{

alert('待完善');

return;

}

}

//显示插入Face窗口

functionshowFaceMenu(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

showModalDialog("dialog/face.html",window,"dialogWidth:280px;dialogHeight:215px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+top+";px");

}

else{

FFOpenWidnow("dialog/face.html",280,180,top+25,left);

}

}

//显示fieldSet窗口

functionshowFieldSetMenu(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

showModalDialog("dialog/fieldSet.html",window,"dialogWidth:330px;dialogHeight:120px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+top+";px");

}

else{

FFOpenWidnow("dialog/fieldSet.html",330,100,top+25,left);

}

}

functiongetWidth(obj){

varParentObj=obj;

varleft=obj.offsetLeft;

while(ParentObj=ParentObj.offsetParent){

left+=ParentObj.offsetLeft;

}

returnleft;

}

functiongetHeight(obj){

varParentObj=obj;

vartop=obj.offsetTop;

while(ParentObj=ParentObj.offsetParent){

top+=ParentObj.offsetTop;

}

returntop;

}

functionshowMediaMenu(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj);

if(document.all){

showModalDialog("dialog/media.html",window,"dialogWidth:330px;dialogHeight:119px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+(top+138)+";");

}

else{

alert('待完善');

}

}

//显示插入文件窗口

functionshowFileMenu(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

showModalDialog("dialog/file.html",window,"dialogWidth:390px;dialogHeight:115px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+top+";");

}

else{

FFOpenWidnow("dialog/file.html",380,100,top+25,left);

}

}

functionsetColor(color){

if(color==""){

return;

}

if(colorType=="BodyBackColor"){

window.frames["design"].document.body.style.backgroundColor=color;

return;

}

format(colorType,color);

}

//插入字幕

functionshowMarqueeMenu(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

showModalDialog("dialog/marquee.html",window,"dialogWidth:439px;dialogHeight:260px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+top+";");

}

else{

FFOpenWidnow("dialog/marquee.html",435,220,top+25,left);

}

}

//插入特殊字符

functionshowSymbolMenu(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

showModalDialog("dialog/symbol.html",window,"dialogWidth:385px;dialogHeight:235px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+top+";");

}

else{

FFOpenWidnow("dialog/symbol.html",370,190,top+25,left);

}

}

//插入文件

functioninsertFile(txt){

vararr=txt.split(".");

varfileName=getFileName(arr[arr.length-1]);

varstr="<imgsrc="img/file/"+fileName+""border=0><ahref=""+txt+""target="_blank">";

arr=txt.split("/");

fileName=arr[arr.length-1];

str+=fileName+"</a>";

vardb=window.frames["design"].document;

insertHTML(str);

}

//插入当前时间

functioninsertTime(b){

vard=newDate();

varyear,month,day,hour,minute,second;

year=d.getFullYear();

month=d.getMonth();

day=d.getDate();

hour=d.getHours();

minute=d.getMinutes();

second=d.getSeconds();

varstr;

if(b){

str=year+"-"+month+"-"+day;

}

else{

str=hour+":"+minute+":"+second;

}

insertHTML(str);

}

//插入引用

functioninsertQuote(){

varstr="<TABLEstyle="BORDER-RIGHT:#cccccc1pxdotted;TABLE-LAYOUT:fixed;BORDER-TOP:#cccccc1pxdotted;BORDER-LEFT:#cccccc1pxdotted;BORDER-BOTTOM:#cccccc1pxdotted"cellSpacing=0cellPadding=6width="95%"align=centerborder=0><TBODY><TR><TDstyle="WORD-WRAP:break-word"bgColor="#f3f3f3"valign="top"><FONTstyle="FONT-WEIGHT:bold;COLOR:green;font-size:13px;">引用:</FONT><BR></TD></TR></TBODY></TABLE>";

insertHTML(str);

}

//插入单选框

functioninsertRadio(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

showModalDialog("dialog/radio.html",window,"dialogWidth:275px;dialogHeight:156px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+top+";");

}

else{

FFOpenWidnow("dialog/radio.html",270,125,top+25,left);

}

}

//插入复选框

functioninsertCheckBox(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

showModalDialog("dialog/checkbox.html",window,"dialogWidth:275px;dialogHeight:156px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+top+";");

}

else{

FFOpenWidnow("dialog/checkbox.html",270,125,top+25,left);

}

}

//插入复选框

functioninsertInputText(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

showModalDialog("dialog/text.html",window,"dialogWidth:275px;dialogHeight:156px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+top+";");

}

else{

FFOpenWidnow("dialog/text.html",270,125,top+25,left);

}

}

//插入多行文本框

functioninsertTextArea(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

showModalDialog("dialog/textarea.html",window,"dialogWidth:305px;dialogHeight:250px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+top+";");

}

else{

FFOpenWidnow("dialog/textarea.html",300,250,top+25,left,true);

}

}

//插入表格

functioninsertTable(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

showModalDialog("dialog/table.html",window,"dialogWidth:265px;dialogHeight:239px;help:no;status:no;scroll:no;dialogLeft:"+left+";dialogTop:"+top+";");

}

else{

FFOpenWidnow("dialog/table.html",256,210,top+25,left,true);

}

}

//插入下拉列表

functioninsertSelect(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

showModalDialog("dialog/select.html",window,"dialogWidth:380px;dialogHeight:250px;help:no;status:no;scroll:auto;dialogLeft:"+left+";dialogTop:"+top+";");

}

else{

FFOpenWidnow("dialog/select.html",380,250,top+25,left);

}

}

//插入按钮

functioninsertButton(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

showModalDialog("dialog/button.html",window,"dialogWidth:239px;dialogHeight:170px;help:no;status:no;scroll:auto;dialogLeft:"+left+";dialogTop:"+top+";");

}

else{

FFOpenWidnow("dialog/button.html",236,139,top+25,left);

}

}

//插入表单

functioninsertForm(obj){

if(currentMode!="Design"){//非设计模式

return;

}

varleft,top;

left=getWidth(obj);

top=getHeight(obj)+138;

if(document.all){

showModalDialog("dialog/form.html",window,"dialogWidth:239px;dialogHeight:170px;help:no;status:no;scroll:auto;dialogLeft:"+left+";dialogTop:"+top+";");

}

else{

FFOpenWidnow("dialog/form.html",236,139,top+25,left);

}

}

//设置模式

functionsetMode(modeType,btnObj){

if(currentMode==modeType){

return;

}

btnObj.style.border="1pxsolid#000000";

varcObj;

if(currentMode=="Preview"){

cObj=document.getElementById("preview");

}

elseif(currentMode=="Design"){

cObj=document.getElementById("design");

}

else{

cObj=document.getElementById("textCode");

}

document.getElementById("bnt"+currentMode).style.border="1pxsolid#999999";

switch(modeType){

case"Code"://代码

varobj=document.getElementById("textCode");

vardb=window.frames["design"].document.body;

varHTMLCode=db.innerHTML;

//防止FF在没有任何代码前产生的换行

if(HTMLCode=="<br>n"||HTMLCode=="<br>"){

HTMLCode="";

}

obj.value=HTMLCode;

cObj.style.display="none";

obj.style.display="block";

break;

case"Design"://设计

cObj.style.display="none";

document.getElementById("design").style.display="block";

break;

case"Preview":

varobj=window.frames["preview"].document.body;

vardb=window.frames["design"].document.body;

obj.style.backgroundColor=db.style.backgroundColor;

if(currentMode=="Code"){

obj.innerHTML=cObj.value;

}

else{

varstr=db.innerHTML;

obj.innerHTML=str;

}

cObj.style.display="none";

document.getElementById("preview").style.display="block";

break;

}

currentMode=modeType;//设置当前模式

}

//创建链接

functioncreateLink(){

if(currentMode!="Design"){//非设计模式

return;

}

if(document.all){

format("CreateLink");

}

else{

varstr=window.prompt("EnterLinkLocation(Example:http://www.baidu.com/orftp://127.0.0.1/)","http://");

if(str==null||str=="http://"||str=="")return;

format("CreateLink",str);

}

}

//新建

functionnewPage(){

if(currentMode!="Design"){//非设计模式

return;

}

window.frames["design"].document.body.innerHTML="";

}

//设置字体

functionsetFaceFamily(obj){

varval=obj.options[obj.selectedIndex].value;

if(val=="")return;

format("fontname",val);

}

//设置字号

functionsetFaceSize(obj){

varval=obj.options[obj.selectedIndex].text;

if(val=="字号")return;

format("fontsize",val);

}

functiongetFileName(str){

str=str.toLowerCase();

varname;

switch(str){

case"avi":

name="avi.gif";

break;

case"bmp":

name="bmp.gif";

break;

case"chm":

name="chm.gif";

break;

case"doc":

name="doc.gif";

break;

case"exe":

name="exe.gif";

break;

case"gif":

name="gif.gif";

break;

case"html":

name="html.gif";

break;

case"htm":

name="html.gif";

break;

case"jpg":

name="jpg.gif";

break;

case"mdb":

name="mdb.gif";

break;

case"mid":

name="mid.gif";

break;

case"mp3":

name="mp3.gif";

break;

case"pdf":

name="pdf.gif";

break;

case"ppt":

name="ppt.gif";

break;

case"rar":

name="rar.gif";

break;

case"rm":

name="rm.gif";

break;

case"rmvb":

name="rm.gif";

break;

case"swf":

name="swf.gif";

break;

case"txt":

name="txt.gif";

break;

case"xls":

name="xls.gif";

break;

case"zip":

name="zip.gif";

break;

default:

name="unknow.gif";

break;

}

returnname;

}

functionsetFocus(){

window.frames["design"].focus();

}

//插入HTML代码

functioninsertHTML(str){

if(ie){

setFocus();

window.frames["design"].document.selection.createRange().pasteHTML(str);

}

else{

varnewStr=window.frames["design"].document.body.innerHTML;

if(newStr.toLowerCase()=="<br>"||newStr.toLowerCase()=="<br>n"){

window.frames["design"].document.body.innerHTML=str;

}

else{

window.frames["design"].document.body.innerHTML+=str;

}

}

setFocus();

}

//FF打开窗口

functionFFOpenWidnow(url,w,h,top,left){

window.open(url,"","location=no,menubar=no,toolbar=no,dependent=yes,dialog=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=no,width="+w+",height="+h+",screenX="+left+",screenY="+top);

}

本地下载

【一款垃圾中的极品HTML编辑器(兼容IE OR FF)】相关文章:

FCKeditor编辑器添加图片上传功能及图片路径问题解决方法

XHEditor编辑器使用文档

一款支持插入表情的编辑器实现代码(简单思路挺重要)

Html 编辑器粘贴内容过滤技术详解

jsp Ewebeditor使用说明

eWebEditor 请选择一个有效的文件的解决方法

dedecms5.5 最新版ckeditor编辑器整合教程

一个Javascript 编写的代码编辑器

修改fckeditor的文件上传功能步骤

FCKeidtor 清除编辑器内容的代码

精品推荐
分类导航