?? onlineeditor.ascx
字號:
/******************************************************************************
Crossday Discuz! Board - HTML <=> BB Code for Discuz!
Copyright 2001-2006 Comsenz Inc. (http://www.comsenz.com)
*******************************************************************************/
var pcodecount = '-1';
var codecount = 0;
var codehtml = new Array();
var prependtags = '';
var appendtags = '';
function atag(aoptions, text) {
if(trim(text) == '') {
return '';
}
href = getoptionvalue('href', aoptions);
if(href.substr(0, 11) == 'javascript:') {
return trim(recursion('a', text, 'atag'));
} else if(href.substr(0, 7) == 'mailto:') {
tag = 'email';
href = href.substr(7);
} else {
tag = 'url';
}
return '[' + tag + '=' + href + ']' + trim(recursion('a', text, 'atag')) + '[/' + tag + ']';
}
//codehtml[pcodecount] = "<br><br><div style=\"" + msgheader + "\"><div class=\"right\"><a href=\"###\" class=\"smalltxt\">[Copy to clipboard]</a></div>CODE:</div><div style=\"" + msgborder + "\">" + text + "</div>";
function parsecode(text) {
pcodecount++;
text = text.replace(/^[\n\r]*([\s\S]+?)[\n\r]*$/ig, '$1');
text = htmlspecialchars(text);
codehtml[pcodecount] = '[code]' + text + '[/code]';
codecount++;
return "[\tDISCUZ_CODE_" + pcodecount + "\t]";
}
function codetag(text) {
pcodecount++;
text = text.replace(/<br[^\>]*>/ig, "\n");
text = text.replace(/^[\n\r]*([\s\S]+?)[\n\r]*$/ig, '$1');
text = text.replace(/<(\/|)[A-Za-z].*?>/ig, '');
codehtml[pcodecount] = "[code]" + text + "[/code]";
codecount++;
return "[\tDISCUZ_CODE_" + pcodecount + "\t]";
}
function divtag(divoptions, text) {
prepend = '';
append = '';
parsestyle(divoptions, prepend, append);
align = getoptionvalue('align', divoptions);
switch(align) {
case 'left':
case 'center':
case 'right':
break;
default:
align = '';
}
if(align) {
prepend += '[align=' + align + ']';
append += '[/align]';
}
append += "\n";
return prepend + recursion('div', text, 'divtag') + append;
}
function fetchoptionvalue(option, text) {
if((position = strpos(text, option)) !== false) {
delimiter = position + option.length;
if(text.charAt(delimiter) == '"') {
delimchar = '"';
} else if(text.charAt(delimiter) == '\'') {
delimchar = '\'';
} else {
delimchar = ' ';
}
delimloc = strpos(text, delimchar, delimiter + 1);
if(delimloc === false) {
delimloc = text.length;
} else if(delimchar == '"' || delimchar == '\'') {
delimiter++;
}
return trim(text.substr(delimiter, delimloc - delimiter));
} else {
return '';
}
}
function parsestyle(tagoptions, prependtags, appendtags) {
var searchlist = [
['align', true, 'text-align:\s*(left|center|right);?', 1],
['color', true, '[a-z0-9-]color:\s*([^;]+);?', 1],
['font', true, 'font-family:\s*([^;]+);?', 1],
['size', true, 'font-size:\s*([\d]+p[x|t]);?', 1],
['b', false, 'font-weight:\s*(bold);?'],
['i', false, 'font-style:\s*(italic);?'],
['u', false, 'text-decoration:\s*(underline);?']
];
style = getoptionvalue('style', tagoptions);
re = /[a-z0-9-]color:\s*rgb\((\d+),\s*(\d+),\s*(\d+)\)(;?)/ig;
style = style.replace(re, function($1, $2, $3, $4, $5) {return("color:#" + parseInt($2).toString(16) + parseInt($3).toString(16) + parseInt($4).toString(16) + $5);});
for(var i = 0; i < searchlist.length; i++) {
re = new RegExp(searchlist[i][2], "ig");
match = re.exec(style);
if(match != null) {
opnvalue = match["searchlist[i][3]"];
re = /([\d]+)p([x|t])/ig;
matches = re.exec(opnvalue);
if(matches != null) {
if(matches[2] == 'x') {
matches[1] = matches[1] * 0.75;
}
switch(matches[1]) {
case matches[1] < 10: opnvalue = 1; break;
case matches[1] < 12: opnvalue = 2; break;
case matches[1] < 14: opnvalue = 3; break;
case matches[1] < 18: opnvalue = 4; break;
case matches[1] < 24: opnvalue = 5; break;
case matches[1] < 36: opnvalue = 6; break;
case matches[1] >= 36: opnvalue = 7; break;
default: opnvalue = 2; break;
}
}
prependtags += '[' + searchlist[i][0] + (searchlist[i][1] == true ? '=' + opnvalue + ']' : ']');
appendtags = '[/' + searchlist[i][0] + ']' + appendtags;
}
}
}
function getoptionvalue(option, text) {
re = new RegExp(option + "(\s+?)?\=(\s+?)?[\"']?(.+?)([\"']|$|>)", "ig");
var matches = re.exec(text);
if(matches != null && matches.length) {
return trim(matches[3]);
}
return '';
}
function fonttag(fontoptions, text) {
var prepend = '';
var append = '';
var tags = new Array();
tags = {'font' : 'face=', 'size' : 'size=', 'color' : 'color='};
for(bbcode in tags) {
optionvalue = fetchoptionvalue(tags[bbcode], fontoptions);
if(optionvalue) {
prepend += '[' + bbcode + '=' + optionvalue + ']';
append = '[/' + bbcode + ']' + append;
}
}
parsestyle(fontoptions, prepend, append);
return prepend + recursion('font', text, 'fonttag') + append;
}
function simpletag(options, text, tagname, parseto) {
if(trim(text) == '') {
return '';
}
text = recursion(tagname, text, 'simpletag', parseto);
return '[' + parseto + ']' + text + '[/' + parseto + ']';
}
function spantag(spanoptions, text) {
prepend = '';
append = '';
parsestyle(spanoptions, prepend, append);
return prepend + recursion('span', text, 'spantag') + append;
}
function ptag(poptions, text) {
align = getoptionvalue('align', poptions);
switch(align) {
case 'left':
case 'center':
case 'right':
break;
default:
align = '';
}
prepend = '';
append = '';
parsestyle(poptions, prepend, append);
if(align) {
prepend += '[align=' + align + ']';
append += '[/align]';
}
append += "\n";
return prepend + recursion('p', text, 'ptag') + append;
}
function litag(listoptions, text) {
return '[*]' + text.replace(/(\s+)$/g, '');
}
function listtag(listoptions, text, tagname) {
text = text.replace(/<li>((.(?!<\/li))*)(?=<\/?ol|<\/?ul|<li|\[list|\[\/list)/ig, '<li>$1</li>') + (is_opera ? '</li>' : '');
text = recursion('li', text, 'litag');
if(tagname == 'ol') {
listtype = fetchoptionvalue('type=', listoptions) ? fetchoptionvalue('type=', listoptions) : 1;
if(listtype == '1' || listtype == 'a' || listtype == 'A') {
opentag = '[list=' + listtype + ']';
}
} else {
opentag = '[list]';
}
return text ? opentag + recursion(tagname, text, 'listtag') + '[/list]' : false;
}
function recursion(tagname, text, dofunction, extraargs) {
if(extraargs == null) {
extraargs = '';
}
tagname = tagname.toLowerCase();
var open_tag = '<' + tagname;
var open_tag_len = open_tag.length;
var close_tag = '</' + tagname + '>';
var close_tag_len = close_tag.length;
var beginsearchpos = 0;
do {
var textlower = text.toLowerCase();
var tagbegin = textlower.indexOf(open_tag, beginsearchpos);
if(tagbegin == -1) {
break;
}
var strlen = text.length;
var inquote = '';
var found = false;
var tagnameend = false;
var optionend = 0;
var t_char = '';
for(optionend = tagbegin; optionend <= strlen; optionend++) {
t_char = text.charAt(optionend);
if((t_char == '"' || t_char == "'") && inquote == '') {
inquote = t_char;
} else if((t_char == '"' || t_char == "'") && inquote == t_char) {
inquote = '';
} else if(t_char == '>' && !inquote) {
found = true;
break;
} else if((t_char == '=' || t_char == ' ') && !tagnameend) {
tagnameend = optionend;
}
}
if(!found) {
break;
}
if(!tagnameend) {
tagnameend = optionend;
}
var offset = optionend - (tagbegin + open_tag_len);
var tagoptions = text.substr(tagbegin + open_tag_len, offset)
var acttagname = textlower.substr(tagbegin * 1 + 1, tagnameend - tagbegin - 1);
if(acttagname != tagname) {
beginsearchpos = optionend;
continue;
}
var tagend = textlower.indexOf(close_tag, optionend);
if(tagend == -1) {
break;
}
var nestedopenpos = textlower.indexOf(open_tag, optionend);
while(nestedopenpos != -1 && tagend != -1) {
if(nestedopenpos > tagend) {
break;
}
tagend = textlower.indexOf(close_tag, tagend + close_tag_len);
nestedopenpos = textlower.indexOf(open_tag, nestedopenpos + open_tag_len);
}
if(tagend == -1) {
beginsearchpos = optionend;
continue;
}
var localbegin = optionend + 1;
var localtext = eval(dofunction)(tagoptions, text.substr(localbegin, tagend - localbegin), tagname, extraargs);
text = text.substring(0, tagbegin) + localtext + text.substring(tagend + close_tag_len);
beginsearchpos = tagbegin + localtext.length;
} while(tagbegin != -1);
return text;
}
function imgtag(attributes) {
var width = '';
var height = '';
re = /src=(["']?)([\s\S]*?)(\1)/i;
var matches = re.exec(attributes);
if(matches != null) {
var src = matches[2];
} else {
return '';
}
re = /width=(["']?)(\d+)(\1)/i;
var matches = re.exec(attributes);
if(matches != null) {
width = matches[2];
}
re = /height=(["']?)(\d+)(\1)/i;
var matches = re.exec(attributes);
if(matches != null) {
height = matches[2];
}
re = /aid=(["']?)attach_(\d+)(\1)/i;
var matches = re.exec(attributes);
var imgtag = 'img';
if(matches != null) {
imgtag = 'localimg';
src = matches[2];
}
return width > 0 && height > 0 ?
'[' + imgtag + '=' + width + ',' + height + ']' + src + '[/' + imgtag + ']' :
'[img]' + src + '[/img]';
}
function tabletag(attributes) {
var width = '';
re = /width=(["']?)(\d{1,3}%?)(\1)/ig;
var matches = re.exec(attributes);
if(matches != null && matches.length) {
width = matches[2].substr(matches[2].length - 1, matches[2].length) == '%' ?
(matches[2].substr(0, matches[2].length - 1) <= 98 ? matches[2] : '98%') :
(matches[2] <= 560 ? matches[2] : '560');
} else {
re = /width\s?:\s?(\d{1,3})([px|%])/ig;
var matches = re.exec(attributes);
if(matches != null && matches.length) {
width = matches[2] == '%' ? (matches[1] <= 98 ? matches[1] : '98%') : (matches[1] <= 560 ? matches[1] : '560');
}
}
return width == '' ? '[table]' : '[table=' + width + ']';
}
function tdtag(attributes) {
var colspan = 1;
var rowspan = 1;
var width = '';
re = /colspan=(["']?)(\d{1,2})(\1)/ig;
var matches = re.exec(attributes);
if(matches != null) {
colspan = matches[2];
}
re = /rowspan=(["']?)(\d{1,2})(\1)/ig;
var matches = re.exec(attributes);
if(matches != null) {
rowspan = matches[2];
}
re = /width=(["']?)(\d{1,3}%?)(\1)/ig;
var matches = re.exec(attributes);
if(matches != null) {
width = matches[2];
}
return width == '' || width == 0 || width == '100%' ?
(colspan == 1 && rowspan == 1 ? '[td]' : '[td=' + colspan + ',' + rowspan + ']') :
'[td=' + colspan + ',' + rowspan + ',' + width + ']';
}
function ParseSmilies(){
if (!smilies.length){
return;
}
//document.write(arguments[0]);
for (i=0;i<smilies.length;i++){
if (smilies[i][0]==arguments[1]){
return smilies[i][1];
}
}
return arguments[0];
}
function html2bbcode(str) {
str = trim(str);
if(str == '') {
return str;
}
str= str.replace(/\s*\[code\]([\s\S]+?)\[\/code\]\s*/ig, function($1, $2) {return codetag($2);});
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -