📄 ftb-mainscript.js
字号:
// *******************************************
// Universal Editor Functions
// *******************************************
function FTB_GetIFrame(ftbName) {
return eval(ftbName + '_editor');
}
function FTB_CopyHtmlToHidden(editor,hiddenHtml,htmlmode) {
if (htmlmode) {
hiddenHtml.value = editor.document.body.innerText;
} else {
hiddenHtml.value = editor.document.body.innerHTML;
}
if (hiddenHtml.value == '<P> </P>') {
hiddenHtml.value = '';
}
}
function FTB_Format(editor,htmlmode,format) {
if (htmlmode) return;
editor.focus();
editor.document.execCommand(format,'',null);
}
function FTB_CheckTag(item,tagName) {
if (item.tagName.search(tagName)!=-1) {
return item;
}
if (item.tagName=='BODY') {
return false;
}
item=item.parentElement;
return FTB_CheckTag(item,tagName);
}
function FTB_CharBefore(sel) {
if (sel.move('character',-1) == -1) {
sel.expand('character');
return sel.text;
} else {
return 'start';
}
}
function FTB_CharAfter(sel) {
var sel2 = sel;
if (sel.expand('character')) {
sel2.move('character',1);
sel2.expand('character');
return sel2.text;
} else {
return 'end';
}
}
function FTB_CharBefore(r) {
if (r.move('character',-1) == -1) {
r.expand('character');
return r.text;
} else {
return 'start';
}
}
function FTB_CharAfter(r) {
var r2 = r;
if (r.expand('character')) {
r2.move('character',1);
r2.expand('character');
return r2.text;
} else {
return 'end';
}
}
function FTB_GetRangeReference(editor) {
editor.focus();
var objReference = null;
var RangeType = editor.document.selection.type;
var selectedRange = editor.document.selection.createRange();
switch(RangeType) {
case 'Control' :
if (selectedRange.length > 0 ) {
objReference = selectedRange.item(0);
}
break;
case 'None' :
objReference = selectedRange.parentElement();
break;
case 'Text' :
objReference = selectedRange.parentElement();
break;
}
return objReference
}
// 特殊字符
function FTB_Event(ftbName,htmlMode,tabMode,breakMode) {
editor = FTB_GetIFrame(ftbName);
var _TAB = 9;
var _ENTER = 13;
var _QUOTE = 222;
// TAB Functions
if (editor.event.keyCode == _TAB && !htmlMode) {
if (tabMode == 'Default') {
var sel = editor.document.selection.createRange();
sel.pasteHTML(' ');
editor.event.cancelBubble = true;
editor.event.returnValue = false;
}
if (tabMode == 'NextControl') {
// do nothing for TabMode.NextControl
}
if (tabMode == 'Disabled') {
editor.event.cancelBubble = true;
editor.event.returnValue = false;
}
}
if (editor.event.keyCode == _QUOTE && !htmlMode) {
var sel = editor.document.selection.createRange();
sel.pasteHTML('"');
editor.event.cancelBubble = true;
editor.event.returnValue = false;
}
if (editor.event.keyCode == _ENTER && !htmlMode) {
if (breakMode == 'LineBreak' || editor.event.ctrlKey) {
var sel = editor.document.selection;
if (sel.type == 'Control') {
return;
}
var r = sel.createRange();
if ((!FTB_CheckTag(r.parentElement(),'LI')) && (!FTB_CheckTag(r.parentElement(),'H'))) {
r.pasteHTML('<br>');
editor.event.cancelBubble = true;
editor.event.returnValue = false;
r.select();
r.collapse(false);
return false;
}
}
}
}
// 粘贴
function FTB_onPaste(ftbName,PasteMode) {
if(PasteMode == 'Disabled') {
alert('禁止粘贴!');
return false;
}
else if (PasteMode == 'NoHtml') {
editor = FTB_GetIFrame(ftbName);
var text = window.clipboardData.getData('Text');
text = text.replace(/<[^>]*>/gi,'');
editor.focus();
s = editor.document.selection.createRange();
s.pasteHTML(text);
return false;
}
else {
// return;
}
}
// ********************************************
// Style Functions
// ********************************************
function FTB_Initialize(ftbName,hiddenHtml,ReadOnly,HtmlModeCss,DesignModeCss) {
editor = FTB_GetIFrame(ftbName);
editor.document.designMode = (ReadOnly ? 'Off' : 'On');
editor.document.open();
editor.document.write(hiddenHtml.value);
editor.document.close();
if (HtmlModeCss != '' || DesignModeCss != '')
{
editor.document.createStyleSheet(DesignModeCss);
editor.document.createStyleSheet(HtmlModeCss);
editor.document.styleSheets[1].disabled = true;
}
editor.document.contentEditable = (ReadOnly ? 'False' : 'True');
editor.document.body.style.margin='6px';
editor.document.body.style.border='0';
FTB_ApplyEditorStyles(ftbName);
}
function FTB_GetCssID(editorID) {
cssID = editorID;
while (cssID.substring(0,1) == '_') {
cssID = cssID.substring(1);
}
return cssID;
}
function FTB_SetButtonStyle(buttonTD,style,checkstyle) {
if (buttonTD == null) return;
if (buttonTD.className != checkstyle)
buttonTD.className = style;
}
function FTB_GetClassSubName(className) {
underscore = className.indexOf("_");
if (underscore < 0) return className;
return className.substring(underscore+1);
}
function FTB_ButtonOver(theTD,editorname,imageOver,imageDown) {
FTB_SetButtonStyle(theTD,FTB_GetCssID(editorname)+'_ButtonOver',null);
if (eval(editorname+'_OverImage').src != '') theTD.background=eval(editorname+'_OverImage').src;
if(theTD.children.length && theTD.children[0].tagName == "IMG" && imageOver){
oldSrc = theTD.children[0].src;
if (oldSrc.indexOf('.over.') == -1) {
theTD.children[0].src=oldSrc.substring(0, oldSrc.length-4) + ".over.gif";
}
}
}
function FTB_ButtonOut(theTD,editorname,imageOver,imageDown) {
FTB_SetButtonStyle(theTD,FTB_GetCssID(editorname)+'_ButtonNormal',null);
document.body.style.cursor = 'default';
theTD.background='';
if(theTD.children.length && theTD.children[0].tagName == "IMG"){
oldSrc = theTD.children[0].src;
if (oldSrc.indexOf('.over.') > 0) {
theTD.children[0].src=oldSrc.substring(0, oldSrc.length-9) + ".gif";
}
if (oldSrc.indexOf('.down.') > 0) {
theTD.children[0].src=oldSrc.substring(0, oldSrc.length-9) + ".gif";
}
}
}
function FTB_ButtonDown(theTD,editorname,imageOver,imageDown) {
document.body.style.cursor = 'default';
FTB_SetButtonStyle(theTD,FTB_GetCssID(editorname)+'_ButtonDown',null);
if (eval(editorname+'_DownImage').src != '') theTD.background=eval(editorname+'_DownImage').src;
if(theTD.children.length && theTD.children[0].tagName == "IMG" && imageDown == 1){
oldSrc = theTD.children[0].src;
if (oldSrc.indexOf('.over.') > 0) {
theTD.children[0].src=oldSrc.substring(0, oldSrc.length-9) + ".down.gif";
}
}
}
function FTB_ButtonUp(theTD,editorname,imageOver,imageDown) {
document.body.style.cursor = 'auto';
FTB_SetButtonStyle(theTD,FTB_GetCssID(editorname)+'_ButtonOver',null);
if (eval(editorname+'_OverImage').src != '') theTD.background=eval(editorname+'_OverImage').src;
if(theTD.children.length && theTD.children[0].tagName == "IMG" && imageOver == 1){
oldSrc = theTD.children[0].src;
if (oldSrc.indexOf('.over.') == -1) {
theTD.children[0].src=oldSrc.substring(0, oldSrc.length-4) + ".over.gif";
}
}
}
function FTB_SetActiveTab(theTD,editorname) {
parentTR = theTD.parentElement;
selectedTab = 1;
totalButtons = parentTR.cells.length-1;
for (var i=1;i< totalButtons;i++) {
parentTR.cells[i].className = FTB_GetCssID(editorname) + "_TabOffRight";
if (theTD == parentTR.cells[i]) { selectedTab = i; }
}
if (selectedTab==1) {
parentTR.cells[0].className = FTB_GetCssID(editorname) + "_StartTabOn";
} else {
parentTR.cells[0].className = FTB_GetCssID(editorname) + "_StartTabOff";
parentTR.cells[selectedTab-1].className = FTB_GetCssID(editorname) + "_TabOffLeft";
}
theTD.className = FTB_GetCssID(editorname) + "_TabOn";
}
function FTB_TabOver() {
document.body.style.cursor='default';
}
function FTB_TabOut() {
document.body.style.cursor='auto';
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -