/** 编辑器 caratename:chenxihu caratetime:214-09-01 21:40:00 email:qqqq2900@126.com homepage:www.xh829.com */ var rockediterarray = []; (function ($) { function rockediter(contid, can){ var me = this; this.selecttext = ''; var obj = get(contid); var rand = js.getrand(); this.oi = rockediterarray.length; this.formatarray={ 'font':['字体样式','FontName', 'down'], 'fontsize':['字体大小','FontSize', 'down'], 'forecolor':['字体颜色','ForeColor', 'down'], 'marks':['插入特殊符号','Marks'], 'images':['上传图片','Images'], 'imageslink':['插入图片链接','Imageslink'], 'backcolor':['字体背景色','BackColor', 'down'], 'html':['查看源码','HTML'], 'arrow_out':['全屏',''], 'emot':['插入表情',''], 'cut':['剪切','Cut'], 'paste':['粘贴','Paste'], 'copy':['复制','Copy'], 'selectall':['全选','SelectAll'], 'hr':['添加水平线','InsertHorizontalRule'], 'link_add':['添加链接','CreateLink'], 'link_del':['删除链接','UnLink'], 'bold':['加粗','Bold'], 'italic':['斜体','Italic'], 'underline':['下划线','Underline'], 'strikethrough':['删除线','StrikeThrough'], 'align_center':['居中对齐','JustifyCenter'], 'align_justify':['两端对齐','JustifyFull'], 'align_left':['左对齐','JustifyLeft'], 'align_right':['右对齐','JustifyRight'], 'list_bullets':['项目符号','insertunorderedlist'], 'list_numbers':['数字编号','insertorderedlist'], 'indent':['增加缩进量','Indent'], 'indent_remove':['减小缩进量','Outdent'], 'undo':['返回上一步','Undo'], 'removeformat':['删除格式','RemoveFormat'] } //初始化 this.init = function(){ this.createtbar(); $('#'+contid+'_tbar a').click(function(event){ me.toolsclick(event, this); return false; }); }; this.createtbar = function(){ var a = can.tbaricons.split(','); var s = ''; for(var i=0; i'; if(can.showtext)s+=' '+c[0]+''; if(c[2] == 'down')s+=''; s+=''; } } $('#'+contid+'_tbar').html(s); }; this.toolsclick = function(event, o1){ var o = $(o1); var xtype = o.attr('xtype'); this.selecttext = this.getSelText(); if(xtype == 'Bold'){ this.strreplace(this.selecttext, '[B]'+this.selecttext+'[/B]'); } if(xtype == 'Italic'){ this.strreplace(this.selecttext, '[I]'+this.selecttext+'[/I]'); } if(xtype == 'Underline'){ this.strreplace(this.selecttext, '[U]'+this.selecttext+'[/U]'); } if(xtype == 'RemoveFormat'){ this.removeformat(); } if(xtype == 'CreateLink'){ this.createlink(); } if(xtype == 'Images'){ this.uploadImages(); } }; this.createlink = function(){ var h = '
'; h+='
连接文字
'; h+='
连接地址
'; h+='
'; js.tanbody('createlinkwindow', '添加连接', 400, 200, {html:h,btn:[{text:'确定'}]}); get('createlinkwindow_texturl').focus(); $('#createlinkwindow_btn0').click(function(){ me.quedingadd(); }); }; this.quedingadd = function(){ var text = $('#createlinkwindow_text').val(); var url = $('#createlinkwindow_texturl').val(); var str1 = '[A,'+url+']'+text+'[/A]'; if(isempt(text))return false; this.strreplace(text,str1); js.tanclose('createlinkwindow'); }; //清除格式 this.removeformat = function(){ var cont = obj.value; cont = cont.replace(/\[.*?\]/gi, ''); cont = cont.replace(/\<.*?\>/gi, ''); obj.value = cont; }; this.addcont = function(str){ obj.value+=str; }; this.strreplace = function(str,str1){ if(isempt(str) || !get(contid))return false; var cont = obj.value; var s = ''; if(isIE){ var patt1 = new RegExp(""+str+"", "gi"); s = cont.replace(patt1, str1); }else{ var st = obj.selectionStart; var et = obj.selectionEnd; s = cont.substr(0, st)+str1; s+=cont.substr(et); } get(contid).value = s; if(!isIE)get(contid).focus(); }; this.getSelText = function(){ var o = obj; var txt = ''; if(isIE){ txt = document.selection.createRange().text; } else { txt = o.value.substr(o.selectionStart,o.selectionEnd-o.selectionStart); } return txt; }; //删除图片 this.uploadImages= function(){ var h = '
'; h+=''; h+=''; h+=' '; h+=' '; h+=''; h+='
'; h+='
图片地址:   ↑从本地上传
'; h+='
'; //h+='
'; //h+='
宽:   高:
'; h+='
'; h+='
'; js.tanbody('createlinkwindow', '插入图片', 400, 200, { html:h,btn:[{text:'确定'}] }); $('#createlinkwindow_btn0').click(function(){ me.uploadImagesback(); }); }; this.uploadImagesback= function(){ var url = get('createlinkwindow_images').value; if(isempt(url))return false; this.addcont('[IMG,'+url+']'); js.tanclose('createlinkwindow'); return false; }; } $.rockediter = function(contid,can){ var fcan = js.apply({ showtext : true, tbaricons : 'bold,italic,underline,|,link_add,images,removeformat' }, can); var clsa = new rockediter(contid, fcan); clsa.init(); rockediterarray.push(clsa); return clsa; }; })(jQuery); function rockediteruploadimage(){ js.upload('rockediteruploadimageautoclose',{title:escape('本地上传图片'),maxup:1,uptype:'image',maxwidth:600}); return false; } function rockediteruploadimageautoclose(a){ var d = a[0]; //$('#createlinkwindow_width').val(d.width); //$('#createlinkwindow_height').val(d.height); $('#createlinkwindow_images').val(d.thumbpath); get('createlinkwindow_imagesview').src=d.thumbpath; }