editor.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <!-- Special modification for NotepadA system, ArOZ Online Beta-->
  4. <head>
  5. <meta charset="UTF-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  7. <title id='pageTitle'>NotepadA - Loading</title>
  8. <script src='../../script/jquery.min.js'></script>
  9. <script>
  10. $('body').css('background-color','white');
  11. function checkIsSaved(){
  12. return true;
  13. }
  14. </script>
  15. <script src="../../script/jquery.min.js"></script>
  16. <style type="text/css" media="screen">
  17. body {
  18. overflow: hidden;
  19. padding-bottom:5px;
  20. background-color:#2b2b2b;
  21. }
  22. #editor {
  23. margin: 0;
  24. position: absolute;
  25. top: 0;
  26. bottom: 15px;
  27. left: 0;
  28. right: 0;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <pre id="editor"></pre>
  34. <script src="src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
  35. <script>
  36. //Get the filename, path and other information from the hash
  37. var filename = "";
  38. var filepath = "";
  39. var lastSave = "";
  40. var fontsize = 12;
  41. var theme = "github";
  42. var editor;
  43. if (window.location.hash.length > 0){
  44. var payload = window.location.hash.substr(1);
  45. payload = JSON.parse(decodeURIComponent(payload));
  46. filepath = payload.filename;
  47. let basename = payload.filename.split("/").pop();
  48. filename = basename;
  49. fontsize = payload.fontsize;
  50. theme = payload.theme;
  51. console.log("NotepadA editor loaded: ", payload);
  52. //Load the content of the file
  53. $.get("../../media?file=" + filepath, function(fileContent){
  54. $("#editor").html(fileContent);
  55. //Start the editor
  56. StartEditor();
  57. });
  58. }else{
  59. alert("Invalid use of editor!")
  60. }
  61. function StartEditor(){
  62. //Init editor
  63. editor = ace.edit("editor");
  64. editor.setTheme("ace/theme/" + theme);
  65. var detectMode = getMode(filepath);
  66. //console.log("[NotepadA] Chaning mode to " + detectMode.toLowerCase());
  67. if ( detectMode != undefined){
  68. editor.session.setMode("ace/mode/" + detectMode.toLowerCase());
  69. }else{
  70. //Default mode: php
  71. editor.session.setMode("ace/mode/php");
  72. }
  73. editor.setOptions({
  74. //fontFamily: "tahoma",
  75. fontSize: fontsize + "pt"
  76. });
  77. lastSave = editor.getValue();
  78. }
  79. //Listener for Ctrl+S
  80. $(window).keypress(function(event) {
  81. if (!(event.which == 115 && event.ctrlKey) && !(event.which == 19)) return true;
  82. //console.log(filepath);
  83. Save();
  84. event.preventDefault();
  85. return false;
  86. });
  87. $(document).on("click","#editor",function() {
  88. //Hide the parent window in NotepadA condition
  89. window.parent.hideToggleMenu();
  90. });
  91. function Print() {
  92. try {
  93. var printWindow = window.open("", "", "height=400,width=800");
  94. printWindow.document.write("<html><head><title>NotepadA Print Window</title>");
  95. printWindow.document.write("</head><xmp>");
  96. printWindow.document.write("filename: " + filename + " \nprint-time: " + new Date().toLocaleString() + "\n");
  97. printWindow.document.write(editor.getSession().getDocument().getValue());
  98. printWindow.document.write("</xmp></html>");
  99. printWindow.document.close();
  100. printWindow.print();
  101. }catch (ex) {
  102. console.error("Error: " + ex.message);
  103. }
  104. }
  105. //Absolute path is used for saving. So no need to worry about the relative path over php issues
  106. function Save(){
  107. code = editor.getValue();
  108. $.post("../writeCode.php", { filename: filepath, content: code })
  109. .done(function( data ) {
  110. if (data.includes("ERROR") == false){
  111. console.log("%c[NotepadA] " + filename + " -> Saved!","color:#1265ea");
  112. lastSave = code;
  113. }else{
  114. console.log(data);
  115. }
  116. });
  117. }
  118. function getDocWidth(){
  119. return $(document).width();
  120. }
  121. function checkIsSaved(){
  122. if (typeof(editor) == "undefined"){
  123. //Editor not started
  124. return
  125. }
  126. if (lastSave == editor.getValue()){
  127. return true;
  128. }else{
  129. return false;
  130. }
  131. }
  132. function insertChar(text){
  133. editor.session.insert(editor.getCursorPosition(), text);
  134. }
  135. function getEditorContenet(){
  136. return editor.getValue();
  137. }
  138. function getFilepath(){
  139. return (filename.replace("../",""));
  140. }
  141. function openInNewTab(){
  142. if (filename.substring(0,14) == "/media/storage"){
  143. window.open("../SystemAOB/functions/extDiskAccess.php?file=" + filename);
  144. }else{
  145. window.open(filename.replace("../",""));
  146. }
  147. }
  148. function getSelectedText(){
  149. return editor.getSession().doc.getTextRange(editor.selection.getRange());
  150. }
  151. function insertGivenText(text){
  152. editor.session.insert(editor.getCursorPosition(), text);
  153. }
  154. function callUndo(){
  155. editor.getSession().getUndoManager().undo();
  156. }
  157. function callRedo(){
  158. editor.getSession().getUndoManager().redo();
  159. }
  160. var nameOverrides = {
  161. ObjectiveC: "Objective-C",
  162. CSharp: "C#",
  163. golang: "Go",
  164. C_Cpp: "C and C++",
  165. Csound_Document: "Csound Document",
  166. Csound_Orchestra: "Csound",
  167. Csound_Score: "Csound Score",
  168. coffee: "CoffeeScript",
  169. HTML_Ruby: "HTML (Ruby)",
  170. HTML_Elixir: "HTML (Elixir)",
  171. FTL: "FreeMarker"
  172. };
  173. function startSearchBox(){
  174. editor.execCommand("find");
  175. }
  176. function getMode(filePath){
  177. var ext = filePath.split(".").pop();
  178. var supportedModes = {
  179. ABAP: ["abap"],
  180. ABC: ["abc"],
  181. ActionScript:["as"],
  182. ADA: ["ada|adb"],
  183. Apache_Conf: ["^htaccess|^htgroups|^htpasswd|^conf|htaccess|htgroups|htpasswd"],
  184. AsciiDoc: ["asciidoc|adoc"],
  185. ASL: ["dsl|asl"],
  186. Assembly_x86:["asm|a"],
  187. AutoHotKey: ["ahk"],
  188. BatchFile: ["bat|cmd"],
  189. Bro: ["bro"],
  190. C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp|ino"],
  191. C9Search: ["c9search_results"],
  192. Cirru: ["cirru|cr"],
  193. Clojure: ["clj|cljs"],
  194. Cobol: ["CBL|COB"],
  195. coffee: ["coffee|cf|cson|^Cakefile"],
  196. ColdFusion: ["cfm"],
  197. CSharp: ["cs"],
  198. Csound_Document: ["csd"],
  199. Csound_Orchestra: ["orc"],
  200. Csound_Score: ["sco"],
  201. CSS: ["css"],
  202. Curly: ["curly"],
  203. D: ["d|di"],
  204. Dart: ["dart"],
  205. Diff: ["diff|patch"],
  206. Dockerfile: ["^Dockerfile"],
  207. Dot: ["dot"],
  208. Drools: ["drl"],
  209. Edifact: ["edi"],
  210. Eiffel: ["e|ge"],
  211. EJS: ["ejs"],
  212. Elixir: ["ex|exs"],
  213. Elm: ["elm"],
  214. Erlang: ["erl|hrl"],
  215. Forth: ["frt|fs|ldr|fth|4th"],
  216. Fortran: ["f|f90"],
  217. FTL: ["ftl"],
  218. Gcode: ["gcode"],
  219. Gherkin: ["feature"],
  220. Gitignore: ["^.gitignore"],
  221. Glsl: ["glsl|frag|vert"],
  222. Gobstones: ["gbs"],
  223. golang: ["go"],
  224. GraphQLSchema: ["gql"],
  225. Groovy: ["groovy"],
  226. HAML: ["haml"],
  227. Handlebars: ["hbs|handlebars|tpl|mustache"],
  228. Haskell: ["hs"],
  229. Haskell_Cabal: ["cabal"],
  230. haXe: ["hx"],
  231. Hjson: ["hjson"],
  232. HTML: ["html|htm|xhtml|vue|we|wpy"],
  233. HTML_Elixir: ["eex|html.eex"],
  234. HTML_Ruby: ["erb|rhtml|html.erb"],
  235. INI: ["ini|conf|cfg|prefs"],
  236. Io: ["io"],
  237. Jack: ["jack"],
  238. Jade: ["jade|pug"],
  239. Java: ["java"],
  240. JavaScript: ["js|jsm|jsx"],
  241. JSON: ["json"],
  242. JSONiq: ["jq"],
  243. JSP: ["jsp"],
  244. JSSM: ["jssm|jssm_state"],
  245. JSX: ["jsx"],
  246. Julia: ["jl"],
  247. Kotlin: ["kt|kts"],
  248. LaTeX: ["tex|latex|ltx|bib"],
  249. LESS: ["less"],
  250. Liquid: ["liquid"],
  251. Lisp: ["lisp"],
  252. LiveScript: ["ls"],
  253. LogiQL: ["logic|lql"],
  254. LSL: ["lsl"],
  255. Lua: ["lua"],
  256. LuaPage: ["lp"],
  257. Lucene: ["lucene"],
  258. Makefile: ["^Makefile|^GNUmakefile|^makefile|^OCamlMakefile|make"],
  259. Markdown: ["md|markdown"],
  260. Mask: ["mask"],
  261. MATLAB: ["matlab"],
  262. Maze: ["mz"],
  263. MEL: ["mel"],
  264. MIXAL: ["mixal"],
  265. MUSHCode: ["mc|mush"],
  266. MySQL: ["mysql"],
  267. Nix: ["nix"],
  268. NSIS: ["nsi|nsh"],
  269. ObjectiveC: ["m|mm"],
  270. OCaml: ["ml|mli"],
  271. Pascal: ["pas|p"],
  272. Perl: ["pl|pm"],
  273. pgSQL: ["pgsql"],
  274. PHP: ["php|phtml|shtml|php3|php4|php5|phps|phpt|aw|ctp|module"],
  275. Pig: ["pig"],
  276. Powershell: ["ps1"],
  277. Praat: ["praat|praatscript|psc|proc"],
  278. Prolog: ["plg|prolog"],
  279. Properties: ["properties"],
  280. Protobuf: ["proto"],
  281. Python: ["py"],
  282. R: ["r"],
  283. Razor: ["cshtml|asp"],
  284. RDoc: ["Rd"],
  285. Red: ["red|reds"],
  286. RHTML: ["Rhtml"],
  287. RST: ["rst"],
  288. Ruby: ["rb|ru|gemspec|rake|^Guardfile|^Rakefile|^Gemfile"],
  289. Rust: ["rs"],
  290. SASS: ["sass"],
  291. SCAD: ["scad"],
  292. Scala: ["scala"],
  293. Scheme: ["scm|sm|rkt|oak|scheme"],
  294. SCSS: ["scss"],
  295. SH: ["sh|bash|^.bashrc"],
  296. SJS: ["sjs"],
  297. Smarty: ["smarty|tpl"],
  298. snippets: ["snippets"],
  299. Soy_Template:["soy"],
  300. Space: ["space"],
  301. SQL: ["sql"],
  302. SQLServer: ["sqlserver"],
  303. Stylus: ["styl|stylus"],
  304. SVG: ["svg"],
  305. Swift: ["swift"],
  306. Tcl: ["tcl"],
  307. Tex: ["tex"],
  308. Text: ["txt"],
  309. Textile: ["textile"],
  310. Toml: ["toml"],
  311. TSX: ["tsx"],
  312. Twig: ["twig|swig"],
  313. Typescript: ["ts|typescript|str"],
  314. Vala: ["vala"],
  315. VBScript: ["vbs|vb"],
  316. Velocity: ["vm"],
  317. Verilog: ["v|vh|sv|svh"],
  318. VHDL: ["vhd|vhdl"],
  319. Wollok: ["wlk|wpgm|wtest"],
  320. XML: ["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl|xaml"],
  321. XQuery: ["xq"],
  322. YAML: ["yaml|yml"],
  323. Django: ["html"]
  324. };
  325. for (var key in supportedModes) {
  326. if (supportedModes.hasOwnProperty(key)) {
  327. var thisExtension = supportedModes[key][0].split("|");
  328. if (thisExtension.length == 1){
  329. if (ext == thisExtension[0]){
  330. return key;
  331. }
  332. }else{
  333. for(var i =0; i < thisExtension.length;i++){
  334. if (ext == thisExtension[i]){
  335. return key;
  336. }
  337. }
  338. }
  339. }
  340. }
  341. }
  342. $(window).bind('keydown', function(event) {
  343. if (event.ctrlKey || event.metaKey) {
  344. switch (String.fromCharCode(event.which).toLowerCase()) {
  345. case 's':
  346. event.preventDefault();
  347. Save();
  348. break;
  349. }
  350. }
  351. });
  352. </script>
  353. </body>
  354. </html>