📄 edit_source.js
字号:
var sHeader='<style>' +
'body {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px;}' +
'td { font-family: Verdana, Arial, Helvetica, sans-serif,"仿細明體";font-size: 11px; border-style: dotted; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}' +
'</style>' +
'<body >';
var bMode=true,sel=null
function bb2html() {
if (!Error_1()) return;
if(confirm('開始進行bbcode到html的轉換.\n\n選擇確定將只進行bbcode到html的轉換,選擇取消將同時進行html標籤的替換\n')){
idEdit.focus();
var html = document.all.SaveContent.value;
html = BBcode2Html(html,false);
document.all.SaveContent.value = html;
} else {
idEdit.focus();
var html = document.all.SaveContent.value;
html = BBcode2Html(html,true);
document.all.SaveContent.value = html;
}
}
function BBcode2Html(str,clearHtml) {
if(clearHtml == true) {
str = str.replace(/&/g,"&");
str = str.replace(/\"/g,""");
str = str.replace(/</g,"<");
str = str.replace(/>/g,">");
}
str = str.replace(/\r/g,"");
str = str.replace(/\n/g,"<BR>");
str = str.replace(/\[url=([^]]*)](.*?)\[\/url]/ig,"<a href=\"$1\" target=\"_blank\">$2</a>");
str = str.replace(/\[color=([^]]*)](.*?)\[\/color]/ig,"<font color=\"$1\">$2</font>");
str = str.replace(/\[email](.*?)\[\/email]/ig,"<a href=\"mailto:$1\">$1</a>");
str = str.replace(/\[email=([^]]*)](.*?)\[\/email]/ig,"<a href=\"mailto:$1\" >$2</a>");
str = str.replace(/\[img](.*?)\[\/img]/ig,"<img src=\"$1\" border=0>");
str = str.replace(/\[size=([^]]*)](.*?)\[\/size]/ig,"<font size=\"$1\">$2</font>");
str = str.replace(/\[font=([^]]*)](.*?)\[\/font]/ig,"<font face=\"$1\">$2</font>");
str = str.replace(/\[b](.*?)\[\/b]/ig,"<B>$1</B>");
str = str.replace(/\[i](.*?)\[\/i]/ig,"<I>$1</I>");
str = str.replace(/\[u](.*?)\[\/u]/ig,"<U>$1</U>");
str = str.replace(/ /g," ");
str = str.replace(/\r/g," ");
str = str.replace(/\[list]/gi,"<ul>");
str = str.replace(/\[list=1]/gi,"<ol type=1>");
str = str.replace(/\[list=a]/gi,"<ol type=a>");
str = str.replace(/\[list=A]/gi,"<ol type=A>");
str = str.replace(/\[\/list]/gi,"</ul></ol>");
str = str.replace(/\[\*\]/g,"<li>");
return str;
}
function EditLoad(data) {
if (data!=null) data=data.replace(/&/ig,'&');
else data='';
bLoad=true;
EditContent.document.designMode="On";
idEdit = EditContent
idEdit.document.open()
idEdit.document.write(sHeader+data)
idEdit.document.close()
idEdit.focus();
}
function Word_Clean(editor,htmlmode) {
/*
str=idEdit.document.all.tags("BODY")[0].innerHTML;
//CUT/ len=sHeader.length;
//CUT/ len=len+62;
//CUT/ x = str.length;
//CUT/ x=x-len-7;
//document.write("The field named "+ sHeader.length +" has value of ");
//CUT/ document.all.SaveContent.value=str.substr(len,x)
document.all.SaveContent.value=str
idEdit.document.body.innerText=getPureHtml(idEdit.document.body.innerHTML);
**/
idEdit.focus();
// 0bject based cleaning
var body = idEdit.document.body;
for (var index = 0; index < body.all.length; index++) {
tag = body.all[index];
//if (tag.Attribute["className"].indexOf("mso") > -1)
tag.removeAttribute("className","",0);
tag.removeAttribute("style","",0);
}
// Regex based cleaning
var html = idEdit.document.body.innerHTML;
html = html.replace(/<o:p> <\/o:p>/g, "");
html = html.replace(/o:/g, "");
html = html.replace(/<st1:.*?>/g, "");
// Final clean up of empty tags
html = html.replace(/<font>/g, "");
html = html.replace(/<span>/g, "");
idEdit.document.body.innerHTML = html;
}
function insertimg(){
if (!Error()) return;
//ab=window.prompt("請輸入圖片的鏈接地址:","http://");
Today = new Date();
newName=Today.valueOf();
url="editor/js/img.php?cId=" + document.content.cId.value + "&newName=" + newName;
ab=showModalDialog(url,"color","dialogWidth:477pt;dialogHeight:240pt;help:0;status:0");
if (ab!="") {
var sel,RangeType
sel = idEdit.document.selection.createRange();
sel.pasteHTML( ab );
sel.select();
}
idEdit.focus();
}
function Error() {
if (bMode) return true;
alert("請選擇「編輯狀態」選項,才能使用系統編輯功能!");
idEdit.focus();
return false;
}
function Error_1() {
if (!bMode) return true;
alert("請選擇「源代碼」選項,才能使用bbcode轉換html功能!");
idEdit.focus();
return false;
}
function format(what,opt) {
if (!Error()) return;
if (opt=="removeFormat"){
what=opt;opt=null
}
if (opt==null) idEdit.document.execCommand(what)
else idEdit.document.execCommand(what,"",opt)
idEdit.focus()
sel=null
}
function getEl(sTag,start) {
while ((start!=null) && (start.tagName!=sTag))
start = start.parentElement
return start
}
function create(what) {
if (!Error()) return;
idEdit.document.execCommand(what, true);
idEdit.focus()
}
function specialtype(Mark){
if (!Error()) return;
var sel,RangeType
sel = idEdit.document.selection.createRange();
RangeType = idEdit.document.selection.type;
if (RangeType == "Text"){
sel.pasteHTML("<" + Mark + ">" + sel.text + "</" + Mark + ">");
sel.select();
}
idEdit.focus();
}
function forecolor() {
if (!Error()) return;
var arr = showModalDialog("editor/js/color.htm","color","dialogWidth:200pt;dialogHeight:175pt;help:0;status:0");
if (arr != null) format('forecolor',arr);
else idEdit.focus();
}
//***************************************************
function inSinglephoto(){
if (!Error()) return;
//ab=window.prompt("請輸入圖片的鏈接地址:","http://");
Today = new Date();
newName=Today.valueOf();
//url="upload.php?type=img&o=display&mode=single&cId=" + document.content.cId.value + "&newName=" + newName;
// var ab=showModalDialog(url,"color","dialogWidth:530pxt;dialogHeight:480px;help:0;status:0");
var ab=showModalDialog('upload.php?sId='+ sId +'&o=display&mode=one&type=img&NodeID=' + NodeID,"color","dialogWidth:260pt;dialogHeight:300pt;help:0;status:0;scroll:0");
if(ab['SonIndexID']!="") {
//alert(parent.parent.document.data_Title.value);
}
if (ab['str']!="" && ab['str']!= null) {
var str = ab['str'];
var sel,RangeType;
sel = idEdit.document.selection.createRange();
sel.pasteHTML( str );
sel.select();
}
idEdit.focus();
}
function inMultiphoto(){
if (!Error()) return;
//ab=window.prompt("請輸入圖片的鏈接地址:","http://");
Today = new Date();
newName=Today.valueOf();
//var NodeID= parent.NodeID;
//var sId = parent.sId;
//imageWin = window.open(HTTPStr + '://' + URL + '/icms/publish/de/upload.php?o=display&mode=single&type=img&cId=' + cId,'','width=530,height=480,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
cd=showModalDialog('upload.php?sId='+ sId +'&o=display&mode=multi&type=img&NodeID=' + NodeID,"color","dialogWidth:260pt;dialogHeight:300pt;help:0;status:0;scroll:0");
// url="upload.php?type=img&o=display&mode=multi&cId=" + document.content.cId.value + "&newName=" + newName;
// cd=showModalDialog(url,"color","dialogWidth:260pt;dialogHeight:300pt;help:0;status:0");
if (cd!="") {
var sel,RangeType
sel = idEdit.document.selection.createRange();
sel.pasteHTML( cd );
sel.select();
}
idEdit.focus();
}
function imageEdit()
{
var leftPos = (screen.availWidth-770) / 2;
var topPos = (screen.availHeight-660) / 2 ;
//alert('a')
imageWin = window.open('photo_editor.php?o=main&sId='+ sId ,'','width=755,height=530,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
}
function str2img(){
if (!Error()) return;
//ab=window.prompt("請輸入圖片的鏈接地址:","http://");
Today = new Date();
newName=Today.valueOf();
url="admin_img.php?mode=str2img&cId=" + document.content.cId.value + "&newName=" + newName;
cd=showModalDialog(url,"color","dialogWidth:260pt;dialogHeight:230pt;help:0;status:0");
if (cd!="") {
var sel,RangeType
sel = idEdit.document.selection.createRange();
sel.pasteHTML( cd );
sel.select();
}
idEdit.focus();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -