?? editor.js
字號:
var IsEdited = false;
var EditorId = 0;
var EditorSrc = "/htmleditorQQ/html_editor.htm";
var editorbtnid = "editorbtn";
var htmleditorid = "htmlcontent";
var texteditorid = "content";
var textcontainerid = "container";
var sourceid = "source";
var contenttypeid = "contenttype";
function IniEditorVar(editorbtn_id, htmleditor_id, texteditor_id,
textcontainer_id, source_id, contenttype_id)
{
editorbtnid = editorbtn_id;
htmleditorid = htmleditor_id;
texteditorid = texteditor_id;
textcontainerid = textcontainer_id;
sourceid = source_id;
contenttypeid = contenttype_id;
}
//add by angus 2006-10-10
function TextToHtml(content) {
//the attr of innerHTML in firefox is diff in ie
if (content.indexOf("<BR>") >= 0) {
var re = /<BR>/ig;
}
else {
var re = /\n/g;
}
var res = "<DIV>" + content.replace(re, "</DIV><DIV>") + "</DIV>";
res = res.replace(/ /ig, " ");
return res.replace(/<DIV><\/DIV>/ig, "<DIV> </DIV>");
}
//function for firefox
function HtmlToText(content) {
//manal change div,p,br
var res = content.replace(/<\/div>/ig, "\n");
res = res.replace(/<\/p>/ig, "\n");
return res.replace(/<br*.>/ig, "\n");;
}
function ChangeEditor() {
if (EditorId != 0) {
// if (!window.confirm("某些格式有可能丟失,您確定嗎?"))
// return;
// 不用提示 - nico
EditorId = 1;
}
try{SyncContent(0);}catch (e){}
EditorId = (EditorId == 0 ? 1 : 0);
var htmlctl = S(htmleditorid);
if(EditorId==0)
{
window.frames[htmleditorid].document.getElementById("tmp").focus();
//return;
}
var commctl = S(textcontainerid);
var ids = [ "editor1","editor2",textcontainerid,htmleditorid];
var bitMap = [[1,0,1,0],[0,1,0,1]][(EditorId==0)?0:1];
for(var i=0;i<ids.length;i++)
{
S(ids[i]).style.display = bitMap[i]?"":"none";
}
if (EditorId == 0) {
commctl.focus();
}
else {
//for firefox
if (htmlctl.src.indexOf(EditorSrc) < 0) {
htmlctl.src = EditorSrc;
return ;
}
}
}
function ChangeHtmlEditor()
{
if(EditorId == 0)
{
ChangeEditor();
}
}
function SetIsEdited()
{
IsEdited = true;
}
function UpdateHtml() {
var htmlEditor = F(htmleditorid);
var sourceCtl = S(sourceid);
if (!IsEdited) {
htmlEditor.PutContents(sourceCtl.innerHTML == "" ? "<DIV> </DIV>" : sourceCtl.innerHTML);
IsEdited = true;
}
else {
var contents = S(texteditorid).value;
if (sourceCtl.innerText != null) {
sourceCtl.innerText = contents;
}
else {
sourceCtl.textContent = contents;
}
htmlEditor.PutContents(TextToHtml(sourceCtl.innerHTML));
}
}
function UpdateText() {
var htmlEditor = F(htmleditorid);
var sourceCtl = S(sourceid);
var textEditor = S(texteditorid);
var ct = htmlEditor.GetContents();
if (sourceCtl.innerText != null) {
try{
sourceCtl.innerHTML = ct;
ct = sourceCtl.innerText;
}
catch(e){ct = htmlEditor.GetPlainContents();}
}
else {
try {
sourceCtl.innerHTML = HtmlToText(ct);
ct = sourceCtl.textContent;
}
catch (e){ct = htmlEditor.GetPlainContents();}
}
textEditor.value = ct;
}
//使得兩個地方內容都一致
function SyncContent(mode) {
var ct = S(contenttypeid);
//用戶使用純文本編輯器
if(EditorId == 0) {
ct.value = "text";
try{UpdateHtml();}catch(e){}
}
//其余都認為使用多媒體編輯器
else {
//模式1為以html值同步
ct.value = "html";
if (mode == 1) {
try{
S(texteditorid).value = F(htmleditorid).GetContents();
}catch(e){}
}
else {
UpdateText();
}
}
}
function OnSend()
{
if(S(contenttypeid).value == "html")
{
if( S("content").value.indexOf("<QQMAILSTATIONERY>") > -1)
{
S("content").value = S("content").value.replace(/<QQMAILSTATIONERY>/g,"");
}
}
}
function HtmlEditor_Onload() {
setTimeout("try{UpdateHtml();}catch(e){}", 100);
}
function IsEditorEmpty()
{
SyncContent(0);
var content = S(sourceid).innerText;
var tmp = content.replace(/ /g, "");
tmp = tmp.replace(/\n/g, "");
if (tmp == "") {
return true;
}
return false;
}
// =======stationery
function UseStationery()
{
ChangeHtmlEditor();
ChangeTab("stationery_div");
if(S("stationery").src !="/htmledition/stationery.html")
{
setTimeout('S("stationery").src="/htmledition/stationery.html";',10); //for ie5
}
}
function ChangeTab(sName)
{
var ids = ["AddrTab","stationery_div"];
var tabHeads = ["addr_cmd","stationery_cmd"];
var classes = ["cptab","cptab cpslt"];
for(var i=0,len=ids.length;i<len;i++)
{
var el = S(ids[i]);
if(el)
{
var idx = (sName == ids[i])?1:0;
S(tabHeads[i]).className = classes[idx];
el.style.display = idx?"":"none";
}
}
}
function ShowInputCtrl(sName,bNotFocus)
{
var tr = S("tr" + sName);
var aHref = S("a" + sName);
var nAction = (tr.style.display == "")?0:1; //如果顯示則隱藏如果隱藏則顯示
var arrData = ["CC","抄送","BCC","密送"];
var sTitle = "";
for(var i=0;i<arrData.length;i+=2)
{
if( arrData[i] == sName)
{
sTitle = arrData[i+1];
break;
}
}
sName = sName.toLowerCase();
sTitle = ["添加","刪除"][nAction] + sTitle;
aHref.innerHTML = sTitle;
tr.style.display = ["none",""][nAction];
if(nAction == 0)
{
S(sName).value = "";
}
else if( null == bNotFocus)
{
S(sName).focus();
}
}
function IsEditorEmpty()
{
SyncContent(0);
var content = S(sourceid).innerText;
var tmp = content.replace(/ /g, "");
tmp = tmp.replace(/\n/g, "");
if (tmp == "") {
return true;
}
return false;
}
function IsExitEditor()
{
if (!IsEditorEmpty() && !confirm("確實要離開該頁面嗎?\n如果離開該頁面,您的內容將會丟失。"))
{
return false;
}
return true;
}
//======== added by sunny base func========
function GetDoc(win){ return (win?win:window).document;}
function GetOwnerDoc(obj)
{
return obj.ownerDocument?obj.ownerDocument:obj.document;
}
function S(i,win) {return GetDoc(win).getElementById(i);};
function F(sID,win)
{
if( sID == "" || sID == null ) return null;
var frame = S(sID,win);
if( !frame) return null;
return frame.contentWindow?frame.contentWindow:(win?win:window).frames[sID];
}
function SN(i,win) {return GetDoc(win).getElementsByName(i);}
//add by angusdu 061103
function AddrSort(type) {
var p = Gel("quickaddr");
var py = Gel("pybtn");
var freq = Gel("freqbtn");
var s = "/cgi-bin/addressbook/addr_listall?templatename=quickaddr.html&";
if (type == 0) {
p.src = s + "sorttype=PinYin";
//py.style.display = "none";
//freq.style.display = "";
}
else {
p.src = s + "sorttype=Freq&subtmpl=AutoComplete";
//py.style.display = "";
//freq.style.display = "none";
}
var dat = [[1,0,0,1],[0,1,1,0]][type];
for(var i=0;i<4;i++)
{
Gel("addr_sort_"+i).style.display = dat[i]?"":"none";
}
}
var sysCtls = new Array("to", "cc", "bcc", "subject", "content");
var userVals = new Array("", "", "", "", "");
var needSave = false;
var enableAS = true;
function EnableAutoSave(enable) {
enableAS = enable;
}
function IsNeedSave(isNeed) {
needSave = isNeed;
}
function ShowProcess(isShow, msg) {
Gel("autosave_txt").innerText = msg;
Gel("load_img").style.display = (isShow ? "" : "none");
}
function LoadValue() {
SyncContent(1);
for (var i = userVals.length - 1; i >= 0; i--) {
var tmp = Gel(sysCtls[i]).value;
if (tmp != userVals[i]){
userVals[i] = tmp;
// alert(userVals[i]);
IsNeedSave(true);
}
}
}
function AutoSave(enable) {
LoadValue();
if (needSave && enable && enableAS) {
DoProcess("autosave", "save");
}
IsNeedSave(false);
setTimeout("AutoSave(true);", 120000);
}
function DoProcess(template, action) {
try {
SyncContent(1);
var vfrm = Gel("frm");
try{vfrm.templatename.value = template;}catch(e){}
vfrm.actiontype.value = action;
if (action == "send") {
DisableAll(true);
try{OnSend();}catch(e){}
ShowProcess(true, msgSend);
}
else {
if (template == "savedraft") {
DisableAll(true);
ShowProcess(true, msgAutoSave);
}
else {
ShowProcess(true, msgSave);
}
}
vfrm.submit();
}
catch (e) {
DisableAll(false);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -