📄 ftb-toolbaritems.js
字号:
// 拼写检查
function FTB_ieSpellCheck(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
if (htmlmode) return;
try {
var tspell = new ActiveXObject('ieSpell.ieSpellExtension');
tspell.CheckAllLinkedDocuments(window.document);
} catch (err) {
if (window.confirm('进行拼写检查需要安装 ieSpell 插件,您要安装吗?'))
{
window.open('http://www.iespell.com/download.php');
}
}
}
// 粗体
function FTB_Bold(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'bold');
}
// 斜体
function FTB_Italic(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'italic');
}
// 下划线
function FTB_Underline(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'underline');
}
// 删除线
function FTB_Strikethrough(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'strikethrough');
}
// 上标
function FTB_Superscript(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'superscript');
}
// 下标
function FTB_Subscript(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'subscript');
}
// 删除字体格式
function FTB_RemoveFormat(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'removeFormat');
}
// 左对齐
function FTB_JustifyLeft(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'justifyleft');
}
// 右对齐
function FTB_JustifyRight(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'justifyright');
}
// 居中对齐
function FTB_JustifyCenter(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'justifycenter');
}
// 两端对齐
function FTB_JustifyFull(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'justifyfull');
}
// 项目符号列表
function FTB_BulletedList(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'insertunorderedlist');
}
// 数字项目列表
function FTB_NumberedList(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'insertorderedlist');
}
// 增加缩进
function FTB_Indent(ftbName,htmlmode) {
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'indent');
}
// 减少缩进
function FTB_Outdent(ftbName,htmlmode) {
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'outdent');
}
// 剪切
function FTB_Cut(ftbName,htmlmode) {
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('cut','',null);
}
// 复制
function FTB_Copy(ftbName,htmlmode) {
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('copy','',null);
}
// 粘贴
function FTB_Paste(ftbName,htmlmode) {
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('paste','',null);
}
// 撤销
function FTB_Undo(ftbName,htmlmode) {
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('undo','',null);
}
// 重复
function FTB_Redo(ftbName,htmlmode) {
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('redo','',null);
}
// 更改大小写
var changetype = 0;
function FTB_ChangeCase(ftbName,htmlmode) {
editor = FTB_GetIFrame(ftbName);
sel = editor.document.selection.createRange();
txt = sel.htmlText;
if(txt != '') {
splitwords = txt.split(' ');
var f = '';
for (var i=0; i<splitwords.length;i++) {
//alert('changing: ' + splitwords[i]);
switch (changetype) {
case 0:
f += splitwords[i].toUpperCase();
break;
case 1:
f += splitwords[i].toLowerCase();
break;
case 2:
tot = splitwords[i].length;
if (tot > 1) {
//alert(splitwords[i].substring(1,2).toLowerCase());
f += splitwords[i].substring(0,1).toUpperCase() + splitwords[i].substring(1,splitwords[i].length).toLowerCase();
} else {
f += splitwords[i].toUpperCase();
}
break;
}
if (i <(splitwords.length-1)) f += ' ';
}
sel.pasteHTML(f);
sel = editor.document.selection.createRange();
sel.findText(f);
sel.select();
editor.focus();
changetype++;
if (changetype > 2) changetype = 0;
}
}
// 清空
function FTB_Delete(ftbName,htmlmode) {
editor = FTB_GetIFrame(ftbName);
if (confirm('确实要删除编辑器中所有的文字和 HTML 代码吗?')) {
editor.document.body.innerHTML = '';
editor.document.body.innerText = '';
}
editor.focus();
}
// 建立超链接
function FTB_CreateLink(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('createlink','1',null);
}
// 去除超链接
function FTB_Unlink(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('unlink','1',null);
}
// 插入水平线
function FTB_InsertRule(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
FTB_Format(editor,htmlmode,'inserthorizontalrule');
}
// 插入日期
function FTB_InsertDate(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
var d = new Date();
sel = editor.document.selection.createRange();
sel.pasteHTML(d.toLocaleDateString());
}
// 插入时间
function FTB_InsertTime(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
var d = new Date();
sel = editor.document.selection.createRange();
sel.pasteHTML(d.toLocaleTimeString());
}
// 字数统计
function FTB_WordCount(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
var iSumWords = 0;
var rng = editor.document.body.createTextRange();
var textvalue = editor.document.body.innerText;
var htmlvalue = editor.document.body.innerHTML;
rng.collapse(true);
while(rng.move('word',1)) {
iSumWords++;
}
alert('纯文本 ' + textvalue.length + ' 字,经转义的HTML ' + htmlvalue.length + ' 字,大约 ' + iSumWords + ' 个单词。');
}
// 清除 Word 格式
function FTB_WordClean(ftbName,htmlmode) {
editor = FTB_GetIFrame(ftbName);
editor.focus();
// 0bject based cleaning
var body = editor.document.body;
for (var index = 0; index < body.all.length; index++) {
tag = body.all[index];
//if (tag.Attribute['className'].indexOf('mso') > -1)
tag.removeAttribute('className','',0);
tag.removeAttribute('style','',0);
}
// Regex based cleaning
var html = editor.document.body.innerHTML;
html = html.replace(/<o:p> <\/o:p>/g, '');
html = html.replace(/o:/g, '');
html = html.replace(/<st1:.*?>/g, '');
// Final clean up of empty tags
html = html.replace(/<font>/g, '');
html = html.replace(/<span>/g, '');
editor.document.body.innerHTML = html;
}
/******** 插入表格 Start ********/
function FTB_InsertTable(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
var TableFilePath = FTB_FilesPath + 'HelperFiles/Table.htm';
tableArr = showModalDialog(TableFilePath,window,'dialogWidth:300px;dialogHeight:220px;center=yes;resizable=no;help=no;status=no');
if (tableArr != null) {
var newTable = editor.document.createElement('TABLE');
for(y = 0; y < tableArr['rows']; y++) {
var newRow = newTable.insertRow();
for(x = 0; x < tableArr['cols']; x++) {
var newCell = newRow.insertCell();
if (tableArr['align'] != '') {
newCell.align = tableArr['align'];
}
}
}
newTable.border = tableArr['border'];
newTable.cellspacing = tableArr['cellspacing'];
newTable.cellpadding = tableArr['cellpadding'];
newTable.width = tableArr['width'];
if (editor.document.selection.type=='Control') {
sel.pasteHTML(newTable.outerHTML);
} else {
sel = editor.document.selection.createRange();
sel.pasteHTML(newTable.outerHTML);
}
} else {
// return false;
}
}
/******** 插入表格 End ********/
/******** 插入图片 Start ********/
function FTB_InsertImage(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
var ImageFilePath = FTB_FilesPath + 'HelperFiles/Image.htm';
imageArr = showModalDialog(ImageFilePath,window,'dialogWidth:320px;dialogHeight:200px;center=yes;resizable=no;help=no;status=no');
if (imageArr != null) {
var newImage = editor.document.createElement('IMG');
newImage.border = 0;
newImage.src = imageArr['src'];
if (imageArr['align'] != '') newImage.align = imageArr['align'];
newImage.alt = imageArr['alt'];
if (editor.document.selection.type=='Control') {
sel.pasteHTML(newImage.outerHTML);
} else {
sel = editor.document.selection.createRange();
sel.pasteHTML(newImage.outerHTML);
}
} else {
// return false;
}
}
/******** 插入图片 End ********/
/******** 插入代码 Start ********/
function FTB_InsertCode(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
var CodeFilePath = FTB_FilesPath + 'HelperFiles/Code.htm';
var LightCode = showModalDialog(CodeFilePath,window,'dialogWidth=560px;dialogHeight=500px;center=yes;resizable=no;help=no;status=no');
if (LightCode != null) {
if (editor.document.selection.type=='Control') {
sel.pasteHTML(LightCode);
} else {
sel = editor.document.selection.createRange();
sel.pasteHTML(LightCode);
}
} else {
// return false;
}
}
/******** 插入代码 End ********/
/******** 预览 Start********/
function FTB_Preview(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
var values = editor.document.body.innerHTML;
msg = open('','DisplayWindow','toolbar=no,directories=no,menubar=no');
msg.document.write('\r\n\
<HTML>\r\n\
<HEAD>\r\n\
<TITLE>荒野新闻系统</TITLE>\r\n\
<META content="text/html; charset=gb2312" http-equiv="Content-Type">\r\n\
<STYLE>\r\n\
body { background: menu; }\r\n\
td,body,select,div,span,button { font-size: 14px; font-family: Arial; }\r\n\
BUTTON {width: 5em; border-width: 1pt; }\r\n\
input { border: 1pt solid black; font-size: 12px; padding: 1pt 3pt; }\r\n\
a:link { color: #0000BB; }\r\n\
a:visited { color: #0000BB; }\r\n\
</STYLE>\r\n\
</HEAD>\r\n\
<BODY>\r\n\
<CENTER><H4>荒野新闻系统</H4></CENTER>\r\n\
' + values + '\r\n\
</BODY>\r\n\
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -