on-off.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>On / Off (bind/unbind) event handle - Editor.md examples</title>
  6. <link rel="stylesheet" href="css/style.css" />
  7. <link rel="stylesheet" href="../css/editormd.css" />
  8. <link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" />
  9. </head>
  10. <body>
  11. <div id="layout">
  12. <header>
  13. <h1>On / Off (bind/unbind) event handle</h1>
  14. <p>Plaese press F12, open the develop tools.</p>
  15. </header>
  16. <div id="test-editormd">
  17. <textarea style="display:none;">#### Example
  18. ```javascript
  19. {
  20. onscroll : function(event) {
  21. console.clear();
  22. console.log("onscroll =>", this, this.id, this.settings, event);
  23. },
  24. onpreviewscroll : function(event) {
  25. console.clear();
  26. console.log("onpreviewscroll =>", this, this.id, this.settings, event);
  27. },
  28. onload : function() {
  29. this.off("previewscroll"); // unbind before handle
  30. // Override settings.onpreviewscroll
  31. this.on("previewscroll", function(){
  32. console.clear();
  33. console.log("on() => Override settings.onpreviewscroll =>", this, this.id, event, (new Date).getTime());
  34. });
  35. // defined event bind
  36. this.on("resize", function(){
  37. console.clear();
  38. console.log("onresize =>", this, this.id, event, (new Date).getTime());
  39. });
  40. }
  41. }
  42. // Or
  43. editor.on("resize", function(){
  44. // ...
  45. });
  46. editor.off("resize");
  47. ```
  48. </textarea>
  49. </div>
  50. </div>
  51. <script src="js/jquery.min.js"></script>
  52. <script src="../editormd.js"></script>
  53. <script type="text/javascript">
  54. var testEditor;
  55. $(function() {
  56. $.get("./test.md", function(md){
  57. testEditor = editormd("test-editormd", {
  58. width : "90%",
  59. height : 720,
  60. appendMarkdown : md,
  61. path : '../lib/',
  62. tex : true,
  63. htmlDecode : true,
  64. flowChart : true,
  65. taskList : true,
  66. sequenceDiagram : true,
  67. onscroll : function(event) {
  68. console.clear();
  69. console.log("onscroll =>", this, this.id, this.settings, event);
  70. },
  71. onpreviewscroll : function(event) {
  72. console.clear();
  73. console.log("onpreviewscroll =>", this, this.id, this.settings, event);
  74. },
  75. onload : function() {
  76. this.off("previewscroll");
  77. // Override settings.onpreviewscroll
  78. this.on("previewscroll", function(){
  79. console.clear();
  80. console.log("on() => Override settings.onpreviewscroll =>", this, this.id, event, (new Date).getTime());
  81. });
  82. // defined event bind
  83. this.on("resize", function(){
  84. console.clear();
  85. console.log("onresize =>", this, this.id, event, (new Date).getTime());
  86. });
  87. }
  88. });
  89. });
  90. });
  91. </script>
  92. </body>
  93. </html>