📄 editor.js
字号:
}
tbody.appendChild(tr);
}
table.appendChild(tbody);
this._insert_element_gecko(contentWin, table);
}
return true;
}
/**
* WYSIWYG_Editor::_insert_element_gecko
*
* Used by Gecko browsers to insert elements into the document for the insertTable method
*
* @param win The window object to insert the element into
* @param elem The element to insert into the content window
**/
WYSIWYG_Editor.prototype._insert_element_gecko = function (win, elem){
var sel = win.getSelection(); // get current selection
var range = sel.getRangeAt(0); // get the first range of the selection (there's almost always only one range)
sel.removeAllRanges(); // deselect everything
range.deleteContents(); // remove content of current selection from document
var container = range.startContainer; // get location of current selection
var pos = range.startOffset;
range=document.createRange(); // make a new range for the new selection
if (container.nodeType==3 && elem.nodeType==3) {
// if we insert text in a textnode, do optimized insertion
container.insertData(pos, elem.nodeValue);
// put cursor after inserted text
range.setEnd(container, pos+elem.length);
range.setStart(container, pos+elem.length);
}else{
var afterNode;
if (container.nodeType==3) {
// when inserting into a textnode we create 2 new textnodes and put the elem in between
var textNode = container;
container = textNode.parentNode;
var text = textNode.nodeValue;
var textBefore = text.substr(0,pos); // text before the split
var textAfter = text.substr(pos); // text after the split
var beforeNode = document.createTextNode(textBefore);
var afterNode = document.createTextNode(textAfter);
// insert the 3 new nodes before the old one
container.insertBefore(afterNode, textNode);
container.insertBefore(elem, afterNode);
container.insertBefore(beforeNode, elem);
// remove the old node
container.removeChild(textNode);
}else{
// else simply insert the node
afterNode = container.childNodes[pos];
container.insertBefore(elem, afterNode);
}
}
}
/**
* WYSIWYG_Editor::setColor
*
* Used to set the text or highlight color of the selected text in Gecko engine browsers
**/
WYSIWYG_Editor.prototype.setColor = function (color, command){
// close the window we made to display the pallete in
if(typeof(pwin)=='object'){ // make sure it exists
if(!pwin.closed){ // if it is still open
pwin.close();
}
}
// only one difference for MSIE
if(this.isMSIE() && command == 'hilitecolor') command = 'backcolor';
//get current selected range
var sel=document.getElementById(this.wysiwyg_content).contentWindow.document.selection;
if(sel!=null){
rng=sel.createRange();
}
document.getElementById(this.wysiwyg_content).contentWindow.focus();
if(document.getElementById(this.wysiwyg_content).contentWindow.document.queryCommandEnabled(command)){
document.getElementById(this.wysiwyg_content).contentWindow.document.execCommand(command, false, color);
}else return false;
document.getElementById(this.wysiwyg_content).contentWindow.focus();
return true;
}
/**
* WYSIWYG_Editor::getPallete
*
* Apply a text color to selected text or starting at current position
*
* @param command string Used to determine which pallete pop-up to display
**/
WYSIWYG_Editor.prototype.getPallete = function (command, optn, evnt) {
// get the pallete HTML code
html = this._get_palette_html(command);
// close the window we made to display the pallete in
// this is in case someone clicked the hilitecolor, then clicked the forcolor button
// without making a choice
if(typeof(pwin)=='object'){ // make sure it exists
if(!pwin.closed){ // if it is still open
pwin.close();
}
}
// OK, now I need to open a new window to capture a click from
pwin = window.open('','colorPallete','dependent=yes, directories=no, fullscreen=no,hotkeys=no,height=120,width=172,left='+evnt.screenX+',top='+evnt.screenY+',locatoin=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no');
pwin.document.write(html);
pwin.document.close(); // prevents page from attempting to load more code
}
/**
* WYSIWYG_Editor::isSupported
*
* Checks that the browser supports this programming by writing an invisible IFRAME and testing its properties
*/
WYSIWYG_Editor.prototype.isSupported = function () {
// This is to get rid of the browser UA check that was previously implemented for this class.
// should be called from somewhere in the body of the document for best results
document.write('<iframe id="WYSIWYG_Editor_Testing_Browser_Features" style="display: none; visibility: hidden;"></iframe>');
test = typeof(document.getElementById('WYSIWYG_Editor_Testing_Browser_Features').contentWindow);
if(test == 'object'){
return true;
}else{
return false;
}
return this.supported;
}
/**
* WYSIWYG_Editor::isMSIE
*
* Checks if browser is MSIE by testing the document.all property that is only supported by MSIE and AOL
*/
WYSIWYG_Editor.prototype.isMSIE = function (){
if(typeof(document.all)=='object'){
return true;
}else{
return false;
}
}
/**
* WYSIWYG_Editor::_get_palette_html
*
* Generates the HTML that will be used in the color palette pop-ups.
*
* @param command string The command that indicates which text color is being set
**/
WYSIWYG_Editor.prototype._get_palette_html = function (command) {
s = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
s = s + '<html>';
s = s + ' <head>';
s = s + ' <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">';
s = s + ' <title>Color Pallete</title>';
s = s + ' <style type="text/css">';
s = s + ' <!--';
s = s + ' html,body{margin: 0px; padding: 0px; color: black; background-color: white;}';
s = s + ' td{border: black none 2px;}';
s = s + ' td:hover{border: white solid 2px;}';
s = s + ' -->';
s = s + ' </style>';
s = s + ' </head>';
s = s + '';
// we want the focus is brought to this new page
s = s + ' <body onload="window.focus()" onblur="window.focus()">';
s = s + ' <table border="0" cellpadding="0" cellspacing="2">';
s = s + ' <tr>';
s = s + ' <td id="cFFFFFF" bgcolor="#FFFFFF" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="cFFCCCC" bgcolor="#FFCCCC" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="cFFCC99" bgcolor="#FFCC99" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="cFFFF99" bgcolor="#FFFF99" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="cFFFFCC" bgcolor="#FFFFCC" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="c99FF99" bgcolor="#99FF99" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="c99FFFF" bgcolor="#99FFFF" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="cCCFFFF" bgcolor="#CCFFFF" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="cCCCCFF" bgcolor="#CCCCFF" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="cFFCCFF" bgcolor="#FFCCFF" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' </tr>';
s = s + ' <tr>';
s = s + ' <td id="cCCCCCC" bgcolor="#CCCCCC" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="cFF6666" bgcolor="#FF6666" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="cFF9966" bgcolor="#FF9966" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="cFFFF66" bgcolor="#FFFF66" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="cFFFF33" bgcolor="#FFFF33" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="c66FF99" bgcolor="#66FF99" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="c33FFFF" bgcolor="#33FFFF" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="c66FFFF" bgcolor="#66FFFF" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="c9999FF" bgcolor="#9999FF" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' <td id="cFF99FF" bgcolor="#FF99FF" width="15" height="15" onclick="str=this.id;color=str.replace(\'c\',\'#\');opener.'+this.instance_name+'.setColor(color,\''+command+'\');window.close();"><img width="1" height="1" alt="" src=""></td>';
s = s + ' </tr>';
s = s + ' <tr>';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -