📄 editor.js
字号:
if (borderShown == "0") {
if (allLinks[a].href.toUpperCase() == "") {
allLinks[a].runtimeStyle.borderBottom = "1px dashed #000000"
}
} else {
allLinks[a].runtimeStyle.cssText = ""
}
}
//if (borderShown == "0") {
// borderShown = "1"
//} else {
// borderShown = "0"
//}
scrollUp()
}
// 返回页面最上部
function scrollUp() {
Editor.scrollBy(0,0);
}
// 缩放操作
var nCurrZoomSize = 100;
var aZoomSize = new Array(10, 25, 50, 75, 100, 150, 200, 500);
function doZoom(size) {
Editor.document.body.runtimeStyle.zoom = size + "%";
nCurrZoomSize = size;
}
// 拼写检查
function spellCheck(){
ShowDialog('dialog/spellcheck.htm', 300, 220, true)
}
// 查找替换
function findReplace(){
ShowDialog('dialog/findreplace.htm', 320, 165, true)
}
// 相对(absolute)或绝对位置(static)
function absolutePosition(){
var objReference = null;
var RangeType = Editor.document.selection.type;
if (RangeType != "Control") return;
var selectedRange = Editor.document.selection.createRange();
for (var i=0; i<selectedRange.length; i++){
objReference = selectedRange.item(i);
if (objReference.style.position != 'absolute') {
objReference.style.position='absolute';
}else{
objReference.style.position='static';
}
}
}
// 上移(forward)或下移(backward)一层
function zIndex(action){
var objReference = null;
var RangeType = Editor.document.selection.type;
if (RangeType != "Control") return;
var selectedRange = Editor.document.selection.createRange();
for (var i=0; i<selectedRange.length; i++){
objReference = selectedRange.item(i);
if (action=='forward'){
objReference.style.zIndex +=1;
}else{
objReference.style.zIndex -=1;
}
objReference.style.position='absolute';
}
}
// 环绕
function imgalign(align){
if (!validateMode()) return;
Editor.focus();
var oControl;
var oSeletion;
var sRangeType;
oSelection = Editor.document.selection.createRange();
sRangeType = Editor.document.selection.type;
if (sRangeType == "Control") {
if (oSelection.item(0).tagName == "IMG"){
oControl = oSelection.item(0)
oControl.align = align;
}
}
Editor.focus();
}
// 是否选中指定类型的控件
function isControlSelected(tag){
if (Editor.document.selection.type == "Control") {
var oControlRange = Editor.document.selection.createRange();
if (oControlRange(0).tagName.toUpperCase() == tag) {
return true;
}
}
return false;
}
// 改变编辑区高度
function sizeChange(size){
if (!BrowserInfo.IsIE55OrMore){
alert("此功能需要IE5.5版本以上的支持!");
return false;
}
for (var i=0; i<parent.frames.length; i++){
if (parent.frames[i].document==self.document){
var obj=parent.frames[i].frameElement;
var height = parseInt(obj.offsetHeight);
if (height+size>=300){
obj.height=height+size;
}
break;
}
}
}
// 热点链接
function mapEdit(){
if (!validateMode()) return;
var b = false;
if (Editor.document.selection.type == "Control") {
var oControlRange = Editor.document.selection.createRange();
if (oControlRange(0).tagName.toUpperCase() == "IMG") {
b = true;
}
}
if (!b){
alert("热点链接只能作用于图片");
return;
}
window.open("dialog/map.htm", 'mapEdit'+sLinkFieldName, 'toolbar=no,location=no,directories=no,status=not,menubar=no,scrollbars=no,resizable=yes,width=450,height=300');
}
// 上传文件成功返回原文件名、保存后的文件名、保存后的路径文件名,提供接口
function addUploadFile(originalFileName, saveFileName, savePathFileName){
doInterfaceUpload(sLinkOriginalFileName, originalFileName);
doInterfaceUpload(sLinkSaveFileName, saveFileName);
doInterfaceUpload(sLinkSavePathFileName, savePathFileName);
}
// 文件上传成功接口操作
function doInterfaceUpload(strLinkName, strValue){
if (strValue=="") return;
if (strLinkName){
var objLinkUpload = parent.document.getElementsByName(strLinkName)[0];
if (objLinkUpload){
if (objLinkUpload.value!=""){
objLinkUpload.value = objLinkUpload.value + "|";
}
objLinkUpload.value = objLinkUpload.value + strValue;
objLinkUpload.fireEvent("onchange");
}
}
}
// 大文件内容自动拆分
function splitTextField(objField, html) {
var strFieldName = objField.name;
var objForm = objField.form;
var objDocument = objField.document;
objField.value = html;
//表单限制值设定,限制值是102399,考虑到中文设为一半
var FormLimit = 50000 ;
// 再次处理时,先赋空值
for (var i=1;i<objDocument.getElementsByName(strFieldName).length;i++) {
objDocument.getElementsByName(strFieldName)[i].value = "";
}
//如果表单值超过限制,拆成多个对象
if (html.length > FormLimit) {
objField.value = html.substr(0, FormLimit) ;
html = html.substr(FormLimit) ;
while (html.length > 0) {
var objTEXTAREA = objDocument.createElement("TEXTAREA") ;
objTEXTAREA.name = strFieldName ;
objTEXTAREA.style.display = "none" ;
objTEXTAREA.value = html.substr(0, FormLimit) ;
objForm.appendChild(objTEXTAREA) ;
html = html.substr(FormLimit) ;
}
}
}
// 远程上传
var sEventUploadAfter;
function remoteUpload(strEventUploadAfter) {
if (config.AutoRemote!="1") return;
if (sCurrMode=="TEXT") return;
sEventUploadAfter = strEventUploadAfter;
var objField = document.getElementsByName("Editor_UploadText")[0];
splitTextField(objField, getHTML());
divProcessing.style.top = (document.body.clientHeight-parseFloat(divProcessing.style.height))/2;
divProcessing.style.left = (document.body.clientWidth-parseFloat(divProcessing.style.width))/2;
divProcessing.style.display = "";
Editor_UploadForm.submit();
}
// 远程上传完成
function remoteUploadOK() {
divProcessing.style.display = "none";
if (oLinkField){
if (sEventUploadAfter){
eval("parent."+sEventUploadAfter);
}
}
}
// 修正Undo/Redo
var history = new Object;
history.data = [];
history.position = 0;
history.bookmark = [];
// 保存历史
function saveHistory() {
if (bEditMode){
if (history.data[history.position] != Editor.document.body.innerHTML){
var nBeginLen = history.data.length;
var nPopLen = history.data.length - history.position;
for (var i=1; i<nPopLen; i++){
history.data.pop();
history.bookmark.pop();
}
history.data[history.data.length] = Editor.document.body.innerHTML;
if (Editor.document.selection.type != "Control"){
history.bookmark[history.bookmark.length] = Editor.document.selection.createRange().getBookmark();
} else {
var oControl = Editor.document.selection.createRange();
history.bookmark[history.bookmark.length] = oControl[0];
}
if (nBeginLen!=0){
history.position++;
}
}
}
}
// 初始历史
function initHistory() {
history.data.length = 0;
history.bookmark.length = 0;
history.position = 0;
}
// 返回历史
function goHistory(value) {
saveHistory();
// undo
if (value == -1){
if (history.position > 0){
Editor.document.body.innerHTML = history.data[--history.position];
setHistoryCursor();
}
// redo
} else {
if (history.position < history.data.length -1){
Editor.document.body.innerHTML = history.data[++history.position];
setHistoryCursor();
}
}
}
// 设置当前书签
function setHistoryCursor() {
if (history.bookmark[history.position]){
r = Editor.document.body.createTextRange()
if (history.bookmark[history.position] != "[object]"){
if (r.moveToBookmark(history.bookmark[history.position])){
r.collapse(false);
r.select();
}
}
}
}
// End Undo / Redo Fix
// 工具栏事件发生
function doToolbar(){
if (bEditMode){
saveHistory();
}
}
//触发焦点事件
function onMouseUp(event){
parent.setContent('set');
//加载Html标签导航
UpdateToolbar();
}
function onMouseOut(event){
//parent.setContent('set');
//加载Html标签导航
//UpdateToolbar();
}
function onMouseOver(event){
//parent.setContent('get');
//加载Html标签导航
//UpdateToolbar();
}
//Html 标签导航
function UpdateToolbar()
{
var ancestors = null;
ancestors=GetAllAncestors();
ShowObject.innerHTML=' ';
for (var i=ancestors.length;--i>=0;)
{
var el = ancestors[i];
if (!el) continue;
var a=document.createElement("span");
a.href="#";
a.el=el;
a.editor=this;
if (i==0)
{
a.className='AncestorsMouseUp';
EditControl=a.el;
}
else a.className='AncestorsStyle';
a.onmouseover=function()
{
if (this.className=='AncestorsMouseUp') this.className='AncestorsMouseUpOver';
else if (this.className=='AncestorsStyle') this.className='AncestorsMouseOver';
};
a.onmouseout=function()
{
if (this.className=='AncestorsMouseUpOver') this.className='AncestorsMouseUp';
else if (this.className=='AncestorsMouseOver') this.className='AncestorsStyle';
};
a.onmousedown=function(){this.className='AncestorsMouseDown';};
a.onmouseup=function(){this.className='AncestorsMouseUpOver';};
a.ondragstart=YCancelEvent;
a.onselectstart=YCancelEvent;
a.onselect=YCancelEvent;
a.onclick=function()
{
this.blur();
SelectNodeContents(this);
return false;
};
if (el.tagName.toLowerCase()!='tbody'){
var txt='<'+el.tagName.toLowerCase();
a.title=el.style.cssText;
if (el.id) txt += "#" + el.id;
if (el.className) txt += "." + el.className;
txt=txt+'>';
a.appendChild(document.createTextNode(txt));
ShowObject.appendChild(a);
}
}
}
function GetAllAncestors()
{
var p = GetParentElement();
var a = [];
while (p && (p.nodeType==1)&&(p.tagName.toLowerCase()!='body'))
{
a.push(p);
p=p.parentNode;
}
a.push(Editor.document.body);
return a;
}
function GetParentElement()
{
var sel=GetSelection();
var range=CreateRange(sel);
switch (sel.type)
{
case "Text":
case "None":
return range.parentElement();
case "Control":
return range.item(0);
default:
return Editor.document.body;
}
}
function GetSelection()
{
return Editor.document.selection;
}
function CreateRange(sel)
{
return sel.createRange();
}
function SelectNodeContents(Obj,pos)
{
var node=Obj.el;
EditControl=node;
for (var i=0;i<ShowObject.children.length;i++)
{
if (ShowObject.children(i).className=='AncestorsMouseUp') ShowObject.children(i).className='AncestorsStyle';
}
Editor.focus();
var range;
var collapsed=(typeof pos!='undefined');
range = Editor.document.body.createTextRange();
range.moveToElementText(node);
(collapsed) && range.collapse(pos);
range.select();
}
function AddUploadFiles(objname,files,filesv){
if(objname!=''){
//alert("OK!");
var obj = parent.document.getElementById(objname);
obj.options[obj.length]=new Option(filesv,files);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -