www.gusucode.com > 仿51.com的php源码 1.1 > home/UBBEditor.js
String.prototype.trim = function(){ return this.replace(/(^\s*)|(\s*$)/g, ""); } String.prototype.lengthByte = function() { return this.replace(/[^\x00-\xff]/g,"**").length; } function getIE(t,z){ e=document.getElementById(t); var t=e.offsetTop; var l=e.offsetLeft; while(e=e.offsetParent){ t+=e.offsetTop; l+=e.offsetLeft; } if(z=='top'){ return t; }else if(z=='left'){ return l; } } function insert(img){ var images = img; var imgtag = "<img src='../User/face/"+images+"'>" document.all('CommentEditor').innerHTML = document.all('CommentEditor').innerHTML+imgtag; if(document.all("face").style.display=="inline"){ document.all("face").style.display="none"; } } function editor_process(pid){ switch(pid){ case 1: var moodListObj = document.getElementById("face"); if (moodListObj) { moodListObj.style.display = (moodListObj.style.display == "inline") ? "none" : "inline"; moodListObj.style.top = getIE('font-face','top')+21 + "px"; moodListObj.style.left = getIE('font-face','left')+ "px"; } if(document.all('CommentEditor')){ document.all('font-face').src='/images/ubbeditor/face_click.gif'; } break; case 2: if(document.all('CommentEditor')){ if(document.all('CommentEditor').style.fontWeight=="bold"){ document.all('font-bold').src='/images/ubbeditor/bold.gif'; document.all('CommentEditor').style.fontWeight="normal"; }else{ document.all('CommentEditor').style.fontWeight="bold"; document.all('font-bold').src='/images/ubbeditor/bold_click.gif'; } } break; case 3: if(document.all('CommentEditor')){ if(document.all('CommentEditor').style.fontStyle=="italic"){ document.all('font-italic').src='/images/ubbeditor/italic.gif'; document.all('CommentEditor').style.fontStyle="normal"; }else{ document.all('CommentEditor').style.fontStyle="italic"; document.all('font-italic').src='/images/ubbeditor/italic_click.gif'; } } break; case 4: if(document.all('CommentEditor')){ if(document.all('CommentEditor').style.textDecoration=="underline"){ document.all('font-underline').src='/images/ubbeditor/underline.gif'; document.all('CommentEditor').style.textDecoration="none"; }else{ document.all('CommentEditor').style.textDecoration="underline"; document.all('font-underline').src='/images/ubbeditor/underline_click.gif'; } } break; case 5: if(document.all('CommentEditor')){ if(document.all('CommentEditor').style.filter=="Glow(Color=#3366FF,Strength=2)"){ document.all('font-glow').src='/images/ubbeditor/glow.gif'; document.all('CommentEditor').style.filter=""; var newstr,rep_str; //rep_str =/<table[\s\S]*?style=['\"]width:95\%\/\/pic\.51\.com\/user\/face\/(\d{1,2})\.gif['\"]>/ig; newstr = document.all('CommentEditor').innerText; document.all('CommentEditor').innerHTML = newstr; }else{ document.all('CommentEditor').innerHTML = "<table style='width:95%;filter:glow(Color=#3366FF,Strength=2);'>"+document.all('CommentEditor').innerHTML+"</table>"; document.all('CommentEditor').style.filter="Glow(Color=#3366FF,Strength=2)"; document.all('font-glow').src='/images/ubbeditor/glow_click.gif'; } } break; case 6: intocolor(); document.all('colorpanel').style.top = getIE('font-color','top')+21 + "px"; document.all('colorpanel').style.left = getIE('font-color','left')+ "px"; document.all('font-color').src='/images/ubbeditor/color_click.gif'; document.all("colorpanel").style.display="inline"; } } function editor_post(obj){ //临时赋值; //alert(document.all("vipstate").value); if(document.all("vipstate").value ==0 && document.all("modestate").value == 1){ alert("您不是VIP,无法使用VIP编辑模式,请升级VIP"); window.open("http://www.wu-liao.com/help/free-vip.php"); return false; } var tempHTML,face,f_str,f_str2; document.all('CommentEditor_temp').innerHTML = document.all('CommentEditor').innerHTML; if(document.all('CommentEditor_temp').innerHTML!=""){ //if(document.all('CommentEditor_temp').innerText.lengthByte()< 3 || document.all('CommentEditor_temp').innerText.lengthByte() > 125){ //alert("留言或评论字数不能小于3或者大于125个字符"); //return false; //} tempHTML = document.all('CommentEditor_temp').innerHTML; //过滤表情图片为UBB格式; face =/<IMG[\s\S]*?src=['\"]http:\/\/www\.wu-liao\.com\/User\/face\/(\d{1,2})\.gif['\"]>/ig; tempHTML =tempHTML.replace(face,"[img=$1.gif]"); //过滤一些特殊字符; f_str =/~/ig; tempHTML = tempHTML.replace(f_str,"~"); f_str2 =/on[a-z]*?=".*?"/ig; tempHTML =tempHTML.replace(f_str2,""); document.all('CommentEditor_temp').innerHTML = tempHTML; tempHTML = document.all('CommentEditor_temp').innerText; tempHTML = tempHTML.trim(); if(tempHTML.lengthByte()==0){ alert("内容不能为空!"); return; } if(document.all('CommentEditor').style.fontWeight == 'bold'){ tempHTML = "[B]"+tempHTML+"[/B]"; } if(document.all('CommentEditor').style.fontStyle=='italic'){ tempHTML = "[I]"+tempHTML+"[/I]"; } if(document.all('CommentEditor').style.textDecoration=='underline'){ tempHTML = "[U]"+tempHTML+"[/U]"; } if(document.all('CommentEditor').style.filter){ tempHTML = "[FILTER="+document.all('CommentEditor').style.filter+"]"+tempHTML+"[/FILTER]"; } if(document.all('CommentEditor').style.color){ tempHTML = "[COLOR="+document.all('CommentEditor').style.color+"]"+tempHTML+"[/COLOR]"; } //tempHTML = "[U="+document.all('CommentEditor').style.fontWeight+","+document.all('CommentEditor').style.fontStyle+","+document.all('CommentEditor').style.textDecoration+","+document.all('CommentEditor').style.filter+","+document.all('CommentEditor').style.color+"]"+tempHTML+"[/font]"; var test; var search_b = tempHTML.match(/\[B\]/); var search_i = tempHTML.match(/\[I\]/); var search_u = tempHTML.match(/\[U\]/); var search_color = tempHTML.match(/\[\/COLOR\]/); var search_filter = tempHTML.match(/\[\/FILTER\]/); if(document.all("vipstate").value ==0){ if(search_b != null || search_i != null || search_u != null || search_color != null || search_filter != null){ tempHTML = document.all('CommentEditor_temp').innerText; } } document.all(obj).value = tempHTML; } } //调色板; 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<2;i++){ for (j=0;j<6;j++){ colorTable=colorTable+'<tr height=12>' colorTable=colorTable+'<td width=11 style="background-color:#000000">' if (i==0){ colorTable=colorTable+'<td width=11 style="background-color:#'+ColorHex[j]+ColorHex[j]+ColorHex[j]+'">'} else{ colorTable=colorTable+'<td width=11 style="background-color:#'+SpColorHex[j]+'">' } colorTable=colorTable+'<td width=11 style="background-color:#000000">' for (k=0;k<3;k++){ for (l=0;l<6;l++){ colorTable=colorTable+'<td width=11 style="background-color:#'+ColorHex[k+i*3]+ColorHex[l]+ColorHex[j]+'">' } } } } colorTable='<table width=253 border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 solid;border-bottom:none;border-collapse: collapse" bordercolor="000000">' +'<tr height=30><td colspan=21 bgcolor=#cccccc>' +'<table cellpadding="0" cellspacing="1" border="0" style="border-collapse: collapse">' +'<tr><td width="3"><td><input type="text" name="DisColor" size="6" disabled style="border:solid 1px #000000;background-color:#ffff00"></td>' +'<td width="3"><td><input type="text" name="HexColor" size="7" style="border:inset 1px;font-family:Arial;" value="#000000"></td></tr></table></td></table>' +'<table border="1" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="000000" onmouseover="doOver()" onmouseout="doOut()" onclick="doclick()" style="cursor:hand;">' +colorTable+'</table>'; colorpanel.innerHTML=colorTable } function doOver() { if ((event.srcElement.tagName=="TD") && (current!=event.srcElement)) { if (current!=null){current.style.backgroundColor = current._background} event.srcElement._background = event.srcElement.style.backgroundColor DisColor.style.backgroundColor = event.srcElement.style.backgroundColor HexColor.value = event.srcElement.style.backgroundColor event.srcElement.style.backgroundColor = "white" current = event.srcElement } } function doOut() { if (current!=null) current.style.backgroundColor = current._background } function doclick(){ if (event.srcElement.tagName=="TD"){ document.all('CommentEditor').style.color= event.srcElement._background; if(document.all("colorpanel").style.display=="inline"){ document.all("colorpanel").style.display="none"; } //return event.srcElement._background } } function CheckCommentForm(){ var str = document.all('CommentEditor').innerText; if(str.length<3){ alert("输入的字符不能少于3个!"); return false; } return true; }