javascript 在线文本编辑器实现代码

Editor

body{ font-size:12px;}
#ed{ height:300px; width:800px; background-color: }
.sssss{ background-image:url(http://www.zzsky.cn/build/images/20099493121.gif)}
.tag{ background-image:url(http://www.zzsky.cn/build/images/20099493121.gif);height:22px; display:inline-table;float:left; ;cursor: pointer; margin-top:8px; margin-left:5px; margin-right:2px; vertical-align:middle; line-height:20px;}
.span0_hover{background-position:-0px -2px;width:22px}
.span1_hover{background-position:-30px -2px;width:22px}
.span2_hover{background-position:-58px -2px;width:22px}
.span3_hover{background-position:-86px -57px;width:73px}
.span4_hover{background-position:-86px -28px;width:73px}
.span5_hover{background-position:-164px -2px;width:22px; background-color:#000000}
.span6_hover{background-position:-194px -2px;width:22px}
.span7_hover{background-position:-45px -192px;width:22px}
.span8_hover{background-position:-76px -192px;width:22px}
.span9_hover{background-position:-58px -247px;width:22px}
.span10_hover{background-position:-86px -247px;width:22px}
.span11_hover{background-position:-113px -247px;width:22px}
.span12_hover{background-position:-476px -192px;width:22px}
.span13_hover{background-position:-505px -192px;width:22px}
.span14_hover{background-position:-333px -247px;width:22px}
.span15_hover{background-position:-532px -192px;width:22px}
.span16_hover{background-position:-560px -192px;width:22px}
.span17_hover{background-position:-455px -247px;width:22px}
.span18_hover{background-position:-222px -2px;width:73px}
.span19_hover{background-position:-380px -2px;width:74px}
.span20_hover{background-position:-460px -2px;width:71px}
.span0{background-position:-0px -57px;width:22px}
.span1{background-position:-30px -57px;width:22px}
.span2{background-position:-58px -57px;width:22px}
.span3{background-position:-86px -57px;width:73px}
.span4{background-position:-86px -28px;width:73px}
.span5{background-position:-164px -57px;width:22px;background-color:#000000}
.span6{background-position:-194px -57px;width:22px}
.span7{background-position:-45px -84px;width:22px}
.span8{background-position:-76px -84px;width:22px}
.span9{background-position:-58px -140px;width:22px}
.span10{background-position:-86px -140px;width:22px}
.span11{background-position:-113px -140px;width:22px}
.span12{background-position:-476px -84px;width:22px}
.span13{background-position:-505px -84px;width:22px}
.span14{background-position:-333px -140px;width:22px}
.span15{background-position:-532px -84px;width:22px}
.span16{background-position:-560px -84px;width:22px}
.span17{background-position:-455px -140px;width:22px}
.span18{background-position:-222px -57px;width:73px}
.span19{background-position:-380px -57px;width:74px}
.span20{background-position:-460px -57px;width:71px}
.span0_active{background-position:-0px -28px;width:22px}
.span1_active{background-position:-30px -28px;width:22px}
.span2_active{background-position:-58px -28px;width:22px}
.span3_active{background-position:-476px -299px;width:22px}
.span4_active{background-position:-505px -299px;width:22px}
.ebody{ height:auto; width:760px; border:1px solid #999999}
.ebar{ width:100%; height:36px; background-color:#F0F2F5;};
.edit{ height:550px; width:100%; border:0px;}
.popupfont{ width:200px; height:auto; border:1px solid #7B9EBD; background-color:#F7F7F7; position:absolute;padding:3px; }
a.c1{ width:96%; height:auto; font-size:10px;display:block;border:1px solid #F7F7F7; padding:3px;color:#666666;text-decoration:none;}
a.c1:hover{width:96%; height:auto; font-size:10px; border:1px solid #FFCF00;display:block;background-color:#F7EBBD;padding:3px;color:#666666;text-decoration:none;}
a.c2{ width:96%; height:auto; font-size:12px;display:block;border:1px solid #F7F7F7; padding:3px;color:#666666;text-decoration:none;}
a.c2:hover{width:96%; height:auto; font-size:12px; border:1px solid #FFCF00;display:block;background-color:#F7EBBD;padding:3px;color:#666666;text-decoration:none;}
a.c3{ width:96%; height:auto; font-size:14px;display:block;border:1px solid #F7F7F7;padding:3px;color:#666666 ;text-decoration:none;}
a.c3:hover{width:96%; height:auto; font-size:14px; border:1px solid #FFCF00;display:block;background-color:#F7EBBD;padding:3px;color:#666666;text-decoration:none;}
a.c4{ width:96%; height:auto; font-size:16px;display:block;border:1px solid #F7F7F7;padding:3px; color:#666666;text-decoration:none;}
a.c4:hover{width:96%; height:auto; font-size:16px; border:1px solid #FFCF00;display:block;background-color:#F7EBBD;padding:3px;color:#666666;text-decoration:none;}
a.c5{ width:96%; height:auto; font-size:18px;display:block;border:1px solid #F7F7F7;padding:3px; color:#666666;text-decoration:none;}
a.c5:hover{width:96%; height:auto; font-size:18px; border:1px solid #FFCF00;display:block;background-color:#F7EBBD;padding:3px;color:#666666;text-decoration:none;}
a.c6{ width:96%; height:auto; font-size:22px;display:block;border:1px solid #F7F7F7; padding:3px;color:#666666;text-decoration:none;}
a.c6:hover{width:96%; height:auto; font-size:22px; border:1px solid #FFCF00;display:block;background-color:#F7EBBD;padding:3px;color:#666666;text-decoration:none;}
a.c7{ width:96%; height:auto; font-size:26px;display:block;border:1px solid #F7F7F7; padding:3px;color:#666666;text-decoration:none;}
a.c7:hover{width:96%; height:auto; font-size:26px; border:1px solid #FFCF00;display:block;background-color:#F7EBBD;padding:3px;color:#666666;text-decoration:none;}
a.n{ width:96%; height:auto; font-size:14px;display:block;border:1px solid #F7F7F7;padding:3px;color:#666666;text-decoration:none; }
a.n:hover{width:96%; height:auto; font-size:14px; border:1px solid #FFCF00;display:block;background-color:#F7EBBD;padding:3px;color:#666666;text-decoration:none;}
.textarea{ border:0px;display:none;}
.toolbarlayer{position:absolute;opacity:0.7;filter:alpha(opacity:70);background-color:#ffffff;height:36px}
.bottom{height:30px;width:100%;background-color:#F7F3F7;font-size:12px;}
.checkbox{margin-top:10px;margin-top/*\**/:6px\9;margin-left:20px;margin-left/*\**/:16px\9;}
.pp{height:auto; border:1px solid #D3D3D3; position:absolute;z-index:5;}
.ppt{
height:24px; width:100%; background-image:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090726/203207031.p.gif); font-size:12px; font-weight: bold; vertical-align:middle; line-height:24px;
}

var Sys = (function(ua){
var s = {};
s.IE = ua.match(/msie ([\d.]+)/)?true:false;
s.Firefox = ua.match(/firefox\/([\d.]+)/)?true:false;
s.Chrome = ua.match(/chrome\/([\d.]+)/)?true:false;
s.IE6 = (s.IE&&([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6))?true:false;
s.IE7 = (s.IE&&([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 7))?true:false;
s.IE8 = (s.IE&&([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 8))?true:false;
return s;
})(navigator.userAgent.toLowerCase());
Sys.IE6&&document.execCommand("BackgroundImageCache", false, true);
var $ = function (id) {
return "string" == typeof id?document.getElementById(id):id;
};
function Each(list, fun){
for (var i = 0, len = list.length; i 显示源代码";
this.bottom.insertBefore(this.original,this.bottom.childNodes[0]);
this.ed=Sys.IE?this.iframe.contentWindow.document:this.iframe.contentDocument;
this.ed.open();
var div = Sys.IE?"

":"";
this.ed.write("body{margin:5px;font-size:16px;word-wrap:break-word}"+div+"");
this.ed.close();
this.ed.contentEditable = true;
this.ed.designMode = "on";//设置编辑区为可编辑
for(var i = 0,l = data.length;i连接地址 

 

"
this[n].elm = [$$(this[n].container,"input")[0],$$(this[n].container,"img")[0],$$(this[n].container,"img")[1]];
this[n].elm[0].focus()
addListener(this[n].elm[1],'click',Bind(this,this.Execa,null,f));
addListener(this[n].elm[2],'click',function(){self.lightbox.Close();self[n].Close();});
}
else
with(this[n]){pos();Show();elm[0].value="";elm[0].focus();}
},
Addtable:function(){
if(Sys.IE)
{
!this.isfocus&&this.iframe.contentWindow.focus();
this.rang = this.ed.selection.createRange();
}
this.lightbox.Show();
if(Sys.IE)this.rang = this.ed.selection.createRange();
if(!this.tablepopup)
{
var self = this;
this.tablepopup = new popoup({width:"300px",title:"插入表格"});
this.tablepopup.pos();
$$(this.tablepopup.container,"div")[1].innerHTML = "

行数: 列数:

表格的宽度: px

表行的高度: px

 

"
var o = $$(this.tablepopup.container,"input");
this.tablepopup.elm = [o[0],o[1],o[2],o[3],$$(this.tablepopup.container,"img")[0],$$(this.tablepopup.container,"img")[1]];
addListener(this.tablepopup.elm[4],'click',Bind(this,this.Execa,null,"CreateTable"));
addListener(this.tablepopup.elm[5],'click',function(){self.lightbox.Close();self.tablepopup.Close();});
}
else
with(this.tablepopup){pos();Show();elm[0].focus();}
this.Fpop = Bind(this,this.Hide);
addListener(this.ed,'click',this.Fpop);
addListener(document,'mousedown',this.Fpop);
},
Hide:function(o){
this.facebgpopup&&(this.facebgpopup.style.display = "none");
this.fontsizepopup&&(this.fontsizepopup.style.display = "none");
this.fontnamepopup&&(this.fontnamepopup.style.display = "none");
this.fontcolorpopup&&(this.fontcolorpopup.style.display = "none");
removeListener(this.ed,'click',this.Fpop);
removeListener(document,'mousedown',this.Fpop);
},
Bubble:function(e){
if(Sys.IE){e.cancelBubble=true}else{e.stopPropagation()}
},
Execa:function(num,stamp){
var exec = {
fontname : function(){
this.fontnamepopup.style.display = "none";
this.ed.execCommand('FontName',false,num);
},
fontSize : function(){
this.fontsizepopup.style.display = "none";
this.ed.execCommand("FontSize",false,num+1)
},
fontColor : function(){
this.fontcolorpopup.style.display = "none";
this.ed.execCommand("ForeColor",false,num);
},
CreateLink : function(){
this.lightbox.Close();this.Linkpopoup.Close();
if(this.Linkpopoup.elm[0].value=="")return;
if(Sys.IE)
{
this.rang.execCommand("CreateLink",false,this.Linkpopoup.elm[0].value);
this.rang.parentElement().target="_blank ";
}
else
{
this.ed.execCommand("CreateLink",false,this.Linkpopoup.elm[0].value);
this.rang = this.iframe.contentWindow.getSelection().getRangeAt(0);
this.rang.commonAncestorContainer.parentNode.target="_blank ";
}
},
InsertImage : function(){
this.lightbox.Close();this.Imagepopoup.Close();
if(this.Imagepopoup.elm[0].value=="")return;
Sys.IE?this.rang.execCommand("InsertImage",false,this.Imagepopoup.elm[0].value):this.ed.execCommand("InsertImage",false,this.Imagepopoup.elm[0].value);
},
Expression : function(){
this.facebgpopup.style.display = "none";
Sys.IE&&(this.iframe.contentWindow.focus());
this.ed.execCommand("InsertImage",false,num);
},
CreateTable : function(){
this.lightbox.Close();this.tablepopup.Close();
var o = this.tablepopup.elm,p = null;
if(Sys.IE)
{
this.rang.execCommand("InsertImage",false,"http://xxx.com/xxxxx.gif");
p = this.rang.parentElement();
}
else
{
this.ed.execCommand("InsertImage",false,"http://xxx.com/xxxxx.gif");
p = this.iframe.contentWindow.getSelection().getRangeAt(0).commonAncestorContainer;
}
var tab = createtab(o[0].value,o[1].value,function(tab){
Attr(tab,{cellPadding:0,cellSpacing:1,border:0,bgColor:"#CCCCCC",width:o[2].value});
},null,function(i,j,td){td.height=o[3].value;td.width=o[2].value/o[1].value; td.style.backgroundColor="#FFFFFF"},this.ed);
var imgs = p.getElementsByTagName("img");
for(var i = 0,l=p.childNodes.length;i

";
this.w = this.container.offsetWidth;
this.h = this.container.offsetHeight;
$$(this.container,"span")[0].innerHTML = this.title;
},
pos:function(){
var str ="left:"+(Math.max(document.documentElement.scrollWidth,document.documentElement.clientWidth) - this.w)/2+"px;top:"+((Math.min(document.documentElement.scrollHeight, document.documentElement.clientHeight)- this.h)/2+document.documentElement.scrollTop)+"px"
Css(this.container,str);
},
Show:function(){
this.container.style.display ="";
},
Close:function(){
this.container.style.display ="none";
}
})
var LightBox ={
obj : null,
config :{
Color : "#fff",
Opacity : 80,
zIndex : 5
},
init : function(options){
Extend(this.config,options||{});
Extend(this,this.config);
delete this.config;
this.obj = document.body.insertBefore(document.createElement("div"), document.body.childNodes[0]);
var str = "display:none; z-index:"+this.zIndex+";left:0px;top:0px;position:fixed;width:100%;height:100%;background-color:"+this.Color+(Sys.IE ? ";filter : alpha(opacity:" + this.Opacity + ")" : ";opacity :"+ this.Opacity / 100);
Css(this.obj,str);
if(Sys.IE6){
this.obj.style.position = "absolute";
var _self = this;
this._resize = function(){
_self.obj.style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
_self.obj.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight)+"px";
};
this.obj.innerHTML = '';
}
return this;
},
Show : function(){
if(Sys.IE6){this._resize(); addListener(window,"resize", this._resize); }
this.obj.style.display = "block";
},
Close : function(){
this.obj.style.display = "none";
if(Sys.IE6)removeListener(window,"resize", LightBox._resize);
}
}
window.onload = function(){
var data = [{Class:"span0",hover:"span0_hover",title:"加粗",action:"Exec",args:"bold"},
{Class:"span1",hover:"span1_hover",title:"斜体",action:"Exec",args:"Italic"},
{Class:"span2",hover:"span2_hover",title:"下划线",action:"Exec",args:"Underline"},
{Class:"span3",hover:"span3_hover",title:"字号",action:"Fontsize",args:null},
{Class:"span4",hover:"span4_hover",title:"字体",action:"FontName",args:null},
{Class:"span5",hover:"span5_hover",title:"文字颜色",action:"Fontcolor",args:null},
{Class:"span6",hover:"span6_hover",title:"插入链接",action:"CreateLink",args:null},
{Class:"span7",hover:"span7_hover",title:"剪贴",action:"Exec",args:"Cut"},
{Class:"span8",hover:"span8_hover",title:"复制",action:"Exec",args:"Copy"},
{Class:"span9",hover:"span9_hover",title:"左对齐",action:"Exec",args:"JustifyLeft"},
{Class:"span10",hover:"span10_hover",title:"居中对齐",action:"Exec",args:"JustifyCenter"},
{Class:"span11",hover:"span11_hover",title:"右对齐",action:"Exec",args:"JustifyRight"},
{Class:"span12",hover:"span12_hover",title:"项目符号",action:"Exec",args:"InsertUnorderedList"},
{Class:"span13",hover:"span13_hover",title:"编号",action:"Exec",args:"InsertOrderedList"},
{Class:"span14",hover:"span14_hover",title:"插入表格",action:"Addtable",args:null},
{Class:"span15",hover:"span15_hover",title:"减少缩进",action:"Exec",args:"Outdent"},
{Class:"span16",hover:"span16_hover",title:"增加缩进",action:"Exec",args:"Indent"},
{Class:"span17",hover:"span17_hover",title:"清除样式",action:"Exec",args:"RemoveFormat"},
{Class:"span18",hover:"span18_hover",title:"插入图片",action:"InsertImage",args:null},
{Class:"span19",hover:"span19_hover",title:"插入表情",action:"Expression",args:null},
{Class:"span20",hover:"span20_hover",title:"自动排版",action:"Layout",args:null}
];
new Editer($('ss'),data,LightBox.init());
}

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

您可能感兴趣的文章:

  • JS 网页安全色调色板 DW风格
  • PHP+Javascript实现在线拍照功能实例
  • javascript实现在线客服效果
  • JS实现在线统计一个页面内鼠标点击次数的方法
  • JS网页在线获取鼠标坐标值的方法
  • 学习js在线html(富文本,所见即所得)编辑器
  • 3款实用的在线JS代码工具(国外)
  • javascript在线编码查询工具
  • 两个JavaScript jsFiddle JSBin在线调试器
  • JS实现的在线调色板实例(附demo源码下载)

Tags:在线文本 编辑器

相关文章

  • 2009-11-11eWebEditor 上传文件提示格式不正确的解决方法
  • 2017-03-03最新版CKEditor的配置方法及插件(Plugin)编写示例
  • 2012-06-06fckeditor 防止上传非法文件 增加登录判断
  • 2011-07-07asp.net+FCKeditor上传图片显示叉叉图片无法显示的问题的解决方法
  • 2010-01-01ASp.net下fckeditor配置图片上传最简单的方法
  • 2013-06-06UEditor 编辑器跨域上传解决方法
  • 2013-06-06关于jsp版ueditor1.2.5的部分问题解决(上传图片失败)
  • 2014-11-11解决SyntaxHighlighter 代码高亮不换行问题的解决方法
  • 2010-05-05Html 编辑器粘贴内容过滤技术详解
  • 2009-07-07Ewebeditor 文件上传问题

最新评论

(0)

相关推荐

  • JS网页在线获取鼠标坐标值的方法

    本文实例讲述了JS网页在线获取鼠标坐标值的方法.分享给大家供大家参考.具体实现方法如下: 复制代码 代码如下: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>显示鼠标坐标</title> </head> <body onMousemove="m

  • javascript在线编码查询工具

    // 进制转换 10进制 > 16进制 16进制 > 10进制 编码转换 数字 > 字符 字符 > 数字 HTML中可使用 囍 表示 囍 字符编码表 名称 范围 数量 查看 汉字 19968~40869 20902 查看 常用符号.数字.字符 33~126 94 查看 数字 48~57 10 查看 大写字母 65~90 26 查看 小写字母 97~122 26 查看 更多参考资料:编码表 字符: ~ 小字 中字 大字 共0个 加载中... [Ctrl+A 全选 注:如需引入外部Js

  • 3款实用的在线JS代码工具(国外)

    1. 压缩工具 用于在线压缩你的JS代码,它有一个选项"Include latest jquery.min.js",这对于提升速度非常有用. 推荐理由:缩小代码 = 更小的文件大小 = 更快的网页加载速度 2. 美化工具 用于将压缩后的代码转换回正常状态,使代码再次可读.该工具也可用于混淆的代码. 推荐理由:漂亮的代码 = 易读 = 更快地开发 3. 混淆工具 用于保护(混淆)你的代码,使代码不可读.很显然,一些模仿者可以使用一个工具去反混淆/解压缩,但是你为代码设置的保护越多越好.

  • JS 网页安全色调色板 DW风格

    DW调色板 var ColorHex=new Array('00','33','66','99','CC','FF') var SpColorHex=new Array('FF0000','00FF00','0000FF','FFFF00','00FFFF','FF00FF') var current=null function intocolor() { var colorTable='' for (i=0;i' colorTable=colorTable+' ' if (i==0){ col

  • 两个JavaScript jsFiddle JSBin在线调试器

    第一个:jsFiddle很强大的JS在线调试工具,支持多种应用多种主流框架,可以在线直接编辑调试:HTML.CSS.JavaScript,用起来非常方便,而且还可以将调试好的结果以非常简洁的页面直接嵌入在其他网页里,这样我需要写演示用的JavaScript实例代码的时候,就完全可以在jsFiddle里面直接完成编写后调试,再将结果直接嵌入Blog正文里即可了,真的是很方便的选择,如下所示(这个例子只能在Firefox里查看Result效果). 第二个:JS Bin另一个在线调试工具,相对于jsF

  • PHP+Javascript实现在线拍照功能实例

    本文实例讲述了PHP+Javascript实现在线拍照功能.分享给大家供大家参考.具体如下: 我们在一些WEB应用中可能会遇到这样的情况,用户需要自己现场拍照并上传到会员系统.比如驾校采集指纹拍照流程.考试现场采集照片等.我们今天要讲的是如何使用javascript和PHP实现一个简单的在线拍照并上传的功能. 实现这个功能的前提是你的电脑设备上需要安装有摄像头设备,以及你的浏览器需要支持flash <!DOCTYPE HTML> <html> <head> <me

  • javascript实现在线客服效果

    在线客服系统在大量的网站都有应用,特别是销售类网站,可以有效的增加网站的可用性,便于客户及时联系商家,从而增加了交易成功的可能性,在线客服系统的实现方式有多种多样,这里介绍一种网上常见并且非常美观的客服系统,以此达到举一反三的目的,能够比较轻松的实现其他外观形式的客服系统,代码示例如下: CSS <style type="text/css"> body { margin:0px } .main_head { background:url(mytest/JS/img3-5_2

  • JS实现的在线调色板实例(附demo源码下载)

    本文实例讲述了JS实现的在线调色板.分享给大家供大家参考,具体如下: 运行效果截图如下: 具体代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>ColorSchemer -

  • JS实现在线统计一个页面内鼠标点击次数的方法

    本文实例讲述了JS实现在线统计一个页面内鼠标点击次数的方法.分享给大家供大家参考.具体实现方法如下: 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/x

  • 学习js在线html(富文本,所见即所得)编辑器

    你要的是所见即所得HTML编辑器,简单来说需要几个基本步骤: 1,需要一个可以编辑同时又可显效果的编辑框.textarea不行,它只能用来输入纯文本,不能显示颜色.斜体之类的文字样式,就像记事本.你可以使用iframe来实现,修改iframe的designMode属性使其可以被编辑. 复制代码 代码如下: <iframe id="myEditer" width="100%" height="150px"></iframe>

随机推荐