📄 toolbar.js
字号:
oA.style.padding = '2px';
oA.style.textDecoration = 'none';
//oA.style.fontSize = toolbar.fontSizeList[i].data;
oA.href = 'javascript:void(0);';
//oA.size = toolbar.fontSizeList[i].data;
oA.FontSize = toolbar.fontSizeList[i].data;
oA.onclick = function () {
if (cEditor.isWYSIWYG()) {
cEditor.SetStyle('FontSize', this.FontSize);
toolbar.fontSizePanel.style.display = 'none';
toolbar.response();
}
else {
cEditor.SetUBBStyle('[size=' + this.FontSize + ']\x01[/size]');
toolbar.fontSizePanel.style.display = 'none';
}
};
oA.onmouseover = function () {CSS.ReplaceClass(this, 'menu-item-out', 'menu-item-over');};
oA.onmouseout = function () {CSS.ReplaceClass(this, 'menu-item-over', 'menu-item-out');};
var oFont = oNode.CreateNode('font');
oFont.size = toolbar.fontSizeList[i].data;
oFont.appendChild(document.createTextNode(toolbar.fontSizeList[i].label));
oA.appendChild(oFont);
oDiv.appendChild(oA);
}
toolbar.fontSizePanel = cEditor.Menu(window, 120, 0, oDiv);
toolbar.fontSizePanel.style.top = Global.GetOffsetTop(this) + this.offsetHeight + 'px';
toolbar.fontSizePanel.style.left = Global.GetOffsetLeft(this) + 'px';
};
},
// 粗体
createBold : function (toolbar, div) {
if (! this.icons.bold[0]) return;
var bold = this.buttons.bold = this.createIcon(div, 'bold');
bold.onclick = function () {
if (cEditor.isXHTML()) return;
if (cEditor.isWYSIWYG()) {
cEditor.SetStyle('Bold', false);
toolbar.refreshState(this, 'Bold');
}
else {
cEditor.SetUBBStyle('[b]\x01[/b]');
}
};
},
// 斜体
createItalic : function (toolbar, div) {
if (! this.icons.italic[0]) return;
var italic = this.buttons.italic = this.createIcon(div, 'italic');
italic.onclick = function () {
if (cEditor.isXHTML()) return;
if (cEditor.isWYSIWYG()) {
cEditor.SetStyle('Italic', false);
toolbar.refreshState(this, 'Italic');
}
else {
cEditor.SetUBBStyle('[i]\x01[/i]');
}
};
},
// 下划线
createUnderline : function (toolbar, div) {
var underline = this.buttons.underline = this.createIcon(div, 'underline');
underline.onclick = function () {
if (cEditor.isXHTML()) return;
if (cEditor.isWYSIWYG()) {
cEditor.SetStyle('Underline', false);
toolbar.refreshState(this, 'Underline');
}
else {
cEditor.SetUBBStyle('[u]\x01[/u]');
}
};
},
// 前景色
createForeColor : function (toolbar, div) {
var foreColor = this.buttons.foreColor = this.createIcon(div, 'foreColor');
foreColor.onclick = function () {
if (cEditor.isXHTML()) return;
//if (!cEditor.isWYSIWYG()) return;
var type = 'ForeColor';
if (toolbar.colorPanel) {
toolbar.colorPanel.parentNode.removeChild(toolbar.colorPanel);
}
var oDiv = oNode.CreateNode('div');
oDiv.appendChild(toolbar.colorList(type));
toolbar.colorPanel = cEditor.Menu(window, 0, 0, oDiv);
toolbar.colorPanel.style.top = Global.GetOffsetTop(this) + this.offsetHeight + 'px';
toolbar.colorPanel.style.left = Global.GetOffsetLeft(this) + 'px';
};
},
// 背景色
createBackColor : function (toolbar, div) {
var backColor = this.buttons.backColor = this.createIcon(div, 'backColor');
backColor.onclick = function () {
if (cEditor.isXHTML()) return;
//if (!cEditor.isWYSIWYG()) return;
var type;
if (Browser.IsIE) {
type = 'BackColor';
}
else {
type = 'HiliteColor';
}
if (toolbar.colorPanel) {
toolbar.colorPanel.parentNode.removeChild(toolbar.colorPanel);
}
var oDiv = oNode.CreateNode('div');
oDiv.appendChild(toolbar.colorList(type));
toolbar.colorPanel = cEditor.Menu(window, 0, 0, oDiv);
toolbar.colorPanel.style.top = Global.GetOffsetTop(this) + this.offsetHeight + 'px';
toolbar.colorPanel.style.left = Global.GetOffsetLeft(this) + 'px';
};
},
//左对齐
createJustifyLeft : function (toolbar, div) {
if (! this.icons.justifyLeft[0]) return;
var justifyLeft = this.buttons.justifyLeft = this.createIcon(div, 'justifyLeft');
justifyLeft.onclick = function () {
if (cEditor.isXHTML()) return;
if (cEditor.isWYSIWYG()) {
cEditor.SetStyle('JustifyLeft', false);
if (!this.overState) {
toolbar.refreshState(this, 'JustifyLeft');
toolbar.changeState(toolbar.buttons.justifyCenter, false);
toolbar.changeState(toolbar.buttons.justifyRight, false);
}
}
else {
cEditor.SetUBBStyle('[align=left]\x01[/align]');
}
};
},
// 居中对齐
createJustifyCenter : function (toolbar, div) {
if (! this.icons.justifyCenter[0]) return;
var justifyCenter = this.buttons.justifyCenter = this.createIcon(div, 'justifyCenter');
justifyCenter.onclick = function () {
if (cEditor.isXHTML()) return;
if (cEditor.isWYSIWYG()) {
cEditor.SetStyle('JustifyCenter', false);
if (!this.overState) {
toolbar.refreshState(this, 'JustifyCenter');
toolbar.changeState(toolbar.buttons.justifyLeft, false);
toolbar.changeState(toolbar.buttons.justifyRight, false);
}
}
else {
cEditor.SetUBBStyle('[align=center]\x01[/align]');
}
};
},
// 右对齐
createJustifyRight : function (toolbar, div) {
if (! this.icons.justifyRight[0]) return;
var justifyRight = this.buttons.justifyRight = this.createIcon(div, 'justifyRight');
justifyRight.onclick = function () {
if (cEditor.isXHTML()) return;
if (cEditor.isWYSIWYG()) {
cEditor.SetStyle('JustifyRight', false);
if (!this.overState) {
toolbar.refreshState(this, 'JustifyRight');
toolbar.changeState(toolbar.buttons.justifyLeft, false);
toolbar.changeState(toolbar.buttons.justifyCenter, false);
}
}
else {
cEditor.SetUBBStyle('[align=right]\x01[/align]');
}
};
},
// 有序列表
createOrderedList : function (toolbar, div) {
if (! this.icons.orderedList[0]) return;
var orderedList = this.buttons.orderedList = this.createIcon(div, 'orderedList');
orderedList.onclick = function () {
if (cEditor.isXHTML()) return;
if (cEditor.isWYSIWYG()) {
cEditor.SetStyle('InsertOrderedList', false);
toolbar.refreshState(this, 'InsertOrderedList');
toolbar.changeState(toolbar.buttons.unorderedList, false);
}
else {
cEditor.SetUBBStyle('[list=1][*]\x01[/list]');
}
};
},
// 无序列表
createUnorderedList : function (toolbar, div) {
if (! this.icons.unorderedList[0]) return;
var unorderedList = this.buttons.unorderedList = this.createIcon(div, 'unorderedList');
unorderedList.onclick = function () {
if (cEditor.isXHTML()) return;
if (cEditor.isWYSIWYG()) {
cEditor.SetStyle('InsertUnorderedList', false);
toolbar.refreshState(this, 'InsertUnorderedList');
toolbar.changeState(toolbar.buttons.orderedList, false);
}
else {
cEditor.SetUBBStyle('[list][*]\x01[/list]');
}
};
},
// 增加缩进
createIndent : function (toolbar, div) {
if (! this.icons.indent[0]) return;
var indent = this.buttons.indent = this.createIcon(div, 'indent');
indent.onclick = function () {
if (cEditor.isXHTML()) return;
if (cEditor.isWYSIWYG()) {
cEditor.SetStyle('Indent', false);
//toolbar.refreshState(this, 'Indent');
}
else {
cEditor.SetUBBStyle('[indent]\x01[/indent]');
}
};
},
// 减少缩进
createOutdent : function (toolbar, div) {
if (! this.icons.outdent[0]) return;
var outdent = this.buttons.outdent = this.createIcon(div, 'outdent');
outdent.onclick = function () {
if (!cEditor.isWYSIWYG()) return;
cEditor.SetStyle('Outdent', false);
//toolbar.refreshState(this, 'Outdent');
};
},
// 创建链接
createLink : function (toolbar, div) {
if (! this.icons.link[0]) return;
var link = this.buttons.link = this.createIcon(div, 'link');
link.onclick = function () {
if (cEditor.isXHTML()) return;
var id = Global.Random();
var panel = PopUp.Panel([
'<div class="editwin-head">',
' <h3>插入链接</h3>',
'</div>',
'<div class="clearfix editwin-body editwin-hide">',
' <p style="margin-top: 5px;">',
' 链接地址:<input type="text" name="url_' + id + '" id="url_' + id + '" class="text" style="width:270px;" />',
' </p>',
' <p>',
' 显示文本:<input type="text" name="text_' + id + '" id="text_' + id + '" class="text" style="width:270px;" />',
' </p>',
' <p style="float:right">',
' <span class="xbtn"><input type="button" value="确认" id="confirm_' + id + '" /></span>',
' <span class="xbtn"><input type="button" value="取消" id="cancel_' + id + '" /></span>',
' </p>',
'</div>'].join(''), 200, 100);
CSS.AddClass(panel, 'editwin');
PopUp.AddPopUp(panel, true);
panel.style.zIndex = 10;
panel.style.left = Global.GetOffsetLeft(this) - (Global.GetOffsetLeft(this) > panel.offsetWidth ? panel.offsetWidth - this.offsetWidth : 0) + 'px';
panel.style.top = Global.GetOffsetTop(this) + this.offsetHeight + 'px';
PopUp.HideModal(panel);
$('confirm_' + id).onclick = function () {
var url = $('url_' + id).value;
var text = $('text_' + id).value;
PopUp.RemovePopUp(panel);
// 赋值
if (cEditor.isWYSIWYG()) {
if (url) {
//cEditor.SelectTextRange();
if (oNode.IsNode(node) && node.tagName.toLowerCase() == 'a') {
node.href = url;
node.innerHTML = (text == clearTag(_text) ? _text : htmlentities(text));
}
else {
if (Browser.IsIE) {
cEditor.SelectRange.clear();
cEditor.InsertContent('<a href="' + url + '">' + (text == clearTag(_text) ? _text : htmlentities(text)) + '</a>');
}
else {
//cEditor.TextRange.deleteContents();
var n = cEditor.Document.createElement('a');
n.href = url;
n.appendChild(text == clearTag(_text) ? node : cEditor.Document.createTextNode(text));
cEditor.InsertContentGecko(n);
}
}
}
}
else {
url && cEditor.SetUBBStyle('[url=\x02]\x01[/url]', url);
}
};
$('cancel_' + id).onclick = function () {
PopUp.RemovePopUp(panel);
};
// 取回值
if (cEditor.isWYSIWYG()) {
var _text = text = Browser.IsIE ? cEditor.TextRange.htmlText : cEditor.SelectRange;
var url = '';
var node = null;
if (cEditor.TextRange && cEditor.TextRange.parentElement) {
node = cEditor.TextRange.parentElement();
if (node.tagName.toLowerCase() == 'a') {
url = node.getAttribute('href', 2);
_text = text = node.innerHTML;
}
else {
node = null;
}
}
else {
var range = cEditor.SelectRange.getRangeAt(0);
var snode = range.startContainer;
var soff = range.startOffset;
var enode = range.endContainer;
var eoff = range.endOffset;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -