📄 textedit.htc
字号:
oDiv.innerHTML = "";
//var oTextRange = document.body.createTextRange() ;
//oTextRange.moveToElementText(oDiv) ;
oDiv.execCommand("Paste") ;
var sData = oDiv.innerHTML ;
alert(oDiv.innerHTML);
oDiv.innerHTML = "" ;
return sData ;*/
}
function cleanAndPaste( html ) {
alert("31");
// Remove all SPAN tags
html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
// Remove Class attributes
html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove Style attributes
html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
// Remove Lang attributes
html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove XML elements and declarations
html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
// Remove Tags with XML namespace declarations: <o:p></o:p>
html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
// Replace the
html = html.replace(/ /, " " );
// Transform <P> to <DIV>
var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ; // Different because of a IE 5.0 error
html = html.replace( re, "<div$2</div>" ) ;
insertHTML( html ) ;
}
// 在当前文档位置插入.
function insertHTML(html) {
alert("1");
if (!validateMode()) return;
if (eWebEditor.document.selection.type.toLowerCase() != "none")
eWebEditor.document.selection.clear() ;
eWebEditor.document.selection.createRange().pasteHTML(html) ;
}
// 设置编辑器的内容
function setHTML(html) {
alert("2");
if (!validateMode()) return;
ContentEdit.value = html;
if(bEditMode){
eWebEditor.document.body.innerHTML = html;
}else{
eWebEditor.document.body.innerText = html;
}
}
// 取编辑器的内容
function getHTML() {
var html;
if(bEditMode){
html = eWebEditor.document.body.innerHTML;
}
else{
html = eWebEditor.document.body.innerText;
}
var re = new RegExp(sBaseUrl.replace(/\//,"\/"),"gi");
html = html.replace(re, "");
if ((html.toLowerCase()=="<p> </p>")||(html.toLowerCase()=="<p></p>")){
html = "";
}
alert(html);
return html;
}
// 在尾部追加内容
function appendHTML(html) {
alert("3");
if (!validateMode()) return;
if(bEditMode){
eWebEditor.document.body.innerHTML += html;
}else{
eWebEditor.document.body.innerText += html;
}
}
// 从Word中粘贴,去除格式
function PasteWord(){
alert("4");
if (!validateMode()) return;
eWebEditor.focus();
if (BrowserInfo.IsIE55OrMore)
cleanAndPaste( GetClipboardHTML() ) ;
else if ( confirm( "此功能要求IE5.5版本以上,你当前的浏览器不支持,是否按常规粘贴进行?" ) )
format("paste") ;
eWebEditor.focus();
}
// 粘贴纯文本
function PasteText(){
alert("5");
if (!validateMode()) return;
eWebEditor.focus();
var sText = HTMLEncode( clipboardData.getData("Text") ) ;
insertHTML(sText);
eWebEditor.focus();
}
// 检测当前是否允许编辑
function validateMode() {
if (bEditMode) return true;
alert("需转换为编辑状态后才能使用编辑功能!");
eWebEditor.focus();
return false;
}
// 格式化编辑器中的内容
function format(what,opt) {
if (!validateMode()) return;
eWebEditor.focus();
if (opt=="RemoveFormat") {
what=opt;
opt=null;
}
if (opt==null) eWebEditor.document.execCommand(what);
else eWebEditor.document.execCommand(what,"",opt);
eWebEditor.focus();
}
// 确保焦点在 eWebEditor 内
function VerifyFocus() {
if ( eWebEditor )
eWebEditor.focus();
}
// 改变模式:代码、编辑、预览
function setMode(NewMode){
if (NewMode!=sCurrMode){
var sBody = "";
switch(sCurrMode){
case "CODE":
sBody = eWebEditor.document.body.innerText;
break;
case "EDIT":
case "VIEW":
sBody = eWebEditor.document.body.innerHTML;
break;
default:
sBody = ContentEdit.value;
break;
}
// 换图片
try{
objCode.className = "StatusBarBtnOff";
objEdit.className = "StatusBarBtnOff";
objPreview.className = "StatusBarBtnOff";
if(NewMode == "EDIT"){ objEdit.className = "StatusBarBtnOn";}
else if(NewMode == "VIEW"){ objPreview.className = "StatusBarBtnOn";}
else {objCode.className = "StatusBarBtnOn";}
}
catch(e){
}
// 换内容
switch (NewMode){
case "CODE":
eWebEditor.document.designMode="On";
eWebEditor.document.open();
eWebEditor.document.write(config.StyleEditorHeader);
eWebEditor.document.body.innerText=sBody;
eWebEditor.document.body.contentEditable="true";
//eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);");
eWebEditor.document.oncontextmenu=new Function("return false;");
eWebEditor.document.close();
bEditMode=false;
break;
case "EDIT":
eWebEditor.document.designMode="On";
eWebEditor.document.open();
eWebEditor.document.write(config.StyleEditorHeader);
eWebEditor.document.body.innerHTML=sBody;
eWebEditor.document.body.contentEditable="true";
//eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);");
eWebEditor.document.oncontextmenu=new Function("return false;");
eWebEditor.document.execCommand("2D-Position",true,true);
eWebEditor.document.execCommand("MultipleSelection", true, true);
eWebEditor.document.execCommand("LiveResize", true, true);
eWebEditor.document.close();
doZoom(nCurrZoomSize);
bEditMode=true;
break;
case "VIEW":
eWebEditor.document.designMode="off";
eWebEditor.document.open();
eWebEditor.document.write(config.StyleEditorHeader+sBody);
eWebEditor.document.body.contentEditable="false";
eWebEditor.document.close();
bEditMode=false;
break;
}
sCurrMode=NewMode;
disableChildren(eWebEditor_Toolbar);
if ((borderShown != "no")&&bEditMode) {
borderShown = "no";
showBorders()
}
}
eWebEditor.focus();
}
// 使工具栏无效
function disableChildren(obj){
if (obj){
obj.disabled=(!bEditMode);
for (var i=0; i < obj.children.length; i++){
disableChildren(obj.children[i]);
}
}
}
// 显示无模式对话框
function ShowDialog(url, width, height, optValidate) {
if (optValidate) {
if (!validateMode()) return;
}
objeWebEditor.focus();
var arr = window.showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
format('ForeColor',arr);
//objeWebEditor.focus();
}
// 显示无模式对话框
function ShowDialog_backcolor(url, width, height, optValidate) {
if (optValidate) {
if (!validateMode()) return;
}
objeWebEditor.focus();
var arr = window.showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
format('backcolor',arr);
//objeWebEditor.focus();
}
// 全屏编辑
function Maximize() {
alert("12");
if (!validateMode()) return;
window.open("dialog/fullscreen.htm?style="+config.StyleName, 'FullScreen'+sLinkFieldName, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,fullscreen=yes');
}
// 替换特殊字符
function HTMLEncode(text){
alert("13");
text = text.replace(/&/g, "&") ;
text = text.replace(/"/g, """) ;
text = text.replace(/</g, "<") ;
text = text.replace(/>/g, ">") ;
text = text.replace(/'/g, "’") ;
text = text.replace(/\ /g," ");
text = text.replace(/\n/g,"<br>");
text = text.replace(/\t/g," ");
return text;
}
// 插入特殊对象
function insert(what) {
alert("41");
if (!validateMode()) return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -