rte_editmode.js
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:2k
源码类别:

OA系统

开发平台:

C#

  1. 
  2. // setEditMode(): switch between html and textview
  3. function setEditMode() {
  4. switchMode.blur(); // htmlview
  5. if (switchMode.checked == true) {
  6. ctlStyle.disabled = ctlFont.disabled = ctlSize.disabled = true;
  7. // btnPost.className = 'disabled';
  8. doc.style.fontFamily = "宋体";
  9. doc.style.fontSize = "12pt";
  10. RichEditor.txtView = false;
  11. doc.innerText = codeSweeper();
  12. doc.innerHTML = ccParser(doc.innerHTML);
  13. } else {
  14. ctlStyle.disabled = ctlFont.disabled = ctlSize.disabled = false;
  15. doc.style.fontFamily = doc.style.fontSize = "";
  16. // btnPost.className = '';
  17. RichEditor.txtView = true;
  18. doc.focus();
  19. doc.innerHTML = doc.innerText;
  20. }
  21. }
  22. // resetMode();
  23. function resetMode(){
  24. if (switchMode.checked == true) {
  25. switchMode.click();
  26. }
  27. }
  28. // ccParser(): colorcode-parser for html-editing view
  29. function ccParser(html) {
  30. html = html.replace(/@/gi,"_AT_");
  31. html = html.replace(/#/gi,"_HASH_");
  32. var htmltag = /(<[w/]+[ ]*[w="'./;: )(-]*>)/gi;
  33. html = html.replace(htmltag,"<span class=ccp_tag>$1</span>");
  34. var imgtag = /<span class=ccp_tag>(&lt;IMG[ ]*[w="'./;: )(-]*&gt;)</span>/gi;
  35. html = html.replace(imgtag,"<span class=ccp_img>$1</span>");
  36. var formtag = /<span class=ccp_tag>(&lt;[/]*(form|input){1}[ ]*[w="'./;: )(-]*&gt;)</span>/gi;
  37. html = html.replace(formtag,"<br><span class=ccp_form>$1</span>");
  38. var tabletag = /<span class=ccp_tag>(&lt;[/]*(table|tbody|th|tr|td){1}([ ]*[w="'./;:)(-]*){0,}&gt;)</span>/gi;
  39. html = html.replace(tabletag,"<span class=ccp_table>$1</span>");
  40. //var Atag = /<span class=ccp_tag>(&lt;(/a&gt;|[W _w="'./;:)(-]&gt;){1})</span>/gi;
  41. var Atag = /<span class=ccp_tag>(&lt;/a&gt;){1}</span>/gi;
  42. html = html.replace(Atag,"<span class=ccp_A>$1</span>");
  43. var Atag = /<span class=ccp_tag>(&lt;a [W _w="'./;:)(-]+&gt;){1,}</span>/gi;
  44. html = html.replace(Atag,"<span class=ccp_A>$1</span>");
  45. var parameter = /=("[ w'./;:)(-]+"|'[ w"./;:)(-]+')/gi;
  46. html = html.replace(parameter,"=<span class=ccp_paramvalue>$1</span>");
  47. var entity = /&amp;([w]+);/gi;
  48. html = html.replace(entity,"<span class=ccp_entity>&amp;$1;</span>");
  49. var comment = /(&lt;!--[W _w="'./;:)(-]*--&gt;)/gi;
  50. html = html.replace(comment,"<br><span class=ccp_htmlcomment>$1</span>");
  51. html = html.replace(/_AT_/gi,"@");
  52. html = html.replace(/_HASH_/gi,"#");
  53. return html;
  54. }