//调用编辑器时,引用页中所有的js与css命名不能以edi_开始,否则可能会发生冲突 //直接将此文件插到head中 //开始 //识别浏览器是否为IE edihrpageautonext var edi_browser = (window.ActiveXObject)?true:false; var edi_wheditor = 0,edi_windowedi = 0,edi_windowds = "",edi_cxmlloadhtml = ""; var edi_ierange = false,edi_winheight_w = null,edi_windowmaxs = false,edi_windowmaxsheight = 0,edi_space_input; //识别浏览器 var os_browser = { os:function(){ if(navigator.userAgent.indexOf("MSIE") > 0){ return "IE"; } if(navigator.userAgent.indexOf("Firefox") > 0){ return "Firefox"; } if(navigator.userAgent.indexOf("Opera") > 0){ return "Opera"; } } } var edi_zhtml; var edi_firefox = (document.all)?0:1; var edi_common = new commonclass(); var edi_scolor = new editor_color(); var edi_editor = new editor_body(); var edi_arrinto = Array("face","pic","table","media","flash","link","hr","color"); var edi_arrleft = Array("700,370","700,360","400,385","460,366","460,366","700,310","700,310","470,325"); var edi_toolname = Array("编辑","代码","预览"); //常用function对象 function commonclass(){ var com = (!edi_common)?this:edi_common; var odiv,i,ii,is,adiv,cdiv,xdivid; var cname,c_name,rinnerhtml,rintodiv,rintoarrsize,xmldoc; //获取document.getElementById对象; com.d = function (obj){ return document.getElementById(obj); } //过滤或替换对象中的指定值,objstr为需要替换的对象,delstr为需要替换的部分,newaddstr为最终的替换值; com.replaces = function (objstr,delstr,newaddstr){ return objstr.replace(delstr,newaddstr); } //当前对象在页面中的绝对位置,setParentop为距页面顶部的值,setParenleft为距页面左侧的值; com.setparentop = function (objs){ var iobjTop = objs.offsetTop; while(objs = objs.offsetParent){ iobjTop += objs.offsetTop } return iobjTop; } com.setparenleft = function (objs){ var iobjleft = objs.offsetLeft; while(objs = objs.offsetParent){ iobjleft += objs.offsetLeft } return iobjleft; } // //改父对象的position属性 com.setparenposition = function (objs,oclass){ var iobjpar,odivs,odiv_id,odiv_pos,oprs; while(objs = objs.offsetParent){ if(objs.currentStyle){ oprs = objs.currentStyle.position; }else{ oprs = window.getComputedStyle(objs,null)["position"]; } if (oprs == "absolute" || oprs == "relative" ){ if (oclass == 0){ //alert(oprs); odiv_pos = "static"; odiv_id = "position___" + oprs + "___" + objs.id; }else{ odivs = objs.id.split("___"); odiv_pos = odivs[1]; odiv_id = odivs[2]; } objs.style.position = odiv_pos; objs.id = odiv_id; } } } //返回一个对象的绝对宽度、高度、左、上的数组,setclass=1为返回的左、上是否加上本身的宽高 com.setobject = function (obj,setwidth,setheight){ var l,t,firenum = 0; t = com.setparentop(obj); l = com.setparenleft(obj); t = (setheight == 1)?t + obj.offsetHeight:t; l = (setwidth == 1)?l + obj.offsetWidth:l; if (os_browser.os() == "Firefox"){ firenum = 1; }else{ if (edi_browser && obj){ firenum = (obj.offsetWidth !== obj.clientWidth && obj.id.indexOf("font") == -1)?1:0; } } return Array(obj.offsetWidth - 2,obj.offsetHeight,l + firenum,t + firenum); } //通过onmouse触发,改变对象的className值 com.editclassname = function (obj,oldname,newclass){ if (obj)obj.className = com.replaces(obj.className,oldname,newclass); } com.cnames = function (cclass){ return (cclass == 0)?Array("_out","_over"):Array("_over","_out"); } //设定几种onmouse的触发条件和方式。分别为over、out、in三种事件,根据mousesup来判断执行。mouseclass为识别是over还是out com.eclass = function (obj,mouseclass,mousesup){ cname = com.cnames(mouseclass); c_name = cname[1]; com.editclassname(obj,cname[0],cname[1]); if (mousesup >= 1){ if (mousesup == 2){ obj.onmousedown = function (){ c_name = "_in"; com.editclassname(obj,cname[1],c_name); } } obj.onmouseout = function (){ com.editclassname(obj,c_name,cname[0]); } } } //onmouse触发鼠标事件改变对象中包含某部分子对象的className com.foreclass = function (obj,mouseclass,mousesup,mousepert,objid,mousepertclass){ odiv = obj.getElementsByTagName("div"); for (ii = 0;ii < odiv.length;ii ++){ com.eclass(odiv[ii],mouseclass,0); } com.eclass(obj,mouseclass,0); if (mousesup >= 1){ if (mousesup == 2){ cname = com.cnames(mouseclass); obj.onmousedown = function (){ cname = com.cnames(0); cname.push("_in"); for (ii = 0;ii < odiv.length;ii ++){ for (i = 0;i < cname.length;i ++){ com.editclassname(odiv[ii],cname[i],cname[2]); } } edi_common.ztbdisplay(obj.id,objid,"x"); //把同层内的所有对象都修改成out状态,同时包括对象的内容对象(body)的style.display状态 //注意需要统一命名规则,mousepert为当前id的序号前缀值,实际的对象id应为如:test_1,内容对象(body)应为如:test_1_body //mousepertclass为获取同层的方式,为空则直接取父对象为基准 if (mousepert){ cdiv = Array(); if (!mousepertclass){ cdiv = obj.offsetParent.getElementsByTagName("div"); } for (ii = 0;ii < cdiv.length;ii ++){ if (cdiv[ii].id.indexOf(mousepert + "_") !== -1 && cdiv[ii].id !== ""){ //这里要处理一下objid(也就是rzid),因为这里是:mousepert + "_" + id + "_" + objid的状态 if (parseInt(edi_common.replaces(this.id,mousepert + "_","")) !== parseInt(edi_common.replaces(cdiv[ii].id,mousepert + "_",""))){ adiv = cdiv[ii].getElementsByTagName("div"); for (i = 0;i < adiv.length;i ++){ edi_common.editclassname(adiv[i],cname[2],cname[0]); } //处理相应的内容对象(body) edi_common.ztbdisplay(cdiv[ii].id,objid); } } } } } } obj.onmouseout = function (){ for (ii = 0;ii < odiv.length;ii ++){ com.eclass(odiv[ii],1,0); } } } } com.ztbdisplay = function (obj,zdivid,displays){ //找到body的id,现在的标题id(obj)是:xxx_1_1的状态,body的id是:xxx_1_body_1的状态 //前面一个id是对象的序号id,后面的是当前编辑器层的识别id,所以以“_”把id截断,将body插入到其中 //xxx_xxx_1_1,xxx_xxx_1_body_1 rintodiv = xdivid = ""; rintodiv = obj.split("_"); for (is = 0;is < rintodiv.length;is ++){ if (parseInt(is) < parseInt(rintodiv.length - 1)){ xdivid += rintodiv[is] + "_"; } } com.zobjdisplay(edi_common.d(xdivid + "body_" + zdivid),displays); } com.zobjdisplay = function (obj,displays){ if (obj)obj.style.display = (displays)?"":"none"; } //弹出一个新的窗口 com.addwindow = function (obj,addivid,divwidth,zdivid,zoldname,znames){ var new_w,newin_url,new_left = 0,new_top = 0; var openurls = ""; new_w = divwidth; new_left = parseInt(new_w[0]/2); new_top = parseInt(new_w[1]/2); openurls = "../inc/editor/tool.php?type=" + znames + "&id=" + zdivid + "&ecolor=" + zoldname + "&injs=" + ((zin_editor_class == false)?0:1); if (os_browser.os() == "IE" || os_browser.os() == "Firefox"){ window.showModalDialog(openurls,window,"dialogWidth:" + new_w[0] + "Px;dialogHeight:" + new_w[1] + "Px;dialogTop:" + new_top + "px;dialogLeft:" + new_left + "px;status:0;scroll:no;help:0"); }else{ window.open(openurls,"","modal=yes,width=" + new_w[0] + ",height=" + new_w[1] + ",top=" + new_top + ",left=" + new_left + ",resizable=no,scrollbars=no,location=no,status=no"); } } //构建一个新的弹出式层,此层可定义宽高、上左位置 //divwidth为宽度,为0或空时,则为与父对象相同 com.addzindex = function (obj,addivid,divwidth,divclass,inheritmouse,zdivid,zvalue,zoldname){ var insize = com.setobject(obj,0,1); adiv = com.d(addivid); if (!adiv){ //如果divwidth为auto自动时,则生成的层宽度、左、上边距都与父对象一致,否则就是一个数组(宽,高,左,上) //inheritmouse = 1时继承父对象的onmouse var zhtml,z_divsid,z_alldiv,z_div0; edi_zhtml = zhtml = new zindex_html(); adiv = com.addobject(addivid,zhtml.zclass(addivid,zdivid,zvalue),divclass,(divwidth == "auto")?insize:divwidth,divwidth); }else{ //处理一下当前的坐标问题 adiv.style.display = ""; adiv.style.left = insize[2] + "px"; adiv.style.top = insize[3] + "px"; //com.setobject(obj,0,1) } if (inheritmouse == 1){ adiv.onmouseover = obj.onmouseover; adiv.onmouseout = obj.onmouseout; } } //生成一个新的对象 com.addobject = function (newobjid,newobjhtml,newclassname,nw,newclass,parend,zindex,dnone){ adiv = document.createElement("div"); adiv.id = newobjid; adiv.innerHTML = newobjhtml; adiv.className = newclassname; if (nw && nw !== "" && nw !== "undefined"){ adiv.style.width = nw[0] + "px"; if (newclass !== "auto"){ adiv.style.height = nw[1] + "px"; } adiv.style.left = nw[2] + "px"; adiv.style.top = nw[3] + "px"; } if (zindex)adiv.style.zIndex = zindex; if (dnone)adiv.style.display = dnone; if (parend && parend !== "" && parend !== "undefined"){ parend.appendChild(adiv); }else{ document.body.appendChild(adiv); } return adiv; } //改变对象或对象内的样式 com.eobjectcname = function (obj,editclass,cclass,iclass){ if (editclass == 1){ cdiv = obj.getElementsByTagName("div"); }else{ cdiv = Array(obj); } for (ii = 0;ii < cdiv.length;ii ++){ if (cclass == 0){ cdiv[ii].className = com.replaces(cdiv[ii].className,iclass,""); }else{ cdiv[ii].className = cdiv[ii].className + iclass; } } } //编辑器是否全屏操作 com.editormax = function (obj,editposition,arrsize,objleft,ecname,objd){ obj.style.position = editposition; obj.style.top = objleft[0]; obj.style.left = objleft[1]; obj.style.width = arrsize[0] + "px"; obj.style.height = (arrsize[1] == 0)?"auto": arrsize[1] + "px"; objd.style.display = (ecname == 1)?"none":""; } //插入操作的弹出层的尺寸及左、上位置 com.zindexinto = function (intoobject,orderid){ var l,t; rintodiv = com.d("editorall_" + orderid); if (rintodiv){ for (ii = 0;ii < edi_arrinto.length;ii ++){ if (intoobject == edi_arrinto[ii]){ rintoarrsize = edi_arrleft[ii].split(","); l = parseInt(rintodiv.offsetWidth)-parseInt(rintoarrsize[0]); t = parseInt(rintodiv.offsetHeight)-parseInt(rintoarrsize[1]); l = Math.ceil(l/2); t = Math.ceil(t/2); return Array(rintoarrsize[0],rintoarrsize[1],l,t); } } } } //插入操作的弹出层的内容层与阴影层的大小(为当前层宽高各去2px) com.zindexintodiv = function (){ if (rintoarrsize)return Array(rintoarrsize[0] - 4,rintoarrsize[1] - 4); } //关闭并清除对象层 com.zindexcloseclear = function (obj){ if (obj)obj.parentNode.removeChild(obj); } //读取xml文件 com.inloadxml = function (xmlurl){ if (window.ActiveXObject){ xmldoc = new ActiveXObject("Microsoft.XMLDOM"); xmldoc.async = false; xmldoc.load(xmlurl); }else if (document.implementation && document.implementation.createDocument){ xmldoc = document.implementation.createDocument("","",null); xmldoc.async = false; xmldoc.load(xmlurl); }else{ return false; } return xmldoc; } } //弹出层所加载的内容 function zindex_html(){ var com = this; var rzhtmlid,rzobjid,rhtml,ii,rsize,rethtml,infoiner,infostyle,infocount,rzid; var rzstyle,rznumber,facepagecount,faceiiclass,faceurl; facepagecount = 0; com.zclass = function (divid,zindexid,value){ rzid = zindexid; return com.z("","edi_zinbody","","",com.zinnerhtml(divid,value)); } com.z = function (divid,divclass,divw,divh,divbody,divonmouse,divstyle){ rhtml = "
" + com.zdivnfalse(divbody) + "
"; return rhtml; } com.it = function (ittype,itname,itclass,itwidth,itvalue,itopacity){ rhtml = ""; for (ii = 0;ii < tr + 1;ii ++){ rhtml += ""; for (i = 0;i < td + 1;i ++){ rhtml += "" + ((tbody)?tbody:"") + ""; } rhtml += ""; } rhtml += ""; return rhtml; } com.c = function (){ return com.z("","edi_c","",""); } com.zh = function (zhclass,zhbody,zhonmouse){ return com.z("",zhclass,"","",zhbody,com.zdivnfalse(zhonmouse)); } com.zdivnfalse = function (obj){ rhtml = ""; if (obj !== "" || obj !== "undefined"){ if (obj)rhtml = obj; } return rhtml; } //根据id识别不同的对象加载不同的层 com.zinnerhtml = function (zid,z_space){ var loadfuntion,lotitles,titlearr; rzhtmlid = zid.split("_")[0]; rinnerhtml = ""; switch(rzhtmlid){ //选择编辑、文本、预览、代码四种模式 case "emore": rinnerhtml = com.zselectoption(edi_toolname,"emore"); break; //字体 case "fontfamily": rhtml = Array("宋体","黑体","幼圆","华文彩云","楷体","隶书","Arial","Arial Black","Comic Sans MS","Verdana","Arial Narrow","Verdana","System","Times New Roman"); rinnerhtml = com.zselectoption(rhtml,"fontfamily"); break; //字号 case "fontsize": rhtml = Array("小","标准","中","大","超","巨"); rsize = Array(1,2,3,4,5,6); rinnerhtml = com.zselectoption(rhtml,"fontsize",rsize); break; //选择size单位 case "pxunits": rhtml = Array("%","px"); rinnerhtml = com.zselectoption(rhtml,"pxunits",z_space); break; //选择位置 case "splace": var space_z,szi,space_in,space_rhtml; space_z = Array("edi_spl_" + z_space + "_l,左对齐","edi_spl_" + z_space + "_c,居中","edi_spl_" + z_space + "_r,右对齐"); space_rhtml = Array(); for (szi = 0;szi < 3;szi ++){ space_in = space_z[szi].split(","); space_rhtml[szi] = com.zh("edi_zitspace",com.zh(space_in[0]) + com.zh("edi_zitsptet",space_in[1]) + com.c()); } rinnerhtml = com.zselectoption(space_rhtml,"splace",z_space); break; } return rinnerhtml; } //加载的层如果是select,则调用此处的值 com.zselectoption = function (optionvalue,optionfamily,optionsize){ var onmouse,oreg,selectmouse = ""; var spaiobj,spaiobj_i,spaiobj_array,spacedivs; rhtml = rsize = ""; for (ii = 0;ii < optionvalue.length;ii ++){ rsize = optionvalue[ii]; rethtml = ""; if (optionfamily == "splace"){ oreg = /'/gi; rsize = rsize.replace(oreg,""); } onmouse = "edi_zhtml.zselectdefit('" + rsize + "','" + optionfamily + "',this," + ii + ");edi_zhtml.zselectclosex('" + optionfamily + "',this);"; switch(optionfamily){ case "fontfamily": case "fontsize": if (optionfamily == "fontsize"){ rsize = "" + rsize + ""; }else{ rethtml += "font-family:" + rsize + ";"; } selectmouse = "onmousedown=\"edi_editor.e_formattext('" + optionfamily + "','" + ((optionfamily == "fontsize")?optionsize[ii]:rsize) + "'," + rzid + ");" + onmouse + "\""; break; case "emore": selectmouse = "onmousedown=\"edi_editor.e_window_switch('" + rsize + "'," + rzid + ");" + onmouse + "\""; break; // //选中单位,或者是对齐方式 //ii:0左对齐,1:居中,2:右对齐 //optionsize: rzid: case "splace": case "pxunits": if (optionfamily == "splace"){ spaiobj = Array("p,pic","p,photo","f,flash","m,media","t,table"); for (spaiobj_i = 0;spaiobj_i < spaiobj.length;spaiobj_i ++){ spaiobj_array = spaiobj[spaiobj_i].split(","); if (spaiobj_array[0] == optionsize){ spacedivs = spaiobj_array[1]; } } }else{ spacedivs = optionsize; } selectmouse = " onmousedown=\"" + onmouse + ";edi_zhtml.splace_objects('" + ii + "','" + rsize + "','" + spacedivs + "')\" "; break; } if (parseInt(ii + 1) == parseInt(optionvalue.length))rethtml += "background-image:none;"; rhtml += com.z("","edi_sp_out","","",rsize," onmouseover='edi_common.eclass(this,0,1)' " + selectmouse + " ",rethtml); } return rhtml; } // //选中单位或对齐方式 com.splace_objects = function (spacevalue,pxunitsvalue,classtypes){ // //space选中的对象 //edi_" + classtypes + "_splace_splace_" + rzid + " //pxunits有两个,一个是宽度,一个是高度 //edi_" + classtypes + "_w_size_" + rzid + " //edi_" + classtypes + "_h_size_" + rzid + " //怎么知道哪个单位是宽度,哪个是高度? //edi_space_input var spacediv,pxunitsdiv; spacediv = edi_common.d("edi_" + classtypes + "_splace_splace_" + rzid + ""); pxunitsdiv = edi_common.d("edi_" + classtypes + "_" + edi_space_input + "_size_" + rzid + ""); if (spacediv){ spacediv.value = spacevalue; } if (pxunitsdiv){ spacediv.value = pxunitsvalue; } } //select的层,显示默认值 com.zselectdefit = function (selectopen,selectname,obj,splace_l){ var zselect,zselect1,hiddens,oname,splace_arr,ovalue; oname = selectname; ovalue = selectopen; if (selectname == "splace" || selectname == "pxunits"){ selectname = obj.parentNode.parentNode.id; selectname = selectname.replace("_content_","_t_"); hiddens = selectname.replace(oname + "_",""); hiddens = hiddens.replace("_t_","_" + ((oname == "splace")?"splace":"size") + "_"); // //给隐藏域赋值 hiddens = edi_common.d(hiddens); if (oname == "splace"){ splace_arr = Array("left","center","right"); ovalue = splace_arr[splace_l]; } if (hiddens)hiddens.value = ovalue; }else{ zselect1 = edi_common.d(selectname + "_t_x_" + rzid); if (zselect1){ zselect1.innerHTML = selectopen; com.zselectclassx(selectname,zselect1); } selectname = selectname + "_t_" + rzid; } zselect = edi_common.d(selectname); if (zselect){ zselect.innerHTML = selectopen; com.zselectclassx(selectname,zselect); } } com.zselectclassx = function (sname,zselect){ if (sname !== "fontfamily" && sname !== "fontsize"){ if (zselect.parentNode.parentNode)edi_common.foreclass(zselect.parentNode.parentNode,1,0); }else{ if (zselect.parentNode)edi_common.eclass(zselect.parentNode,1,0); } } //关闭select com.zselectclosex = function (oftitle,obj){ var zparentid; if (oftitle == "splace" || oftitle == "pxunits"){ zparentid = obj.parentNode.parentNode.id; }else{ zparentid = oftitle + "_content_" + rzid; edi_common.zindexcloseclear(edi_common.d(oftitle + "_x_content_" + rzid)); } edi_common.zindexcloseclear(edi_common.d(zparentid)); } //插入层的标题部分 com.zintotitle = function (titlename,titleid){ infoiner = (titleid == "color")?"1":""; return com.zh("edi_zintotitle" + infoiner,com.z("","edi_zinto_i1") + com.zh("",titlename) + com.zh("edi_s_out edi_zintocl" + infoiner,com.zh("edi_zinto_close")," onMouseOver=editor_tools(this,'closezindexobj'," + rzid + ",'" + titleid + "') ")); } //插入层的menu部分 com.zintomenu = function (menubody,menuid){ var menuhtml = "",menuclass; for (ii = 0;ii < menubody.length;ii ++){ (ii > 0)?menuclass = "out":menuclass = "in"; menuhtml += com.z("edi_" + menuid + "_tool_menu_" + ii,"edi_f","","",com.z("","edi_m_l_" + menuclass,"","",menubody[ii]) + com.z("","edi_m_r_" + menuclass)," onmouseover=edi_common.foreclass(this,0,2,'edi_" + menuid + "_tool_menu'," + rzid + ") "); } return com.z("","edi_zinfomenu","","",menuhtml); } //调色板取色器 com.loadcoloradd = function (z_id){ var scolor_1,scolor_2; scolor_1 = edi_common.d("showcolor_loadall_" + z_id); scolor_2 = edi_common.d("showcolor_loadser_" + z_id); if (scolor_1)scolor_1.innerHTML = com.tb("","","",0,0,0,0,0,edi_scolor.zswatches(z_id)); if (scolor_2)scolor_2.innerHTML = com.tb("","","",0,0,0,0,0,edi_scolor.zbrightness(z_id)); edi_scolor.initialcolor(z_id); } } //调色板 function editor_color(){ var com = (!edi_scolor)?this:edi_scolor; var zcolor,zi,zchtml,selrgb,drrgb,hexch,cvalue,chtml,cohml; selrgb = drrgb = ""; selgray = '120'; hexch = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); com.initialcolor = function (zid){ //zcolor = com.zdivarray("showcolor,rgbcolor,selcolor,graycolor,graytable",zid); var zdivall; zdivall = Array("showcolor","rgbcolor","selcolor","graycolor","graytable"); zcolor = Array(); for (zi = 0;zi < zdivall.length;zi ++){ zcolor[zi] = edi_common.d(zdivall[zi] + "_" + zid); } return zcolor; } com.ztbtd = function (tname,tdcolor,tdw,tdh,tdbody,tdtitle){ cohml = "<" + tname + " "; if (tdtitle !== "")cohml += " title='" + tdtitle + "' "; if (tdcolor !== "")cohml += " bgcolor='#" + tdcolor + "' "; cohml += " height='" + tdh + "' width='" + tdw + "'>" + tdbody + ""; return cohml; } com.events = function (event){ return event||window.event; } com.zdivarray = function (zdivname,zdivid){ // zcolor = zdivname.split(","); // zchtml = Array(); // for (zi = 0;zi < zcolor.length;zi ++){ // zchtml[zi] = edi_common.d(zcolor[zi] + "_" + zdivid); // } // if (!zcolor[4]){ // window.setTimeout(function(){edi_scolor.zdivarray(zdivname,zdivid)},100); // }else{ // return (zchtml[0] == null)?"":zchtml; // } } com.tohexcolor = function (n) { var h, l; n = Math.round(n); l = n % 16; h = Math.floor((n / 16)) % 16; return (hexch[((!isNaN(h))?h:0)] + hexch[((!isNaN(l))?l:0)]); } com.docolor = function (cwith,lwith){ cvalue = Array('0x' + cwith.substring(1, 3),'0x' + cwith.substring(3, 5),'0x' + cwith.substring(5, 7)); if(lwith > 120){ lwith = lwith - 120; cvalue = Array((cvalue[0] * (120 - lwith) + 255 * lwith) / 120,(cvalue[1] * (120 - lwith) + 255 * lwith) / 120,(cvalue[2] * (120 - lwith) + 255 * lwith) / 120); }else{ cvalue = Array((cvalue[0] * lwith) / 120,(cvalue[1] * lwith) / 120,(cvalue[2] * lwith) / 120); } return '#' + com.tohexcolor(cvalue[0]) + com.tohexcolor(cvalue[1]) + com.tohexcolor(cvalue[2]); } com.endcolor = function(){ if(drrgb != selrgb){ drrgb = selrgb; for(zi = 0; zi <= 30; zi ++){ zcolor[4].rows[zi].cells[0].bgColor = com.docolor(selrgb, 240 - zi * 8); } } zcolor[2].value = com.docolor(zcolor[1].value,zcolor[3].value); zcolor[0].style.backgroundColor = zcolor[2].value; } com.tbtrcolor = function (r, g, b, n){ cvalue = Array(((r * 16 + r) * 3 * (15 - n) + 0x80 * n) / 15,((g * 16 + g) * 3 * (15 - n) + 0x80 * n) / 15,((b * 16 + b) * 3 * (15 - n) + 0x80 * n) / 15); return com.ztbtd("td",com.tohexcolor(cvalue[0]) + com.tohexcolor(cvalue[1]) + com.tohexcolor(cvalue[2]),8,8,""); } com.zswatches = function(zindexid){ var n1,n2,n3,cnum; cnum= new Array(1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0); chtml = ""; for(i = 0; i < 16; i ++){ chtml += ""; for(j = 0; j < 30; j ++){ n1 = j % 5;n2 = Math.floor(j / 5) * 3;n3 = n2 + 3; chtml += com.tbtrcolor((cnum[n3] * n1 + cnum[n2] * (5 - n1)),(cnum[n3 + 1] * n1 + cnum[n2 + 1] * (5 - n1)),(cnum[n3 + 2] * n1 + cnum[n2 + 2] * (5 - n1)), i); } chtml += ""; } //return edi_zhtml.tb("colortable_" + zindexid,"","",0,0,0,0,0,chtml," onmouseover='edi_scolor.getover(event)' onmouseout='edi_scolor.getout(event)' onclick='edi_scolor.getclick(event)' "); return edi_zhtml.tb("colortable_" + zindexid,"","",0,0,0,0,0,chtml," onmouseover='edi_scolor.getover(event)' onmouseout='edi_scolor.getout(event)' onclick='edi_scolor.getclick(event)' "); } com.zbrightness = function (zindexid){ chtml = ""; for(i = 255; i >= 0; i -= 8.5){ var s = Math.floor(i * 16 / 17); chtml += com.ztbtd("tr",com.tohexcolor(i) + com.tohexcolor(i) + com.tohexcolor(i),"","",com.ztbtd("td","",20,4,"",s),s); } return edi_zhtml.tb("graytable_" + zindexid,"","",0,0,0,0,0,chtml," onmouseover='edi_scolor.grayover(event)' onmouseout='edi_scolor.grayout(event)' onclick='edi_scolor.grayclick(event)' "); } //调色板鼠标事件触发 com.getover = function (event){ zevent = com.events(event); zcolor[1].value = (edi_browser)?zevent.srcElement.bgColor:zevent.target.bgColor; com.endcolor(); } com.getout = function (){ if (selrgb!== ""){ zcolor[1].value = selrgb; com.endcolor(); } } com.getclick = function (event){ zevent = com.events(event); (edi_browser)?selrgb = zevent.srcElement.bgColor:selrgb = zevent.target.bgColor; com.endcolor(); } com.grayover = function (event){ zevent = com.events(event); zcolor[3].value = (edi_browser)?zevent.srcElement.title:zevent.target.title; com.endcolor(); } com.grayout = function (){ if (selgray!== ""){ zcolor[3].value = selgray; com.endcolor(); } } com.grayclick = function (event){ zevent = com.events(event); (edi_browser)?selgray = zevent.srcElement.title:selgray = zevent.target.title; com.endcolor(); } // //常用颜色选择 //edi_editor.inbody_t('" . $typesub . "'," . $id . ",'','#" . $edi_colorsamplec[$i] . "') //zdivall = Array("showcolor","rgbcolor","selcolor","graycolor","graytable"); //edi_scolor.gcolorins(this,'" . $typesub . "'," . $id . ",'#" . $edi_colorsamplec[$i] . "') com.gcolorins = function (obj,typesub,tid,colors){ var zcolors; zcolors = com.initialcolor(tid); if (zcolors[0] && zcolors[1] && zcolors[2]){ zcolors[0].style.backgroundColor = colors; zcolors[1].value = colors; zcolors[2].value = colors; } obj.onclick = function (){ edi_editor.inbody_t(typesub,tid,'',colors) } } } // //弹出编辑器全屏 //editor_win_maxs(edi_common.d("edi_topwin_max_" + orderid),"wintool",orderid) function editor_win_maxs(obj,toolname,orderid,maxwins){ var inname,inxlass,otoolname,editors,ecname = 1; var medit = Array(edi_common.d("editorall_" + orderid),edi_common.d("wintextm_" + orderid),edi_common.d("mintools_" + orderid)); var mwidth,mheight; var parleft,partop = 0; if (medit[1].style.display == "" || maxwins == 1){ document.documentElement.style.overflow = "hidden"; edi_wheditor = medit[0].offsetWidth - 20; // //父对象的left与top //如果各级父对象中有relative或absolute,则其会按照父对象来设置left与top //需要解决这一问题 //将所有的父对象的position:都清除,改为:ediotmaxtool partop = document.documentElement.scrollTop; edi_common.setparenposition(medit[0],0); edi_windowmaxs = true; edi_common.editormax(medit[0],"absolute",Array(document.documentElement.clientWidth - 20,document.documentElement.clientHeight - 21),Array(partop,0),1,medit[1]); inxlass = (medit[2].style.display == "none")?1:3; }else{ edi_common.setparenposition(medit[0],1); document.documentElement.style.overflow = "auto"; document.documentElement.style.overflowX = "hidden"; edi_windowmaxs = false; edi_common.editormax(medit[0],"relative",Array(edi_wheditor,0),Array("",""),0,medit[1]); ecname = 0; inxlass = (medit[2].style.display == "none")?0:2; } edi_editorwindow(inxlass,orderid); edi_common.eobjectcname(obj,1,ecname,"_i"); } //给工具栏所有的图标都加上鼠标事件 function editor_tools(obj,toolname,orderid,parameters){ var inname,inxlass,otoolname,editors,ecname = 1; edi_common.eclass(obj,0,2); edi_editor.editor_images(obj,toolname,orderid); otoolname = toolname; obj.onmouseup = function (){ //图标的事件触发 switch(toolname){ //编辑窗口全屏与否 case "wintool": editor_win_maxs(obj,toolname,orderid); break; //完整工具栏与简单工具栏的切换 case "wineditor": var mtool = Array(edi_common.d("mintools_" + orderid),edi_common.d("maxtools_" + orderid),edi_common.d("wintextm_" + orderid)); if (mtool[0].style.display == ""){ mtool[0].style.display = "none"; mtool[1].style.display = ""; ecname = 0; inxlass = (mtool[2].style.display == "")?0:1; }else{ mtool[0].style.display = ""; mtool[1].style.display = "none"; inxlass = (mtool[2].style.display == "")?2:3; } edi_editorwindow(inxlass,orderid); edi_common.eobjectcname(obj,1,ecname,"_i"); break; //关闭层 case "closezindexobj": edi_common.zindexcloseclear(edi_common.d(parameters + "_content_" + orderid)); break; //插下分页符 case "lauto": //edi_editor.inbody_t(toolname,orderid); edi_editor.e_formattext(toolname,"",orderid); break; //插入 default: if (edi_windowedi == 0 && edi_windowds !== edi_toolname[1]){ if (toolname == "textcolor" || toolname == "textbg" || toolname == "textcolor_x" || toolname == "textbg_x"){ toolname = "color"; } toolname = edi_common.replaces(toolname,"_x",""); inname = edi_editor.e_comparison(toolname); if (inname !== false){ edi_editor.e_formattext(inname,"",orderid); }else{ //edi_common.addzindex(obj,toolname + "_content_" + orderid,edi_common.zindexinto(toolname,orderid),"edi_zintozindex",0,orderid,"",otoolname); // edi_common.addwindow(obj,toolname + "_content_" + orderid,edi_common.zindexinto(toolname,orderid),orderid,otoolname,toolname); } } } } } //document.selection.createRange().pasteHTML //处理按钮弹出下拉菜单事件 // //如果是选中对齐方式:splace_edi_flash_splace,1,'f' function emore_select(newid,orderid,selectvalue,sinst){ if (edi_windowedi == 0 || newid == "emore" || newid == "emore_x"){ obj = edi_common.d(newid + "_" + orderid); edi_space_input = sinst; edi_common.foreclass(obj,0,0); edi_common.addzindex(obj,newid + "_content_" + orderid,"auto","edi_toolzindex",1,orderid,selectvalue); obj.onmouseout = function (){ edi_common.foreclass(obj,1,0); adiv = edi_common.d(newid + "_content_" + orderid); (adiv)?adiv.style.display = "none":false; } } } function editor_body(){ var com = this; var editors; // //打开编辑属性 com.e_loadbodyhtmls = function (zid){ var edtbody,edtinhtml; editors = com.e_loadeditors("editor_body_" + zid,1); editors.document.designMode="On"; editors.document.open(); editors.document.write(""); editors.document.close(); editors.document.contentEditable = true; edtbody = edi_common.d("editorbody_" + zid); edtinhtml = edi_common.d("editor_body_" + zid); if (edtbody && edtinhtml){ edtinhtml.contentWindow.document.body.innerHTML = edtbody.value; } } //获取编辑器编辑框 com.e_loadeditors = function (obj,oclass,window_class){ var windowf = window; if (window_class){ if (os_browser.os() == "IE" || os_browser.os() == "Firefox"){ windowf = window.dialogArguments; }else{ windowf = window.opener; } } return edi_browser?windowf.eval(obj):((oclass == 1)?windowf.edi_common.d(obj).contentWindow:windowf.edi_common.d(obj)); } //在当前对象中加一个相同大小的图片并透明 com.editor_images = function (obj,objname,zid){ var addimg,imgs; imgs = edi_common.d(objname + "edi_imgs_" + zid); if (!imgs){ var addimg = document.createElement("img"); addimg.className = "edi_imgs"; addimg.id = objname + "edi_imgs_" + zid; addimg.style.display = "none"; addimg.style.width = (obj.clientWidth - 2) + "px"; addimg.style.height = (obj.clientHeight - 2) + "px"; addimg.onmousedown = function (){ com.ieraney(zid); } obj.appendChild(addimg); addimg.style.display = ""; } } //查找是否处理文字事件 com.e_comparison = function (obj){ var allt,allb,allts,allbs,ai,retstr = false; allt = "paste,cut,copy,cancel,recovery,fontfamily,fontsize,bold,italic,underline,strike,textcolor,textbg,clear,lnumber,lleft,lsymbol,lcenter,linden,lright,lnoinden,unlink,link,hr"; allb = "paste,cut,copy,undo,redo,fontname,fontsize,bold,italic,underline,RemoveFormat,ForeColor,BackColor,DELETE,insertorderedlist,Justifyleft,InsertUnorderedList,JustifyCenter,Outdent,JustifyRight,indent,unlink,CreateLink,InsertHorizontalRule"; allts = allt.split(","); allbs = allb.split(","); for (ai = 0;ai < allts.length;ai ++){ if (allts[ai] == obj){ retstr = allbs[ai]; } } return retstr; } //处理编辑器事件 com.e_formattext = function (command,option,zid){ var fonttext,editors; if (!option || option == "")option = null; editors = com.e_loadeditors("editor_body_" + zid,0); //分不同的触发事件 editors.focus(); switch(command){ //先获取选中的文字内容,再把选中的内容复制到这里进行处理,同时删除选中的部分,处理完成后把内容插入到原处 case "strike": com.intexto(editors,com.fonts(com.selecttext(editors),"text-decoration:line-through;"),true); break; //插入分页符 case "lauto": com.intexto(editors,"

",false); break; //FontName FontSize case "fontfamily": case "fontsize": com.esecommandtext(editors,((command == "fontfamily")?"FontName":"FontSize"),option); break; //常规 default: com.esecommandtext(editors,command,option); } } //处理文本 com.fonts = function (fonttext,fontstyle){ return "" + fonttext + ""; } //获取选中的文本对象 com.selecttext = function (obj){ return edi_browser?obj.document.selection.createRange().text:obj.contentWindow.getSelection(); } //将处理过的文本插入到光标处 com.intexto = function (obj,texts,delid){ //先要删除文本 if (delid == true){ com.esecommandtext(obj,"DELETE"); obj.focus(); } if (edi_browser){ obj.focus(); if (edi_ierange == false){ obj.document.selection.createRange().pasteHTML(texts); }else{ edi_ierange.pasteHTML(texts); } }else{ obj.contentWindow.document.execCommand("inserthtml",null,texts); } obj.focus(); } com.ieraney = function (rzid){ //IE下记录光标的位置 var editors,e_parents; if (edi_browser){ editors = com.e_loadeditors("editor_body_" + rzid,1); editors.focus(); edi_ierange = editors.document.selection.createRange(); } } //自动将文字变为选中状态 com.setSelectText = function (obj,starttext,endtext){ if(edi_browser){ var range = obj.createTextRange(); range.collapse(); range.moveEnd("character",endtext); range.moveStart("character",starttext); range.select(); }else{ obj.focus(); obj.setSelectionRange(starttext,endtext); } } //处理常规的文本对象 com.esecommandtext = function (obj,command,option){ if (edi_browser){ obj.document.execCommand(command,true,option); }else{ obj.contentDocument.execCommand(command,false,option); } obj.focus(); } //切换编辑器窗口 com.e_window_switch = function (obj,zid){ var whtml,wbody,winnerhtml; var tpiner,tpsize,tpsize_body,edi_firm_divwin; whtml = edi_toolname; com.e_window_switch_not(((obj == whtml[1])?1:0),zid); //开始切换 wbody = edi_common.d("editor_body_" + zid).contentWindow.document.body; switch(obj){ // //编辑模式 case whtml[0]: // //预览模式 case whtml[2]: if (edi_windowds !== whtml[0] && edi_windowds !== "")wbody.innerHTML = edi_browser?wbody.innerText:wbody.textContent; // //如果是预览 if (obj == whtml[2]){ // //生成一个全屏的窗口,加载内容,需要注意的时,如果是在后台管理系统中,弹出的全屏窗口需要是最初层框架的父框架(top) //请注意,在后台中目前支持一层框架,超过两层以上的框架,有部分功能(如全屏编辑)可能会出错。 window.frameElement //tparents = ((zin_editor_class == true)?window:window.top); if (zin_editor_class == false){ tparents = window.top; edi_firm_divwin = window.frameElement.id; }else{ tparents = window; } if (zin_editor_class == false && edi_tpinerdiv_top == false){ // //加载js与css文件到顶层 edi_tpinerdiv_top = true; tparents.at.loadjavacss("../style/editor/style.css","css"); tparents.at.loadjavacss("../inc/js/editor_public.js","js"); } document.documentElement.style.overflow = "hidden"; tpiner = "
预览窗口
"; tpiner += "
"; if (zin_editor_class == true){ tpiner += "
全屏编辑
"; } tpiner += "
关闭预览
"; tpiner += "
"; tpiner += "
" + wbody.innerHTML + "
"; tpsize = Array(tparents.document.documentElement.clientWidth,tparents.document.documentElement.clientHeight,tparents.document.documentElement.scrollTop); edi_tpinerdiv = tparents.edi_common.addobject("edi_tpinerdiv_" + zid,tpiner,"edi_toolnoesbody",Array(tpsize[0],tpsize[1],0,tpsize[2])); edi_tpinerdiv.style.zIndex = 10000000; tpsize_body = tparents.edi_common.d("edi_tpinerdiv_body"); tpsize_body.style.height = (tpsize[1] - 40) + "px"; } break; // //代码模式 case whtml[1]: if (edi_windowds !== whtml[1]){ if (edi_browser){ wbody.innerText = wbody.innerHTML; }else{ wbody.textContent = wbody.innerHTML; } } break; } edi_windowds = obj; } // //关闭预览 com.closeedtoolnoe = function (edit_id){ //alert(tparents.edi_tpinerdiv); edi_common.zindexcloseclear(edi_common.d("edi_tpinerdiv_" + edit_id)); } // //全屏编辑 com.openwindtoolsedit = function (edit_id,editname){ var winfreames = window; // //先关闭全屏 com.closeedtoolnoe(edit_id); if (zin_editor_class == false){ winfreames = window.frames[String(editname)]; } // //最小化编辑 // //打开编辑 if (edi_windowmaxs == true){ winfreames.editor_win_maxs(tparents.edi_common.d("edi_topwin_max_" + edit_id),"wintool",edit_id); } if (zin_editor_class == true)winfreames.editor_win_maxs(edi_common.d("edi_topwin_max_" + edit_id),"wintool",edit_id); } //工具栏禁用效果 com.e_window_switch_not = function (toolid,zid){ var wetool,wopacity,wetdivs,wetdivsw; // //先要判断工具栏的具体 宽度 //两个,一个是简化的,一个是正常的 wetdivs = Array(edi_common.d("edi_tool_min_tonoe" + zid),edi_common.d("edi_tool_max_tonoe" + zid)); wetool = Array(edi_common.d("mintools_not_" + zid),edi_common.d("maxtools_not_" + zid)); wopacity = (toolid == 1)?"":"none"; for (var wi = 0;wi < 2;wi ++){ wetool[wi].style.display = wopacity; wetdivsw = parseInt(wetdivs[wi].scrollWidth) - 60; wetool[wi].style.width = ((wetdivsw <= 0)?0:wetdivsw) + "px"; } } //将图片等插入到编辑框中 com.inbody_t = function (t_class,rzid,closebut,colorer){ var ininput1,ininput2,editors,window_f,bodyhtml = ""; editors = com.e_loadeditors("editor_body_" + rzid,0,true); window.close(); if (editors && closebut !== "close"){ switch(t_class){ case "pic": //图片是1001与1002 ininput1 = edi_common.d("upload_more_photo_1001" + rzid + "_i"); ininput2 = edi_common.d("upload_more_photo_1002" + rzid + "_i"); if (ininput1 && ininput2){ bodyhtml = com.inbody_tpic(ininput1) + com.inbody_tpic(ininput2); } break; case "flash": case "media": //swf & media 文件 ininput1 = edi_common.d(((t_class == "flash")?"upload_more_flash_1003":"upload_more_media_1004") + rzid + "_i"); ininput2 = edi_common.d("edi_" + t_class + "_link_" + rzid); //var s = "upload_more_flash_1003"; if (ininput1 && ininput2){ bodyhtml = com.inbody_tflash(ininput1.value,com.inbody_wspach(t_class,rzid),0) + com.inbody_tflash(ininput2.value,com.inbody_wspach(t_class,rzid),((t_class == "flash")?0:1)); //edi_media_link_ } break; //字体颜色 selcolor_ case "textcolor": case "textcolor_x": case "textbg": case "textbg_x": ininput1 = edi_common.d("selcolor_" + rzid); if (ininput1){ com.esecommandtext(editors,((t_class.replace("_x","") == "textcolor")?"ForeColor":"BackColor"),((colorer)?colorer:ininput1.value)); } break; //表情 case "face": bodyhtml = ""; break; //分页符 //case "lauto": //bodyhtml = "
"; //break; } if (bodyhtml !== "")com.intexto(editors,bodyhtml,false); } } //分解pic com.inbody_tpic = function(ininput_pic){ var aimage_value,aimage,imagehtml = ""; if (ininput_pic.value !== ""){ aimage_value = ininput_pic.value.split("‖‖"); for (i = 0;i < aimage_value.length;i ++){ aimage = aimage_value[i].split("^^^"); //imagehtml += "
"; if (aimage[1] !== ""){ imagehtml += "
"; imagehtml += "
" + aimage[1] + "
"; }else{ imagehtml += ""; } } } return imagehtml; } //flash & media com.inbody_tflash = function (flashurl,flashsize,fclass){ var tflash,tsrc,twidth,theight,spaces; tflash = ""; spaces = Array("left","center","right"); if (flashurl && flashurl !== "" && flashurl !== "undefined" && flashurl !== "http://"){ tsrc = com.inbody_turls(flashurl); twidth = (flashsize[0] !== "")?"width='" + flashsize[0] + "'":""; theight = (flashsize[1] !== "")?"height='" + flashsize[1] + "'":""; if (fclass == 0){ tflash += ""; tflash += ""; tflash += ""; tflash += ""; // //在IE下外加居中或居右 if (edi_browser){ if (parseInt(flashsize[2]) > 0){ tflash = "
" + tflash + "
"; } } }else{ tflash += ""; } } return tflash; } //取大小及位置 //取出来的是一个数组,宽+单位,高+单位,位置 //edi_flash_w;edi_flash_w_size;edi_flash_splace;edi_flash_splace_size; com.inbody_wspach = function (bodyclass,editorid,eclass){ var in_w,in_wsize,in_h,in_hsize,in_splace,allarr; allarr = Array(); in_w = edi_common.d("edi_" + bodyclass + "_w_" + editorid); in_wsize = edi_common.d("edi_" + bodyclass + "_w_size_" + editorid); in_h = edi_common.d("edi_" + bodyclass + "_h_" + editorid); in_hsize = edi_common.d("edi_" + bodyclass + "_h_size_" + editorid); in_splace = edi_common.d("edi_" + bodyclass + "_splace_splace_" + editorid); allarr[0] = (in_w.value == "")?"":in_w.value + ((!eclass)?((in_wsize.value == "")?"px":in_wsize.value):""); allarr[1] = (in_h.value == "")?"":in_h.value + ((!eclass)?((in_hsize.value == "")?"px":in_hsize.value):""); allarr[2] = in_splace.value; return allarr; } //判断是本地还是远程 com.inbody_turls = function (iurl){ var aurl = iurl.toLowerCase(); return ((aurl.indexOf("http://") !== -1)?"":"../") + iurl; } } // //当前编辑器的内容编辑框高度(分为几种模式,相对于本身框架的) function edi_editorwindow(window_type,editor_class,edittype){ var ifrheight,ifrbody,ifr_type; //取本身框架的高度 ifrheight = ((edi_windowmaxs == true && zin_editor_class == true)?window.screen.availHeight:((edi_windowmaxsheight > 0)?edi_windowmaxsheight:document.documentElement.clientHeight)); //当前的内容框架 ifrbody = edi_common.d("editor_body_" + editor_class); //模式: //0为默认的全部展开 //1为全部展开的全屏模 //2为简捷工具栏 //3为简捷工具栏的全屏 if (!edittype){ edi_winheight_w = window_type; } ifr_type = Array(130,93,96,59); if (ifrbody){ ifrbody.style.height = ((edi_windowmaxsheight > 0 && edi_windowmaxs == false)?edi_windowmaxsheight:(ifrheight * 1 - ifr_type[window_type] * 1 - ((zin_editor_class == true && window_type < 3)?140:0))) + "px"; } } //启用编辑器高度自适应 function edi_editorheight(etype,eclass){ edi_editorwindow(etype,eclass,true); if (edi_winheight_w !== null){ etype = edi_winheight_w; } window.setTimeout(function (){edi_editorheight(etype,eclass)},50); } // //编辑器高度与父对象相同 function edi_parentheight(typclass,edi_div){ if (typclass){ edi_div.parentNode.style.height = (parseInt(edi_div.clientHeight) + 0) + "px"; } } //加载编辑器 function c_editor_tools(editor_id,content,toolsclass,bodyheight){ var loadfuntion,edi_div,toomin = 0; edi_div = at.d(content); if (edi_div){ if (zin_editor_class == true){ toomin = 1; } if (bodyheight || bodyheight > 0)edi_windowmaxsheight = bodyheight; xml_loadhtml = xmlposthtml = at.xmlhttps("../inc/editor/editor.php?type=all&id=" + editor_id + "&toolmin=" + toomin + "&tool=" + ((toolsclass || toolsclass !== "")?toolsclass:0),true,"u=false"); loadfuntion = nsyhtml = function (){ at.addobject("tool_" + content,((zin_editor_class == true)?xmlposthtml:xml_loadhtml),"","",edi_div); edi_editor.e_loadbodyhtmls(editor_id); // //第一次 edi_editorheight(0,editor_id); edi_parentheight(toolsclass,edi_div); } if (zin_editor_class == true){ at.xmlposts("nsyhtml()"); }else{ at.xmlposts(loadfuntion(),false,"editor"); } } } //