📄 wysiwyg_editor.js
字号:
return false; } } var code = '[payto]'; code += '(seller)' + GE("seller").value + '(/seller)'; code += '(subject)' + GE("subject").value + '(/subject)'; code += '(body)' + GE("saledes").value + '(/body)'; code += '(price)' + GE("price").value + '(/price)'; code += '(ordinary_fee)' + GE("ordinary_fee").value + '(/ordinary_fee)'; code += '(express_fee)' + GE("express_fee").value + '(/express_fee)'; code += '(demo)' + GE("demo").value + '(/demo)'; code += '(contact)' + GE("contact").value + '(/contact)'; code += '(method)' + method + '(/method)'; code += '[/payto]'; AddCode(code,''); closep();}function addattach(aid){ editor.focusEditor(); sm=' [attachment='+aid+'] '; AddCode(sm,'');}function windcode(code){ text = editor.getsel(); switch(code){ case "htmlmode": editor.setMode(); return false; case "windcode": return false; case "bold": AddTxt = "[b]" + text + "[/b]";break; case "italic": AddTxt = "[i]" + text + "[/i]";break; case "underline": AddTxt = "[u]" + text + "[/u]";break; case "strikethrough": AddTxt = "[strike]" + text + "[/strike]";break; case "subscript": AddTxt = "[sub]" + text + "[/sub]";break; case "superscript": AddTxt = "[sup]" + text + "[/sup]";break; case "justifyleft": AddTxt = "[align=left]" + text + "[/align]";break; case "justifycenter": AddTxt = "[align=center]" + text + "[/align]";break; case "justifyright": AddTxt = "[align=right]" + text + "[/align]";break; case "justifyfull": AddTxt = "[align=justify]" + text + "[/align]";break; case "inserthorizontalrule": text='';AddTxt="[hr]";break; case "indent": AddTxt = "[blockquote]" + text + "[/blockquote]";break; case "createlink": if(text){ AddTxt = "[url=" + text + "]" + text + "[/url]"; } else{ txt = prompt('URL:',"http://"); if(txt){ AddTxt = "[url=" + txt + "]" + txt + "[/url]"; }else{ AddTxt = "[url][/url]"; } } break; case "insertorderedlist": if(text){ AddTxt = "[list=a][li]" + text + "[/li][/list]"; } else{ txt=prompt('a,A,1',"a"); while(txt!="A" && txt!="a" && txt!="1" && txt!=null){ txt=prompt('a,A,1',"a"); } if(txt!=null){ if(txt=="1"){ AddTxt="[list=1]"; } else if(txt=="a"){ AddTxt="[list=a]"; } else if(txt=="A"){ AddTxt="[list=A]"; } ltxt="1"; while(ltxt!="" && ltxt!=null){ ltxt=prompt(I18N['listitem'],""); if (ltxt!=""){ AddTxt+="[li]"+ltxt+"[/li]"; } } AddTxt+="[/list]"; } } break; case "insertunorderedlist": if(text){ AddTxt = "[list][li]" + text + "[/li][/list]"; } else{ AddTxt="[list]"; txt="1"; while(txt!="" && txt!=null){ txt=prompt(I18N['listitem'],""); if(txt!=""){ AddTxt+="[li]"+txt+"[/li]"; } } AddTxt+="[/list]"; } break; default : return false; } AddText(AddTxt,text);}function windselect(cmdID,value){ text = editor.getsel(); switch(cmdID){ case "fontname": AddTxt = "[font=" + value + "]" + text + "[/font]";break; case "fontsize": AddTxt = "[size=" + value + "]" + text + "[/size]";break; case "formatblock": AddTxt = value ? "[" + value + "]" + text + "[/" + value + "]" : "";break; default : AddTxt = ""; } AddText(AddTxt,text);}function AddText(code,text){ var startpos = text == '' ? code.indexOf(']') + 1 : code.indexOf(text); if(document.selection){ var sel = document.selection.createRange(); sel.text = code; sel.moveStart('character',-code.length + startpos); sel.moveEnd('character', -code.length + text.length + startpos); sel.select(); } else if(typeof editor._textArea.selectionStart != 'undefined'){ var prepos = editor._textArea.selectionStart; editor._textArea.value = editor._textArea.value.substr(0,prepos) + code + editor._textArea.value.substr(editor._textArea.selectionEnd); editor._textArea.selectionStart = prepos + startpos; editor._textArea.selectionEnd = prepos + startpos + text.length; } else{ document.FORM.atc_content.value += code; }}function AddCode(code,text){ if(editor._editMode=='textmode'){ AddText(code,text); } else{ editor.insertHTML(code); }}function htmltocode(str){ if(IsChecked('atc_html')){ return str; } code_htm = new Array(); code_num = 0; str = str.replace(/(\r\n|\n|\r)/ig, ''); str = str.replace(/<br[^>]*>/ig,'\n'); str = str.replace(/<p[^>\/]*\/>/ig,'\n'); str = str.replace(/\[code\](.+?)\[\/code\]/ig, function($1, $2) {return phpcode($2);}); str = str.replace(/\son[\w]{3,16}\s?=\s*([\'\"]).+?\1/ig,''); //if(IsChecked('atc_convert')){ str = str.replace(/<hr[^>]*>/ig,'[hr]'); str = str.replace(/<(sub|sup|u|strike|b|i|pre)>/ig,'[$1]'); str = str.replace(/<\/(sub|sup|u|strike|b|i|pre)>/ig,'[/$1]'); str = str.replace(/<(\/)?strong>/ig,'[$1b]'); str = str.replace(/<(\/)?em>/ig,'[$1i]'); str = str.replace(/<(\/)?blockquote([^>]*)>/ig,'[$1blockquote]'); str = str.replace(/<img[^>]*smile=\"(\d+)\"[^>]*>/ig,'[s:$1]'); str = str.replace(/<img[^>]*src=[\'\"\s]*([^\s\'\"]+)[^>]*>/ig,'[img]'+'$1'+'[/img]'); str = str.replace(/<a[^>]*href=[\'\"\s]*([^\s\'\"]*)[^>]*>(.+?)<\/a>/ig,'[url=$1]'+'$2'+'[/url]'); str = str.replace(/<h([1-6]+)([^>]*)>(.*?)<\/h\1>/ig,function($1,$2,$3,$4){return h($3,$4,$2);}); str = searchtag('table',str,'table',1); str = searchtag('font',str,'Font',1); str = searchtag('div',str,'ds',1); str = searchtag('p',str,'p',1); str = searchtag('span',str,'ds',1); str = searchtag('ol',str,'list',1); str = searchtag('ul',str,'list',1); //} for(i in code_htm){ str = str.replace("[\twind_phpcode_" + i + "\t]", code_htm[i]); } str = str.replace(/<[^>]*?>/ig, ''); str = str.replace(/&/ig, '&'); str = str.replace(/</ig, '<'); str = str.replace(/>/ig, '>'); return str;}function searchtag(tagname,str,action,type){ if(type == 2){ var tag = ['[',']']; } else{ var tag = ['<','>']; } var head = tag[0] + tagname; var head_len = head.length; var foot = tag[0] + '/' + tagname + tag[1]; var foot_len = foot.length; var strpos = 0; do{ var strlower = str.toLowerCase(); var begin = strlower.indexOf(head,strpos); if(begin == -1){ break; } var strlen = str.length; for(var i = begin + head_len; i < strlen; i++){ if(str.charAt(i)==tag[1]) break; } if(i>=strlen) break; var firsttag = i; var style = str.substr(begin + head_len, firsttag - begin - head_len); var end = strlower.indexOf(foot,firsttag); if (end == -1) break; var nexttag = strlower.indexOf(head,firsttag); while(nexttag != -1 && end != -1){ if(nexttag > end) break; end = strlower.indexOf(foot, end + foot_len); nexttag = strlower.indexOf(head, nexttag + head_len); } if(end == -1){ strpos = firsttag; continue; } firsttag++; var findstr = str.substr(firsttag, end - firsttag); str = str.substr(0,begin) + eval(action)(style,findstr,tagname) + str.substr(end+foot_len); strpos = begin; }while(begin != -1); return str;}function h(style,code,size){ size = 7 - size; code = '[size=' + size + '][b]' + code + '[/b][/size]'; return p(style,code);}function p(style,code){ if(style.indexOf('align=') != -1){ style = findvalue(style,'align='); code = '[align=' + style + ']' + code + '[/align]'; } else{ code += "\n"; } return code;}function ds(style,code){ var styles = [ ['align' , 1, 'align='], ['align', 1 , 'text-align:'], ['color' , 2 , 'color:'], ['font' , 1 , 'font-family:'], ['b' , 0 , 'font-weight:' , 'bold'], ['i' , 0 , 'font-style:' , 'italic'], ['u' , 0 , 'text-decoration:' , 'underline'], ['strike' , 0 , 'text-decoration:' , 'line-through'] ]; style = style.toLowerCase(); for(var i=0;i<styles.length;i++){ var begin = style.indexOf(styles[i][2]); if(begin == -1){ continue; } var value = ''; if(styles[i][1] < 2){ value = findvalue(style,styles[i][2]); } else{ begin = style.indexOf('rgb',begin); if(begin == -1){ continue; } else{ value = WYSIWYD._colorToRgb(style.substr(begin,style.indexOf(')')-begin+1)); } } if(styles[i][1] == 0){ if(value == styles[i][3]){ code = '[' + styles[i][0] + ']' + code + '[/' + styles[i][0] + ']'; } } else{ code = '[' + styles[i][0] + '=' + value + ']' + code + '[/' + styles[i][0] + ']'; } } return code;}function list(type,code,tagname){ code = code.replace(/<(\/)?li>/ig,'[$1li]'); if(tagname == 'ul'){ return '[list]'+code+'[/list]'; } if(type && type.indexOf('type=')!='-1'){ type = findvalue(type,'type='); if(type!='a' && type!='A' && type!='1'){ type='1'; } return '[list=' + type + ']' + code + '[/list]'; } else{ return '[list=1]'+code+'[/list]'; }}function Font(style,str){ var styles = new Array(); styles ={'size' : 'size=','color' : 'color=','font' : 'face=','backcolor' : 'background-color:'}; style = style.toLowerCase(); for(st in styles){ var begin = style.indexOf(styles[st]); if(begin == -1){ continue; } var value = findvalue(style,styles[st]); str = '[' + st + '=' + value + ']' + str + '[/' + st + ']'; } return str;}function table(style,str){ str = str.replace(/<tr([^>]*)>/ig,'[tr]'); str = str.replace(/<\/tr>/ig,'[/tr]'); str = searchtag('td',str,'td',1); var styles = ['width=','width:']; style = style.toLowerCase(); var s = ''; for(i in styles){ if(style.indexOf(styles[i]) == -1){ continue; } s = '=' + findvalue(style,styles[i]); break; } return '[table' + s + ']' + str + '[/table]';}function td(style,str){ if(style == ''){ return '[td]' + str + '[/td]'; } var colspan = 1; var rowspan = 1; var width = ''; var value; if(style.indexOf('colspan=') != -1){ value = findvalue(style,'colspan='); if(value>1) colspan = value; } if(style.indexOf('rowspan=') != -1){ value = findvalue(style,'rowspan='); if(value>1) rowspan = value; } if(style.indexOf('width=') != -1){ width = findvalue(style,'width='); } if(width == ''){ return (colspan == 1 && rowspan == 1 ? '[td]' : '[td=' + colspan + ',' + rowspan + ']') + str + '[/td]'; } else{ return '[td=' + colspan + ',' + rowspan + ',' + width + ']' + str + '[/td]'; }}function findvalue(style,find){ var firstpos = style.indexOf(find)+find.length; var len = style.length; var start = 0; for(var i=firstpos;i<len;i++){ var t_char = style.charAt(i); if(start==0){ if(t_char == '"' || t_char == "'"){ start = i+1; }else if(t_char != ' '){ start = i; } continue; } if(t_char=='"' || t_char=="'" || t_char==' ' || t_char==';'){ break; } } return style.substr(start,i-start);}function codetohtml(str){ code_htm = new Array(); code_num = 0; if(!IsChecked('atc_html')){ str = str.replace(/</ig,'<'); str = str.replace(/>/ig,'>'); } str = str.replace(/\n/ig,'<br />'); str = str.replace(/\[code\](.+?)\[\/code\]/ig, function($1, $2) {return phpcode($2);}); //if(IsChecked('atc_convert')){ str = str.replace(/\[hr\]/ig,'<hr />'); str = str.replace(/\[\/(size|color|font|backcolor)\]/ig,'</font>'); str = str.replace(/\[(sub|sup|u|i|strike|b|blockquote|li)\]/ig,'<$1>'); str = str.replace(/\[\/(sub|sup|u|i|strike|b|blockquote|li)\]/ig,'</$1>'); str = str.replace(/\[\/align\]/ig,'</p>'); str = str.replace(/\[(\/)?h([1-6])\]/ig,'<$1h$2>'); str = str.replace(/\[align=(left|center|right|justify)\]/ig,'<p align="$1">'); str = str.replace(/\[size=(\d+?)\]/ig,'<font size="$1">'); str = str.replace(/\[color=([^\[\<]+?)\]/ig, '<font color="$1">'); str = str.replace(/\[backcolor=([^\[\<]+?)\]/ig, '<font style="background-color:$1">'); str = str.replace(/\[font=([^\[\<]+?)\]/ig, '<font face="$1">'); str = str.replace(/\[list=(a|A|1)\](.+?)\[\/list\]/ig,'<ol type="$1">$2</ol>'); str = str.replace(/\[(\/)?list\]/ig,'<$1ul>'); str = str.replace(/\[s:(\d+)\]/ig,function($1,$2){ return smilepath($2);}); str = str.replace(/\[img\]([^\[]*)\[\/img\]/ig,'<img src="$1" border="0" />'); str = str.replace(/\[url=([^\]]+)\]([^\[]+)\[\/url\]/ig, '<a href="$1">'+'$2'+'</a>'); str = searchtag('table',str,'tableshow',2); //} for(i in code_htm){ str = str.replace("[\twind_phpcode_" + i + "\t]", code_htm[i]); } return str;}function phpcode(code){ code_num ++; code_htm[code_num] = '[code]' + code + '[/code]'; return "[\twind_phpcode_" + code_num + "\t]";}function tableshow(style,str){ if(style.substr(0,1) == '='){ width = style.substr(1); } else{ width = '100%'; } str = str.replace(/\[td=(\d{1,2}),(\d{1,2})(,(\d{1,3}%?))?\]/ig,'<td colspan="$1" rowspan="$2" width="$4">'); str = str.replace(/\[(tr|td)\]/ig,'<$1>'); str = str.replace(/\[\/(tr|td)\]/ig,'</$1>'); return '<table width=' + width + ' class="t" cellspacing=0>' + str + '</table>';}function smilepath(NewCode){ return '<img src="' + imgpath + '/post/smile/' + face[NewCode] + '" smile="' + NewCode + '" /> ';}function checklength(theform,postmaxchars){ if(postmaxchars != 0){ message = '\n' + I18N['maxbits'] + postmaxchars; } else{ message = ''; } var msg = editor._editMode == "textmode" ? editor.getHTML() : htmltocode(editor.getHTML()); alert(I18N['currentbits'] + strlen(msg) + message);}function Addaction(addTitle){ editor.focusEditor(); AddCode(addTitle,'');}function addsmile(NewCode){ editor.focusEditor(); if(editor._editMode=='textmode'){ sm = '[s:' + NewCode + ']'; AddText(sm,''); } else{ sm = '<img src="' + imgpath + '/post/smile/' + face[NewCode] + '" smile="' + NewCode + '" /> '; editor.insertHTML(sm); }}function IsChecked(id){ return document.getElementById(id) && document.getElementById(id).checked === true ? true : false;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -