好友
阅读权限10
听众
最后登录1970-1-1
|
m_height
本帖最后由 ak2500 于 2011-2-23 23:55 编辑
/*ui.jsAuthor: ChiChouLastUpdate: 2010-06-30*/var m_viewmode=0;var m_height=500;var idMsg;function OnPaste(){ //粘贴
OnChangeView(0); var codeSrc=$("codesrc"); if(document.all){ codeSrc.select(); document.execCommand("Paste"); location.replace("#"); return; } else { MyMsgBox("仅支持IE浏览器。","错误"); } }function OnColor(stx){ //着色
if(OnCheckCode(1)==1) return; var src = $("codesrc").value; var clsHightlight = new CLASS_HIGHLIGHT(src,stx); var szCode=clsHightlight.highlight(); $("codeFrame").innerHTML=szCode; $("txthtml").value="<div style='border:"+$("codeEditor").style.border+";background:"+$("codeEditor").style.background+"'>"+szCode+"</div>"; $("txtubb").value=HTML2UBB(szCode); OnChangeView(1); MyMsgBox("语法着色完成。您可以:<p><button onclick=\"OnCopyCode()\" title=\"Copy\">复制代码</button> <button onclick=\"OnChangeView(0)\">重新编辑</button></p>","操作完成"); idMsg=setTimeout('OnCloseMsg()',10000);}function OnCheckCode(src){ //检查代码是否为空
var code; switch(src){ case 1: code = $("codesrc").value;break; case 2: code = $("txthtml").innerText;break;} if(code.length == 0){ MyMsgBox("请先输入代码。","错误"); idMsg=setTimeout("OnCloseMsg()",3000); //2秒自动关闭
return 1; } return 0;}function OnChangeColor(color){ //修改背景颜色
OnChangeView(1); var obj=$("codeFrame") obj.style.border = "1px solid #" + bdcolor[color; obj.style.background = "#"+bgcolor[color;}function OnCopyCode(){ //复制着色后的代码
if(!document.all){ MyMsgBox("复制功能仅支持IE。","错误"); return; } if(OnCheckCode(2)==1) return; //检查代码
switch(m_viewmode){ case 1://Rich Edit
var objEditor = $("codeEditor"); objEditor.contentEditable = true; //设置编辑状态可用
objEditor.focus(); //设置焦点
document.execCommand("SelectAll",false,""); //选定
document.execCommand("Copy",false,""); //复制
document.execCommand("Unselect",false,""); //取消选择
objEditor.contentEditable = false; //设置编辑状态为禁止
window.location.replace("#"); //返回顶部
break; case 2://HTML
window.clipboardData.setData('text',$("txthtml").value); break; case 3://UBB
window.clipboardData.setData('text',$("txtubb").value); break; } MyMsgBox("复制成功。马上分享您的代码吧!","操作完成"); //完成
idMsg=setTimeout('OnCloseMsg()',3000); //3秒自动关闭
}function OnChangeView(mode){ OnCloseMsg(); m_viewmode=mode; var boxes=new Array("codesrc","codeEditor","txthtml","txtubb"); var tli=$("viewtab").getElementsByTagName("li"); for(i=0;i<tli.length;i++){ tli[i.className=i==mode?"on":""; $(boxes[i).style.display=i==mode?"block":"none";} $(boxes[mode).focus();}/*Create elements*/function createMenu(){ var szReturn=""; for(var i in m_fonts){szReturn=szReturn + "<li class='lst_items_out' style='font-family:"+m_fonts[i+"'>"+m_fonts[i+"</li>";} return szReturn;}function createStxList(){ var szReturn=""; for(var i in m_syntax){szReturn=szReturn+"<button title=\""+m_syntax[i+"\" onclick=\"OnColor('"+i+"')\">"+i+"</button>";} szReturn=szReturn+""; return szReturn;}function createColorMenu(){ var szReturn="<ul id='selcolor'>"; for(var i in bgcolor){szReturn=szReturn+"<li style='background-color:#"+bgcolor[i+"' onclick='OnChangeColor(\""+i+"\")'></li>";} szReturn=szReturn+"</ul>"; return szReturn;}function SelectFont(){ inputobj=$("sel_font"); btnobj=$("sel_font_lst"); optionobj=$("lst_items"); optionobj.style.display=optionobj.style.display==""?"none":""; for(var i=0;i<optionobj.childNodes.length;i++){ optionobj.focus(); optionobj.childNodes[i.onmouseover=function (){ this.className="lst_items_over"; } optionobj.childNodes[i.onmouseout=function (){ this.className="lst_items_out"; } optionobj.childNodes[i.onclick=function (){ inputobj.innerHTML=this.innerHTML; inputobj.style.fontFamily=this.innerHTML; optionobj.blur(); optionobj.style.display="none"; } }}function $(szID){return document.getElementById(szID);}function HTML2UBB(str){ str = str.replace(/\r/g,""); str = str.replace(/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"+"/ig,""); str = str.replace(/<script[^>]*?>([\w\W]*?)<\/script>/ig,""); str = str.replace(/<a[^>]+href="([^"]+)"[^>*>(.*?)<\/a>/ig,"\n$2\n"); str = str.replace(/<font[^>+color=([^ >+)[^>*>(.*?)<\/font>/ig,"[color=$1]$2"); str = str.replace(/<img[^>+src="([^"+)"[^>]*>/ig,"\n[img$1[/img\n"); str = str.replace(/<([\/]?)b>/ig,"[$1b"); str = str.replace(/<([\/]?)strong>/ig,"[$1b"); str = str.replace(/<([\/]?)u>/ig,"[$1u"); str = str.replace(/<([\/]?)i>/ig,"[$1i"); str = str.replace(/ /g," "); str = str.replace(/&/g,"&"); str = str.replace(/"/g,"\""); str = str.replace(/</g,"<"); str = str.replace(/>/g,">"); str = str.replace(/<br>/ig,"\n"); str = str.replace(/<[^>]*?>/g,""); str = str.replace(/\[url=([^\]]+)\]\n(\[img\][^\[]+?\[\/img\])\n\[\/url\]/g,"[url=$1$2[/url"); str = str.replace(/\n+/g,"\n"); return str;}function getFont(){ var o=$("sel_font"); switch(o.tagName){ case "TEXTAREA": case "INPUT": case "SELECT": return o.value; break; case "DIV": case "SPAN": return o.innerHTML; break; default: return o.innerHTML; break; }}function addRows(){ m_height+=10; $("mainframe").style.height=m_height+"px";}function minusRows(){ if(m_height>100){ m_height-=10; $("mainframe").style.height=m_height+"px"; }}function MyMsgBox(szInfo,szTitle){ clearTimeout(idMsg); document.getElementById('msgframe').style.display='block'; objMsgBox=document.getElementById('msgbox'); objMsgBox.style.display='block'; document.getElementById('msgboxtit').innerHTML=szTitle+"<a id=\"closebtn\" title=\"关闭消息\" href=\"#\" onclick=\"OnCloseMsg()\"></a>"; document.getElementById('msgtext').innerHTML=szInfo;}function OnCloseMsg(){ document.getElementById('msgbox').style.display='none'; document.getElementById('msgframe').style.display='none'; clearTimeout(idMsg);}function ShowAbout(){ MyMsgBox("<h2><img src=\"images/logo.gif\"><br/>关于 CodeColorist</h2>版本: 2.1 作者: ChiChou", "About"); idMsg=setTimeout('OnCloseMsg()',10000); //10秒自动关闭} |
|