⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editor.js

📁 NONO一族J2EE新闻系统 采用了目前流行的J2EE技术
💻 JS
字号:
/////////////////////////////////////////
//editor functions
///////////////////////////////////////
//create editor object
function createEditor(editorName, editorObjectName, toolbarPaneName, workspaceName, resourcePath){
  var editorObj = findObject(editorObjectName);
  if(editorObj == null){
    err("editorObj object not exist!");
    return false;
  }
  if(editorObj.loaded)return false;
  
  //get browser version
  var userAgent = navigator.userAgent.toLowerCase();
  editorObj.isIE5 = (userAgent.indexOf("msie 5.0")  > -1);
  editorObj.isIE55 = (userAgent.indexOf("msie 5.5")  > -1);
  editorObj.isIE6 = (userAgent.indexOf("msie 6.0")  > -1);
  editorObj.isIE = (editorObj.isIE5 || editorObj.isIE55 || editorObj.isIE6);
  
  //init member variables
  editorObj.loaded=false;
  editorObj.pureText=true;
  editorObj.HTMLMode = true;
  editorObj.bodyTag="<head><style type=\"text/css\">body {font-size:	10.8pt}</style><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\"></head><BODY bgcolor=\"#FFFFFF\" MONOSPACE></BODY>";
  editorObj.resourcePath = resourcePath;
  editorObj.textarea = findObject(editorName);
  editorObj.toolbars = findObject(toolbarPaneName);
  
  //init composition
  if(editorObj.isIE){
    editorObj.composition = findObject(workspaceName);
  }
  else{
    editorObj.composition = findObject(workspaceName).contentWindow;
  }
  
  //init member functions
  editorObj.setMode = setMode;
  editorObj.cleanHTML = cleanHTML;
  editorObj.getText = getText;
  editorObj.setText = setText;
  editorObj.getPureHtml = getPureHtml;
  editorObj.textToTextarea = textToTextarea;
  editorObj.textToComposition = textToComposition;
  editorObj.showWorkspaceHTML = showWorkspaceHTML;
  editorObj.showWorkspaceCode = showWorkspaceCode;
  
  
  //operation commands
  editorObj.emptyOperation = emptyOperation;
  editorObj.createRange = createRange;
  editorObj.execCommand = execCommand;
  editorObj.insertHTML = insertHTML;
  editorObj.insertFlash = insertFlash;
  editorObj.insertRM = insertRM;
  editorObj.insertWMV = insertWMV;
  editorObj.insertImage = insertImage;
  editorObj.foreColorDlg = foreColorDlg;
  editorObj.backColorDlg = backColorDlg;
  
  //composition component init
  editorObj.composition.document.open();
  editorObj.composition.document.write(this.bodyTag);
  editorObj.composition.document.close();
	editorObj.composition.document.designMode="On";
  	
	this.loaded = true;
  return true;
}

//Show HTML in workspace
function showWorkspaceHTML(){
	this.toolbars.style.display = "block";
	this.setMode(true);
	return;
}

//Show code in workspace
function showWorkspaceCode(){
	this.toolbars.style.display = "none";
	this.setMode(false);
	return;
}

//Change edit mode(html or code)
function setMode(isHTML)
{
  if(this.HTMLMode == isHTML)return;
  this.HTMLMode = isHTML;
  var cont;
  if (this.HTMLMode) {
    cont = this.composition.document.body.innerText;
    this.composition.document.body.innerHTML = cont;
  }
  else {
    this.cleanHTML();
    this.cleanHTML();

    cont = this.composition.document.body.innerHTML;
    this.composition.document.body.innerText = cont;    
  }

  this.composition.focus();
  return;
}

//Get the content text
function getText(){
	if (this.HTMLMode){
		this.cleanHTML();
		this.cleanHTML();
		return this.composition.document.body.innerHTML;
	}
	else
	{
		return this.composition.document.body.innerText;
	}
}

//Set the content
function setText(str){
	if (this.HTMLMode)
		this.composition.document.body.innerHTML = str;
	else
		this.composition.document.body.innerText = str;
	return;
}

//Clean html tags
function cleanHTML(){
  var fonts = findObjectListByTag("FONT", this.composition.document);
  var curr;
  for (var i = fonts.length - 1; i >= 0; i--) {
    curr = fonts[i];
    if (curr.style.backgroundColor == "#ffffff") curr.outerHTML	= curr.innerHTML;
  }
  return;
}

//Get pure html code
function getPureHtml(){
  var str = "";
  var paras = findObjectListByTag("P", this.composition.document);
  if (paras.length > 0)	{
    for	(var i=paras.length-1; i >= 0; i--) str	= paras[i].innerHTML + "\n" + str;
  } else {
    str	= this.composition.document.body.innerHTML;
  }
  return str;
}

//Copy the content from composition to textarea
function textToTextarea(){
	this.textarea.value = this.getText();
	return;
}

//Copy the content from textarea to composition
function textToComposition(){
	this.setText(this.textarea.value);
	return;
}

//Do nothing
function emptyOperation(){
  return true;
}

//Create a selection range of the workspace.
function createRange(){
  return this.composition.document.selection.createRange();
}
  
//Execute browser's command
function execCommand(command, param) {
  if (!this.HTMLMode)return;
  
  this.composition.focus();
  var editRange = this.createRange();
  editRange.execCommand(command, true, param);
  
  this.composition.focus();
  editRange.select();
}

//insert html code
function insertHTML(str, scope){
  if (!this.HTMLMode)return;
  this.composition.focus();
  var editRange = this.createRange(scope);
  editRange.pasteHTML(str);
}

//insert flash
function insertFlash(desc){
  if (!this.HTMLMode)return;
  
  var url;
  if(desc == null){
    url = window.prompt("Please input the url of the flash movie", "http://");
  }
  else{
    url = window.prompt(desc, "http://");
  }
	if( url != null ){
		this.insertHTML("<embed src='" + url + "' type='application/x-shockwave-flash'></embed>");
	}
}

//insert RM
function insertRM(desc){
  if (!this.HTMLMode)return;
  
  var url;
  if(desc == null){
    url = window.prompt("Please input the url of the flash movie", 'http://');
  }
  else{
    url = window.prompt(desc, 'http://');
  }
	if( url != null ){
	  tag = "<object id=\"RVOCX\" classid=\"CLSID:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" width=\"320\" height=\"240\">\n" +
	        "<param name=\"SRC\" value=\"" + url + "\">\n" + 
	        "<param name=\"CONTROLS\" value=\"ImageWindow\">\n" +
	        "<param name=\"CONSOLE\" value=\"cons\">\n" +
	        "<embed src=\"" + url + "\" type=\"audio/x-pn-realaudio-plugin\" width=\"320\" height=\"240\" controls=\"ImageWindow\" console=\"cons\"></embed>\n" +
	        "</object>\n";
	  this.insertHTML(tag);
	}
}

//insert WMV
function insertWMV(desc){
  if (!this.HTMLMode)return;
  
  var url;
  if(desc == null){
    url = window.prompt("Please input the url of the flash movie", 'http://');
  }
  else{
    url = window.prompt(desc, 'http://');
  }
	if( url != null ){
		this.insertHTML("<embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=" + url + "  width=320 height=240></embed>\n");
	}
}

//insert Image
function insertImage(){
  this.execCommand("InsertImage");
}

//get the parent element of the "start" tag
function getEl(sTag, start){
  while	((start != null) && (start.tagName != sTag)){
		start = start.parentElement;
	}
  return start;
}

//get the closest tag of the select range
function getCurrentTag(){
  var editRange = this.createRange(scope);
}

//show fore color dialog
function foreColorDlg(){
  var color = modalDialog(this.resourcePath +
                      "/selectcolor.jsp?resourcePath=" + this.resourcePath +
                      "&language=" + this.language +
                      "&styleName=" + this.styleName , 390, 450);
  if(color == null)return;
  
  this.execCommand('ForeColor', color);
}

//show back color dialog
function backColorDlg(){
  var color = modalDialog(this.resourcePath +
                      "/selectcolor.jsp?resourcePath=" + this.resourcePath +
                      "&language=" + this.language +
                      "&styleName=" + this.styleName , 390, 450);
  if(color == null)return;
  
  this.execCommand('BackColor', color);
}


/*
/////////////////////////////////////////////////
//table functions
/////////////////////////////////////////////////
//a table struct
function TTable(columnCount, rowCount, align, 
                cellpadding, cellspacing, border, 
                height, width, 
                bgcolor, bordercolor, background){
  if(columnCount == null || rowCount == null){
    error("invalid table parameters!");
    return null;
  }
  this.columnCount = columnCount;
  this.rowCount = rowCount;
  this.align = align;
  this.cellpadding = cellpadding;
  this.cellspacing = cellspacing;
  this.border = ((border == null) ? 1 : border);
  this.height = height;
  this.width = width;
  this.bgcolor = bgcolor;
  this.bordercolor = bordercolor;
  this.background = background;
}
// create a table
function insertTable(newTable){
  if(newTable == null){
    error("table struct not create!");
    return;
  }
  var doc = this.composition.document;
  var table = doc.createElement("table");
  
  if(newTable.align != null)table.align = newTable.align;
  if(newTable.cellpadding != null)table.cellpadding = newTable.cellpadding;
  if(newTable.cellspacing != null)table.cellspacing = newTable.cellspacing;
  if(newTable.border != null)table.border = newTable.border;
  if(newTable.height != null)table.height = newTable.height;
  if(newTable.width != null)table.width = newTable.width;
  if(newTable.bgcolor != null)table.bgcolor = newTable.bgcolor;
  if(newTable.bordercolor != null)table.bordercolor = newTable.bordercolor;
  if(newTable.background != null)table.background = newTable.background;
  
  for(var i = 0; i < newTable.rowCount; ++i){
    var tr = doc.createElement("tr");
    table.appendChild(tr);
    for(var j = 0; j < newTable.columnCount; ++j){
      var td = doc.createElement("td");
      tr.appendChild(td);
      td.innerHTML = "&nbsp;";
    }
  }
  this.insertHTML(table.outerHTML);
}

function insertTableDlg(){
  var table = modalDialog(this.resourcePath +
                      "/inserttable.jsp?resourcePath=" + this.resourcePath +
                      "&language=" + this.language +
                      "&styleName=" + this.styleName , 420, 330);
  if(table == null)return;
  
  this.insertTable(table);
}

function insertRow(isAfter){
  
}

*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -