?? editor.js
字號:
return false;
}
}
switch(sCurrMode){
case "VIEW":
return true;
break;
case "EDIT":
if (event.ctrlKey){
// Ctrl+D:從Word粘貼
if (key == "D"){
PasteWord();
return false;
}
// Ctrl+R:查找替換
if (key == "R"){
findReplace();
return false;
}
// Ctrl+Z:Undo
if (key == "Z"){
goHistory(-1);
return false;
}
// Ctrl+Y:Redo
if (key == "Y"){
goHistory(1);
return false;
}
}
if(!event.ctrlKey && event.keyCode != 90 && event.keyCode != 89) {
if (event.keyCode == 32 || event.keyCode == 13){
saveHistory()
}
}
return true;
break;
default:
if (event.keyCode==13){
var sel = eWebEditor.document.selection.createRange();
sel.pasteHTML("<BR>");
event.cancelBubble = true;
event.returnValue = false;
sel.select();
sel.moveEnd("character", 1);
sel.moveStart("character", 1);
sel.collapse(false);
return false;
}
// 屏蔽事件
if (event.ctrlKey){
// Ctrl+B,I,U
if ((key == "B")||(key == "I")||(key == "U")){
return false;
}
}
}
}
// 取剪粘板中的HTML格式數據
function GetClipboardHTML() {
var oDiv = document.getElementById("eWebEditor_Temp_HTML")
oDiv.innerHTML = "" ;
var oTextRange = document.body.createTextRange() ;
oTextRange.moveToElementText(oDiv) ;
oTextRange.execCommand("Paste") ;
var sData = oDiv.innerHTML ;
oDiv.innerHTML = "" ;
return sData ;
}
// 清除WORD冗余格式并粘貼
function cleanAndPaste( html ) {
// 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) {
if (isModeView()) return false;
if (eWebEditor.document.selection.type.toLowerCase() != "none"){
eWebEditor.document.selection.clear() ;
}
if (sCurrMode!="EDIT"){
html=HTMLEncode(html);
}
eWebEditor.document.selection.createRange().pasteHTML(html) ;
}
// 設置編輯器的內容
function setHTML(html) {
ContentEdit.value = html;
switch (sCurrMode){
case "CODE":
eWebEditor.document.designMode="On";
eWebEditor.document.open();
eWebEditor.document.write(config.StyleEditorHeader);
eWebEditor.document.body.innerText=html;
eWebEditor.document.body.contentEditable="true";
eWebEditor.document.close();
bEditMode=false;
break;
case "EDIT":
eWebEditor.document.designMode="On";
eWebEditor.document.open();
eWebEditor.document.write(config.StyleEditorHeader+html);
eWebEditor.document.body.contentEditable="true";
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;
eWebEditor.document.onselectionchange = function () { doToolbar();}
break;
case "TEXT":
eWebEditor.document.designMode="On";
eWebEditor.document.open();
eWebEditor.document.write(config.StyleEditorHeader);
eWebEditor.document.body.innerText=html;
eWebEditor.document.body.contentEditable="true";
eWebEditor.document.close();
bEditMode=false;
break;
case "VIEW":
eWebEditor.document.designMode="off";
eWebEditor.document.open();
eWebEditor.document.write(config.StyleEditorHeader+html);
eWebEditor.document.body.contentEditable="false";
eWebEditor.document.close();
bEditMode=false;
break;
}
eWebEditor.document.body.onpaste = onPaste ;
eWebEditor.document.body.onhelp = onHelp ;
eWebEditor.document.onkeydown = new Function("return onKeyDown(eWebEditor.event);");
eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);");
if ((borderShown != "0")&&bEditMode) {
borderShown = "0";
showBorders();
}
initHistory();
}
// 取編輯器的內容
function getHTML() {
var html;
if((sCurrMode=="EDIT")||(sCurrMode=="VIEW")){
html = eWebEditor.document.body.innerHTML;
}else{
html = eWebEditor.document.body.innerText;
}
if (sCurrMode!="TEXT"){
if ((html.toLowerCase()=="<p> </p>")||(html.toLowerCase()=="<p></p>")){
html = "";
}
}
return html;
}
// 在尾部追加內容
function appendHTML(html) {
if (isModeView()) return false;
if(sCurrMode=="EDIT"){
eWebEditor.document.body.innerHTML += html;
}else{
eWebEditor.document.body.innerText += html;
}
}
// 從Word中粘貼,去除格式
function PasteWord(){
if (!validateMode()) return;
eWebEditor.focus();
if (BrowserInfo.IsIE55OrMore)
cleanAndPaste( GetClipboardHTML() ) ;
else if ( confirm( "此功能要求IE5.5版本以上,你當前的瀏覽器不支持,是否按常規粘貼進行?" ) )
format("paste") ;
eWebEditor.focus();
}
// 粘貼純文本
function PasteText(){
if (!validateMode()) return;
eWebEditor.focus();
var sText = HTMLEncode( clipboardData.getData("Text") ) ;
insertHTML(sText);
eWebEditor.focus();
}
// 檢測當前是否允許編輯
function validateMode() {
if (sCurrMode=="EDIT") return true;
alert("需轉換為編輯狀態后才能使用編輯功能!");
eWebEditor.focus();
return false;
}
// 檢測當前是否在預覽模式
function isModeView(){
if (sCurrMode=="VIEW"){
alert("預覽時不允許設置編輯區內容。");
return true;
}
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){
if (!BrowserInfo.IsIE55OrMore){
if ((NewMode=="CODE") || (NewMode=="EDIT") || (NewMode=="VIEW")){
alert("HTML編輯模式需要IE5.5版本以上的支持!");
return false;
}
}
if (NewMode=="TEXT"){
if (sCurrMode==ModeEdit.value){
if (!confirm("警告!切換到純文本模式會丟失您所有的HTML格式,您確認切換嗎?")){
return false;
}
}
}
var sBody = "";
switch(sCurrMode){
case "CODE":
if (NewMode=="TEXT"){
eWebEditor_Temp_HTML.innerHTML = eWebEditor.document.body.innerText;
sBody = eWebEditor_Temp_HTML.innerText;
}else{
sBody = eWebEditor.document.body.innerText;
}
break;
case "TEXT":
sBody = eWebEditor.document.body.innerText;
sBody = HTMLEncode(sBody);
break;
case "EDIT":
case "VIEW":
if (NewMode=="TEXT"){
sBody = eWebEditor.document.body.innerText;
}else{
sBody = eWebEditor.document.body.innerHTML;
}
break;
default:
sBody = ContentEdit.value;
break;
}
// 換圖片
try{
document.all["eWebEditor_CODE"].className = "StatusBarBtnOff";
document.all["eWebEditor_EDIT"].className = "StatusBarBtnOff";
document.all["eWebEditor_TEXT"].className = "StatusBarBtnOff";
document.all["eWebEditor_VIEW"].className = "StatusBarBtnOff";
document.all["eWebEditor_"+NewMode].className = "StatusBarBtnOn";
}
catch(e){
}
sCurrMode = NewMode;
ModeEdit.value = NewMode;
setHTML(sBody);
disableChildren(eWebEditor_Toolbar);
}
}
// 使工具欄無效
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;
}
eWebEditor.focus();
var arr = showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
eWebEditor.focus();
}
// 全屏編輯
function Maximize() {
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 createLink(){
if (!validateMode()) return;
if (eWebEditor.document.selection.type == "Control") {
var oControlRange = eWebEditor.document.selection.createRange();
if (oControlRange(0).tagName.toUpperCase() != "IMG") {
alert("鏈接只能是圖片或文本");
return;
}
}
ShowDialog("dialog/hyperlink.htm", 350, 170, true);
}
// 替換特殊字符
function HTMLEncode(text){
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;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -