pedit.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="apple-mobile-web-app-capable" content="yes" />
  6. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  7. <meta name="theme-color" content="#ff9224">
  8. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css">
  9. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  10. <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
  11. <!-- Editor -->
  12. <script src=" https://cdn.jsdelivr.net/npm/[email protected]/dist/suneditor.min.js "></script>
  13. <link href=" https://cdn.jsdelivr.net/npm/[email protected]/dist/css/suneditor.min.css " rel="stylesheet">
  14. <script src="src/en.js"></script>
  15. <style>
  16. body{
  17. margin: 0px;
  18. }
  19. #editorWrapper{
  20. position: fixed;
  21. left: 0px;
  22. top: 0px;
  23. width: 100%;
  24. height: 100%;
  25. }
  26. #maineditor{
  27. width: 100%;
  28. height: calc(100vh - 0.4em);
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="editorWrapper">
  34. <textarea id="maineditor"></textarea>
  35. </div>
  36. <script>
  37. //Start a new editor if there is no file ported in
  38. var editor;
  39. if (parent.inputFiles == null){
  40. //New Editor
  41. initEditor();
  42. }else{
  43. //Get the filepath and load it
  44. var filepath = parent.inputFiles;
  45. //Load the given file
  46. $.get("/api/fs/download?file=" + filepath, function(data) {
  47. if (data.error == undefined){
  48. var titleMatch = data.match(/<title>(.*?)<\/title>/i);
  49. if (titleMatch && titleMatch[1]) {
  50. var title = titleMatch[1];
  51. console.log("Title found: " + title);
  52. parent.setPageTitle(title);
  53. }
  54. var contentWithoutHead = data.replace(/<head[^>]*>[\s\S]*?<\/head>/gi, '');
  55. var contentWithoutBody = contentWithoutHead.replace(/<body[^>]*>|<\/body>/gi, '');
  56. $("#maineditor").html(contentWithoutBody);
  57. initEditor();
  58. } else {
  59. alert("Failed to load post content: " + data.error);
  60. }
  61. }).fail(function() {
  62. alert("Error loading post content.");
  63. });
  64. }
  65. $(window).on("resize", function(){
  66. $("#suneditor_maineditor").css("width", window.innerWidth + "px");
  67. });
  68. function getContent(){
  69. return editor.getContents();
  70. }
  71. function initEditor(){
  72. editor = SUNEDITOR.create(document.getElementById('maineditor'),
  73. {
  74. lang: SUNEDITOR_LANG['en'],
  75. buttonList: [
  76. ['undo', 'redo', 'save', 'preview'],
  77. ['font', 'fontSize', 'formatBlock'],
  78. ['paragraphStyle', 'blockquote'],
  79. ['bold', 'underline', 'italic', 'strike', 'subscript', 'superscript'],
  80. ['fontColor', 'hiliteColor'],
  81. ['removeFormat'],
  82. '/', // Line break
  83. ['outdent', 'indent'],
  84. ['align', 'horizontalRule', 'list', 'lineHeight'],
  85. ['table', 'link', 'image', 'video', 'audio' /** ,'math' */], // You must add the 'katex' library at options to use the 'math' plugin.
  86. /** ['imageGallery'] */ // You must add the "imageGalleryUrl".
  87. ['showBlocks', 'codeView']
  88. ],
  89. paragraphStyles : [
  90. {
  91. name: 'Segment',
  92. class: '__se__ ui segment',
  93. },
  94. {
  95. name: 'Red Segment',
  96. class: '__se__ ui red segment',
  97. },
  98. {
  99. name: 'Blue Segment',
  100. class: '__se__ ui blue segment',
  101. },
  102. {
  103. name: 'Green Segment',
  104. class: '__se__ ui green segment',
  105. },
  106. {
  107. name: 'Message',
  108. class: '__se__ ui message',
  109. },
  110. {
  111. name: 'Red Message',
  112. class: '__se__ ui red message',
  113. },
  114. {
  115. name: 'Blue Message',
  116. class: '__se__ ui blue message',
  117. },
  118. {
  119. name: 'Green Message',
  120. class: '__se__ ui green message',
  121. }
  122. ],
  123. "resizingBar": false,
  124. callBackSave : function (contents, isChanged) {
  125. parent.handleSavefile(contents);
  126. return false;
  127. }
  128. }
  129. );
  130. return editor;
  131. }
  132. </script>
  133. </body>
  134. </html>