📄 ftb-toolbaritems.js
字号:
</HTML>');
}
/******** 预览 End ********/
// 打印
function FTB_Print(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.document.execCommand('print','',null);
}
/******** 插入表单元素 Start ********/
function FTB_InsertInputText(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('InsertInputText');
}
function FTB_InsertTextArea(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('InsertTextArea');
}
function FTB_InsertInputRadio(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('InsertInputRadio');
}
function FTB_InsertInputCheckbox(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('InsertInputCheckbox');
}
function FTB_InsertInputButton(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('InsertInputButton');
}
function FTB_InsertMarquee(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('InsertMarquee');
}
/******** 插入表单元素 End ********/
/******** 插入媒体文件 Start ********/
function FTB_InsertFlash(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
var FlashFilePath = FTB_FilesPath + 'HelperFiles/Flash.htm';
imageArr = showModalDialog(FlashFilePath,window,'dialogWidth:320px;dialogHeight:180px;center=yes;resizable=no;help=no;status=no');
if (imageArr != null) {
var newImage = editor.document.createElement('IMG');
newImage.src = FTB_FilesPath + 'images/Flash.GIF';
newImage.alt = '[Flash=' + imageArr['url'] + ']';
newImage.width = imageArr['width'];
newImage.height = imageArr['height'];
if (editor.document.selection.type=='Control') {
sel.pasteHTML(newImage.outerHTML);
} else {
sel = editor.document.selection.createRange();
sel.pasteHTML(newImage.outerHTML);
}
} else {
// return false;
}
}
function FTB_InsertWMV(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
var WMVFilePath = FTB_FilesPath + 'HelperFiles/WMV.htm';
imageArr = showModalDialog(WMVFilePath,window,'dialogWidth:320px;dialogHeight:180px;center=yes;resizable=no;help=no;status=no');
if (imageArr != null) {
var newImage = editor.document.createElement('IMG');
newImage.src = FTB_FilesPath + 'images/MediaVideo.GIF';
newImage.alt = '[WMV=' + imageArr['url'] + ']';
newImage.width = imageArr['width'];
newImage.height = imageArr['height'];
if (editor.document.selection.type=='Control') {
sel.pasteHTML(newImage.outerHTML);
} else {
sel = editor.document.selection.createRange();
sel.pasteHTML(newImage.outerHTML);
}
} else {
// return false;
}
}
function FTB_InsertWMA(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
var inputUrl = prompt('请输入Windows Media Player音频文件地址:', 'http://');
if (inputUrl != null && inputUrl != '' && inputUrl != 'undefined' && inputUrl != 'http://') {
editor.focus();
var newImage = editor.document.createElement('IMG');
newImage.src = FTB_FilesPath + 'images/MediaAudio.GIF';
newImage.alt = '[WMA=' + inputUrl + ']';
if (editor.document.selection.type=='Control') {
sel.pasteHTML(newImage.outerHTML);
} else {
sel = editor.document.selection.createRange();
sel.pasteHTML(newImage.outerHTML);
}
}
}
function FTB_InsertRM(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
var RMFilePath = FTB_FilesPath + 'HelperFiles/RM.htm';
imageArr = showModalDialog(RMFilePath,window,'dialogWidth:320px;dialogHeight:180px;center=yes;resizable=no;help=no;status=no');
if (imageArr != null) {
var newImage = editor.document.createElement('IMG');
newImage.src = FTB_FilesPath + 'images/RealMedia.GIF';
newImage.alt = '[RM=' + imageArr['url'] + ']';
newImage.width = imageArr['width'];
newImage.height = imageArr['height'];
if (editor.document.selection.type=='Control') {
sel.pasteHTML(newImage.outerHTML);
} else {
sel = editor.document.selection.createRange();
sel.pasteHTML(newImage.outerHTML);
}
} else {
// return false;
}
}
function FTB_InsertRA(ftbName,htmlmode) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
var inputUrl = prompt('请输入RealPlayer音频文件地址:', 'http://');
if (inputUrl != null && inputUrl != '' && inputUrl != 'undefined' && inputUrl != 'http://') {
editor.focus();
var newImage = editor.document.createElement('IMG');
newImage.src = FTB_FilesPath + 'images/RealAudio.GIF';
newImage.alt = '[RA=' + inputUrl + ']';
if (editor.document.selection.type=='Control') {
sel.pasteHTML(newImage.outerHTML);
} else {
sel = editor.document.selection.createRange();
sel.pasteHTML(newImage.outerHTML);
}
}
}
/******** 插入媒体文件 End ********/
/******** 下拉菜单 Start ********/
// 字体
function FTB_SetFontFace(ftbName,htmlmode,name,value) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
value = value == 'Times' ? 'Times New Roman' : value;
editor.focus();
editor.document.execCommand('fontname','',value);
}
// 字号
function FTB_SetFontSize(ftbName,htmlmode,name,value) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('fontsize','',value);
}
// 字体颜色
function FTB_SetFontForeColor(ftbName,htmlmode,name,value) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('forecolor','',value);
}
// 背景颜色
function FTB_SetFontBackColor(ftbName,htmlmode,name,value) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
editor.document.execCommand('backcolor','',value);
}
/******** 样式 Start ********/
function FTB_SetStyle(ftbName,htmlmode,name,value) {
editor = FTB_GetIFrame(ftbName);
if (value == '[Remove Style]') {
if (editor.document.selection.type == 'Control') {
var oControlRange = editor.document.selection.createRange();
var oControlItem = oControlRange.item(0);
var oTextRange = editor.document.body.createTextRange();
oTextRange.moveToElementText(oControlItem);
oTextRange.select();
var sHTML = oTextRange.htmlText;
sHTML = sHTML.replace(/<SPAN[^>]*>([\s\S]*?)<\/SPAN>/ig, '<FONT face=ftb_removestyle>$1</FONT>');
oTextRange.pasteHTML(sHTML);
} else {
var oRange = editor.document.selection.createRange();
oRange.execCommand('FontName', false, 'ftb_removestyle');
}
FTB_RemoveStyle(editor.document.body);
FTB_RemoveStyleClean(editor.document.body);
} else {
if (editor.document.selection.type == 'Control') {
var oControlRange = editor.document.selection.createRange();
var oControlItem = oControlRange.item(0);
var oTextRange = editor.document.body.createTextRange();
oTextRange.moveToElementText(oControlItem);
oTextRange.select();
var sHTML = oTextRange.htmlText;
sHTML = sHTML.replace(/<SPAN[^>]*>([\s\S]*?)<\/SPAN>/ig, '$1'); oTextRange.pasteHTML('<FONT face=ftb_span>' + sHTML + '</FONT>');
} else {
var oRange = editor.document.selection.createRange();
var sBookmark = oRange.getBookmark();
var sHTML = oRange.htmlText;
sHTML = sHTML.replace(/class=\w*/ig,'');
oRange.pasteHTML(sHTML);
oRange.moveToBookmark(sBookmark);
oRange.execCommand('FontName', false, 'ftb_span');
}
FTB_FontsToSpans(editor.document, editor.document.body, value);
FTB_JoinSpans(editor.document.body, null);
FTB_RemoveEmptySpans(editor.document.body);
}
}
function FTB_RemoveStyle(oElement) {
for(var i=0;i<oElement.childNodes.length;i++) {
FTB_RemoveStyle(oElement.childNodes[i]);
}
if(oElement.tagName=='SPAN') {
if(oElement.innerHTML.indexOf('ftb_removestyle')!=-1) {
oElement.removeNode(false);
}
}
}
function FTB_RemoveStyleClean(oElement) {
for(var i=0;i<oElement.childNodes.length;i++) {
FTB_RemoveStyleClean(oElement.childNodes[i]);
}
if(oElement.tagName=='FONT') {
if(oElement.face=='ftb_removestyle') {
oElement.removeNode(false);
}
}
}
function FTB_FontsToSpans(oDocument, oElement, sClass) {
for(var i=0;i<oElement.childNodes.length;i++) {
FTB_FontsToSpans(oDocument, oElement.childNodes[i], sClass);
}
if(oElement.tagName=='FONT') {
if(oElement.face=='ftb_span') {
sPreserve=oElement.innerHTML;
oSpan=oDocument.createElement('SPAN');
oElement.replaceNode(oSpan);
oSpan.innerHTML=sPreserve;
oSpan.className=sClass;
} else {
var sStyle = '';
if (oElement.face.length) {
sStyle += 'font-family: ' + oElement.face + ';';
}
if (oElement.size.length) {
var sSize = oElement.size;
if (sSize=='1') sSize = 'xx-small';
if (sSize=='2') sSize = 'x-small';
if (sSize=='3') sSize = 'small';
if (sSize=='4') sSize = 'medium';
if (sSize=='5') sSize = 'large';
if (sSize=='6') sSize = 'x-large';
if (sSize=='7') sSize = 'xx-large';
if (sSize.substring(0, 1)=='-') sSize = 'smaller';
if (sSize.substring(0, 1)=='+') sSize = 'larger';
sStyle += 'font-size: ' + sSize + ';';
}
if (oElement.color.length) {
sStyle += 'color: ' + oElement.color + ';';
}
if (sStyle.length) {
sPreserve=oElement.innerHTML;
oSpan=oDocument.createElement('SPAN');
oElement.replaceNode(oSpan);
oSpan.innerHTML=sPreserve;
oSpan.style.cssText=sStyle;
}
}
}
}
function FTB_JoinSpans(oElement, oParent) {
for(var i=0;i<oElement.childNodes.length;i++) {
var oChild = oElement.childNodes[i];
oElement = FTB_JoinSpans(oChild, oElement);
}
if (oElement.tagName=='SPAN' && oParent != null && oParent.tagName =='SPAN') {
if (oElement.innerText == oParent.innerText) {
sElementClass=oElement.className;
sParentClass=oParent.className;
if(sParentClass.length && !sElementClass.length) {
oElement.setAttribute('class', sParentClass);
}
var parentAttributes = oParent.style.cssText.split('; ');
var elementAttributes = oElement.style.cssText.split('; ');
for (var i=0;i<parentAttributes.length;i++) {
var parentPairs = parentAttributes[i].split(':');
var sPKey = parentPairs[0];
var sPValue = parentPairs[1];
var bKeyExists = false;
for (var k=0;k<elementAttributes.length;k++) {
var elementPairs = elementAttributes[k].split(':');
var sEKey = elementPairs[0];
var sEValue = elementPairs[1];
if (sEKey == sPKey) {
bKeyExists = true; break;
}
}
if (!bKeyExists) {
oElement.style.cssText = oElement.style.cssText + ';' + sPKey + ':' + sPValue;
}
}
oParent.removeNode(false);
return oElement;
}
}
return oParent;
}
function FTB_RemoveEmptySpans(oElement) {
for(var i=0;i<oElement.childNodes.length;i++) {
FTB_RemoveEmptySpans(oElement.childNodes[i]);
}
if (oElement.tagName=='SPAN' && oElement.className.length==0 && oElement.style.cssText=='') {
oElement.removeNode(false);
}
}
/******** 样式 End ********/
// 插入 HTML
function FTB_InsertHtml(ftbName,htmlmode,name,value) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
sel = editor.document.selection.createRange();
sel.pasteHTML(value);
}
// 插入符号
function FTB_InsertSymbol(ftbName,htmlmode,name,value) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
sel = editor.document.selection.createRange();
sel.pasteHTML(value);
}
// 段落格式
function FTB_SetParagraph(ftbName,htmlmode,name,value) {
if (htmlmode) return;
editor = FTB_GetIFrame(ftbName);
editor.focus();
if (value == '<BODY>') {
editor.document.execCommand('formatBlock','','Normal');
editor.document.execCommand('removeFormat');
return;
}
editor.document.execCommand('formatBlock','',value);
}
/******** 下拉菜单 End ********/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -