📄 editor.js
字号:
var editor_obj = document.all["_" +objname + "_editor"];
var isTextarea = (editor_obj.tagName.toLowerCase() == 'textarea');
if (isTextarea) { return editor_obj.value; }
else { return editor_obj.contentWindow.document.body.innerHTML; }
}
/* ---------------------------------------------------------------------- *\
Function : editor_setHTML
Description : set HTML contents of editor (in either wywisyg or html mode)
Usage : editor_setHTML('objname',"<b>html</b> <u>here</u>");
\* ---------------------------------------------------------------------- */
function editor_setHTML(objname, html) {
var editor_obj = document.all["_" +objname + "_editor"];
var isTextarea = (editor_obj.tagName.toLowerCase() == 'textarea');
if (isTextarea) { editor_obj.value = html; }
else { editor_obj.contentWindow.document.body.innerHTML = html; }
}
/* ---------------------------------------------------------------------- *\
Function : editor_appendHTML
Description : append HTML contents to editor (in either wywisyg or html mode)
Usage : editor_appendHTML('objname',"<b>html</b> <u>here</u>");
\* ---------------------------------------------------------------------- */
function editor_appendHTML(objname, html) {
var editor_obj = document.all["_" +objname + "_editor"];
var isTextarea = (editor_obj.tagName.toLowerCase() == 'textarea');
if (isTextarea) { editor_obj.value += html; }
else { editor_obj.contentWindow.document.body.innerHTML += html; }
}
/* ---------------------------------------------------------------- */
function _isMouseOver(obj,event) { // determine if mouse is over object
var mouseX = event.clientX;
var mouseY = event.clientY;
var objTop = obj.offsetTop;
var objBottom = obj.offsetTop + obj.offsetHeight;
var objLeft = obj.offsetLeft;
var objRight = obj.offsetLeft + obj.offsetWidth;
if (mouseX >= objLeft && mouseX <= objRight &&
mouseY >= objTop && mouseY <= objBottom) { return true; }
return false;
}
/* ---------------------------------------------------------------- */
function editor_cMenu_generate(editorWin,objname) {
var parentWin = window;
editorWin.event.returnValue = false; // cancel default context menu
// define content menu options
var cMenuOptions = [ // menu name, shortcut displayed, javascript code
['Cut', 'Ctrl-X', function() {}],
['Copy', 'Ctrl-C', function() {}],
['Paste', 'Ctrl-C', function() {}],
['Delete', 'DEL', function() {}],
['---', null, null],
['Select All', 'Ctrl-A', function() {}],
['Clear All', '', function() {}],
['---', null, null],
['About this editor...', '', function() {
alert("about this editor");
}]];
editor_cMenu.options = cMenuOptions; // save options
// generate context menu
var cMenuHeader = ''
+ '<div id="_'+objname+'_cMenu" onblur="editor_cMenu(this);" oncontextmenu="return false;" onselectstart="return false"'
+ ' style="position: absolute; visibility: hidden; cursor: default; width: 167px; background-color: threedface;'
+ ' border: solid 1px; border-color: threedlightshadow threeddarkshadow threeddarkshadow threedlightshadow;">'
+ '<table border=0 cellspacing=0 cellpadding=0 width="100%" style="width: 167px; background-color: threedface; border: solid 1px; border-color: threedhighlight threedshadow threedshadow threedhighlight;">'
+ ' <tr><td colspan=2 height=1></td></tr>';
var cMenuList = '';
var cMenuFooter = ''
+ ' <tr><td colspan=2 height=1></td></tr>'
+ '</table></div>';
for (var menuIdx in editor_cMenu.options) {
var menuName = editor_cMenu.options[menuIdx][0];
var menuKey = editor_cMenu.options[menuIdx][1];
var menuCode = editor_cMenu.options[menuIdx][2];
// separator
if (menuName == "---" || menuName == "separator") {
cMenuList += ' <tr><td colspan=2 class="cMenuDivOuter"><div class="cMenuDivInner"></div></td></tr>';
}
// menu option
else {
cMenuList += '<tr class="cMenu" onMouseOver="editor_cMenu(this)" onMouseOut="editor_cMenu(this)" onClick="editor_cMenu(this, \'' +menuIdx+ '\',\'' +objname+ '\')">';
if (menuKey) { cMenuList += ' <td align=left class="cMenu">' +menuName+ '</td><td align=right class="cMenu">' +menuKey+ '</td>'; }
else { cMenuList += ' <td colspan=2 class="cMenu">' +menuName+ '</td>'; }
cMenuList += '</tr>';
}
}
var cMenuHTML = cMenuHeader + cMenuList + cMenuFooter;
document.all['_'+objname+'_cMenu'].outerHTML = cMenuHTML;
editor_cMenu_setPosition(parentWin, editorWin, objname);
parentWin['_'+objname+'_cMenu'].style.visibility = 'visible';
parentWin['_'+objname+'_cMenu'].focus();
}
/* ---------------------------------------------------------------- */
function editor_cMenu_setPosition(parentWin, editorWin, objname) { // set object position that won't overlap window edge
var event = editorWin.event;
var cMenuObj = parentWin['_'+objname+'_cMenu'];
var mouseX = event.clientX + parentWin.document.all['_'+objname+'_editor'].offsetLeft;
var mouseY = event.clientY + parentWin.document.all['_'+objname+'_editor'].offsetTop;
var cMenuH = cMenuObj.offsetHeight;
var cMenuW = cMenuObj.offsetWidth;
var pageH = document.body.clientHeight + document.body.scrollTop;
var pageW = document.body.clientWidth + document.body.scrollLeft;
// set horzontal position
if (mouseX + 5 + cMenuW > pageW) { var left = mouseX - cMenuW - 5; } // too far right
else { var left = mouseX + 5; }
// set vertical position
if (mouseY + 5 + cMenuH > pageH) { var top = mouseY - cMenuH + 5; } // too far down
else { var top = mouseY + 5; }
cMenuObj.style.top = top;
cMenuObj.style.left = left;
}
/* ---------------------------------------------------------------- */
function editor_cMenu(obj,menuIdx,objname) {
var action = event.type;
if (action == "mouseover" && !obj.disabled && obj.tagName.toLowerCase() == 'tr') {
obj.className = 'cMenuOver';
for (var i=0; i < obj.cells.length; i++) { obj.cells[i].className = 'cMenuOver'; }
}
else if (action == "mouseout" && !obj.disabled && obj.tagName.toLowerCase() == 'tr') {
obj.className = 'cMenu';
for (var i=0; i < obj.cells.length; i++) { obj.cells[i].className = 'cMenu'; }
}
else if (action == "click" && !obj.disabled) {
document.all['_'+objname+'_cMenu'].style.visibility = "hidden";
var menucode = editor_cMenu.options[menuIdx][2];
menucode();
}
else if (action == "blur") {
if (!_isMouseOver(obj,event)) { obj.style.visibility = 'hidden'; }
else {
if (obj.style.visibility != "hidden") { obj.focus(); }
}
}
else { alert("editor_cMenu, unknown action: " + action); }
}
/* ---------------------------------------------------------------------- */
//创建以新的配置的对象
function newConfig(contentName)
{
var config = new Object(); // 创建一个新的配置对象
config.width = "800px";
config.height = "400px";
config.bodyStyle = 'background-color: white; font-family: "Verdana"; font-size: x-small;';
config.debug = 0;
// NOTE: You can remove any of these blocks and use the default config!
config.toolbar = [
['fontname'],
['fontsize'],
['fontstyle'],
['linebreak'],
['bold','italic','underline','separator'],
// ['strikethrough','subscript','superscript','separator'],
['justifyleft','justifycenter','justifyright','separator'],
['OrderedList','UnOrderedList','Outdent','Indent','separator'],
['forecolor','backcolor','separator'],
// ['HorizontalRule','Createlink','InsertImage','htmlmode','separator'],
// ['about','help','popupeditor'],
];
// 配置对象的字体
config.fontnames = {
"宋体": "宋体",
"Arial": "arial, helvetica, sans-serif",
"Courier New": "courier new, courier, mono",
"Georgia": "Georgia, Times New Roman, Times, Serif",
"Tahoma": "Tahoma, Arial, Helvetica, sans-serif",
"Times New Roman": "times new roman, times, serif",
"Verdana": "Verdana, Arial, Helvetica, sans-serif",
"impact": "impact",
"WingDings": "WingDings"
};
// 配置字体的大小
config.fontsizes = {
"1 (8 pt)": "1",
"2 (10 pt)": "2",
"3 (12 pt)": "3",
"4 (14 pt)": "4",
"5 (18 pt)": "5",
"6 (24 pt)": "6",
"7 (36 pt)": "7"
};
// 配置字体的样式
//// config.stylesheet = "http://www.domain.com/sample.css";
// 配置字体的样式
config.fontstyles = [ // make sure classNames are defined in the page the content is being display as well in or they won't work!
{ name: "headline", className: "headline", classStyle: "font-family: arial black, arial; font-size: 28px; letter-spacing: -2px;" },
{ name: "arial red", className: "headline2", classStyle: "font-family: arial black, arial; font-size: 12px; letter-spacing: -2px; color:red" },
{ name: "verdana blue", className: "headline4", classStyle: "font-family: verdana; font-size: 18px; letter-spacing: -2px; color:blue" }
// leave classStyle blank if it's defined in config.stylesheet (above), like this:
// { name: "verdana blue", className: "headline4", classStyle: "" }
];
// 设置对象,和对象的样式
editor_generate(contentName,config); // 指定输入区域的样式
}
//创建以新的配置的对象:信息修改部分
function update_newConfig()
{
var config = new Object(); // 创建一个新的配置对象
config.width = "800px";
config.height = "400px";
config.bodyStyle = 'background-color: white; font-family: "Verdana"; font-size: x-small;';
config.debug = 0;
// NOTE: You can remove any of these blocks and use the default config!
config.toolbar = [
['fontname'],
['fontsize'],
['fontstyle'],
['linebreak'],
['bold','italic','underline','separator'],
// ['strikethrough','subscript','superscript','separator'],
['justifyleft','justifycenter','justifyright','separator'],
['OrderedList','UnOrderedList','Outdent','Indent','separator'],
['forecolor','backcolor','separator'],
// ['HorizontalRule','Createlink','InsertImage','htmlmode','separator'],
['about','help','popupeditor'],
];
// 配置对象的字体
config.fontnames = {
"宋体": "宋体",
"Arial": "arial, helvetica, sans-serif",
"Courier New": "courier new, courier, mono",
"Georgia": "Georgia, Times New Roman, Times, Serif",
"Tahoma": "Tahoma, Arial, Helvetica, sans-serif",
"Times New Roman": "times new roman, times, serif",
"Verdana": "Verdana, Arial, Helvetica, sans-serif",
"impact": "impact",
"WingDings": "WingDings"
};
// 配置字体的大小
config.fontsizes = {
"1 (8 pt)": "1",
"2 (10 pt)": "2",
"3 (12 pt)": "3",
"4 (14 pt)": "4",
"5 (18 pt)": "5",
"6 (24 pt)": "6",
"7 (36 pt)": "7"
};
// 配置字体的样式
//// config.stylesheet = "http://www.domain.com/sample.css";
// 配置字体的样式
config.fontstyles = [ // make sure classNames are defined in the page the content is being display as well in or they won't work!
{ name: "headline", className: "headline", classStyle: "font-family: arial black, arial; font-size: 28px; letter-spacing: -2px;" },
{ name: "arial red", className: "headline2", classStyle: "font-family: arial black, arial; font-size: 12px; letter-spacing: -2px; color:red" },
{ name: "verdana blue", className: "headline4", classStyle: "font-family: verdana; font-size: 18px; letter-spacing: -2px; color:blue" }
// leave classStyle blank if it's defined in config.stylesheet (above), like this:
// { name: "verdana blue", className: "headline4", classStyle: "" }
];
// 设置对象,和对象的样式
editor_generate('content',config); // 指定中文输入区域的样式
}
//浏览器版本的控制
function browserControl()
{
_editor_url = ""; // 当前文件的绝对的路径
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]); // 获得IE浏览器的版本号
/*
* 判断其他浏览器的方式
*/
if (navigator.userAgent.indexOf('Mac') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera') >= 0) { win_ie_ver = 0; }
// 这里是判断浏览器,需要IE5.5以上的版本支持
if (win_ie_ver >= 5.5) {
// document.write('<scr'+'ipt src="' +_editor_url+ 'js/editor.js" language="Javascript1.2"></scr'+'ipt>');
} else {
alert("不支持当前浏览器的版本");
document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>');
}
// -->
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -