⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmleditor.js

📁 LyBBS基于Struts1.3/Ajax的架构
💻 JS
📖 第 1 页 / 共 2 页
字号:
var lybbs_edit;
var lybbs_RangeType;
var lybbs_selection;
var lybbs_charset="UTF-8";
var lybbs_bLoad=false;
var lybbs_pureText=true;
var lybbs_bTextMode=1;//1-design,2-html
var ischeck=false;

function lybbs_InitDocument(contentValue, charset) {	
  if (charset!=null)
     lybbs_charset=charset;
  if (lybbs_bIsIE5){
    var lybbs_bodyTag="<style type=\"text/css\">.quote{margin:5px 20px;border:1px solid #CCCCCC;padding:5px; background:#F3F3F3 }\nbody{boder:0px}.HtmlCode{margin:5px 20px;border:1px solid #CCCCCC;padding:5px;background:#FDFDDF;font-size:14px;font-family:Tahoma;font-style : oblique;line-height : normal ;font-weight:bold;}\n</style></head><body bgcolor=\"#FFFFFF\" title=\"Ctrl+Enter\u76f4\u63a5\u63d0\u4ea4\u8d34\u5b50\" onkeydown=\"ctlent();\">";
  }else{
    var lybbs_bodyTag="<style type=\"text/css\">.quote{margin:5px 20px;border:1px solid #CCCCCC;padding:5px; background:#F3F3F3 }\nbody{boder:0px}.HtmlCode{margin:5px 20px;border:1px solid #CCCCCC;padding:5px;background:#FDFDDF;font-size:14px;font-family:Tahoma;font-style : oblique;line-height : normal ;font-weight:bold;}\n</style></head><body bgcolor=\"#FFFFFF\">";
  }
  var h=openner.theform.content.value;
  if (navigator.appVersion.indexOf("MSIE 6.0",0)==-1){
    IframeID.document.designMode="On"
  }
  IframeID.document.open();
  IframeID.document.write ('<html>');
  IframeID.document.write ('<head>');
  if (lybbs_bIsIE5){
    IframeID.document.write ('<script language="javascript" type="text/javascript">');
    IframeID.document.write ('function ctlent(eventobject) {');
    IframeID.document.write ('if(event.ctrlKey&&window.event.keyCode==13) {');
    IframeID.document.write ('parent.copyPost(); ');
    IframeID.document.write ('}}');
    IframeID.document.write ('function imgresize(o){');
    IframeID.document.write ('if(o.width > 500 ){');
    IframeID.document.write ('	o.style.width=\'500px\';');
    IframeID.document.write ('}');
    IframeID.document.write ('if(o.height > 800){');
    IframeID.document.write ('	o.style.height=\'800px\';');
    IframeID.document.write ('}');
    IframeID.document.write ('}');
    IframeID.document.write ('<\/script>');
  }
  IframeID.document.write(lybbs_bodyTag);
  IframeID.document.write("</body>");
  IframeID.document.write("</html>");
  if (h!=""){
    if(lybbs_bIsIE5) {
      IframeID.document.body.innerText=addScript(toBr(h));
    }
    else {
      IframeID.document.body.textContent=addScript(toBr(h));
    }
  }
  IframeID.document.close();
  if (navigator.appVersion.indexOf("MSIE 6.0")!=-1) {
    IframeID.document.body.contentEditable = "true";
  }
  IframeID.document.charset=lybbs_charset;
  lybbs_bLoad=true;
  IframeID.focus();
}
/**
function ctlent() {
  var ispost=0;
  if (document.all){
    if(event.ctrlKey && event.keyCode==13){
      lybbs_CopyData();
      lybbs_Checkdata()
      if (ischeck==true){this.document.submitok.submit();}
    }
  }
}
**/
function lybbs_setMode(n,v) {
  lybbs_setStyle();
  var content;
  var commonbar=document.getElementById("commonbar");
  var htmlbar=document.getElementById("htmlbar");
  switch (n){
    case 1:
      commonbar.style.display="";
      htmlbar.style.display="";
      if (lybbs_bIsIE5){
        content=IframeID.document.body.innerText;
        IframeID.document.body.innerHTML=content;
      }else{
        var html = IframeID.document.body.ownerDocument.createRange();
        html.selectNodeContents(IframeID.document.body);
        IframeID.document.body.innerHTML = html.toString();
      }
      break;
    case 2:
      commonbar.style.display="none";
      htmlbar.style.display="none";
      if(lybbs_bTextMode!=1){
        content=IframeID.document.body.innerText;
      }
      else{
        content=IframeID.document.body.innerHTML;
      }
      if (content){
        if (lybbs_bIsIE5){//IE
          IframeID.document.body.innerText=content;
        }else{//Nc
          var html=document.createTextNode(content);
          IframeID.document.body.innerHTML = "";
          IframeID.document.body.appendChild(html);
        }
      }
      break;
  }
  lybbs_bTextMode=n;
  lybbs_setTab(n);
}

function lybbs_setTab(n) {
  //the style of html and design button
  var mhtml=document.getElementById("lybbs_TabHtml");
  var mdesign=document.getElementById("lybbs_TabDesign");
  if(n==1){
    mhtml.className="lybbs_TabOff";
    mdesign.className="lybbs_TabOn";
  }else if(n==2){
    mhtml.className="lybbs_TabOn";
    mdesign.className="lybbs_TabOff";
  }
}

function lybbs_setStyle() {
  var bs = IframeID.document.body.style;
  bs.fontFamily="Arial";
  bs.fontSize="10.5pt";
  bs.scrollbar3dLightColor= '#D4D0C8';
  bs.scrollbarArrowColor= '#000000';
  bs.scrollbarBaseColor= '#D4D0C8';
  bs.scrollbarDarkShadowColor= '#D4D0C8';
  bs.scrollbarFaceColor= '#D4D0C8';
  bs.scrollbarHighlightColor= '#808080';
  bs.scrollbarShadowColor= '#808080';
  bs.scrollbarTrackColor= '#D4D0C8';
  bs.border='0';
}

function lybbs_validateMode() {
  if (lybbs_bTextMode==1) {
    return true;
  }
  else {
    alert("Error: HTML Mode");
    IframeID.focus();
    return false;
  }
}

var colour
function FormatText(command, option) {
  var codewrite
  if (lybbs_bIsIE5){
    if (option=="removeFormat"){
       command=option;
       option=null;
    }
    IframeID.focus();
    IframeID.document.execCommand(command, false, option);
    lybbs_pureText = false;
    IframeID.focus();
  }
  else {
    try {
      IframeID.focus();
      IframeID.document.execCommand(command, false, option);
      IframeID.focus();
    }
    catch (e) {}
  }
}

//Colour top offset
function getOffsetTop(elm) {
  var mOffsetTop = elm.offsetTop;
  var mOffsetParent = elm.offsetParent;
  while(mOffsetParent){
    mOffsetTop += mOffsetParent.offsetTop;
    mOffsetParent = mOffsetParent.offsetParent;
  }
  return mOffsetTop;
}

//Colour left offset
function getOffsetLeft(elm) {
  var mOffsetLeft = elm.offsetLeft;
  var mOffsetParent = elm.offsetParent;
  while(mOffsetParent) {
    mOffsetLeft += mOffsetParent.offsetLeft;
    mOffsetParent = mOffsetParent.offsetParent;
  }
  return mOffsetLeft;
}

function AddText(text) {
  if (IframeID.document.body.createTextRange && IframeID.document.body.caretPos) {      
    var caretPos = IframeID.document.body.caretPos;      
    caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?text + ' ' : text;
  }
  else {
    IframeID.document.body.innerHTML += text;
  }
  IframeID.focus(caretPos);
}

function fixtag(text){
  text = text.replace(/&|\/|<|>|\*|#|:|;|=|\?|\)|\(|%|\[|\]|\$| /g, "") ;
  return text ;
}

function escapeUrl(text){
  text = text.replace(/&#/g, "");
  text = text.replace(/ /g, "%20");
  text = text.replace(/"/g, "");
  text = text.replace(/'/g, "");
  text = text.replace(/</g, "");
  text = text.replace(/>/g, "");
  text = text.replace(/\*/g, "");
  return text ;
}

function checkInvalidUrl(text) {
  text=text==null?"":text.toLowerCase();
  if(text.indexOf("onerror")!=-1) { return true; }
  else if(text.indexOf("script")!=-1) { return true; }
  return false;
}

function HTML(text){
  text = text.replace(/&/g, "&amp;") ;
  text = text.replace(/"/g, "&quot;") ;
  text = text.replace(/</g, "&lt;") ;
  text = text.replace(/>/g, "&gt;") ;
  text = text.replace(/'/g, "&#146;") ;
  return text ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -