📄 editor.js
字号:
text = text.replace(/&/g, "&") ;
text = text.replace(/"/g, """) ;
text = text.replace(/</g, "<") ;
text = text.replace(/>/g, ">") ;
text = text.replace(/\ /g," ");
text = text.replace(/\n/g,"<br>");
text = text.replace(/\t/g," ");
return text;
}
function insert(what) {
if (!validateMode()) {return;}
eWebEditor.focus();
saveHistory();
var sel = eWebEditor.document.selection.createRange();
switch(what){
case "excel":
insertHTML("<object classid='clsid:0002E510-0000-0000-C000-000000000046' id='Spreadsheet1' codebase='file:\\Bob\software\office2000\msowc.cab' width='100%' height='250'><param name='HTMLURL' value><param name='HTMLData' value='<html xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40"><head><style type="text/css"><!--tr{mso-height-source:auto;}td{black-space:nowrap;}.wc4590F88{black-space:nowrap;font-family:Verdana,Arial,Helvetica,sans-serif;mso-number-format:General;font-size:auto;font-weight:auto;font-style:auto;text-decoration:auto;mso-background-source:auto;mso-pattern:auto;mso-color-source:auto;text-align:general;vertical-align:bottom;border-top:none;border-left:none;border-right:none;border-bottom:none;mso-protection:locked;}--></style></head><body><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:OWCVersion>9.0.0.2710</x:OWCVersion><x:Label Style='border-top:solid .5pt silver;border-left:solid .5pt silver;border-right:solid .5pt silver;border-bottom:solid .5pt silver'><x:Caption>Microsoft Office Spreadsheet</x:Caption> </x:Label><x:Name>Sheet1</x:Name><x:WorksheetOptions><x:Selected/><x:Height>7620</x:Height><x:Width>15240</x:Width><x:TopRowVisible>0</x:TopRowVisible><x:LeftColumnVisible>0</x:LeftColumnVisible> <x:ProtectContents>False</x:ProtectContents> <x:DefaultRowHeight>210</x:DefaultRowHeight> <x:StandardWidth>2389</x:StandardWidth> </x:WorksheetOptions> </x:ExcelWorksheet></x:ExcelWorksheets> <x:MaxHeight>80%</x:MaxHeight><x:MaxWidth>80%</x:MaxWidth></x:ExcelWorkbook></xml><![endif]--><table class=wc4590F88 x:str><col width="56"><tr height="14"><td></td></tr></table></body></html>'> <param name='DataType' value='HTMLDATA'> <param name='AutoFit' value='0'><param name='DisplayColHeaders' value='-1'><param name='DisplayGridlines' value='-1'><param name='DisplayHorizontalScrollBar' value='-1'><param name='DisplayRowHeaders' value='-1'><param name='DisplayTitleBar' value='-1'><param name='DisplayToolbar' value='-1'><param name='DisplayVerticalScrollBar' value='-1'> <param name='EnableAutoCalculate' value='-1'> <param name='EnableEvents' value='-1'><param name='MoveAfterReturn' value='-1'><param name='MoveAfterReturnDirection' value='0'><param name='RightToLeft' value='0'><param name='ViewableRange' value='1:65536'></object>");
break;
case "nowdate":
var d = new Date();
insertHTML(d.toLocaleDateString());
break;
case "nowtime":
var d = new Date();
insertHTML(d.toLocaleTimeString());
break;
case "br":
insertHTML("<br>")
break;
case "code":
insertHTML('<table width=95% border="0" align="Center" cellpadding="6" cellspacing="0" style="border: 1px Dotted #CCCCCC; TABLE-LAYOUT: fixed"><tr><td bgcolor=#FDFDDF style="WORD-WRAP: break-word"><font style="color: #990000;font-weight:bold">以下是代码片段:</font><br>'+HTMLEncode(sel.text)+'</td></tr></table>');
break;
case "quote":
insertHTML('<table width=95% border="0" align="Center" cellpadding="6" cellspacing="0" style="border: 1px Dotted #CCCCCC; TABLE-LAYOUT: fixed"><tr><td bgcolor=#F3F3F3 style="WORD-WRAP: break-word"><font style="color: #990000;font-weight:bold">以下是引用片段:</font><br>'+HTMLEncode(sel.text)+'</td></tr></table>');
break;
case "big":
insertHTML("<big>" + sel.text + "</big>");
break;
case "small":
insertHTML("<small>" + sel.text + "</small>");
break;
default:
alert("错误参数调用!");
break;
}
sel=null;
}
var borderShown = config.ShowBorder;
function showBorders() {
if (!validateMode()) {return;}
var allForms = eWebEditor.document.body.getElementsByTagName("FORM");
var allInputs = eWebEditor.document.body.getElementsByTagName("INPUT");
var allTables = eWebEditor.document.body.getElementsByTagName("TABLE");
var allLinks = eWebEditor.document.body.getElementsByTagName("A");
// form
for (a=0; a < allForms.length; a++) {
if (borderShown == "0") {
allForms[a].runtimeStyle.border = "1px dotted #FF0000"
} else {
allForms[a].runtimeStyle.cssText = ""
}
}
// input
for (b=0; b < allInputs.length; b++) {
if (borderShown == "0") {
if (allInputs[b].type.toUpperCase() == "HIDDEN") {
allInputs[b].runtimeStyle.border = "1px dashed #000000"
allInputs[b].runtimeStyle.width = "15px"
allInputs[b].runtimeStyle.height = "15px"
allInputs[b].runtimeStyle.backgroundColor = "#FDADAD"
allInputs[b].runtimeStyle.color = "#FDADAD"
}
} else {
if (allInputs[b].type.toUpperCase() == "HIDDEN")
allInputs[b].runtimeStyle.cssText = ""
}
}
// table
for (i=0; i < allTables.length; i++) {
if (borderShown == "0") {
allTables[i].runtimeStyle.border = "1px dotted #BFBFBF"
} else {
allTables[i].runtimeStyle.cssText = ""
}
allRows = allTables[i].rows
for (y=0; y < allRows.length; y++) {
allCellsInRow = allRows[y].cells
for (x=0; x < allCellsInRow.length; x++) {
if (borderShown == "0") {
allCellsInRow[x].runtimeStyle.border = "1px dotted #BFBFBF"
} else {
allCellsInRow[x].runtimeStyle.cssText = ""
}
}
}
}
// A
for (a=0; a < allLinks.length; a++) {
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() {
eWebEditor.scrollBy(0,0);
}
var nCurrZoomSize = 100;
var aZoomSize = new Array(10, 25, 50, 75, 100, 150, 200, 500);
function doZoom(size) {
eWebEditor.document.body.runtimeStyle.zoom = size + "%";
nCurrZoomSize = size;
}
function findReplace(){
showDialog('findreplace.htm', true)
}
function absolutePosition(){
var objReference = null;
var RangeType = eWebEditor.document.selection.type;
if (RangeType != "Control") {return;}
var selectedRange = eWebEditor.document.selection.createRange();
for (var i=0; i<selectedRange.length; i++){
objReference = selectedRange.item(i);
if (objReference.style.position != 'relative') {
objReference.style.position='relative';
}else{
objReference.style.position='static';
}
}
}
function zIndex(action){
var objReference = null;
var RangeType = eWebEditor.document.selection.type;
if (RangeType != "Control") {return;}
var selectedRange = eWebEditor.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='relative';
}
}
function isControlSelected(tag){
if (tag){
if (eWebEditor.document.selection.type == "Control") {
var oControlRange = eWebEditor.document.selection.createRange();
if (oControlRange(0).tagName.toUpperCase() == tag) {
return true;
}
}
}
return false;
}
function findParentElement(tag) {
var el = null;
if (eWebEditor.document.selection.type != "Control") {
el = eWebEditor.document.selection.createRange().parentElement();
while (el.tagName.toUpperCase() != tag){
el = el.parentElement;
if (el == null){
break;
}
}
}
return el;
}
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;}
saveHistory();
var b = false;
if (eWebEditor.document.selection.type == "Control") {
var oControlRange = eWebEditor.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 paragraphAttr(){
if (!validateMode()) {return;}
eWebEditor.focus();
if (!tagInSelection("P")){
alert("段落属性只能应用于段落,请至少选择一个段落!");
return;
}
showDialog('paragraph.htm', true);
}
function tagInSelection(tag){
var sel = eWebEditor.document.selection.createRange();
sel.type = eWebEditor.document.selection.type;
if (sel.type!="Control"){
var oBody = eWebEditor.document.body;
var aAllEl = oBody.getElementsByTagName(tag);
var aSelEl = new Array();
var oRngTemp = oBody.createTextRange();
for(var i=0;i<aAllEl.length;i++){
oRngTemp.moveToElementText(aAllEl(i));
if (sel.inRange(oRngTemp)){
aSelEl[aSelEl.length] = aAllEl[i];
}else{
if ( ((sel.compareEndPoints("StartToEnd",oRngTemp)<0)&&(sel.compareEndPoints("StartToStart",oRngTemp)>0)) || ((sel.compareEndPoints("EndToStart",oRngTemp)>0)&&(sel.compareEndPoints("EndToEnd",oRngTemp)<0)) ){
aSelEl[aSelEl.length] = aAllEl[i];
}
}
}
if (aSelEl.length>0){
return true;
}
}
return false;
}
function splitTextField(objField, html) {
objField.value = html;
if (config.ServerExt != "asp") {return;}
var strFieldName = objField.name;
var objForm = objField.form;
var objDocument = objField.document;
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 history = new Object;
history.data = [];
history.position = 0;
history.bookmark = [];
history.saved = false;
function saveHistory() {
history.saved = true;
var html = getHTML();
if (history.data[history.position] != html){
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] = html;
if (eWebEditor.document.selection.type != "Control"){
try{
history.bookmark[history.bookmark.length] = eWebEditor.document.selection.createRange().getBookmark();
}catch(e){
history.bookmark[history.bookmark.length] = "";
}
} else {
var oRng = eWebEditor.document.selection.createRange();
var el = oRng.item(0);
history.bookmark[history.bookmark.length] = "[object]|" + el.tagName + "|" + getElementTagIndex(el);
}
if (nBeginLen!=0){
history.position++;
}
}
}
function getElementTagIndex(el){
var els = eWebEditor.document.body.getElementsByTagName(el.tagName);
for (var i=0; i<els.length; i++){
if (els[i]==el){
return i;
}
}
return null;
}
function initHistory() {
history.data.length = 0;
history.bookmark.length = 0;
history.position = 0;
history.saved = false;
}
function goHistory(value) {
if (!history.saved){saveHistory();}
//eWebEditor.focus();
// undo
if (value == -1){
if (history.position > 0){
history.position = history.position - 1;
setHTML(history.data[history.position], true);
setHistoryCursor();
}
// redo
} else {
if (history.position < history.data.length -1){
history.position = history.position + 1;
setHTML(history.data[history.position], true);
setHistoryCursor();
}
}
eWebEditor.focus();
}
function setHistoryCursor() {
var s_Bookmark = history.bookmark[history.position];
if (s_Bookmark){
//eWebEditor_Toolbar.focus();
eWebEditor_Layout.focus();
if (s_Bookmark.substring(0,8) != "[object]"){
r = eWebEditor.document.body.createTextRange();
if (r.moveToBookmark(history.bookmark[history.position])){
//r.duplicate();
//r.collapse(false);
r.select();
}
}else{
if (sCurrMode=="EDIT"){
r = eWebEditor.document.body.createControlRange();
var a = s_Bookmark.split("|");
var els = eWebEditor.document.body.getElementsByTagName(a[1]);
var el = els[a[2]];
r.addElement(el);
r.select();
}
}
}
}
function getStyleEditorHeader(){
if ((sCurrMode=="EDIT") || (sCurrMode=="VIEW")){
return config.StyleEditorHeader1 + sExtCSS + config.StyleEditorHeader2;
}else{
return config.StyleEditorHeader1 + config.StyleEditorHeader2;
}
}
// n_Type - 0:en; 1:chs; 2:en+chs(1);3,en+chs(2)
function getCount(n_Type){
var str=getText();
str = str.replace(/\n/g,"");
str = str.replace(/\r/g,"");
var l=str.length;
var n=0;
for (var i=0;i<l;i++){
if (str.charCodeAt(i)<0||str.charCodeAt(i)>255){
if (n_Type!=0){
n++;
if (n_Type==3){
n++;
}
}
}else{
if (n_Type!=1){
n++;
}
}
}
return n;
}
function getText(){
eWebEditor_Temp_HTML.innerHTML = getHTML();
var s = eWebEditor_Temp_HTML.innerText;
return s;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -