editor.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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><a href="index.html" style="color: inherit;"><img class="ts mini spaced image" src="img/module_icon.png" style="margin-right: 12px;"> Blog Writer</h4></a>
  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. var currentWebDeployRoot = "";
  116. if (inputFiles != null && inputFiles.length > 0){
  117. //Edit mode
  118. inputFiles = inputFiles[0];
  119. }else{
  120. //New post mode
  121. }
  122. getWebRoot();
  123. function newEditor(){
  124. editorWindow.newEditor();
  125. }
  126. function handleWindowResize(){
  127. $(editorWindow.document).find("#suneditor_maineditor").css("width", "100%");
  128. var newHeight = window.innerHeight - 300;
  129. if (newHeight < 500){
  130. newHeight = 500;
  131. }
  132. $(editorWindow.document).find("#suneditor_maineditor").css("height", newHeight + "px");
  133. $(editorWindow.document).find(".se-wrapper").css("height", newHeight - 138 + "px");
  134. $(editorWindow.document).find(".se-wrapper-inner").css("height", newHeight - 138 + "px");
  135. $("#editorFrame").css("height", (newHeight + 100) + "px");
  136. }
  137. $(window).on("resize", function(){
  138. handleWindowResize();
  139. });
  140. function clearTocasStyle(){
  141. console.log("Cleaning Styles")
  142. $("body").find("li, ul").each(function(){
  143. $(this).addClass("unstyled");
  144. });
  145. }
  146. function savePost(btn){
  147. $(btn).addClass("loading");
  148. var title = $("#title").val();
  149. var tags = $("#tags").val();
  150. if (title.trim() == ""){
  151. title = "Untitled Post"
  152. }
  153. //Get the content of the post
  154. var postContent = editorWindow.getContent();
  155. console.log(postContent);
  156. if (postContent == ""){
  157. $(btn).removeClass("loading");
  158. alert("Nothing to post :(")
  159. return;
  160. }
  161. //Create post
  162. ao_module_agirun("Blog/backend/savePost.js", {
  163. filepath: editingFile,
  164. title: title,
  165. tags: tags,
  166. content: postContent,
  167. webroot: currentWebDeployRoot
  168. }, function(data){
  169. if (data.error !== undefined){
  170. alert(data.error);
  171. }else{
  172. //Return the filepath of the post storage
  173. editingFile = data;
  174. $("#savepath").text(data);
  175. }
  176. $(btn).removeClass("loading");
  177. });
  178. }
  179. function discardAndExit(){
  180. if (confirm("Confirm Exit?")){
  181. window.location.href = "index.html"
  182. }
  183. }
  184. function getWebRoot(callback = undefined){
  185. $.get("../system/network/www/webRoot", function(data){
  186. if (data == null || data == "" || data == undefined){
  187. callback("");
  188. return;
  189. }
  190. currentWebDeployRoot = data;
  191. if (callback != undefined){
  192. callback(data);
  193. }
  194. });
  195. }
  196. </script>
  197. </body>
  198. </html>