codemirror-searchbox-test.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <title>CodeMirror searchbox Test</title>
  5. <meta charset="UTF-8">
  6. <meta name="description" content="" />
  7. <meta name="keywords" content="" />
  8. <link rel="stylesheet" href="../examples/css/style.css" />
  9. </head>
  10. <body>
  11. <div id="layout">
  12. <textarea id="test" style="display:none;">###Hello world!</textarea>
  13. </div>
  14. <script src="../examples/js/jquery.min.js"></script>
  15. <link rel="stylesheet" href="../lib/codemirror/codemirror.min.css" />
  16. <script src="../lib/codemirror/codemirror.min.js"></script>
  17. <script src="../lib/codemirror/modes.min.js"></script>
  18. <script src="../lib/codemirror/addons.min.js"></script>
  19. <script src="js/searchbox.js"></script>
  20. <style>
  21. html, body, #layout, .CodeMirror {
  22. width: 100%;
  23. height: 100%;
  24. overflow: hidden;
  25. font-family: Consolas;
  26. font-size: 13px;
  27. }
  28. .ace_search {
  29. font-family:"微软雅黑",Arial;
  30. padding-bottom: 4px;
  31. }
  32. .ace_replacebtn, .ace_button {
  33. padding: 0 5px;
  34. font-size: 12px;
  35. }
  36. .ace_button {
  37. border-radius: 3px;
  38. padding: 2px 5px;
  39. margin-left: 3px;
  40. }
  41. .ace_button.checked {
  42. border-color: #ccc;
  43. background-color: #fafafa;
  44. }
  45. .ace_search {
  46. display: inline-block;
  47. max-width: 320px;
  48. }
  49. .ace_search_form, .ace_replace_form {
  50. display: inline-block;
  51. float: none;
  52. }
  53. .ace_search_options {
  54. display: block;
  55. }
  56. </style>
  57. <script type="text/javascript">
  58. $(function() {
  59. var enableSearchbox = true;
  60. var codeMirrorConfig = {
  61. mode: "gfm",
  62. theme: "default",
  63. tabSize: 4,
  64. dragDrop: false,
  65. autofocus: true,
  66. indentUnit : 4,
  67. searchbox: enableSearchbox, // IE9+
  68. lineNumbers: true,
  69. lineWrapping: true,
  70. matchBrackets: true,
  71. indentWithTabs: true,
  72. styleActiveLine: true,
  73. styleSelectedText: true,
  74. autoCloseBrackets: true,
  75. showTrailingSpace: true,
  76. highlightSelectionMatches: {
  77. showToken: /\w/
  78. }
  79. };
  80. $.get("../examples/test.md", function(md){
  81. $("#test").html(md);
  82. var codeMirrorEditor = CodeMirror.fromTextArea($("#test")[0], codeMirrorConfig);
  83. var codeMirror = $(".CodeMirror");
  84. $(window).keydown(function() {
  85. if (!enableSearchbox) return false;
  86. $(".ace_replacebtn").eq(0).html("替换");
  87. $(".ace_replacebtn").eq(1).html("全部替换");
  88. $(".ace_searchbtn").eq(2).remove();//.html("全部").css({width: "36px", padding :"0 4px"});
  89. $(".ace_button").eq(0).html("正则搜索");
  90. $(".ace_button").eq(1).html("区分大小写");
  91. $(".ace_button").eq(2).html("全词搜索");
  92. });
  93. });
  94. });
  95. </script>
  96. </body>
  97. </html>