📄 editor.js
字号:
this.getPallete(command, optn, evnt);
}else if(command=='createlink'){
var szURL=prompt('Enter a URL:', '');
if(document.getElementById(this.wysiwyg_content).contentWindow.document.queryCommandEnabled(command)){
document.getElementById(this.wysiwyg_content).contentWindow.document.execCommand('CreateLink',false,szURL);
return true;
}else return false;
}else{
if(document.getElementById(this.wysiwyg_content).contentWindow.document.queryCommandEnabled(command)){
document.getElementById(this.wysiwyg_content).contentWindow.document.execCommand(command, false, optn);
return true;
}else return false;
}
document.getElementById(this.wysiwyg_content).contentWindow.focus();
}
/**
* WYSIWYG_Editor::_load_content
*
* Puts the passed content into the editor or textarea (Use this one *after* displaying the editor.)
*
* @param content string The string containing the properly-formatted HTML source to use
*/
WYSIWYG_Editor.prototype._load_content = function (){
document.getElementById(this.wysiwyg_hidden).value=this.content;
}
/**
* WYSIWYG_Editor::toggleMode
*
* Toggles between design view and source view in the IFRAME element
**/
WYSIWYG_Editor.prototype.toggleMode = function (){
// change the display styles
if(this.viewMode == 2){
document.getElementById(this.wysiwyg_content).contentWindow.document.body.style.fontFamily = '';
document.getElementById(this.wysiwyg_content).contentWindow.document.body.style.fontSize = '';
document.getElementById(this.wysiwyg_content).contentWindow.document.body.style.color = '';
document.getElementById(this.wysiwyg_content).contentWindow.document.body.style.fontWeight = '';
document.getElementById(this.wysiwyg_content).contentWindow.document.body.style.backgroundColor = '';
document.getElementById(this.instance_name+'_toolbars').style.visibility='visible';
}else{
document.getElementById(this.wysiwyg_content).contentWindow.document.body.style.fontFamily = 'monospace';
document.getElementById(this.wysiwyg_content).contentWindow.document.body.style.fontSize = '10pt';
document.getElementById(this.wysiwyg_content).contentWindow.document.body.style.color = '#000';
document.getElementById(this.wysiwyg_content).contentWindow.document.body.style.backgroundColor = '#fff';
document.getElementById(this.wysiwyg_content).contentWindow.document.body.style.fontWeight = 'normal';
document.getElementById(this.instance_name+'_toolbars').style.visibility='hidden';
}
// do the content swapping
if(this.isMSIE()){
this._toggle_mode_ie();
}else{
this._toggle_mode_gecko();
}
}
/**
* WYSIWYG_Editor::_toggle_mode_ie
*
* Toggles between design view and source view in the IFRAME element for MSIE
**/
WYSIWYG_Editor.prototype._toggle_mode_ie = function (){
if(this.viewMode == 2){
document.getElementById(this.wysiwyg_content).contentWindow.document.body.innerHTML = document.getElementById(this.wysiwyg_content).contentWindow.document.body.innerText;
document.getElementById(this.wysiwyg_content).contentWindow.focus();
this.viewMode = 1; // WYSIWYG
}else{
document.getElementById(this.wysiwyg_content).contentWindow.document.body.innerText = document.getElementById(this.wysiwyg_content).contentWindow.document.body.innerHTML;
document.getElementById(this.wysiwyg_content).contentWindow.focus();
this.viewMode = 2; // Code
}
}
/**
* WYSIWYG_Editor::_toggle_mode_gecko
*
* Toggles between design view and source view in the IFRAME element for Gecko browsers
**/
WYSIWYG_Editor.prototype._toggle_mode_gecko = function (){
if(this.viewMode == 2){
var html = document.getElementById(this.wysiwyg_content).contentWindow.document.body.ownerDocument.createRange();
html.selectNodeContents(document.getElementById(this.wysiwyg_content).contentWindow.document.body);
document.getElementById(this.wysiwyg_content).contentWindow.document.body.innerHTML = html.toString();
document.getElementById(this.wysiwyg_content).contentWindow.focus();
this.viewMode = 1; // WYSIWYG
}else{
var html = document.createTextNode(document.getElementById(this.wysiwyg_content).contentWindow.document.body.innerHTML);
document.getElementById(this.wysiwyg_content).contentWindow.document.body.innerHTML = '';
document.getElementById(this.wysiwyg_content).contentWindow.document.body.appendChild(html);
document.getElementById(this.wysiwyg_content).contentWindow.focus();
this.viewMode = 2; // Code
}
}
/**
* WYSIWYG_Editor::_get_offset_left
*
* Used to define position of pop-up pallete window in Gecko browsers
**/
WYSIWYG_Editor.prototype._get_offset_left = function (elm){
var mOffsetLeft=elm.offsetLeft;
var mOffsetParent=elm.offsetParent;
while(mOffsetParent){
mOffsetLeft += mOffsetParent.offsetLeft;
mOffsetParent=mOffsetParent.offsetParent;
}
return mOffsetLeft;
}
/**
* WYSIWYG_Editor::_get_offset_top
*
* Used to define position of pop-up pallete window in Gecko browsers
**/
WYSIWYG_Editor.prototype._get_offset_top = function (elm){
var mOffsetTop=elm.offsetTop;
var mOffsetParent=elm.offsetParent;
while(mOffsetParent){
mOffsetTop += mOffsetParent.offsetTop;
mOffsetParent=mOffsetParent.offsetParent;
}
return mOffsetTop;
}
/**
* WYSIWYG_Editor::insertTable
*
* Used for inserting a table into the IFRAME content window
**/
WYSIWYG_Editor.prototype.insertTable = function (){
colstext = prompt('Enter the number of columns per row.');
rowstext = prompt('Enter the number of rows to create.');
rows = parseInt(rowstext,'0');
cols = parseInt(colstext,'0');
if(this.isMSIE()){
return this._insert_table_ie(cols,rows);
}else{
return this._insert_table_gecko(cols,rows);
}
}
/**
* WYSIWYG_Editor::_insert_table_ie
*
* This is the browser engine-specific code for inserting a table for MSIE browsers.
*
* @param cols The number of columns to create
* @param rows The number of rows to create
**/
WYSIWYG_Editor.prototype._insert_table_ie = function (cols, rows){
document.getElementById(this.wysiwyg_content).contentWindow.focus();
//get current selected range
var cursor=document.getElementById(this.wysiwyg_content).contentWindow.document.selection.createRange();
if((rows > 0) && (cols > 0)){
var tableHTML = '<table border="'+this.table_border+'" cellpadding="'+this.table_cell_padding+'" cellspacing="'+this.table_cell_spacing+'">';
while(rows>0){
rows--;
var rowCols = cols;
tableHTML = tableHTML + '<tr>';
while(parseInt(rowCols)>0){
rowCols--;
tableHTML=tableHTML+'<td> </td>';
}
tableHTML = tableHTML + '</tr>';
}
tableHTML = tableHTML + '</table>';
cursor.pasteHTML(tableHTML);
document.getElementById(this.wysiwyg_content).contentWindow.focus();
}
return true;
}
/**
* WYSIWYG_Editor::_insert_table_gecko
*
* This is the browser engine-specific code for inserting a table for Gecko browsers.
*
* @param cols The number of columns to create
* @param rows The number of rows to create
**/
WYSIWYG_Editor.prototype._insert_table_gecko = function (cols, rows){
contentWin=document.getElementById(this.wysiwyg_content).contentWindow;
if((rows > 0) && (cols > 0)){
table=contentWin.document.createElement('table');
table.setAttribute('border', this.table_border);
table.setAttribute('cellpadding', this.table_cell_padding);
table.setAttribute('cellspacing', this.table_cell_spacing);
tbody=contentWin.document.createElement('tbody');
for(i=0;i<rows;i++){
tr=contentWin.document.createElement('tr');
for(j=0;j<cols;j++){
td=contentWin.document.createElement('td');
br=contentWin.document.createElement('br');
td.appendChild(br);
tr.appendChild(td);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -