e73a9d8ecf3d70252a28a76fb6632daf7d288884.svn-base 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6. <title></title>
  7. <script type="text/javascript" src="../internal.js"></script>
  8. <style type="text/css">
  9. html,body{
  10. _overflow:hidden;
  11. }
  12. *{margin: 0;padding: 0;line-height: 20px;}
  13. .wrapper{width: 520px;height: 300px; margin: 10px 15px;font-size: 12px}
  14. textarea{width:510px ;height: 300px;resize: none;margin:5px;*margin-left:-12px;}
  15. </style>
  16. </head>
  17. <body>
  18. <div class="wrapper">
  19. <p>
  20. <label for="language"><var id="lang_input_selectLang"></var></label>
  21. <select id="language">
  22. <option value="as3">ActionScript3</option>
  23. <option value="bash">Bash/Shell</option>
  24. <option value="cpp">C/C++</option>
  25. <option value="css">Css</option>
  26. <option value="cf">CodeFunction</option>
  27. <option value="c#">C#</option>
  28. <option value="delphi">Delphi</option>
  29. <option value="diff">Diff</option>
  30. <option value="erlang">Erlang</option>
  31. <option value="groovy">Groovy</option>
  32. <option value="html">Html</option>
  33. <option value="java">Java</option>
  34. <option value="jfx">JavaFx</option>
  35. <option value="js">Javascript</option>
  36. <option value="pl">Perl</option>
  37. <option value="php">Php</option>
  38. <option value="plain">Plain Text</option>
  39. <option value="ps">PowerShell</option>
  40. <option value="python">Python</option>
  41. <option value="ruby">Ruby</option>
  42. <option value="scala">Scala</option>
  43. <option value="sql">Sql</option>
  44. <option value="vb">Vb</option>
  45. <option value="xml">Xml</option>
  46. </select>
  47. </p>
  48. <label for="code"></label><textarea id="code" cols="" rows=""></textarea>
  49. </div>
  50. <script type="text/javascript">
  51. var sels = $G("language"),
  52. code = $G('code');
  53. var state = editor.queryCommandState("highlightcode");
  54. if(state){
  55. var pN = domUtils.findParent(editor.selection.getRange().startContainer,function(node){
  56. return /syntaxhighlighter/ig.test(node.className);
  57. });
  58. if(pN){
  59. var divs = pN.getElementsByTagName("div"),di;
  60. for(var i = divs.length-1,container;container = divs[i--];){
  61. if(container.className == "container"){
  62. di = container;
  63. break;
  64. }
  65. }
  66. for(var str=[],c=0,ci;ci=di.childNodes[c++];){
  67. str.push(ci[parent.baidu.editor.browser.ie?'innerText':'textContent']);
  68. }
  69. $G("code").value = str.join("\n");
  70. $G("language").value = pN.className.match(/highlighter[\s]+([a-z\d]*#?)/)[1];
  71. }
  72. }
  73. code.onkeydown= function(evt){
  74. evt = evt || event;
  75. if(evt.keyCode == 9){
  76. if (('selectionStart' in code) && code.selectionStart == code.selectionEnd) {
  77. var offset = code.selectionStart;
  78. code.value = code.value.substring (0, code.selectionStart) +
  79. " " + code.value.substring (code.selectionStart);
  80. code.selectionStart = code.selectionEnd = offset + 4;
  81. $focus(code);
  82. }
  83. else {
  84. var textRange = document.selection.createRange();
  85. textRange.text = " " + textRange.text ;
  86. textRange.collapse(false);
  87. textRange.select();
  88. $focus(code);
  89. }
  90. evt.returnValue = false;
  91. evt.preventDefault();
  92. }
  93. if((evt.ctrlKey||evt.metaKey) && evt.keyCode == 13){
  94. dialog.onok();
  95. }
  96. };
  97. dialog.onok = function(){
  98. var language = sels.value;
  99. if(code.value.replace(/^\s*|\s*$/ig,"")){
  100. editor.execCommand("highlightcode",code.value,language);
  101. dialog.close();
  102. }else{
  103. alert(lang.importCode);
  104. }
  105. };
  106. $focus(code);
  107. sels.onchange = function(){
  108. $focus(code);
  109. }
  110. </script>
  111. </body>
  112. </html>