?? editor.js
字號(hào):
/*
*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆
*★ ★
*☆ eWebEditor - eWebSoft在線編輯器 ☆
*★ ★
*☆ 版權(quán)所有: eWebSoft.com ☆
*★ ★
*☆ 程序制作: eWeb開發(fā)團(tuán)隊(duì) ☆
*★ email:webmaster@webasp.net ★
*☆ QQ:589808 ☆
*★ ★
*☆ 相關(guān)網(wǎng)址: [產(chǎn)品介紹]http://www.eWebSoft.com/Product/eWebEditor/ ☆
*★ [支持論壇]http://bbs.eWebSoft.com/ ★
*☆ ☆
*★ 主頁地址: http://www.eWebSoft.com/ eWebSoft團(tuán)隊(duì)及產(chǎn)品 ★
*☆ http://www.webasp.net/ WEB技術(shù)及應(yīng)用資源網(wǎng)站 ☆
*★ http://bbs.webasp.net/ WEB技術(shù)交流論壇 ★
*★ ★
*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆
*/
// 當(dāng)前模式
var sCurrMode = null;
var bEditMode = null;
// 連接對象
var oLinkField = null;
// 瀏覽器版本檢測
var BrowserInfo = new Object() ;
BrowserInfo.MajorVer = navigator.appVersion.match(/MSIE (.)/)[1] ;
BrowserInfo.MinorVer = navigator.appVersion.match(/MSIE .\.(.)/)[1] ;
BrowserInfo.IsIE55OrMore = BrowserInfo.MajorVer >= 6 || ( BrowserInfo.MajorVer >= 5 && BrowserInfo.MinorVer >= 5 ) ;
var yToolbars = new Array(); // 工具欄數(shù)組
// 當(dāng)文檔完全調(diào)入時(shí),進(jìn)行初始化
var bInitialized = false;
function document.onreadystatechange(){
if (document.readyState!="complete") return;
if (bInitialized) return;
bInitialized = true;
var i, s, curr;
// 初始每個(gè)工具欄
for (i=0; i<document.body.all.length;i++){
curr=document.body.all[i];
if (curr.className == "yToolbar"){
InitTB(curr);
yToolbars[yToolbars.length] = curr;
}
}
oLinkField = parent.document.getElementsByName(sLinkFieldName)[0];
// IE5.5以下版本只能使用純文本模式
if (!BrowserInfo.IsIE55OrMore){
config.InitMode = "TEXT";
}
if (ContentFlag.value=="0") {
ContentEdit.value = oLinkField.value;
ContentLoad.value = oLinkField.value;
ModeEdit.value = config.InitMode;
ContentFlag.value = "1";
}
setMode(ModeEdit.value);
setLinkedField() ;
}
// 初始化一個(gè)工具欄上的按鈕
function InitBtn(btn) {
btn.onmouseover = BtnMouseOver;
btn.onmouseout = BtnMouseOut;
btn.onmousedown = BtnMouseDown;
btn.onmouseup = BtnMouseUp;
btn.ondragstart = YCancelEvent;
btn.onselectstart = YCancelEvent;
btn.onselect = YCancelEvent;
btn.YUSERONCLICK = btn.onclick;
btn.onclick = YCancelEvent;
btn.YINITIALIZED = true;
return true;
}
//Initialize a toolbar.
function InitTB(y) {
// Set initial size of toolbar to that of the handle
y.TBWidth = 0;
// Populate the toolbar with its contents
if (! PopulateTB(y)) return false;
// Set the toolbar width and put in the handle
y.style.posWidth = y.TBWidth;
return true;
}
// Hander that simply cancels an event
function YCancelEvent() {
event.returnValue=false;
event.cancelBubble=true;
return false;
}
// Toolbar button onmouseover handler
function BtnMouseOver() {
if (event.srcElement.tagName != "IMG") return false;
var image = event.srcElement;
var element = image.parentElement;
// Change button look based on current state of image.
if (image.className == "Ico") element.className = "BtnMouseOverUp";
else if (image.className == "IcoDown") element.className = "BtnMouseOverDown";
event.cancelBubble = true;
}
// Toolbar button onmouseout handler
function BtnMouseOut() {
if (event.srcElement.tagName != "IMG") {
event.cancelBubble = true;
return false;
}
var image = event.srcElement;
var element = image.parentElement;
yRaisedElement = null;
element.className = "Btn";
image.className = "Ico";
event.cancelBubble = true;
}
// Toolbar button onmousedown handler
function BtnMouseDown() {
if (event.srcElement.tagName != "IMG") {
event.cancelBubble = true;
event.returnValue=false;
return false;
}
var image = event.srcElement;
var element = image.parentElement;
element.className = "BtnMouseOverDown";
image.className = "IcoDown";
event.cancelBubble = true;
event.returnValue=false;
return false;
}
// Toolbar button onmouseup handler
function BtnMouseUp() {
if (event.srcElement.tagName != "IMG") {
event.cancelBubble = true;
return false;
}
var image = event.srcElement;
var element = image.parentElement;
if (element.YUSERONCLICK) eval(element.YUSERONCLICK + "anonymous()");
element.className = "BtnMouseOverUp";
image.className = "Ico";
event.cancelBubble = true;
return false;
}
// Populate a toolbar with the elements within it
function PopulateTB(y) {
var i, elements, element;
// Iterate through all the top-level elements in the toolbar
elements = y.children;
for (i=0; i<elements.length; i++) {
element = elements[i];
if (element.tagName == "SCRIPT" || element.tagName == "!") continue;
switch (element.className) {
case "Btn":
if (element.YINITIALIZED == null) {
if (! InitBtn(element)) {
alert("Problem initializing:" + element.id);
return false;
}
}
element.style.posLeft = y.TBWidth;
y.TBWidth += element.offsetWidth + 1;
break;
case "TBGen":
element.style.posLeft = y.TBWidth;
y.TBWidth += element.offsetWidth + 1;
break;
case "TBSep":
element.style.posLeft = y.TBWidth + 2;
y.TBWidth += 5;
break;
case "TBHandle":
element.style.posLeft = 2;
y.TBWidth += element.offsetWidth + 7;
break;
default:
alert("Invalid class: " + element.className + " on Element: " + element.id + " <" + element.tagName + ">");
return false;
}
}
y.TBWidth += 1;
return true;
}
// 設(shè)置所屬表單的提交或reset事件
function setLinkedField() {
if (! oLinkField) return ;
var oForm = oLinkField.form ;
if (!oForm) return ;
// 附加submit事件
oForm.attachEvent("onsubmit", AttachSubmit) ;
if (! oForm.submitEditor) oForm.submitEditor = new Array() ;
oForm.submitEditor[oForm.submitEditor.length] = AttachSubmit ;
if (! oForm.originalSubmit) {
oForm.originalSubmit = oForm.submit ;
oForm.submit = function() {
if (this.submitEditor) {
for (var i = 0 ; i < this.submitEditor.length ; i++) {
this.submitEditor[i]() ;
}
}
this.originalSubmit() ;
}
}
// 附加reset事件
oForm.attachEvent("onreset", AttachReset) ;
if (! oForm.resetEditor) oForm.resetEditor = new Array() ;
oForm.resetEditor[oForm.resetEditor.length] = AttachReset ;
if (! oForm.originalReset) {
oForm.originalReset = oForm.reset ;
oForm.reset = function() {
if (this.resetEditor) {
for (var i = 0 ; i < this.resetEditor.length ; i++) {
this.resetEditor[i]() ;
}
}
this.originalReset() ;
}
}
}
// 附加submit提交事件,大表單數(shù)據(jù)提交,遠(yuǎn)程文件獲取,保存eWebEditor中的內(nèi)容
function AttachSubmit() {
var oForm = oLinkField.form ;
if (!oForm) return;
var html = getHTML();
ContentEdit.value = html;
if (sCurrMode=="TEXT"){
html = HTMLEncode(html);
}
splitTextField(oLinkField, html);
}
// 提交表單
function doSubmit(){
var oForm = oLinkField.form ;
if (!oForm) return ;
oForm.submit();
}
// 附加Reset事件
function AttachReset() {
if(bEditMode){
eWebEditor.document.body.innerHTML = ContentLoad.value;
}else{
eWebEditor.document.body.innerText = ContentLoad.value;
}
}
// 顯示幫助
function onHelp(){
ShowDialog('dialog/help.htm','400','300');
return false;
}
// 粘貼時(shí)自動(dòng)檢測是否來源于Word格式
function onPaste() {
if (sCurrMode=="VIEW") return false;
if (sCurrMode=="EDIT"){
var sHTML = GetClipboardHTML() ;
if (config.AutoDetectPasteFromWord && BrowserInfo.IsIE55OrMore) {
var re = /<\w[^>]* class="?MsoNormal"?/gi ;
if ( re.test(sHTML)){
if ( confirm( "你要粘貼的內(nèi)容好象是從Word中拷出來的,是否要先清除Word格式再粘貼?" ) ){
cleanAndPaste( sHTML ) ;
return false ;
}
}
}
eWebEditor.document.selection.createRange().pasteHTML(sHTML) ;
return false;
}else{
eWebEditor.document.selection.createRange().pasteHTML(HTMLEncode( clipboardData.getData("Text"))) ;
return false;
}
}
// 快捷鍵
function onKeyDown(event){
var key = String.fromCharCode(event.keyCode).toUpperCase();
// F2:顯示或隱藏指導(dǎo)方針
if (event.keyCode==113){
showBorders();
return false;
}
if (event.ctrlKey){
// Ctrl+Enter:提交
if (event.keyCode==10){
doSubmit();
return false;
}
// Ctrl++:增加編輯區(qū)
if (key=="+"){
sizeChange(300);
return false;
}
// Ctrl+-:減小編輯區(qū)
if (key=="-"){
sizeChange(-300);
return false;
}
// Ctrl+1:代碼模式
if (key=="1"){
setMode("CODE");
return false;
}
// Ctrl+2:設(shè)計(jì)模式
if (key=="2"){
setMode("EDIT");
return false;
}
// Ctrl+3:純文本
if (key=="3"){
setMode("TEXT");
return false;
}
// Ctrl+4:預(yù)覽
if (key=="4"){
setMode("VIEW");
return false;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -