📄 richtext.js
字号:
htmlSrc.selectNodeContents(oRTE.body);
oRTE.body.innerHTML = htmlSrc.toString();
}
}
}
//Function to format text in the text box
function FormatText(rte, command, option) {
var oRTE;
if (document.all) {
oRTE = frames[rte];
//get current selected range
var selection = oRTE.document.selection;
if (selection != null) {
rng = selection.createRange();
}
} else {
oRTE = document.getElementById(rte).contentWindow;
//get currently selected range
var selection = oRTE.getSelection();
rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
}
try {
if ((command == "forecolor") || (command == "hilitecolor")) {
//save current values
parent.command = command;
currentRTE = rte;
//position and show color palette
buttonElement = document.getElementById(command + '_' + rte);
document.getElementById('cp' + rte).style.left = getOffsetLeft(buttonElement) + "px";
document.getElementById('cp' + rte).style.top = (getOffsetTop(buttonElement) + buttonElement.offsetHeight) + "px";
if (document.getElementById('cp' + rte).style.visibility == "hidden") {
document.getElementById('cp' + rte).style.visibility = "visible";
document.getElementById('cp' + rte).style.display = "inline";
} else {
document.getElementById('cp' + rte).style.visibility = "hidden";
document.getElementById('cp' + rte).style.display = "none";
}
} else if (command == "createlink") {
var szURL = prompt("Enter a URL:", "");
try {
//ignore error for blank urls
oRTE.document.execCommand("Unlink", false, null);
oRTE.document.execCommand("CreateLink", false, szURL);
} catch (e) {
//do nothing
}
} else {
//oRTE.focus();
oRTE.document.execCommand(command, false, option);
//oRTE.focus();
}
} catch (e) {
alert(e);
}
}
//Function to set color
function setColor(color) {
var rte = currentRTE;
var oRTE;
if (document.all) {
oRTE = frames[rte];
} else {
oRTE = document.getElementById(rte).contentWindow;
}
var parentCommand = parent.command;
if (document.all) {
//retrieve selected range
var sel = oRTE.document.selection;
if (parentCommand == "hilitecolor") parentCommand = "backcolor";
if (sel != null) {
var newRng = sel.createRange();
newRng = rng;
newRng.select();
}
} else {
//oRTE.focus();
}
oRTE.document.execCommand(parentCommand, false, color);
//oRTE.focus();
document.getElementById('cp' + rte).style.visibility = "hidden";
document.getElementById('cp' + rte).style.display = "none";
}
//Function to add image
function AddImage(rte) {
var oRTE;
if (document.all) {
oRTE = frames[rte];
//get current selected range
var selection = oRTE.document.selection;
if (selection != null) {
rng = selection.createRange();
}
} else {
oRTE = document.getElementById(rte).contentWindow;
//get currently selected range
var selection = oRTE.getSelection();
rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
}
imagePath = prompt('Enter Image URL:', 'http://');
if ((imagePath != null) && (imagePath != "")) {
//oRTE.focus();
oRTE.document.execCommand('InsertImage', false, imagePath);
}
//oRTE.focus();
}
//function to perform spell check
function checkspell() {
try {
var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
tmpis.CheckAllLinkedDocuments(document);
}
catch(exception) {
if(exception.number==-2146827859) {
if (confirm("ieSpell not detected. Click Ok to go to download page."))
window.open("http://www.iespell.com/download.php","DownLoad");
} else {
alert("Error Loading ieSpell: Exception " + exception.number);
}
}
}
function getOffsetTop(elm) {
var mOffsetTop = elm.offsetTop;
var mOffsetParent = elm.offsetParent;
while(mOffsetParent){
mOffsetTop += mOffsetParent.offsetTop;
mOffsetParent = mOffsetParent.offsetParent;
}
return mOffsetTop;
}
function getOffsetLeft(elm) {
var mOffsetLeft = elm.offsetLeft;
var mOffsetParent = elm.offsetParent;
while(mOffsetParent) {
mOffsetLeft += mOffsetParent.offsetLeft;
mOffsetParent = mOffsetParent.offsetParent;
}
return mOffsetLeft;
}
function Select(rte, selectname) {
var oRTE;
if (document.all) {
oRTE = frames[rte];
//get current selected range
var selection = oRTE.document.selection;
if (selection != null) {
rng = selection.createRange();
}
} else {
oRTE = document.getElementById(rte).contentWindow;
//get currently selected range
var selection = oRTE.getSelection();
rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
}
var idx = document.getElementById(selectname).selectedIndex;
// First one is always a label
if (idx != 0) {
var selected = document.getElementById(selectname).options[idx].value;
var cmd = selectname.replace('_' + rte, '');
oRTE.document.execCommand(cmd, false, selected);
document.getElementById(selectname).selectedIndex = 0;
}
//oRTE.focus();
}
function kb_handler(evt) {
var rte = evt.target.id;
//contributed by Anti Veeranna (thanks Anti!)
if (evt.ctrlKey) {
var key = String.fromCharCode(evt.charCode).toLowerCase();
var cmd = '';
switch (key) {
case 'b': cmd = "bold"; break;
case 'i': cmd = "italic"; break;
case 'u': cmd = "underline"; break;
};
if (cmd) {
FormatText(rte, cmd, true);
//evt.target.ownerDocument.execCommand(cmd, false, true);
// stop the event bubble
evt.preventDefault();
evt.stopPropagation();
}
}
}
function docChanged (evt) {
alert('changed');
}
function stripHTML(oldString) {
var newString = oldString.replace(/(<([^>]+)>)/ig,"");
//replace carriage returns and line feeds
newString = escape(newString);
newString = newString.replace("%0D%0A"," ");
newString = newString.replace("%0A"," ");
newString = newString.replace("%0D"," ");
newString = unescape(newString);
//trim string
newString = trim(newString);
return newString;
}
function trim(inputString) {
// Removes leading and trailing spaces from the passed string. Also removes
// consecutive spaces and replaces it with one space. If something besides
// a string is passed in (null, custom object, etc.) then return the input.
if (typeof inputString != "string") return inputString;
var retValue = inputString;
var ch = retValue.substring(0, 1);
while (ch == " ") { // Check for spaces at the beginning of the string
retValue = retValue.substring(1, retValue.length);
ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == " ") { // Check for spaces at the end of the string
retValue = retValue.substring(0, retValue.length-1);
ch = retValue.substring(retValue.length-1, retValue.length);
}
// Note that there are two spaces in the string - look for multiple spaces within the string
while (retValue.indexOf(" ") != -1) {
// Again, there are two spaces in each of the strings
retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length);
}
return retValue; // Return the trimmed string back to the user
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -