editor.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. <script src="../script/jquery.min.js"></script>
  9. <script src="../script/ao_module.js"></script>
  10. <link rel="stylesheet" href="../script/tocas/tocas.css">
  11. <script src="../script/tocas/tocas.js"></script>
  12. <!-- Special handler to remove tocas css style-->
  13. <script>
  14. function clearTocasStyle(){
  15. console.log("Cleaning Styles")
  16. $("body").find("li, ul").each(function(){
  17. $(this).addClass("unstyled");
  18. });
  19. }
  20. window.clearTocasStyle = clearTocasStyle();
  21. </script>
  22. <!-- Editor -->
  23. <link href="script/suneditor/suneditor.min.css" rel="stylesheet">
  24. <script src="script/suneditor/suneditor.min.js"></script>
  25. <script src="script/suneditor/en.js"></script>
  26. <link rel="manifest" crossorigin="use-credentials" href="manifest.json">
  27. <title>Blog</title>
  28. <style>
  29. body {
  30. background-color: white;
  31. }
  32. .blog.main{
  33. background-color: #ff9224;
  34. border: 1px solid #ff9224;
  35. color: white;
  36. }
  37. .blog.main:hover{
  38. background-color: #c7721c !important;
  39. border: 1px solid #c7721c !important;
  40. color: white !important;
  41. }
  42. .blog.green{
  43. background-color: #47d191;
  44. border: 1px solid #47d191;
  45. color: white;
  46. }
  47. .blog.green:hover{
  48. background-color: #38a170 !important;
  49. border: 1px solid #38a170 !important;
  50. color: white !important;
  51. }
  52. .blog.red{
  53. background-color: #c4413d;
  54. border: 1px solid #c4413d;
  55. color: white;
  56. }
  57. .blog.red:hover{
  58. background-color: #8c302d !important;
  59. border: 1px solid #8c302d !important;
  60. color: white !important;
  61. }
  62. .topPad{
  63. margin-top: 4px;
  64. }
  65. #editorFrame{
  66. width: 100%;
  67. border: 0px solid transparent;
  68. height: 400px;
  69. }
  70. </style>
  71. </head>
  72. <body>
  73. <br><br>
  74. <div class="ts container">
  75. <div>
  76. <h4><img class="ts mini spaced image" src="img/module_icon.png" style="margin-right: 12px;"> Blog Writer</h4>
  77. </div>
  78. <div class="ts divider"></div>
  79. <div class="ts stackable grid">
  80. <div class="twelve wide column">
  81. <iframe id="editorFrame" src="framedEditor.html"></iframe>
  82. </div>
  83. <div class="four wide column">
  84. <form class="ts form">
  85. <div class="field">
  86. <h5>Post Title & Metatags</h5>
  87. </div>
  88. <div class="field">
  89. <label>Post Title</label>
  90. <input id="title" type="text">
  91. </div>
  92. <div class="field">
  93. <label>Tags (Seperate by ",")</label>
  94. <input id="tags" type="text">
  95. </div>
  96. <div class="field">
  97. </div>
  98. </form>
  99. <h5>Post Information</h5>
  100. <p><i class="hide icon"></i><span id="viewstate">Private Post</span></p>
  101. <p><span id="savepath">Not Saved</span></p>
  102. <h5>Actions</h5>
  103. <button class="ts fluid small button blog main" onclick="savePost(this);"><i class="save icon"></i> Save</button>
  104. <button class="ts fluid small button blog green topPad"><i class="upload icon"></i> Save & Publish</button>
  105. <br><br>
  106. <button class="ts fluid small button blog red topPad" onclick="discardAndExit();"><i class="remove icon"></i> Discard Changes</button>
  107. </div>
  108. </div>
  109. <br><br><br>
  110. </div>
  111. <script>
  112. var editingFile = "";
  113. var inputFiles = ao_module_loadInputFiles();
  114. var editorWindow = $("#editorFrame")[0].contentWindow;
  115. if (inputFiles != null && inputFiles.length > 0){
  116. //Edit mode
  117. inputFiles = inputFiles[0];
  118. }else{
  119. //New post mode
  120. }
  121. function newEditor(){
  122. editorWindow.newEditor();
  123. }
  124. function handleWindowResize(){
  125. $(editorWindow.document).find("#suneditor_maineditor").css("width", "100%");
  126. var newHeight = window.innerHeight - 300;
  127. if (newHeight < 500){
  128. newHeight = 500;
  129. }
  130. $(editorWindow.document).find("#suneditor_maineditor").css("height", newHeight + "px");
  131. $(editorWindow.document).find(".se-wrapper").css("height", newHeight - 138 + "px");
  132. $(editorWindow.document).find(".se-wrapper-inner").css("height", newHeight - 138 + "px");
  133. $("#editorFrame").css("height", (newHeight + 100) + "px");
  134. }
  135. $(window).on("resize", function(){
  136. handleWindowResize();
  137. });
  138. function clearTocasStyle(){
  139. console.log("Cleaning Styles")
  140. $("body").find("li, ul").each(function(){
  141. $(this).addClass("unstyled");
  142. });
  143. }
  144. function savePost(btn){
  145. $(btn).addClass("loading");
  146. var title = $("#title").val();
  147. var tags = $("#tags").val();
  148. if (title.trim() == ""){
  149. title = "Untitled Post"
  150. }
  151. //Get the content of the post
  152. var postContent = editorWindow.getContent();
  153. console.log(postContent);
  154. if (postContent == ""){
  155. $(btn).removeClass("loading");
  156. alert("Nothing to post :(")
  157. return;
  158. }
  159. //Create post
  160. ao_module_agirun("Blog/backend/savePost.js", {
  161. filepath: editingFile,
  162. title: title,
  163. tags: tags,
  164. content: postContent
  165. }, function(data){
  166. if (data.error !== undefined){
  167. alert(data.error);
  168. }else{
  169. //Return the filepath of the post storage
  170. editingFile = data;
  171. $("#savepath").text(data);
  172. }
  173. $(btn).removeClass("loading");
  174. });
  175. }
  176. function discardAndExit(){
  177. if (confirm("Confirm Exit?")){
  178. window.location.href = "index.html"
  179. }
  180. }
  181. </script>
  182. </body>
  183. </html>