📄 edithtml.js
字号:
/*
* File : $Source: /usr/local/cvs/opencms/modules/org.opencms.editors.msdhtml/resources/system/workplace/editors/msdhtml/edithtml.js,v $
* Date : $Date: 2006/04/28 15:20:52 $
* Version: $Revision: 1.11 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
var foundRange = null;
var foundLink = null;
function hasSelectedText() {
// create a range on the current selection
var range = EDITOR.EDIT_HTML.DOM.selection.createRange();
var selectedRange = null;
if (typeof(range.text) != 'undefined') {
// if this is undefined, the selection is a MS IE "ControlSelection", which can not be used
selectedRange = range;
}
if ((selectedRange == null) || (selectedRange.htmlText == null) || (selectedRange.htmlText == "") || (selectedRange.htmlText.search(/<P> <\/P>/) != -1)) {
// no text selected, check if an image is selected
try {
range = range.item(0);
if (typeof(range.tagName) != 'undefined') {
var imgTag = range.tagName;
if (imgTag == "IMG" || imgTag == "img") {
return true;
}
}
} catch (e) {}
// no valid selection, display message
return false;
} else {
return true;
}
}
// pastes the html content at the current cursor position
function insertHtml(htmlContent) {
document.EDIT_HTML.focus();
document.EDIT_HTML.DOM.selection.createRange().pasteHTML(htmlContent);
}
// creates a link at the selected position using the passed link information object
function createLink(linkInformation) {
// remove old anchor
if (foundLink != null) {
foundLink.removeNode();
}
if (linkInformation["type"] == "anchor") {
// create an anchor
if (typeof(foundRange.text) != 'undefined') {
// common text link
if (linkInformation["name"].length > 0) {
foundRange.execCommand("CreateLink", false, "/");
var el = foundRange.parentElement();
while ((el.tagName != "BODY") && (el.tagName != "A")) {
if (el.tagName == "IMG") {
// set border to 0 for images, this is what you want in 99% of all cases
el.border = 0;
}
el = el.parentElement;
}
el.name = linkInformation["name"];
el.removeAttribute("HREF", false);
if (USE_LINKSTYLEINPUTS) {
if (linkInformation["style"].length > 0) {
el.style.cssText = linkInformation["style"];
}
if (linkInformation["class"].length > 0) {
el.className = linkInformation["class"];
}
}
}
} else {
// image link
var el = foundRange.item(0);
var thelink = "<a ";
thelink += "name='"+linkInformation["name"]+"' ";
if (USE_LINKSTYLEINPUTS) {
if(linkInformation["style"].length > 0) {
thelink += "style='"+linkInformation["style"]+"' ";
}
if(linkInformation["class"].length > 0) {
thelink += "class='"+linkInformation["class"]+"' ";
}
}
thelink += ">" + el.outerHTML + "</a>";
if(el.parentElement.tagName == "A") {
el.parentElement.outerHTML = thelink;
} else {
el.outerHTML = thelink;
}
}
} else {
// create a complete link
if (typeof(foundRange.text) != 'undefined') {
// common text link
if (linkInformation["href"].length > 0) {
foundRange.execCommand("CreateLink", false, "/");
var el = foundRange.parentElement();
while ((el.tagName != "BODY") && (el.tagName != "A")) {
if (el.tagName == "IMG") {
// Set border to 0 for images, this is what you want in 99% of all cases
el.border = 0;
}
el = el.parentElement;
}
if (linkInformation["href"].length > 0) {
el.setAttribute("HREF", linkInformation["href"], 0);
} else {
el.removeAttribute("HREF", false);
}
if (linkInformation["title"].length > 0) {
el.setAttribute("TITLE", linkInformation["title"], 0);
} else {
el.removeAttribute("TITLE", false);
}
if ((linkInformation["target"].length > 0) && (linkInformation["href"].length > 0)) {
el.target = linkInformation["target"];
} else {
el.removeAttribute("TARGET", false);
}
if (USE_LINKSTYLEINPUTS) {
if (linkInformation["style"].length > 0) {
el.style.cssText = linkInformation["style"];
}
if (linkInformation["class"].length > 0) {
el.className = linkInformation["class"];
}
}
}
} else {
// image link
var el = foundRange.item(0);
var thelink = "<a ";
if(linkInformation["href"].length > 0) {
thelink += "href='"+linkInformation["href"]+"' ";
}
if((linkInformation["target"].length > 0) && (linkInformation["href"].length > 0)) {
thelink += "target='"+linkInformation["target"]+"' ";
}
if (linkInformation["title"].length > 0) {
thelink += "title='"+linkInformation["title"]+"' ";
}
if (USE_LINKSTYLEINPUTS) {
if(linkInformation["style"].length > 0) {
thelink += "style='"+linkInformation["style"]+"' ";
}
if(linkInformation["class"].length > 0) {
thelink += "class='"+linkInformation["class"]+"' ";
}
}
thelink += ">" + el.outerHTML + "</a>";
if(el.parentElement.tagName == "A") {
el.parentElement.outerHTML = thelink;
} else {
el.outerHTML = thelink;
}
}
}
}
function getSelectedLink() {
// get the editor element, a complete range of the editor and the editor selection
var link = null;
linkEditorAll = EDITOR.EDIT_HTML.DOM.all.tags("A");
linkEditorRange = EDITOR.EDIT_HTML.DOM.body.createTextRange();
linkEditorSelection = EDITOR.EDIT_HTML.DOM.selection;
foundLink = null;
foundRange = null;
// Get all links in editor (ie. tags like <A HREF>)
var allLinks = linkEditorAll;
// Create a range on the current selection
var range = linkEditorSelection.createRange();
if (typeof(range.text) != 'undefined') {
// if this is undefined, the selection is a MS IE "ControlSelection", which can not be used for adding a link
for (i = 0; i < allLinks.length; i++) {
// create range on whole text
var mainrange = linkEditorRange;
// move range to the current A-element
mainrange.moveToElementText(allLinks[i]);
// compare the selection with the current range, and expand if neccessary
if (mainrange.inRange(range)) {
foundRange = mainrange;
} else if (range.inRange(mainrange) || range.isEqual(mainrange)) {
foundRange = range;
} else {
var s2e = range.compareEndPoints("StartToEnd", mainrange);
var s2s = range.compareEndPoints("StartToStart", mainrange);
var e2s = range.compareEndPoints("EndToStart", mainrange);
var e2e = range.compareEndPoints("EndToEnd", mainrange);
if ((s2s == -1) && (e2s >= 0)) {
foundRange = range;
foundRange.setEndPoint("EndToEnd", mainrange);
} else if ((s2e == -1) && (e2e >= 0)) {
foundRange = range;
foundRange.setEndPoint("StartToStart", mainrange);
}
}
// Finally fill the link object
if (foundRange != null) {
// Use expanded selection to fill input areas
foundRange.select();
link = new Object();
foundLink = allLinks[i];
link["href"] = encodeURIComponent(foundLink.getAttribute("HREF", 2));
link["target"] = foundLink.target;
link["name"] = foundLink.getAttribute("NAME", 2);
link["title"] = foundLink.getAttribute("TITLE", 2);
if (USE_LINKSTYLEINPUTS) {
link["style"] = encodeURIComponent(foundLink.style.getAttribute("CSSTEXT", 2));
link["class"] = foundLink.getAttribute("CLASSNAME", 2);
}
break;
}
}
if (foundLink == null) {
foundRange = range;
}
} else if ("Control" == linkEditorSelection.type) {
var el = range.item(0);
if (el.tagName == "IMG" || el.tagName == "img") {
if(el.parentElement.tagName == "A") {
link = new Object();
foundLink = el.parentElement;
link["href"] = encodeURIComponent(foundLink.getAttribute("HREF", 2));
link["target"] = foundLink.target;
link["name"] = foundLink.getAttribute("NAME", 2);
link["title"] = foundLink.getAttribute("TITLE", 2);
if (USE_LINKSTYLEINPUTS) {
link["style"] = encodeURIComponent(foundLink.style.getAttribute("CSSTEXT", 2));
link["class"] = foundLink.getAttribute("CLASSNAME", 2);
}
}
foundRange = range;
}
}
return link;
}
// Script for MS DHTML editor
var binlist=null;
// Command IDs for the MS DHTML editor
DECMD_BOLD = 5000
DECMD_COPY = 5002
DECMD_CUT = 5003
DECMD_DELETE = 5004
DECMD_DELETECELLS = 5005
DECMD_DELETECOLS = 5006
DECMD_DELETEROWS = 5007
DECMD_FINDTEXT = 5008
DECMD_FONT = 5009
DECMD_GETBACKCOLOR = 5010
DECMD_GETBLOCKFMT = 5011
DECMD_GETBLOCKFMTNAMES = 5012
DECMD_GETFONTNAME = 5013
DECMD_GETFONTSIZE = 5014
DECMD_GETFORECOLOR = 5015
DECMD_HYPERLINK = 5016
DECMD_IMAGE = 5017
DECMD_INDENT = 5018
DECMD_INSERTCELL = 5019
DECMD_INSERTCOL = 5020
DECMD_INSERTROW = 5021
DECMD_INSERTTABLE = 5022
DECMD_ITALIC = 5023
DECMD_JUSTIFYCENTER = 5024
DECMD_JUSTIFYLEFT = 5025
DECMD_JUSTIFYRIGHT = 5026
DECMD_LOCK_ELEMENT = 5027
DECMD_MAKE_ABSOLUTE = 5028
DECMD_MERGECELLS = 5029
DECMD_ORDERLIST = 5030
DECMD_OUTDENT = 5031
DECMD_PASTE = 5032
DECMD_REDO = 5033
DECMD_REMOVEFORMAT = 5034
DECMD_SELECTALL = 5035
DECMD_SEND_BACKWARD = 5036
DECMD_BRING_FORWARD = 5037
DECMD_SEND_BELOW_TEXT = 5038
DECMD_BRING_ABOVE_TEXT = 5039
DECMD_SEND_TO_BACK = 5040
DECMD_BRING_TO_FRONT = 5041
DECMD_SETBACKCOLOR = 5042
DECMD_SETBLOCKFMT = 5043
DECMD_SETFONTNAME = 5044
DECMD_SETFONTSIZE = 5045
DECMD_SETFORECOLOR = 5046
DECMD_SPLITCELL = 5047
DECMD_UNDERLINE = 5048
DECMD_UNDO = 5049
DECMD_UNLINK = 5050
DECMD_UNORDERLIST = 5051
DECMD_PROPERTIES = 5052
// OLECMDEXECOPT
OLECMDEXECOPT_DODEFAULT = 0
OLECMDEXECOPT_PROMPTUSER = 1
OLECMDEXECOPT_DONTPROMPTUSER = 2
// DHTMLEDITCMDF
DECMDF_NOTSUPPORTED = 0
DECMDF_DISABLED = 1
DECMDF_ENABLED = 3
DECMDF_LATCHED = 7
DECMDF_NINCHED = 11
// DHTMLEDITAPPEARANCE
DEAPPEARANCE_FLAT = 0
DEAPPEARANCE_3D = 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -