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

📄 html_editorax.js

📁 java 写的一个新闻发布系统
💻 JS
📖 第 1 页 / 共 2 页
字号:
//***************************************************************************// WYSIWYG HTML Editor based on Microsoft Internet Explorer MSHTML control// Copyright : Jahia Ltd 2002// Author : Jerome Bedat jbedat@jahia.org//***************************************************************************// Public APIfunction setHTML(stableHTML){    if (g_state.bMode) {        idEditbox.document.body.innerHTML = stableHTML;    } else {        idEditbox.document.body.innerText = stableHTML;    }    htmlEditor_MoveSelection(true);}function getHTML() {    var stableRet = (g_state.bMode ? idEditbox.document.body.innerHTML : idEditbox.document.body.innerText);    return stableRet;}function getText() {    var stableRet = "";    if (g_state.bMode) {        stableRet = idEditbox.document.body.innerText;    } else {        setMode(true);        stableRet = idEditbox.document.body.innerText;        setMode(false);    }    return stableRet;}function getBody() {    var oRet = idEditbox.document.body;    return oRet;}function getWidth() {    var nRet = document.body.offsetWidth;    return nRet;}function getHeight() {    var nRet = document.body.offsetHeight;    return nRet;}function insertHTML(stableHTML) {    var sType;    var sel = g_state.GetSelection();    sType = sel.type;    if (g_state.bMode) {        if (sType=="Control") {            sel.item(0).outerHTML = stableHTML;        } else {            sel.pasteHTML(stableHTML);        }    } else {        sel.text = stableHTML;    }}function setFocus() {    idEditbox.focus();}function appendHTML(stableHTML) {    if (g_state.bMode) {        idEditbox.document.body.insertAdjacentHTML("beforeEnd",stableHTML);    } else {        idEditbox.document.body.insertAdjacentText("beforeEnd",stableHTML);    }}function setBGColor(stableValue) {    g_state.bgColor = stableValue;    if (g_state.bMode) { idEditbox.document.body.bgColor = g_state.bgColor; }}function getBGColor() {    var stableRet = g_state.bgColor;    return stableRet;}function setDefaultStyle(stableValue) {    g_state.css = stableValue;    if (g_state.bMode) { idEditbox.document.body.style.cssText = g_state.css; }}function getDefaultStyle() {    var oRet = g_state.css;    return oRet;}function setSkin(stableSkin) {    if (stableSkin == null) {        document.styleSheets.skin.cssText = g_state.defaultSkin;    } else {        document.styleSheets.skin.cssText = stableSkin;    }    document.styleSheets.skin.disabled = false;}function setPopupSkin(stableSkin) {    if (stableSkin == null) {        document.styleSheets.popupSkin.cssText = g_state.popupSkin;    } else {        document.styleSheets.popupSkin.cssText = stableSkin;    }}function setToolbar(id,g_state) {    var el = document.all[id];    if (el) { el.style.display = (g_state) ? "" : "none"; }    if (id=="tbmode") { setSize(); }}function setLinks(arLinks) {    g_state.aLinks = arLinks;}function setBindings(aBindings) {    if ((aBindings) && (aBindings.length>0)) {        g_state.aBindings = aBindings;        for (var iField = DBSelect.length-1; iField > 0; iField--) {            DBSelect[iField] = null;        }        for (var iField = 0; iField < g_state.aBindings.length; iField++) {            DBSelect.add(new Option(g_state.aBindings[iField]));        }        tbDBSelect.style.display = "inline";    } else {        tbDBSelect.style.display = "";    }}function setMode(bMode) {    if (bMode!=g_state.bMode) {        g_state.bMode = bMode;        var objBody = idEditbox.document.body;        if (!bMode&& !g_state.bMode) {            objBody.bgColor = objBody.style.cssText = "";            if (g_state.customButtons) {                idStandardBar.style.display = "none";            } else {                idToolbar.style.display = "none";            }            objBody.innerText = idEditbox.document.body.innerHTML;            objBody.className = "textMode";        }        if ((bMode) && (g_state.bMode)) {            setDefaultStyle(g_state.css);            setBGColor(g_state.bgColor);            objBody.className = idStandardBar.style.display = idToolbar.style.display = "";            objBody.innerHTML = idEditbox.document.body.innerText;        }        setSize();        htmlEditor_MoveSelection(true);        setFocus();    }    return bMode;}function addButton(sID,sButton) {    if (!sID) {        tbButtons.insertAdjacentHTML("beforeEnd","<BR>");    } else {        tbButtons.insertAdjacentHTML("beforeEnd","<INPUT CLASS=\"input\" TYPE=\"button\" ONCLICK=\"onButtonClick(this)\" CLASS=\"userButton\" ID=\"" + sID + "\" VALUE=\"" + sButton + "\">&nbsp;");    }    g_state.customButtons = true;}function format(stableHow, stableValue) {    var oSel	= g_state.GetSelection();    var sType = oSel.type;    var oTarget = (sType == "None" ? idEditbox.document : oSel);    var oBlock = (oSel.parentElement != null ? util_GetBlock(oSel.parentElement()) : oSel.item(0));    setFocus();    switch(stableHow)    {        case "InsertImage":            oTarget.execCommand(stableHow, 'http://');            break;        case "BackColor":            var el = null;            if (oSel.parentElement != null) {                el = util_GetElement(oSel.parentElement(),"TD");                if (!el) el = util_GetElement(oSel.parentElement(),"TH");                if (!el) el = util_GetElement(oSel.parentElement(),"TR");                if (!el) el = util_GetElement(oSel.parentElement(),"TABLE");            } else {                el = util_GetElement(oSel.item(0),"TABLE");            }            if (el) {                el.bgColor = stableValue;            } else {                setBGColor(stableValue);            }            break;        case "Justify":            if (oBlock)            {            oBlock.style.textAlign = "";            if (((oBlock.tagName=="TABLE") || (oBlock.tagName=="IMG")) && (("left"==oBlock.align) && ("Left"==stableValue))) {                oBlock.align = "";                break;            }            oBlock.align = stableValue;            if ((oBlock.tagName=="HR") || ((oBlock.tagName=="IMG") && stableValue!="Center"))                break;            }            stableHow=stableHow+stableValue;            stableValue="";            // Fall through        default:            oTarget.execCommand(stableHow, false, stableValue);            break;    }    g_state.RestoreSelection();    setFocus();    return true;}// Editorfunction loadEditor() {    g_state = new textState();    window.onresize = setSize;    var stable = "";    stable += ""    + "<STYLE>"    +	".DataBound{border:1 solid #999999;margin:1;font-family:Courier;background:#F1F1F1}\n"    +	".textMode {border-top: 1px black solid;font: 10pt courier}\n.NOBORDER TD {border:1px gray solid}"    +	"BODY {border: 1px black solid;}"    + "</STYLE>"    + "<BODY ONCONTEXTMENU=\"return false\">"    +	"<DIV></DIV>"    + "</BODY>";    idEditbox.document.designMode = "on";    idEditbox.document.open("text/html","replace");    idEditbox.document.write(stable);    idEditbox.document.close();    idEditbox.document.body.onblur = g_state.SaveSelection;    idEditbox.document.onkeyup = htmlEditor_KeyUpHandler;    idEditbox.document.onmousedown = htmlEditor_ClickHandler;    idEditbox.document.ondblclick = htmlEditor_DblClickHandler;    setTimeout("pageReady()",0);    setHTML(theOldValue);    setHiddenValue(theOldValue);    setFocus();}function htmlEditor_MoveSelection(bDir) {    var tr = idEditbox.document.body.createTextRange();    tr.collapse(bDir);    tr.select();}function htmlEditor_ClickHandler() {    g_state.selection = null;}function htmlEditor_KeyUpHandler() {    var ev = this.parentWindow.event;    if (ev.keyCode==9) {        g_state.SaveSelection();    } else {        g_state.selection=null;    }}function htmlEditor_DblClickHandler() {    var el = this.parentWindow.event.srcElement;    if (el.tagName=="IMG") {        el.removeAttribute("width");        el.removeAttribute("height");        el.style.removeAttribute("width");        el.style.removeAttribute("height");        el.width = el.width;        el.height = el.height;    }    if (el.tagName=="TABLE") { popup_Table(); }}function setSize() {    document.all.idEditbox.style.pixelHeight = document.body.clientHeight - 300;    document.all.idEditbox.style.pixelWidth = document.body.clientWidth - menuWidth;}function pageReady() {    idEditbox.document.body.oncontextmenu = new Function("return false");    // if (g_state.stableSearch!="") { idPopup.document.domain = idEditbox.document.domain = document.domain = g_state.stableSearch; }    if (self.parent.RTELoaded) { self.parent.RTELoaded(self); }    if (document.styleSheets.skin.disabled) { setSkin(null); }    setSize();    idEditor.style.visibility="";}function onButtonClick(el) {    if (parent.RTEButton) { parent.RTEButton(self, el.id); }}// Loading toolsfunction loadToolbar() {    // var aIds = new Array("cut","copy","paste","bar1","redo","undo","bar2","bold","italic","underline","bar3","left","center","right","bar4","orderedlist","unorderedlist","outdent","indent","bar5","line","link","table","image","bar6","bgcolor","textcolor","bar7","print","preview");    var aIds = new Array("cut","copy","paste","bar1","redo","undo","bar2","bold","italic","underline","bar3","left","center","right","bar4","orderedlist","unorderedlist","outdent","indent","bar5","line","link","table","bar6","bgcolor","textcolor","bar7","print","preview");    // var aTips = new Array(TEXT_TIPCUT_TEXT,TEXT_TIPCOPY_TEXT,TEXT_TIPPASTE_TEXT,"",TEXT_TIPREDO_TEXT,TEXT_TIPUNDO_TEXT,"",TEXT_TIPB_TEXT,TEXT_TIPI_TEXT,TEXT_TIPU_TEXT,"",TEXT_TIPLJ_TEXT,TEXT_TIPCJ_TEXT,TEXT_TIPRJ_TEXT,"",TEXT_TIPOTEXT_TEXT,TEXT_TIPUTEXT_TEXT,TEXT_TIPDINDENT_TEXT,TEXT_TIPIINDENT_TEXT,"",TEXT_TIPLINE_TEXT,TEXT_TIPLINK_TEXT,TEXT_TIPTABLE_TEXT,TEXT_TIPPICTURE_TEXT,"",TEXT_TIPBGCOLOR_TEXT,TEXT_TIPFGCOLOR_TEXT,"",TEXT_TIPPRINT_TEXT,TEXT_TIPIE_TEXT);    var aTips = new Array(TEXT_TIPCUT_TEXT,TEXT_TIPCOPY_TEXT,TEXT_TIPPASTE_TEXT,"",TEXT_TIPREDO_TEXT,TEXT_TIPUNDO_TEXT,"",TEXT_TIPB_TEXT,TEXT_TIPI_TEXT,TEXT_TIPU_TEXT,"",TEXT_TIPLJ_TEXT,TEXT_TIPCJ_TEXT,TEXT_TIPRJ_TEXT,"",TEXT_TIPOTEXT_TEXT,TEXT_TIPUTEXT_TEXT,TEXT_TIPDINDENT_TEXT,TEXT_TIPIINDENT_TEXT,"",TEXT_TIPLINE_TEXT,TEXT_TIPLINK_TEXT,TEXT_TIPTABLE_TEXT,"",TEXT_TIPBGCOLOR_TEXT,TEXT_TIPFGCOLOR_TEXT,"",TEXT_TIPPRINT_TEXT,TEXT_TIPIE_TEXT);    // var aCommand = new Array("format('cut')","format('copy')","format('paste')",null,"format('redo')","format('undo')",null,"format('bold')","format('italic')","format('underline')",null,"format('Justify','Left')","format('Justify','Center')","format('Justify','Right')",null,"format('insertorderedlist')","format('insertunorderedlist')","format('outdent')","format('indent')",null,"format('InsertHorizontalRule')","format('CreateLink')","popup_Table()","format('InsertImage')",null,"popup_Color('BackColor')","popup_Color('ForeColor')",null,"format('print')","popup_Preview()");    var aCommand = new Array("format('cut')","format('copy')","format('paste')",null,"format('redo')","format('undo')",null,"format('bold')","format('italic')","format('underline')",null,"format('Justify','Left')","format('Justify','Center')","format('Justify','Right')",null,"format('insertorderedlist')","format('insertunorderedlist')","format('outdent')","format('indent')",null,"format('InsertHorizontalRule')","format('CreateLink')","popup_Table()",null,"popup_Color('BackColor')","popup_Color('ForeColor')",null,"format('print')","popup_Preview()");    var stable = "<DIV ID=idStandardBar><NOBR>", iLeft=0, iHeight=24;    for (var i = 0 ; i < aSizes.length; i++)    {        stable	+= ""        + "<SPAN CLASS=tbButton ONKEYPRESS=\"if (event.keyCode==13) {" + aCommand[i] + ";event.keyCode=0}\" " + (aTips[i]=="" ? "" : ("TABINDEX=" + (i+1))) + " "        +	"ID=\"tb" + aIds[i] + "\" "        +	"STYLE=\"width: " + aSizes[i] + ";height:" + iHeight        +	"\""        + ">"        +	"<SPAN "        +	"STYLE=\""        +	"position:absolute;"        +	"width:" + aSizes[i] + ";height:" + iHeight + ";"        +	"clip: rect(0 " + aSizes[i] + " " + iHeight + " 0)"        +	"\""        +	">"        +	"<IMG "        +	"TITLE=\"" + aTips[i] + "\" "        +	"ONCLICK=\"" + aCommand[i] + "; event.cancelBubble=true\" "        +	"ONMOUSEDOWN=\"if (event.button==1) this.style.pixelTop=-" + (iHeight*2) + "\" "        +	"ONMOUSEOVER=\"this.style.pixelTop=-" + iHeight + "\" "        +	"ONMOUSEOUT=\"this.style.pixelTop=0\" "        +	"ONMOUSEUP=\"this.style.pixelTop=-" + iHeight + "\" "        +	"SRC=\"" + TEXT_TOOLBARGIF_TEXT + "\" "        +	"STYLE=\"position:absolute;top:0;left:-" + iLeft + "\""

⌨️ 快捷键说明

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