(function($){
if($.xheditor)return false;//防止JS重复加载
$.fn.xheditor=function(options)
{
var arrSuccess=[];
this.each(function(){
if(!$.nodeName(this,'TEXTAREA'))return;
if(options===false)//卸载
{
if(this.xheditor)
{
this.xheditor.remove();
this.xheditor=null;
}
}
else//初始化
{
if(!this.xheditor)
{
var tOptions=/({.*})/.exec($(this).attr('class'));
if(tOptions)
{
try{tOptions=eval('('+tOptions[1]+')');}catch(ex){};
options=$.extend({},tOptions,options );
}
var editor=new $.xheditor(this,options);
if(editor.init())
{
this.xheditor=editor;
arrSuccess.push(editor);
}
else editor=null;
}
else arrSuccess.push(this.xheditor);
}
});
if(arrSuccess.length===0)arrSuccess=false;
if(arrSuccess.length===1)arrSuccess=arrSuccess[0];
return arrSuccess;
}
var xCount=0,browerVer=$.browser.version,isIE=$.browser.msie,isMozilla=$.browser.mozilla,isSafari=$.browser.safari,isOpera=$.browser.opera,bShowPanel=false,bClickCancel=true,bShowModal=false,bCheckEscInit=false;
var _jPanel,_jShadow,_jCntLine,_jPanelButton;
var jModal,jModalShadow,layerShadow,jOverlay,jHideSelect,onModalRemove;
var editorRoot;
$('script[src*=xheditor]').each(function(){
var s=this.src;
if(s.match(/xheditor[^\/]*\.js/i)){editorRoot=s.replace(/[\?#].*$/, '').replace(/(^|[\/\\])[^\/]*$/, '$1');return false;}
});
var specialKeys={ 27: 'esc', 9: 'tab', 32:'space', 13: 'enter', 8:'backspace', 145: 'scroll',
20: 'capslock', 144: 'numlock', 19:'pause', 45:'insert', 36:'home', 46:'del',
35:'end', 33: 'pageup', 34:'pagedown', 37:'left', 38:'up', 39:'right',40:'down',
112:'f1',113:'f2', 114:'f3', 115:'f4', 116:'f5', 117:'f6', 118:'f7', 119:'f8',
120:'f9', 121:'f10', 122:'f11', 123:'f12' };
var itemColors=['#FFFFFF','#CCCCCC','#C0C0C0','#999999','#666666','#333333','#000000','#FFCCCC','#FF6666','#FF0000','#CC0000','#990000','#660000','#330000','#FFCC99','#FF9966','#FF9900','#FF6600','#CC6600','#993300','#663300','#FFFF99','#FFFF66','#FFCC66','#FFCC33','#CC9933','#996633','#663333','#FFFFCC','#FFFF33','#FFFF00','#FFCC00','#999900','#666600','#333300','#99FF99','#66FF99','#33FF33','#33CC00','#009900','#006600','#003300','#99FFFF','#33FFFF','#66CCCC','#00CCCC','#339999','#336666','#003333','#CCFFFF','#66FFFF','#33CCFF','#3366FF','#3333FF','#000099','#000066','#CCCCFF','#9999FF','#6666CC','#6633FF','#6600CC','#333399','#330099','#FFCCFF','#FF99FF','#CC66CC','#CC33CC','#993399','#663366','#330033'];
var arrBlocktag=[{n:'p',t:'普通段落'},{n:'h1',t:'标题1'},{n:'h2',t:'标题2'},{n:'h3',t:'标题3'},{n:'h4',t:'标题4'},{n:'h5',t:'标题5'},{n:'h6',t:'标题6'},{n:'pre',t:'已编排格式'},{n:'address',t:'地址'}];
var arrFontname=[{n:'宋体',c:'SimSun'},{n:'仿宋体',c:'FangSong_GB2312'},{n:'黑体',c:'SimHei'},{n:'楷体',c:'KaiTi_GB2312'},{n:'微软雅黑',c:'Microsoft YaHei'},{n:'Arial'},{n:'Arial Narrow'},{n:'Arial Black'},{n:'Comic Sans MS'},{n:'Courier New'},{n:'System'},{n:'Times New Roman'},{n:'Tahoma'},{n:'Verdana'}];
var arrFontsize=[{n:'xx-small',wkn:'x-small',s:'8pt',t:'极小'},{n:'x-small',wkn:'small',s:'10pt',t:'特小'},{n:'small',wkn:'medium',s:'12pt',t:'小'},{n:'medium',wkn:'large',s:'14pt',t:'中'},{n:'large',wkn:'x-large',s:'18pt',t:'大'},{n:'x-large',wkn:'xx-large',s:'24pt',t:'特大'},{n:'xx-large',wkn:'-webkit-xxx-large',s:'36pt',t:'极大'}];
var menuAlign=[{s:'左对齐',v:'justifyleft'},{s:'居中',v:'justifycenter'},{s:'右对齐',v:'justifyright'},{s:'两端对齐',v:'justifyfull'}],menuList=[{s:'数字列表',v:'insertOrderedList'},{s:'符号列表',v:'insertUnorderedList'}];
var htmlPastetext='
使用键盘快捷键(Ctrl+V)把内容粘贴到方框里,按 确定
';
var htmlLink='链接地址:
打开方式: 默认 新窗口 当前窗口 父窗口
链接文字:
';
var htmlImg='图片文件:
替换文本:
对齐方式: 默认 左对齐 右对齐 顶端 居中 基线 底边
宽度高度: x
边框大小:
水平间距: 垂直间距:
';
var htmlFlash='动画文件:
宽度高度: x
';
var htmlMedia='媒体文件:
宽度高度: x
';
var htmlTable='行数列数: x
标题单元:
宽度高度: x
边框大小:
表格间距: 表格填充:
对齐方式: 默认 左对齐 居中 右对齐
表格标题:
';
var htmlAbout='xhEditor v1.1.5 (build 110301)
xhEditor是基于jQuery开发的跨平台轻量XHTML编辑器,基于LGPL 开源协议发布。
Copyright © xhEditor.com . All rights reserved.
';
var itemEmots={'default':{name:'默认',width:24,height:24,line:7,list:{'smile':'微笑','tongue':'吐舌头','titter':'偷笑','laugh':'大笑','sad':'难过','wronged':'委屈','fastcry':'快哭了','cry':'哭','wail':'大哭','mad':'生气','knock':'敲打','curse':'骂人','crazy':'抓狂','angry':'发火','ohmy':'惊讶','awkward':'尴尬','panic':'惊恐','shy':'害羞','cute':'可怜','envy':'羡慕','proud':'得意','struggle':'奋斗','quiet':'安静','shutup':'闭嘴','doubt':'疑问','despise':'鄙视','sleep':'睡觉','bye':'再见'}}};
var arrTools={Cut:{t:'剪切 (Ctrl+X)'},Copy:{t:'复制 (Ctrl+C)'},Paste:{t:'粘贴 (Ctrl+V)'},Pastetext:{t:'粘贴文本',h:isIE?0:1},Blocktag:{t:'段落标签',h:1},Fontface:{t:'字体',h:1},FontSize:{t:'字体大小',h:1},Bold:{t:'加粗 (Ctrl+B)',s:'Ctrl+B'},Italic:{t:'斜体 (Ctrl+I)',s:'Ctrl+I'},Underline:{t:'下划线 (Ctrl+U)',s:'Ctrl+U'},Strikethrough:{t:'删除线'},FontColor:{t:'字体颜色',h:1},BackColor:{t:'背景颜色',h:1},SelectAll:{t:'全选 (Ctrl+A)'},Removeformat:{t:'删除文字格式'},Align:{t:'对齐',h:1},List:{t:'列表',h:1},Outdent:{t:'减少缩进 (Shift+Tab)',s:'Shift+Tab'},Indent:{t:'增加缩进 (Tab)',s:'Tab'},Link:{t:'超链接 (Ctrl+K)',s:'Ctrl+K',h:1},Unlink:{t:'取消超链接'},Img:{t:'图片',h:1},Flash:{t:'Flash动画',h:1},Media:{t:'多媒体文件',h:1},Emot:{t:'表情',s:'ctrl+e',h:1},Table:{t:'表格',h:1},Source:{t:'源代码'},Preview:{t:'预览'},Print:{t:'打印 (Ctrl+P)',s:'Ctrl+P'},Fullscreen:{t:'全屏编辑 (Esc)',s:'Esc'}};
var toolsThemes={
mini:'Bold,Italic,Underline,Strikethrough,|,Align,List,|,Link,Img',
simple:'Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,|,Align,List,Outdent,Indent,|,Link,Img,Emot',
full:'Cut,Copy,Paste,Pastetext,|,Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,SelectAll,Removeformat,|,Align,List,Outdent,Indent,|,Link,Unlink,Img,Flash,Media,Emot,Table,|,Source,Preview,Print,Fullscreen'};
toolsThemes.mfull=toolsThemes.full.replace(/\|(,Align)/i,'/$1');
var arrDbClick={'a':'Link','img':'Img','embed':'Embed'},uploadInputname='filedata';
var arrEntities={'<':'<','>':'>','"':'"','®':'®','©':'©'};//实体
var regEntities=/[<>"®©]/g;
$.xheditor=function(textarea,options)
{
var defaults={skin:'default',tools:'full',clickCancelDialog:true,linkTag:false,internalScript:false,inlineScript:false,internalStyle:true,inlineStyle:true,showBlocktag:false,forcePtag:true,upLinkExt:"zip,rar,txt",upImgExt:"jpg,jpeg,gif,png",upFlashExt:"swf",upMediaExt:"wmv,avi,wma,mp3,mid",modalWidth:350,modalHeight:220,modalTitle:true,defLinkText:'点击打开链接',layerShadow:3,emotMark:false,upBtnText:'上传',cleanPaste:2,hoverExecDelay:100,html5Upload:true,upMultiple:99};
var _this=this,_text=textarea,_jText=$(_text),_jForm=_jText.closest('form'),_jTools,_jArea,_win,_jWin,_doc,_jDoc;
var bookmark;
var bInit=false,bSource=false,bFullscreen=false,bCleanPaste=false,outerScroll,bShowBlocktag=false,sLayoutStyle='',ev=null,timer,bDisableHoverExec=false,bQuickHoverExec=false;
var lastPoint=null,lastAngle=null;//鼠标悬停显示
var editorHeight=0;
var settings=_this.settings=$.extend({},defaults,options );
var plugins=settings.plugins,strPlugins=[];
if(plugins)
{
arrTools=$.extend({},arrTools,plugins);
$.each(plugins,function(n){strPlugins.push(n);});
strPlugins=strPlugins.join(',');
}
if(settings.tools.match(/^\s*(m?full|simple|mini)\s*$/i))
{
var toolsTheme=toolsThemes[$.trim(settings.tools)];
settings.tools=(settings.tools.match(/m?full/i)&&plugins)?toolsTheme.replace('Table','Table,'+strPlugins):toolsTheme;//插件接在full的Table后面
}
if(!settings.tools.match(/(^|,)\s*About\s*(,|$)/i))settings.tools+=',About';
settings.tools=settings.tools.split(',');
if(settings.editorRoot)editorRoot=settings.editorRoot;
editorRoot=getLocalUrl(editorRoot,'abs');
if(settings.urlBase)settings.urlBase=getLocalUrl(settings.urlBase,'abs');
//基本控件名
var idCSS='xheCSS_'+settings.skin,idContainer='xhe'+xCount+'_container',idTools='xhe'+xCount+'_Tool',idIframeArea='xhe'+xCount+'_iframearea',idIframe='xhe'+xCount+'_iframe',idFixFFCursor='xhe'+xCount+'_fixffcursor';
var headHTML='',bodyClass='',skinPath=editorRoot+'xheditor_skin/'+settings.skin+'/',arrEmots=itemEmots,urlType=settings.urlType,urlBase=settings.urlBase,emotPath=settings.emotPath,emotPath=emotPath?emotPath:editorRoot+'xheditor_emot/',selEmotGroup='';
arrEmots=$.extend({},arrEmots,settings.emots);
emotPath=getLocalUrl(emotPath,'rel',urlBase?urlBase:null);//返回最短表情路径
bShowBlocktag=settings.showBlocktag;
if(bShowBlocktag)bodyClass+=' showBlocktag';
var arrShortCuts=[];
this.init=function()
{
//加载样式表
if($('#'+idCSS).length===0)$('head').append(' ');
//初始化编辑器
var cw = settings.width || _text.style.width || _jText.outerWidth();
editorHeight = settings.height || _text.style.height || _jText.outerHeight();
if(is(editorHeight,'string'))editorHeight=editorHeight.replace(/[^\d]+/g,'');
if(cw<=0||editorHeight<=0)//禁止对隐藏区域里的textarea初始化编辑器
{
alert('当前textarea处于隐藏状态,请将之显示后再初始化xhEditor,或者直接设置textarea的width和height样式');
return false;
}
if(/^[0-9\.]+$/i.test(''+cw))cw+='px';
//编辑器CSS背景
var editorBackground=settings.background || _text.style.background;
//工具栏内容初始化
var arrToolsHtml=[' '],tool,cn,regSeparator=/\||\//i;
$.each(settings.tools,function(i,n)
{
if(n.match(regSeparator))arrToolsHtml.push(' ');
if(n==='|')arrToolsHtml.push(' ');
else if(n==='/')arrToolsHtml.push(' ');
else
{
tool=arrTools[n];
if(!tool)return;
if(tool.c)cn=tool.c;
else cn='xheIcon xheBtn'+n;
arrToolsHtml.push(' ');
if(tool.s)_this.addShortcuts(tool.s,n);
}
if(n.match(regSeparator))arrToolsHtml.push(' ');
});
arrToolsHtml.push(' ');
_jText.after($(' '));
_jTools=$('#'+idTools);_jArea=$('#'+idIframeArea);
headHTML=' ';
var loadCSS=settings.loadCSS;
if(loadCSS)
{
if(is(loadCSS,'array'))for(var i in loadCSS)headHTML+=' ';
else
{
if(loadCSS.match(/\s*';
iframeHTML+='