📄 toolbar.js
字号:
var last_bk_color = "";
function bt_over(obj)
{
obj = event.srcElement;
var last_bk_color2 = obj.style.background;
//alert(last_bk_color);
if(last_bk_color == "")
obj.style.background = "#ffffff";
last_bk_color = last_bk_color2
}
function bt_out(obj)
{
obj = event.srcElement;
obj.style.background = last_bk_color;
last_bk_color=""
}
/*
*/
function ToolBar(editor)
{
this._ImagePath = editor._ResourcePath+"images/ee/"+editor._Themes+"/";
this._Editor = editor;
this.Bar = editor.toolBar;
this.BarDiv = editor.toolBarDiv;
//build a button
this.BuildButton = function (btInfo,handler)
{
var title = btInfo[1];
var picurl = btInfo[0];
if(!title) title="";
var html = "";
if(handler == null)
{
html = "<img src=\""+this._ImagePath+btInfo+"\" >"
return createElement(html,this.BarDiv);
}
else
{
html = "<img title=\""+title+"\" onmouseover=\"bt_over(this);\" onmouseout=\"bt_out(this);\"";
html +=" style=\"cursor:hand;background:#9EBEF5;\" ";
html +=" src=\""+this._ImagePath+picurl+"\" onclick=\""+handler+";\">"
var obj = createElement(html,this.BarDiv);
obj.attachEvent("onclick",handler);
obj.attachEvent("onmouseover",bt_over);
obj.attachEvent("onmouseout",bt_out);
return obj;
}
}
this.BuildSelect = function(sel,handler)
{
var obj = createElement("SELECT",this.BarDiv);
obj.style.cssText = sel.cssText;
for(var i=0;i<sel.options.length;i++)
{
var _option = sel.options[i];
if(_option.text == "") _option.text = _option.value;
obj.options.add(new Option(_option.text,_option.value));
obj.options[obj.options.length-1].style.cssText = _option.cssText;
}
obj.attachEvent("onchange",handler);
return obj;
}
this.BuildBar = function ()
{
this.BuildSelect(UI.toolBar.Selects.Paragraph,this.Paragraph.bind(this));
this.BuildSelect(UI.toolBar.Selects.FontName,this.FontName.bind(this));
this.BuildSelect(UI.toolBar.Selects.FontSize,this.FontSize.bind(this));
this.BuildButton(UI.toolBar.Seperater);
this.BuildSelect(UI.toolBar.Selects.ForeColor,this.ForeColor.bind(this));
this.BuildButton(UI.toolBar.Buttons.ForeColor,this.ForeColorD.bind(this));
this.BuildSelect(UI.toolBar.Selects.BackColor,this.BackColor.bind(this));
this.BuildButton(UI.toolBar.Buttons.BackColor,this.BackColorD.bind(this));
this.BuildButton(UI.toolBar.Seperater);
this.BuildButton(UI.toolBar.Buttons.ZoomIn,this.ZoomIn.bind(this));
this.BuildButton(UI.toolBar.Buttons.ZoomOut,this.ZoomOut.bind(this));
createElement("<br>",this.BarDiv);
this.BuildButton(UI.toolBar.Buttons.Bold,this.Bold.bind(this));
this.BuildButton(UI.toolBar.Buttons.Italic,this.Italic.bind(this));
this.BuildButton(UI.toolBar.Buttons.Underline,this.Underline.bind(this));
this.BuildButton(UI.toolBar.Buttons.Strikethrough,this.Strikethrough.bind(this));
this.BuildButton(UI.toolBar.Buttons.Subscript,this.Subscript.bind(this));
this.BuildButton(UI.toolBar.Buttons.Superscript,this.Superscript.bind(this));
this.BuildButton(UI.toolBar.Seperater);
this.BuildButton(UI.toolBar.Buttons.Undo,this.Undo.bind(this));
this.BuildButton(UI.toolBar.Buttons.Redo,this.Redo.bind(this));
this.BuildButton(UI.toolBar.Buttons.Print,this.Print.bind(this));
this.BuildButton(UI.toolBar.Seperater);
this.BuildButton(UI.toolBar.Buttons.Insertimagefromgallery,this.Gallery.bind(this));
this.BuildButton(UI.toolBar.Buttons.Createlink,this.Createlink.bind(this));
this.BuildButton(UI.toolBar.Buttons.Unlink,this.Unlink.bind(this));
this.BuildButton(UI.toolBar.Buttons.Removeformat,this.Removeformat.bind(this));
this.BuildButton(UI.toolBar.Seperater);
this.BuildButton(UI.toolBar.Buttons.Inserttime,this.Inserttime.bind(this));
this.BuildButton(UI.toolBar.Buttons.Insertdate,this.Insertdate.bind(this));
this.BuildButton(UI.toolBar.Buttons.Wordcount,this.Wordcount.bind(this));
this.BuildButton(UI.toolBar.Seperater);
this.BuildButton(UI.toolBar.Buttons.Justifyright,this.Justifyright.bind(this));
this.BuildButton(UI.toolBar.Buttons.Justifyleft,this.Justifyleft.bind(this));
this.BuildButton(UI.toolBar.Buttons.Justifycenter,this.Justifycenter.bind(this));
this.BuildButton(UI.toolBar.Seperater);
this.BuildButton(UI.toolBar.Buttons.Bullets,this.Bullets.bind(this));
this.BuildButton(UI.toolBar.Buttons.Numberedlist,this.Numberedlist.bind(this));
this.BuildButton(UI.toolBar.Buttons.Indent,this.Indent.bind(this));
this.BuildButton(UI.toolBar.Buttons.Outdent,this.Outdent.bind(this));
this.BuildButton(UI.toolBar.Seperater);
}
this.BuildBar();
}
/*****************************
*
* prototype extend
*
*****************************
*/
ToolBar.prototype.ZoomIn = function ()
{
var obj = this._Editor.editorDiv;
if(obj.style.pixelHeight == "")
obj.style.pixelHeight = obj.offsetHeight;
var old = obj.style.pixelHeight;
if(old - 50 < 0) return;
obj.style.pixelHeight -= 50;
this._Editor.fitSize();
}
ToolBar.prototype.ZoomOut = function ()
{
var obj = this._Editor.editorDiv;
if(obj.style.pixelHeight == "")
obj.style.pixelHeight = obj.offsetHeight;
obj.style.pixelHeight += 50;
this._Editor.fitSize();
}
/*
toolbutton 's eventHandler
*/
ToolBar.prototype.execCommand = function(p1,p2,p3){this._Editor.execCommand(p1,p2,p3);};
ToolBar.prototype.Paragraph = function (){
var obj=event.srcElement;
var value = obj.options[obj.selectedIndex].value;
this.execCommand("formatBlock", "false",value);
}
/*
*/
ToolBar.prototype.ForeColor = function (){
var obj=event.srcElement;
var value = obj.options[obj.selectedIndex].value;
this.execCommand("ForeColor", "false",value);
}
/*
*/
ToolBar.prototype.BackColor = function (){
var obj=event.srcElement;
var value = obj.options[obj.selectedIndex].value;
this.execCommand("BackColor", "false", value);
}
/*
*/
ToolBar.prototype.FontSize = function (){
var obj=event.srcElement;
var value = obj.options[obj.selectedIndex].value;
this.execCommand("FontSize", "false", value);
}
/*
*/
ToolBar.prototype.FontName = function (){
var obj=event.srcElement;
var value = obj.options[obj.selectedIndex].value;
this.execCommand("FontName", "false", value);
}
/*
*/
ToolBar.prototype.Removeformat = function (){
this.execCommand("removeformat");
}
/*
参数:left/center/right
*/
ToolBar.prototype.Justifyleft = function(){this.Justify("left");}
ToolBar.prototype.Justifycenter = function(){this.Justify("center");}
ToolBar.prototype.Justifyright = function(){this.Justify("right");}
ToolBar.prototype.Justify = function Justify(aStr){
switch(aStr){
case "left":
this.execCommand("JustifyLeft");
break;
case "center":
this.execCommand("JustifyCenter");
break;
case "right":
this.execCommand("JustifyRight");
break;
default:
return false;
}
}
/*
字体颜色
*/
ToolBar.prototype.ForeColorD = function ForeColorD(){
var arr = showModalDialog(this._Editor._ResourcePath+"Dialogs/selcolor.htm", window, "dialogWidth:300px; dialogHeight:300px; status:0; help:0");
if (arr)
{
this.ForeColor(arr);
}
this._Editor.focus();
}
/*
字体背景颜色
*/
ToolBar.prototype.BackColorD = function BackColorD(){
var arr = showModalDialog(this._Editor._ResourcePath+"Dialogs/selcolor.htm", window, "dialogWidth:300px; dialogHeight:300px; status:0; help:0");
if (arr)
{
this.BackColor(arr);
}
this._Editor.focus();
}
/*
*/
//文字加粗
ToolBar.prototype.Bold = function (){
this.execCommand("bold");
}
//倾斜
ToolBar.prototype.Italic = function (){
this.execCommand("italic");
}
//下划线
ToolBar.prototype.Underline = function (){
this.execCommand("underline");
}
ToolBar.prototype.Strikethrough = function () {
this.execCommand("strikethrough");
}
ToolBar.prototype.Superscript = function () {
this.execCommand("Superscript");
}
ToolBar.prototype.Subscript = function () {
this.execCommand("Subscript");
}
ToolBar.prototype.Undo = function () {
this.execCommand("undo");
}
ToolBar.prototype.Redo = function () {
this.execCommand("redo");
}
ToolBar.prototype.Print = function () {
this.execCommand("print");
}
//超链接
ToolBar.prototype.Createlink = function (){
this.execCommand("createlink");
}
//取消链接
ToolBar.prototype.Unlink = function unurl(){
this.execCommand("unlink");
}
/*
Insert operations
*/
ToolBar.prototype.Insertdate = function ()
{
this._Editor.insertText(new Date().toLocaleDateString());
}
ToolBar.prototype.Inserttime = function ()
{
this._Editor.insertText(new Date().toLocaleTimeString());
}
ToolBar.prototype.Wordcount = function ()
{
this._Editor.WordCount();
}
/*
*/
ToolBar.prototype.Bullets = function (){
this.execCommand("insertunorderedlist");
}
ToolBar.prototype.Numberedlist = function (){
this.execCommand("insertorderedlist");
}
ToolBar.prototype.Indent = function (){
this.execCommand("indent");
}
ToolBar.prototype.Outdent = function (){
this.execCommand("outdent");
}
/*
external dialog
*/
ToolBar.prototype.Gallery = function ()
{
var folder = 'ee_client/images/upload/';
var galleryscript = this._Editor._ResourcePath+'Dialogs/imagegallery.aspx?rif='+folder+'&cif='+folder;
//if (parameters && parameters != '') galleryscript += '&' + parameters;
var imgArr = showModalDialog(galleryscript,window,'dialogWidth:560px; dialogHeight:500px;help:0;status:0;resizeable:1;');
if (imgArr != null) {
var imagestring = '<IMG SRC="' + imgArr['filename'] + '" HEIGHT=' + imgArr['height'] + ' WIDTH=' + imgArr['width'] + ' BORDER=0>';
this._Editor.insertHTML(imagestring);
} else {
//alert("您没有选择图片。");
}
}
/*
*/
/*
footBar
*/
function footBar(editor)
{
this._ImagePath = editor._ResourcePath+"images/ee/"+editor._Themes+"/";
this._Editor = editor;
this.Bar = editor.footBar;
this.BarDiv = editor.footBarDiv;
//build a button
this.BuildButton = function (btInfo,handler)
{
var title = btInfo[1];
var picurl = btInfo[0];
if(!title) title="";
var html = "";
var obj=null;
if(handler == null)
{
html = "<img src=\""+this._ImagePath+btInfo+"\" >"
return createElement(html,this.BarDiv);
}
else
{
if(typeof(btInfo) == "string")
{
html = btInfo;
obj = createElement(html,this.BarDiv);
}else{
html = "<img title=\""+title+"\" onmouseover=\"bt_over(this);\" onmouseout=\"bt_out(this);\"";
html +=" style=\"cursor:hand;background:#9EBEF5;\" ";
html +=" src=\""+this._ImagePath+picurl+"\" onclick=\""+handler+";\">"
obj = createElement(html,this.BarDiv);
}
obj.attachEvent("onclick",handler);
obj.attachEvent("onmouseover",bt_over);
obj.attachEvent("onmouseout",bt_out);
return obj;
}
}
this.BuildBar = function ()
{
this.BuildButton(UI.footBar.Buttons.Mod,this.Mod.bind(this));
}
this.BuildBar();
}
/*
改变MOD
*/
footBar.prototype.Mod = function(){
var sender = event.srcElement;
if(sender.value=="HTML")
{
sender.value="VIEW";
this._Editor.SetMod(1);
}else{
sender.value="HTML";
this._Editor.SetMod(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -