📄 richedit.js
字号:
/*
##############################################
# BigMole Dynamic Discussion Board 2.0 #
# By Emil A Eklund (http://BigMole.5188.org/contact.html#emil) #
# and Erik Arvidson (http://BigMole.5188.org/contact.html#erik) #
# April 24, 1999 #
##############################################
# Feel free to use this script for personal #
# and non-profit organisation's websites, #
# as long as you're giving us credits for it #
# in other words, not removing nur modifying #
# this notice in any of the files it apperes #
##############################################
# For comercial use contact Emil or Erik #
##############################################
This is based on Scoot Isaac's wysiwyg editor
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// richTextEditor.html
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
window.onload = initRichTextEditorPrime;
// Default format is WYSIWYG HTML
var format="HTML";
// Set the focus to the editor
function setFocus() {
textEdit.focus();
}
// Execute a command against the editor
// At minimum one argument is required. Some commands
// require a second optional argument:
// eg., ("formatblock","<H1>") to make an H1
function execCommand(command) {
if (format=="HTML") {
var edit = textEdit.document.selection.createRange();
if (arguments[1]==null)
edit.execCommand(command);
else
edit.execCommand(command,false, arguments[1]);
edit.select();
// textEdit.focus();
}
}
// Initialize the editor with an empty document
function initRichTextEditorPrime() {
textEdit.document.designMode="On";
textEdit.document.open();
textEdit.document.write("");
textEdit.document.close();
// textEdit.focus() // I don't wan't to set the focus on load
}
// Swap between WYSIWYG mode and raw HTML mode
function swapModes() {
var tmp;
if (format=="HTML") {
if (ieVersion() == 5)
tmp = "" + textEdit.document.documentElement.outerHTML + ""; // This gives the entire doc
else
tmp = "" + textEdit.document.body.outerHTML + "";
textEdit.document.open();
textEdit.document.write(formatHTMLCode(tmp));
textEdit.document.close();
format="Text";
}
else {
tmp = "" + textEdit.document.body.innerText + "";
textEdit.document.open();
textEdit.document.write(tmp);
textEdit.document.close();
format="HTML";
}
textEdit.focus();
var s = textEdit.document.body.createTextRange();
s.collapse(false);
s.select();
}
// The following two functions formats the HTML when switching to WYSIWYG mode
function formatHTMLCode(str) {
return "<div style='" + codeStyle + "'>" + formatCode(str.replace(/&/g, "&")) + "</div>";
}
function formatCode(s) {
var str = "";
var IN_TEXT = 1;
var IN_ELEMENT = 2;
var state = IN_TEXT;
while (s.length > 0) {
var endTagBreak, emptyTagBreak;
if (state == IN_ELEMENT) {
var endIndex = s.indexOf(">");
var endTag = (s.substring(0,1) == "/");
if (endIndex != -1) {
str += s.substring(0,endIndex) + "></span>";
if (endTag && endTagBreak || emptyTagBreak)
str += "<br>";
s = s.substring(endIndex+1, s.length);
state = IN_TEXT;
}
else {
str += s + "</span>";
s = "";
}
}
else {
var startIndex = s.indexOf("<");
var endTags = new Array("P", "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "BLOCKQUOTE", "OL", "LI", "PRE", "UL", "TITLE", "BODY", "META", "HEAD");
var startTags = new Array("BR", "HR", "META", "HTML", "BODY", "HEAD");
if (startIndex != -1) {
var tagName;
var nameStartIndex;
var gtIndex = s.indexOf(">");
var spaceIndex = s.indexOf(" ");
var slashIndex = s.indexOf("/");
endTagBreak = false;
emptyTagBreak = false;
if (slashIndex != -1 && slashIndex == startIndex+1)
nameStartIndex = slashIndex + 1;
else
nameStartIndex = startIndex + 1;
if (spaceIndex != -1 && spaceIndex > startIndex && spaceIndex < gtIndex)
tagName = s.substring(nameStartIndex,spaceIndex);
else if (gtIndex != -1)
tagName = s.substring(nameStartIndex,gtIndex);
else
tagName = s.substring(nameStartIndex,s.length);
for (var i=0; i<endTags.length; i++) {
if (endTags[i] == tagName) {
endTagBreak = true;
break;
}
}
for (var i=0; i<startTags.length; i++) {
if (startTags[i] == tagName) {
emptyTagBreak = true;
break;
}
}
str += s.substring(0,startIndex) + "<span style='" + elementCodeStyle + "'><";
s = s.substring(startIndex+1, s.length);
state = IN_ELEMENT;
}
else {
str += s;
s = "";
}
}
}
return str;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// end richTextEditor.html
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -