📄 editorfunction.js
字号:
var htmlModeFlag = false;
function InitDocument()
{
editContent.document.designMode = "On";
editContent.document.open();
editContent.document.write('<html><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"></head><body></body></html>');
editContent.document.close();
}
function doCommand(comm,value)
{
if(comm == "copy" && editContent.document.selection.createRange().text == "")
{
alert("Please select text!");
return;
}
if (value == null || value == "")
editContent.document.execCommand(comm);
else
editContent.document.execCommand(comm,"",value);
editContent.focus();
}
function doCommandAfterCheck(comm,value)
{
if(!checkHtmlMode())
return;
else
doCommand(comm,value);
}
function htmlMode(flag)
{
if(flag)
{
var cont = editContent.document.body.innerHTML;
editContent.document.body.innerText = cont;
htmlModeFlag = true;
}
else
{
var cont = editContent.document.body.innerText;
editContent.document.body.innerHTML = cont;
htmlModeFlag = false;
}
}
function insertLink()
{
if (!checkHtmlMode())
return;
if(editContent.document.selection.createRange().text == "")
{
alert("Please select text!");
return;
}
editContent.document.execCommand('CreateLink');
htmlModeFlag = false;
editContent.focus();
}
function insertTable()
{
if (!checkHtmlMode())
return;
var arr = showModalDialog("editorFiles/insertTable.html", "", "dialogWidth: 212px; dialogHeight: 160px; status:0");
if (arr != null)
{
var arr_tmp;
arr_tmp = arr.split("*");
row = arr_tmp[0];
col = arr_tmp[1];
var string = "<table border=1>";
for(i = 1; i <= row; i++)
{
string = string + "<tr>";
for(j = 1; j <= col; j++)
{
string = string + "<td></td>";
}
string = string + "</tr>";
}
string = string+"</table>";
content = editContent.document.body.innerHTML;
content = content + string;
editContent.document.body.innerHTML = content;
}
else
{
editContent.focus();
}
}
function insertFlash()
{
var retval = window.prompt('Please enter the location','http://');
if(retval != null && retval != 'undefined')
{
editContent.document.write("<embed src='"+retval+"' type='application/x-shockwave-flash'></embed>");
}
}
function insertImage()
{
var arr = showModalDialog("ImageUploadForm.jsp", window, "dialogWidth:420px;dialogHeight:180px;status:no;");
if(arr != null)
{
//alert(arr);
editContent.document.execCommand('InsertImage','',arr);
//var old_content = editContent.document.body.innerHTML;
//editContent.document.body.innerHTML = old_content + '<img src="' + arr + '" border="0" />';
}
editContent.focus();
return;
}
function checkHtmlMode()
{
if(!htmlModeFlag)
return true;
alert("Please cancel HTML view!");
editContent.focus();
return false;
}
// bold
function strongFont()
{
if(!checkHtmlMode())
return;
if(editContent.document.selection.createRange().text == "")
{
alert("Please select text!");
return;
}
editContent.document.execCommand("bold");
editContent.focus();
}
// italic
function italicFont()
{
if(!checkHtmlMode())
return;
if(editContent.document.selection.createRange().text == "")
{
alert("Please select text!");
return;
}
editContent.document.execCommand("italic");
editContent.focus();
}
// left align
function alignLeft()
{
if(!checkHtmlMode())
return;
editContent.document.execCommand("justifyleft");
editContent.focus();
}
// center align
function alignCenter()
{
if(!checkHtmlMode())
return;
editContent.document.execCommand("justifycenter");
editContent.focus();
}
// right align
function alignRight()
{
if(!checkHtmlMode())
return;
editContent.document.execCommand("justifyright");
editContent.focus();
}
// list
function insertOrderList()
{
if(!checkHtmlMode())
return;
editContent.document.execCommand("insertorderedlist");
editContent.focus();
}
// list 2
function insertUnorderList()
{
if(!checkHtmlMode())
return;
editContent.document.execCommand("insertunorderedlist");
editContent.focus();
}
// outdent
function outDent()
{
if(!checkHtmlMode())
return;
editContent.document.execCommand("outdent");
editContent.focus();
}
// indent
function inDent()
{
if(!checkHtmlMode())
return;
editContent.document.execCommand("indent");
editContent.focus();
}
// text color
function setColor()
{
if(!checkHtmlMode())
return;
if(editContent.document.selection.createRange().text == "")
{
alert("Please select text!");
return;
}
var arr = showModalDialog("editorFiles/color.htm", "", "dialogWidth:18.5em; dialogHeight:17em; status:0");
if (arr != null)
editContent.document.execCommand("forecolor","",arr);
else
editContent.focus();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -