📄 edithtml.js
字号:
// OLE_TRISTATE
OLE_TRISTATE_UNCHECKED = 0
OLE_TRISTATE_CHECKED = 1
OLE_TRISTATE_GRAY = 2
// Define Arrays for the context menue
var MENU_SEPARATOR = "";
var ContextMenu = new Array();
var GeneralContextMenu = new Array();
var TableContextMenu = new Array();
var AbsPosContextMenu = new Array();
// Variables for the link editor
var linkEditor = null;
var linkEditorRange = null;
var linkEditorSelection = null;
var linkEditorStyleInputs = null;
// Constructor for custom object that represents an item on the context menu
function ContextMenuItem(string, cmdId) {
this.string = string;
this.cmdId = cmdId;
}
// Displays the context menue
function ShowContextMenu() {
var menuStrings = new Array();
var menuStates = new Array();
var state;
var i
var idx = 0;
// Rebuild the context menu.
ContextMenu.length = 0;
// Always show general menu
for (i=0; i<GeneralContextMenu.length; i++) {
ContextMenu[idx++] = GeneralContextMenu[i];
}
// Is the selection inside a table? Add table menu if so
if (document.all.EDIT_HTML.QueryStatus(DECMD_INSERTROW) != DECMDF_DISABLED) {
for (i=0; i<TableContextMenu.length; i++) {
ContextMenu[idx++] = TableContextMenu[i];
}
}
// Set up the actual arrays that get passed to SetContextMenu
for (i=0; i<ContextMenu.length; i++) {
menuStrings[i] = ContextMenu[i].string;
if (menuStrings[i] != MENU_SEPARATOR) {
state = document.all.EDIT_HTML.QueryStatus(ContextMenu[i].cmdId);
} else {
state = DECMDF_ENABLED;
}
if (state == DECMDF_DISABLED || state == DECMDF_NOTSUPPORTED) {
menuStates[i] = OLE_TRISTATE_GRAY;
} else if (state == DECMDF_ENABLED || state == DECMDF_NINCHED) {
menuStates[i] = OLE_TRISTATE_UNCHECKED;
} else { // DECMDF_LATCHED
menuStates[i] = OLE_TRISTATE_CHECKED;
}
}
// Set the context menu
document.all.EDIT_HTML.SetContextMenu(menuStrings, menuStates);
}
function ContextMenuAction(itemIndex) {
if (ContextMenu[itemIndex].cmdId == DECMD_INSERTTABLE) {
InsertTable();
} else {
document.all.EDIT_HTML.ExecCommand(ContextMenu[itemIndex].cmdId, OLECMDEXECOPT_DODEFAULT);
}
}
function DisplayChanged() {
var s = document.all.EDIT_HTML.QueryStatus(DECMD_GETBLOCKFMT);
if (s == DECMDF_DISABLED || s == DECMDF_NOTSUPPORTED) {
document.all.BLOCK.disabled = true;
} else {
document.all.BLOCK.disabled = false;
document.all.BLOCK.value = document.all.EDIT_HTML.ExecCommand(DECMD_GETBLOCKFMT, OLECMDEXECOPT_DODEFAULT);
}
s = document.all.EDIT_HTML.QueryStatus(DECMD_GETFONTNAME);
if (s == DECMDF_DISABLED || s == DECMDF_NOTSUPPORTED) {
document.all.FONTFACE.disabled = true;
} else {
var value = document.all.EDIT_HTML.ExecCommand(DECMD_GETFONTNAME, OLECMDEXECOPT_DODEFAULT);
if ((value != null) && (USE_FONTFACE == true)) {
document.all.FONTFACE.disabled = false;
document.all.FONTFACE.value = value;
} else {
document.all.FONTFACE.disabled = true;
}
}
if (s == DECMDF_DISABLED || s == DECMDF_NOTSUPPORTED) {
document.all.FONTSIZE.disabled = true;
} else {
var value = document.all.EDIT_HTML.ExecCommand(DECMD_GETFONTSIZE, OLECMDEXECOPT_DODEFAULT);
if ((value != null) && USE_FONTSIZE) {
document.all.FONTSIZE.disabled = false;
document.all.FONTSIZE.value = value;
} else {
document.all.FONTSIZE.disabled = true;
}
}
if(document.activeElement != EDITOR.EDIT_HTML) {
EDITOR.EDIT_HTML.focus();
}
}
function checkPopup() {
if (openWindow && focusCount > 0) {
try {
openWindow.focus();
} catch(e) {
}
focusCount = 0;
}
}
function saveContent() {
var _form = document.EDITOR;
var _editor = _form.EDIT_HTML;
if (_editor.DOM.documentElement) {
// IE5
_form.content.value = encodeURIComponent(_editor.filterSourceCode(_editor.DocumentHTML));
} else {
// IE4
_form.content.value = encodeURIComponent(_editor.DocumentHTML);
}
}
function doEditHTML(para) {
var _form = document.EDITOR;
var _editor = _form.EDIT_HTML;
switch (para) {
case 1:
// exit
_form.action.value = actionExit;
_form.target = "_top";
saveContent();
_form.submit();
break;
case 2:
// save & exit
_form.action.value = actionSaveExit;
_form.target = "_top";
saveContent();
_form.submit();
break;
case 3:
// exit
_form.action.value = actionSave;
_form.target = "_self";
saveContent();
_form.submit();
break;
case 55:
// save and reload top
_form.action.value = actionSaveAction;
_form.target = "_top";
saveContent();
_form.submit();
break;
case 4:
// undo
_editor.ExecCommand(DECMD_UNDO);
break;
case 5:
// redo
_editor.ExecCommand(DECMD_REDO);
break;
case 6:
// search
_editor.ExecCommand(DECMD_FINDTEXT, 1);
break;
case 9:
// cut
_editor.ExecCommand(DECMD_CUT);
break;
case 10:
// copy
_editor.ExecCommand(DECMD_COPY);
break;
case 11:
// paste
_editor.ExecCommand(DECMD_PASTE);
break;
case 21:
// font style selection <h1>, <h2>...
_editor.ExecCommand(DECMD_SETBLOCKFMT, 0, _form.BLOCK.value);
break;
case 22:
// font name selection <font name="...">
_editor.ExecCommand(DECMD_SETFONTNAME, 0, _form.FONTFACE.value);
break;
case 23:
// font size selection
_editor.ExecCommand(DECMD_SETFONTSIZE, 0, parseInt(_form.FONTSIZE.value));
break;
case 24:
// bold
_editor.ExecCommand(DECMD_BOLD);
break;
case 25:
// italic
_editor.ExecCommand(DECMD_ITALIC);
break;
case 26:
// underline
_editor.ExecCommand(DECMD_UNDERLINE);
break;
case 31:
// left align
_editor.ExecCommand(DECMD_JUSTIFYLEFT);
break;
case 32:
// center align
_editor.ExecCommand(DECMD_JUSTIFYCENTER);
break;
case 33:
// right align
_editor.ExecCommand(DECMD_JUSTIFYRIGHT);
break;
case 34:
// <ul>
_editor.ExecCommand(DECMD_UNORDERLIST);
break;
case 35:
// <ol>
_editor.ExecCommand(DECMD_ORDERLIST);
break;
case 36:
// indent
_editor.ExecCommand(DECMD_INDENT);
break;
case 37:
// outdent
_editor.ExecCommand(DECMD_OUTDENT);
break;
case 38:
ColorSelected = -1;
SelColor = -1;
CheckFGCol= window.setInterval("setFGColor(SelColor)",500);
SelColor = showModalDialog(skinUri + "components/js_colorpicker/index.html", colorPicker, "resizable: yes; help: no; status: no; scroll: no;");
if (SelColor != null) {
ColorSelected = 1;
}
break;
case 39:
ColorSelected=-1;
SelColor=-1;
CheckBGCol= window.setInterval("setBGColor(SelColor)",500);
SelColor = showModalDialog(skinUri + "components/js_colorpicker/index.html", colorPicker, "resizable: yes; help: no; status: no; scroll: no;");
if (SelColor != null) {
ColorSelected = 1;
}
break;
case 40:
checkTableSelection();
break;
case 41:
link = window.open(workplacePath + 'action/edit_html_link.html','SetLink', "width=450, height=300, resizable=no,status=no, top=300, left=250");
break;
case 42:
_editor.ExecCommand(DECMD_IMAGE, 1);
makeImageLinks();
break;
case 45:
_editor.ExecCommand(DECMD_HYPERLINK, 2, EDITOR.URL.value);
break;
case 46:
vfslink = window.open(workplacePath + 'action/edit_html_vfslink.html','SetLink', "width=450, height=300, resizable=no, top=300, left=250");
break;
case 47:
_editor.showDetails = !_editor.showDetails;
break;
case 48:
openWindow = window.open("dialogs/specialchars.jsp","characters", "width=450, height=300, resizable=no, scrollbars=no, location=no, menubar=no, toolbar=no, dependent=yes, top=300, left=250");
focusCount = 1;
openWindow.focus();
break;
case 49:
// hyperlink (internal function)
_editor.ExecCommand(DECMD_HYPERLINK, 1);
break;
case 50:
if (hasSelectedText()) {
var winheight = (USE_LINKSTYLEINPUTS?220:170);
var linkInformation = getSelectedLink();
var params = "?showCss=" + USE_LINKSTYLEINPUTS;
if (linkInformation != null) {
params += "&href=" + linkInformation["href"];
params += "&target=" + linkInformation["target"];
params += "&title= "+linkInformation["title"];
if (USE_LINKSTYLEINPUTS) {
params += "&style=" + linkInformation["style"];
params += "&class=" + linkInformation["class"];
}
}
openWindow = window.open('dialogs/link.jsp' + params,'SetLink', "width=480, height=" + winheight + ", scrollbars=no, location=no, menubar=no, toolbar=no, status=no, dependent=yes, resizable=yes, top=300, left=250");
focusCount = 1;
openWindow.focus();
} else {
alert (LANG_NOSELECTION);
}
break;
case 51:
checkTableElSelection("TR");
break;
case 52:
checkTableElSelection("TD");
break;
case 53:
if (hasSelectedText()) {
var winheight = (USE_LINKSTYLEINPUTS?180:130);
var linkInformation = getSelectedLink();
var params = "?showCss=" + USE_LINKSTYLEINPUTS;
if (linkInformation != null) {
params += "&name=" + linkInformation["name"];
if (USE_LINKSTYLEINPUTS) {
params += "&style=" + linkInformation["style"];
params += "&class=" + linkInformation["class"];
}
}
openWindow = window.open('dialogs/anchor.jsp' + params, 'SetAnchor', "width=350, height=" + winheight + ", scrollbars=no, location=no, menubar=no, toolbar=no, status=no, dependent=yes, resizable=yes, top=300, left=250");
focusCount = 1;
openWindow.focus();
} else {
alert (LANG_NOSELECTION);
}
break;
default:
alert("Sorry, the requested function " + para + " is not implemented.");
}
}
function openGallery(galleryType) {
openWindow = window.open(workplacePath + "galleries/gallery_fs.jsp?gallerytypename=" + galleryType, "GalleryBrowser", "width=650, height=700, resizable=yes, top=20, left=100");
focusCount = 1;
openWindow.focus();
}
// Includes the document source into the HTML editor and sets up the context menue
function initContent() {
document.EDITOR.EDIT_HTML.SourceCodePreservation = true;
document.EDITOR.EDIT_HTML.DocumentHTML = decodeURIComponent(text);
GeneralContextMenu[0] = new ContextMenuItem(LANG_CUT, DECMD_CUT);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -