📄 toolbar.js
字号:
try {
node = range.cloneContents();
}
catch (e) {
node = '';
}
var n = cEditor.Document.createElement('div');
oNode.AddNode(node, n);
n.innerHTML = '[free]' + n.innerHTML + '[/free]';
cEditor.InsertContentGecko(n);
while (n.firstChild) {
var fc = n.removeChild(n.firstChild);
oNode.InsertBefore(fc, n);
}
n.parentNode.removeChild(n);
}
}
}
},
// 隐藏
createHide : function (toolbar, div) {
if (! this.icons.hide[0]) return;
var hide = this.buttons.hide = this.createIcon(div, 'hide');
hide.onclick = function () {
if (cEditor.isXHTML()) return;
if (cEditor.isUBB()) {
cEditor.SetUBBStyle('[hide]\x01[/hide]');
return;
}
if (cEditor.isWYSIWYG()) {
var text = Browser.IsIE ? cEditor.TextRange.htmlText : cEditor.SelectRange;
if (Browser.IsIE) {
//cEditor.SelectRange.clear();
cEditor.InsertContent('[hide]' + text + '[/hide]');
}
else {
var range = cEditor.SelectRange.getRangeAt(0);
node = range.cloneContents();
var n = cEditor.Document.createElement('div');
n.appendChild(node);
n.innerHTML = '[hide]' + n.innerHTML + '[/hide]';
cEditor.InsertContentGecko(n);
while (n.firstChild) {
var fc = n.removeChild(n.firstChild);
oNode.InsertBefore(fc, n);
}
n.parentNode.removeChild(n);
}
}
return;
var id = Global.Random();
var panel = PopUp.Panel([
'<div class="editwin-head">',
' <h3>插入隐藏内容</h3>',
'</div>',
'<div class="clearfix editwin-body editwin-hide">',
' <p>',
' <textarea rows="5" cols="35" id="content_' + id + '"></textarea>',
' </p>',
' <p>',
' <input type="radio" name="select_' + id + '" id="one_' + id + '" checked="checked" /> 浏览者回复本帖后才显示',
' </p>',
' <p>',
' <input type="radio" name="select_' + id + '" id="two_' + id + '" /> 浏览者积分高于 <input type="text" class="text" size="4" id="score_' + id + '" /> 时才显示',
' </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');
panel.style.zIndex = 10;
panel.style.left = Global.GetOffsetLeft(hide) + 'px';
panel.style.top = Global.GetOffsetTop(hide) + hide.offsetHeight + 'px';
PopUp.AddPopUp(panel, true);
PopUp.HideModal(panel);
$('content_' + id).focus();
$('confirm_' + id).onclick = function () {
var content = $('content_' + id).value;
var score = $('score_' + id).value;
var checked = $('two_' + id).checked;
if (checked) {
if (score == '' || !/^\d+$/.test(score)) {
alert('需要输入一个分数值。');
return;
}
score = '=' + score;
}
PopUp.RemovePopUp(panel);
if (content.replace(/\s*/g, '') == '') return;
content = content.replace(/</g, '<').replace(/>/g, '>').replace(/\r\n|\r|\n/g, '<br />');
content = '[hide' + score + ']' + content + '[/hide]';
cEditor.SelectTextRange();
cEditor.InsertContent(content);
//cEditor.GetRange();
};
$('cancel_' + id).onclick = function () {
PopUp.RemovePopUp(panel);
};
};
},
// 创建quote
createQuote : function (toolbar, div) {
if (! this.icons.quote[0]) return;
var quote = this.buttons.quote = this.createIcon(div, 'quote');
quote.onclick = function () {
if (cEditor.isXHTML()) return;
if (cEditor.isUBB()) {
cEditor.SetUBBStyle('[quote]\x01[/quote]');
return;
}
var id = Global.Random();
var panel = PopUp.Panel([
'<div class="editwin-head">',
' <h3>插入引用</h3>',
'</div>',
'<div class="clearfix editwin-body editwin-code">',
' <p>',
' <textarea rows="10" cols="35" id="content_' + id + '"></textarea>',
' </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>',
'</div>'].join(''), 200, 100);
CSS.AddClass(panel, 'editwin');
panel.style.zIndex = 10;
panel.style.left = Global.GetOffsetLeft(quote) + 'px';
panel.style.top = Global.GetOffsetTop(quote) + quote.offsetHeight + 'px';
PopUp.AddPopUp(panel, true);
PopUp.HideModal(panel);
$('content_' + id).focus();
$('confirm_' + id).onclick = function () {
var content = $('content_' + id).value;
PopUp.RemovePopUp(panel);
if (content.replace(/\s*/g, '') == '') return;
content = content.replace(/</g, '<').replace(/>/g, '>').replace(/\r\n|\r|\n/g, '<br />');
content = '<div class="maxcode-quote">' + content + '</div>';
cEditor.SelectTextRange();
cEditor.InsertContent(content);
//cEditor.GetRange();
};
$('cancel_' + id).onclick = function () {
PopUp.RemovePopUp(panel);
};
};
},
// 全屏
createFullScreen : function (toolbar, div) {
if (! this.icons.fullScreen[0] || this.FullScreen == false) return;
var self = this;
var fullScreen = this.buttons.fullScreen = this.createIcon(div, 'fullScreen');
CSS.AddClass(fullScreen, 'fullscreen');
var p;
var w, h;
var mousewheel;
var isFullscreen = false;
// 全屏
var switchToFullScreen = function () {
var editor = cEditor.EditorWindow;
editor.style.position = isFullscreen ? 'static' : 'absolute';
if (!isFullscreen
|| typeof w == 'undefined'
|| typeof h == 'undefined') {
///
w = editor.style.width;
h = editor.offsetHeight;
}
self.setResizable(isFullscreen);
var html = parent.document.getElementsByTagName('html')[0];
var body = parent.document.body;
html.style.overflow = body.style.overflow = isFullscreen ? 'auto' : 'hidden';
var _w, _h;
if (isFullscreen) {
_w = w;
_h = h + 'px';
if (Browser.IsOpera) mousewheel.RemoveEvent();
}
else {
editor.style.width = '0';
editor.style.height = '0';
editor.style.zIndex = 1;
editor.style.left = parent.Global.GetScrollLeft() + 'px';
editor.style.top = parent.Global.GetScrollTop() + 'px';
if (Browser.IsIE56) {
_w = parent.Global.GetClientWidth() + 'px';
_h = parent.Global.GetClientHeight() + 'px';
}
else {
_w = '100%';
_h = '100%';
}
if (Browser.IsOpera) mousewheel = new MouseWheel();
}
editor.style.width = _w;
editor.style.height = _h;
self.changeState(this, false);
this.style.width = (isFullscreen ? self.icons['fullScreen'][2] : 70) + 'px';
this.innerHTML = isFullscreen ? self.icons['fullScreen'][4] : '取消全屏';
isFullscreen = !isFullscreen;
};
fullScreen.onclick = switchToFullScreen;
this.SwitchToFullScreen = function () {switchToFullScreen.apply(fullScreen)};
},
// 创建图标对象
createIcon : function (p, type) {
var icon = oNode.CreateNode('a');
CSS.AddClass(icon, 'icon');
icon.appendChild(oNode.CreateTextNode(this.icons[type][4] || ''));
p.appendChild(icon);
//icon.draggable = false;
icon.type = type;
icon.title = this.icons[type][3] || '';
icon.href = 'javascript:;';
var src, standone = false;
if (typeof this.icons[type][1] == 'string') {
src = this.icons[type][1];
standone = true;
}
else {
src = this.iconSrc;
}
if (/http:\/\//i.test(src)) {
src = 'url(' + src + ') no-repeat 0 0';
}
else {
src = 'url(' + this.iconsRoot + src + ') no-repeat ' + (standone ? 0 : '-' + this.icons[type][1] + 'px') + ' 0';
}
src = 'transparent ' + src;
icon.style.background = src;
if (this.icons[type][2]) {
try {
icon.style.width = this.icons[type][2] + 'px';
}
catch (e) {}
}
var self = this;
icon.onmouseover = function () {
if (cEditor.isXHTML()) return;
this.style.backgroundPosition = (typeof self.icons[this.type][1] == 'string' ? 0 : '-' + self.icons[this.type][1]) + 'px -' + self.yOffset + 'px'
};
icon.onmouseout = function () {
if (cEditor.isXHTML()) return;
if (this.overState) return;this.style.backgroundPosition = (typeof self.icons[this.type][1] == 'string' ? 0 : '-' + self.icons[this.type][1]) + 'px 0'
};
return icon;
},
// 颜色列表
colorList : function (type) {
this.colorType = type;
if (this.colorNode) return this.colorNode;
var toolbar = this;
var element = oNode.CreateNode('div');
element.style.width = '216px';
var custom = [
'#000000', '#333333', '#666666',
'#999999', '#AAAAAA', '#CCCCCC',
'#FFFFFF', '#FFF000', '#000000',
'#000FFF', '#FF0000', '#00FF00',
'#0000FF', '#FFFF00', '#00FFFF',
'#FF00FF', '#ABCDEF', '#123456'
];
for (var i = 0; i < custom.length; i++) {
element.appendChild(toolbar.colorBlock(custom[i]));
}
var L, M, N;
var colors = ['00', '33', '66', '99', 'CC', 'FF'];
var H = 18;
var V = 12;
var hV = Math.floor(V / 2);
for (var i = 0; i < H * V; i++) {
var h = i % H;
var v = Math.floor(i / H);
if (h < hV && v < hV) {
L = colors[0];
}
else if (h < hV && v >= hV) {
L = colors[3];
}
else if (h < V && v < hV) {
L = colors[1];
}
else if (h < V && v >= hV) {
L = colors[4];
}
else if (h < H && v < V) {
L = colors[2];
}
else {
L = colors[5];
}
M = colors[h % hV];
N = colors[v % hV];
element.appendChild(toolbar.colorBlock('#' + L + M + N));
}
toolbar.colorNode = element;
return element;
},
// 颜色块
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -