📄 edit1.asp
字号:
} else {
var oRTE = document.getElementById(this.name).contentWindow.document;
oRTE.open();
oRTE.write(frameHtml);
oRTE.close();
//attach a keyboard handler for Mozilla to make keyboard shortcuts for formatting text work
oRTE.addEventListener("keypress", kb_handler, true);
}
}
this.update = function(){
//alert("this.update");
this.setViewMode(false);
//set message value
var oHdnMessage = document.getElementById('hdn' + this.name);
var oRTE = document.getElementById(this.name);
if (this.isRichText) {
if (oHdnMessage.value == null) oHdnMessage.value = "";
if (document.all) {
oHdnMessage.value = frames[this.name].document.body.innerHTML;
} else {
oHdnMessage.value = oRTE.contentWindow.document.body.innerHTML;
}
//if there is no content (other than formatting) set value to nothing
if (stripHTML(oHdnMessage.value.replace(" ", " ")) == "") oHdnMessage.value = "";
this.html = stripWordHTML(oHdnMessage.value);
}
}
this.setToolbarsVisible = function(isVisible){
//alert("this.setToolbarsVisible");
visibleStyle = isVisible?"visible":"hidden";
for (x=0;x<this.toolbarNames.length;x++){
document.getElementById(this.toolbarNames[x] + "_" + this.name).style.visibility = visibleStyle;
}
}
this.setViewMode = function(isSrcView){
//alert("this.setViewMode");
HyperTextArea.activeArea = this;
//contributed by Bob Hutzel (thanks Bob!)
var oRTE;
if (document.all) {
oRTE = frames[this.name].document;
} else {
oRTE = document.getElementById(this.name).contentWindow.document;
}
//only change the view if it is different than the current state
if (isSrcView && !this.isSrcView){
this.isSrcView = true;
this.setToolbarsVisible(false);
if (document.all) {
oRTE.body.innerText = oRTE.body.innerHTML;
} else {
var htmlSrc = oRTE.createTextNode(oRTE.body.innerHTML);
oRTE.body.innerHTML = "";
oRTE.body.appendChild(htmlSrc);
}
}else if(!isSrcView && this.isSrcView){
this.isSrcView = false;
this.setToolbarsVisible(true);
if (document.all) {
oRTE.body.innerHTML = oRTE.body.innerText;
} else {
var htmlSrc = oRTE.body.ownerDocument.createRange();
htmlSrc.selectNodeContents(oRTE.body);
oRTE.body.innerHTML = htmlSrc.toString();
}
}
}
this.toggleHTMLSrc = function(){
//alert("this.toggleHTMLSrc");
if (document.getElementById("chkSrc" + this.name).checked) {
this.setViewMode(true);
} else {
this.setViewMode(false);
}
}
//TODO would really like to be able to plug functionality in here.
//This would include the ability to launch a wizard, and then insert arbitrary text at the insertion point
this.formatText = function (command,option){
//alert("this.formatText");
//所有与文字处理有关的功能都会调用此方法,在这个方法里面可以添加相关的新功能
HyperTextArea.activeArea = this;
var oRTE;
if (document.all) {
oRTE = frames[this.name];
} else {
oRTE = document.getElementById(this.name).contentWindow;
}
if ((command == "forecolor") || (command == "backcolor")) {
this.command = command;
controlElement = document.getElementById(this.name +"_" + command);
//获得颜色选择窗口
cp = document.getElementById('cp' + this.name);
this.cpWindow.area = this;
cp.style.left = getOffsetLeft(controlElement) + "px";
cp.style.top = (getOffsetTop(controlElement) + controlElement.offsetHeight) + "px";
if (cp.style.visibility == "hidden") {
//打开颜色选择窗口
cp.style.visibility="visible";
} else {
cp.style.visibility="hidden";
}
//get current selected range
var sel = oRTE.document.selection;
if (sel != null) {
this.rng = sel.createRange();
//alert(this.rng.text);
}
} else if (command == "createlink") {
//TODO need a way to make this more flixible.
//Would especially like to be able to insert a link with both the containing text and the URL
var szURL = prompt("Enter a URL:", "");
oRTE.document.execCommand("Unlink",false,null)
oRTE.document.execCommand("CreateLink",false,szURL)
} else if (command == 'paste') {
oRTE.focus();
oRTE.document.execCommand(command);
oRTE.focus();
} else {
oRTE.focus();
oRTE.document.execCommand(command, false, option);
oRTE.focus();
}
}
this.setColor = function(color){
//选择前景色与背景色时调用
HyperTextArea.activeArea = this;
var oRTE;
if (document.all) {
oRTE = frames[this.name];
} else {
oRTE = document.getElementById(this.name).contentWindow;
}
if (document.all) {
//得到选定矩形
var sel = oRTE.document.selection;
if (sel != null) {
var newRng = sel.createRange();
newRng = this.rng;
newRng.select();
}
} else {
oRTE.focus();
}
//设置文本前景或背景颜色
oRTE.document.execCommand(this.command, false, color);
oRTE.focus();
//关闭颜色选择窗口
document.getElementById('cp' + this.name).style.visibility = "hidden";
}
this.addImage = function(imagePath){
//alert("this.addImage");
HyperTextArea.activeArea = this;
if(!imagePath){
imagePath = prompt('Enter Image URL:', 'http://');
}
var oRTE;
if (document.all) {
oRTE = frames[this.name];
} else {
oRTE = document.getElementById(this.name).contentWindow;
}
if ((imagePath != null) && (imagePath != "")) {
oRTE.focus()
oRTE.document.execCommand('InsertImage', false, imagePath);
}
oRTE.focus()
}
//TODO should look into ways to make this cross browser and platform
this.checkspell = function(){
//alert("this.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);
}
}
}
this.select = function(menu,cmd){
//alert("this.select");
HyperTextArea.activeArea = this;
var oRTE;
if (document.all) {
oRTE = frames[this.name];
} else {
oRTE = document.getElementById(this.name).contentWindow;
}
var idx = menu.selectedIndex;
// First one is always a label
if (idx != 0) {
var selected = menu.options[idx].value;
oRTE.document.execCommand(cmd, false, selected);
menu.selectedIndex = 0;
}
oRTE.focus();
}
//用于插入表格地弹出窗口
this.insertTableDialog = function(){
w = window.open("","tableDialog","top=300,left=300,width=300,height=150");
w.area = this;
d = w.document;
d.open();
d.write(getTableDialogAsString());
d.close();
}
this.insertTable = function(rows,cols,spacing,padding,border){
rows = rows||3;
cols = cols||3;
spacing = spacing||2;
padding = padding||2;
if(border == true){
border = 1;
}
border = border||0;
if (document.all) {
oRTE = frames[this.name];
} else {
oRTE = document.getElementById(this.name).contentWindow;
}
doc = oRTE.document;
table = doc.createElement("table");
table.setAttribute("border", border);
table.setAttribute("cellpadding", padding);
table.setAttribute("cellspacing", spacing);
table.setAttribute("class", "hyperTable");
for (var i=0; i < rows; i++) {
var tr = doc.createElement("tr");
for (var j=0; j < cols; j++) {
var td = doc.createElement("td");
var content = doc.createTextNode('\u00a0');
td.appendChild(content);
tr.appendChild(td);
}
table.appendChild(tr);
}
this.insertElement(table);
}
this.insertElement = function(el){
if (document.all) {
oRTE = frames[this.name];
} else {
oRTE = document.getElementById(this.name).contentWindow;
}
doc = oRTE.document;
if (document.all) {
selection = doc.selection;
var html = el.outerHTML;
var range = selection.createRange();
try {
range.pasteHTML(html);
} catch (e) {
// catch error when range is evil for IE
}
}else{
selection = oRTE.getSelection();
var range = selection.getRangeAt(0);
selection.removeAllRanges();
range.deleteContents();
var container = range.startContainer||selection.focusNode;
var pos = range.startOffset;
afterNode = container.childNodes[pos];
try{
container.insertBefore(el, container.afterNode);
}catch (e){
//if this is a text node, then break it up into a text node, new element, text node
if(container.nodeName.toLowerCase() == "#text"){
text0 = container.data.substring(0,range.startOffset);
text1 = container.data.substring(range.startOffset,container.data.length-1);
container.data = text0;
parent = container.parentNode;
parent.insertBefore(el,container.nextSibling);
newTextNode = document.createTextNode(text1);
parent.insertBefore(newTextNode,el.nextSibling);
}else {
alert(el.nodeName.toLowerCase() + " cannot be placed here for the following reason:\n\n" + e);
}
}
}
}
this.init();
if(!this.delayRender){
this.render(this.html);
}
}
function TextFormatButton(name,label,icon,command,option){
this.name = name;
this.label = label;
this.icon = icon;
this.command = command;
this.option = option||"";
//the next two values are set by the HyperTextArea object
this.area = null;
this.resourcePath = null;
this.getRenderedText = function(){
text = '<td><div id="'+this.area.name+'_'+this.name+'">'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -