123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- <!DOCTYPE html>
- <html lang="en">
- <!-- Special modification for NotepadA system, ArOZ Online Beta-->
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <title id='pageTitle'>NotepadA - Loading</title>
- <script src='../../script/jquery.min.js'></script>
- <script>
- $('body').css('background-color','white');
- function checkIsSaved(){
- return true;
- }
- </script>
- <script src="../../script/jquery.min.js"></script>
- <style type="text/css" media="screen">
- body {
- overflow: hidden;
- padding-bottom:5px;
- background-color:#2b2b2b;
- }
- #editor {
- margin: 0;
- position: absolute;
- top: 0;
- bottom: 15px;
- left: 0;
- right: 0;
- }
- </style>
- </head>
- <body>
- <pre id="editor"></pre>
- <script src="src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
- <script>
- //Get the filename, path and other information from the hash
- var filename = "";
- var filepath = "";
- var lastSave = "";
- var fontsize = 12;
- var theme = "github";
- var tabid = "";
- var editor = undefined;
- window.onhashchange = function(e){
- initEditor();
- }
- initEditor();
- function initEditor(){
- if (window.location.hash.length > 0){
- var payload = window.location.hash.substr(1);
- payload = JSON.parse(decodeURIComponent(payload));
- filepath = payload.filename;
- let basename = payload.filename.split("/").pop();
- filename = basename;
- fontsize = payload.fontsize;
- theme = payload.theme;
- tabid = payload.tabid;
- console.log("NotepadA editor loaded: ", payload);
- //Load the content of the file
- $.get("../../media?file=" + filepath, function(fileContent){
- if (fileContent.error !== undefined){
- //Failed to get file
- setTimeout(function(){
- parent.removeTab(tabid);
- },300);
- return
- }
- if (typeof fileContent == "object"){
- //Loading a json file
- fileContent = JSON.stringify(fileContent);
- }
- $("#editor").text(fileContent);
- //Start the editor if not started
- if (editor == undefined){
- StartEditor();
- }
- });
- }else{
- alert("Invalid use of editor!")
- }
- }
-
- document.addEventListener("mousedown", function(event) {
- //When click on this document, focus this
- if (parent.ao_module_virtualDesktop){
- parent.ao_module_focus();
- }
- }, true);
- function StartEditor(){
- //Init editor
- editor = ace.edit("editor");
- editor.setTheme("ace/theme/" + theme);
- var detectMode = getMode(filepath);
- //console.log("[NotepadA] Chaning mode to " + detectMode.toLowerCase());
- if ( detectMode != undefined){
- editor.session.setMode("ace/mode/" + detectMode.toLowerCase());
-
- }else{
- //Default mode: php
- editor.session.setMode("ace/mode/php");
- }
- editor.setOptions({
- //fontFamily: "tahoma",
- fontSize: fontsize + "pt"
- });
- lastSave = editor.getValue();
- }
-
-
- //Listener for Ctrl+S
- $(window).keypress(function(event) {
- if (!(event.which == 115 && event.ctrlKey) && !(event.which == 19)) return true;
- //console.log(filepath);
- Save();
- event.preventDefault();
- return false;
- });
-
- $(document).on("click","#editor",function() {
- //Hide the parent window in NotepadA condition
- window.parent.hideToggleMenu();
- });
- function Print() {
- try {
- var printWindow = window.open("", "", "height=400,width=800");
- printWindow.document.write(`<html><head><title>${filename} ${new Date().toLocaleString()}</title>`);
- printWindow.document.write("</head><xmp>");
- printWindow.document.write(editor.getSession().getDocument().getValue());
- printWindow.document.write("</xmp></html>");
- printWindow.document.close();
- printWindow.print();
- }catch (ex) {
- console.error("Error: " + ex.message);
- }
- }
-
- //Absolute path is used for saving. So no need to worry about the relative path over php issues
- function Save(){
- code = editor.getValue();
- parent.ao_module_agirun(parent.moduleRootPath + "backend/filesaver.js", {
- filepath: filepath,
- content: code
- }, function(data){
- if (data.error == undefined){
- //Finish writting to the file
- console.log("%c[NotepadA] " + filename + " -> Saved!","color:#1265ea");
- lastSave = code;
- }else{
- alert(data.error);
- console.log(data);
- }
- })
- /*
- $.post("../writeCode.php", { filename: filepath, content: code })
- .done(function( data ) {
- if (data.includes("ERROR") == false){
- console.log("%c[NotepadA] " + filename + " -> Saved!","color:#1265ea");
- lastSave = code;
- }else{
- console.log(data);
- }
- });
- */
- }
-
- function getDocWidth(){
- return $(document).width();
- }
-
- function checkIsSaved(){
- if (typeof(editor) == "undefined"){
- //Editor not started
- return
- }
- if (lastSave == editor.getValue()){
- return true;
- }else{
- return false;
- }
- }
-
- function insertChar(text){
- editor.session.insert(editor.getCursorPosition(), text);
- }
-
- function getEditorContenet(){
- return editor.getValue();
- }
-
- function getFilepath(){
- return (filepath);
- }
-
- function openInNewTab(){
- window.open("../../media?file=" + filepath);
- }
-
- function getSelectedText(){
- return editor.getSession().doc.getTextRange(editor.selection.getRange());
- }
-
- function insertGivenText(text){
- editor.session.insert(editor.getCursorPosition(), text);
- }
-
- function callUndo(){
- editor.getSession().getUndoManager().undo();
- }
-
- function callRedo(){
- editor.getSession().getUndoManager().redo();
- }
- var nameOverrides = {
- ObjectiveC: "Objective-C",
- CSharp: "C#",
- golang: "Go",
- C_Cpp: "C and C++",
- Csound_Document: "Csound Document",
- Csound_Orchestra: "Csound",
- Csound_Score: "Csound Score",
- coffee: "CoffeeScript",
- HTML_Ruby: "HTML (Ruby)",
- HTML_Elixir: "HTML (Elixir)",
- FTL: "FreeMarker"
- };
- function startSearchBox(){
- editor.execCommand("find");
- }
- function getMode(filePath){
- var ext = filePath.split(".").pop();
- var supportedModes = {
- ABAP: ["abap"],
- ABC: ["abc"],
- ActionScript:["as"],
- ADA: ["ada|adb"],
- Apache_Conf: ["^htaccess|^htgroups|^htpasswd|^conf|htaccess|htgroups|htpasswd"],
- AsciiDoc: ["asciidoc|adoc"],
- ASL: ["dsl|asl"],
- Assembly_x86:["asm|a"],
- AutoHotKey: ["ahk"],
- BatchFile: ["bat|cmd"],
- Bro: ["bro"],
- C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp|ino"],
- C9Search: ["c9search_results"],
- Cirru: ["cirru|cr"],
- Clojure: ["clj|cljs"],
- Cobol: ["CBL|COB"],
- coffee: ["coffee|cf|cson|^Cakefile"],
- ColdFusion: ["cfm"],
- CSharp: ["cs"],
- Csound_Document: ["csd"],
- Csound_Orchestra: ["orc"],
- Csound_Score: ["sco"],
- CSS: ["css"],
- Curly: ["curly"],
- D: ["d|di"],
- Dart: ["dart"],
- Diff: ["diff|patch"],
- Dockerfile: ["^Dockerfile"],
- Dot: ["dot"],
- Drools: ["drl"],
- Edifact: ["edi"],
- Eiffel: ["e|ge"],
- EJS: ["ejs"],
- Elixir: ["ex|exs"],
- Elm: ["elm"],
- Erlang: ["erl|hrl"],
- Forth: ["frt|fs|ldr|fth|4th"],
- Fortran: ["f|f90"],
- FTL: ["ftl"],
- Gcode: ["gcode"],
- Gherkin: ["feature"],
- Gitignore: ["^.gitignore"],
- Glsl: ["glsl|frag|vert"],
- Gobstones: ["gbs"],
- golang: ["go"],
- GraphQLSchema: ["gql"],
- Groovy: ["groovy"],
- HAML: ["haml"],
- Handlebars: ["hbs|handlebars|tpl|mustache"],
- Haskell: ["hs"],
- Haskell_Cabal: ["cabal"],
- haXe: ["hx"],
- Hjson: ["hjson"],
- HTML: ["html|htm|xhtml|vue|we|wpy"],
- HTML_Elixir: ["eex|html.eex"],
- HTML_Ruby: ["erb|rhtml|html.erb"],
- INI: ["ini|conf|cfg|prefs"],
- Io: ["io"],
- Jack: ["jack"],
- Jade: ["jade|pug"],
- Java: ["java"],
- JavaScript: ["js|jsm|jsx"],
- JSON: ["json"],
- JSONiq: ["jq"],
- JSP: ["jsp"],
- JSSM: ["jssm|jssm_state"],
- JSX: ["jsx"],
- Julia: ["jl"],
- Kotlin: ["kt|kts"],
- LaTeX: ["tex|latex|ltx|bib"],
- LESS: ["less"],
- Liquid: ["liquid"],
- Lisp: ["lisp"],
- LiveScript: ["ls"],
- LogiQL: ["logic|lql"],
- LSL: ["lsl"],
- Lua: ["lua"],
- LuaPage: ["lp"],
- Lucene: ["lucene"],
- Makefile: ["^Makefile|^GNUmakefile|^makefile|^OCamlMakefile|make"],
- Markdown: ["md|markdown"],
- Mask: ["mask"],
- MATLAB: ["matlab"],
- Maze: ["mz"],
- MEL: ["mel"],
- MIXAL: ["mixal"],
- MUSHCode: ["mc|mush"],
- MySQL: ["mysql"],
- Nix: ["nix"],
- NSIS: ["nsi|nsh"],
- ObjectiveC: ["m|mm"],
- OCaml: ["ml|mli"],
- Pascal: ["pas|p"],
- Perl: ["pl|pm"],
- pgSQL: ["pgsql"],
- PHP: ["php|phtml|shtml|php3|php4|php5|phps|phpt|aw|ctp|module"],
- Pig: ["pig"],
- Powershell: ["ps1"],
- Praat: ["praat|praatscript|psc|proc"],
- Prolog: ["plg|prolog"],
- Properties: ["properties"],
- Protobuf: ["proto"],
- Python: ["py"],
- R: ["r"],
- Razor: ["cshtml|asp"],
- RDoc: ["Rd"],
- Red: ["red|reds"],
- RHTML: ["Rhtml"],
- RST: ["rst"],
- Ruby: ["rb|ru|gemspec|rake|^Guardfile|^Rakefile|^Gemfile"],
- Rust: ["rs"],
- SASS: ["sass"],
- SCAD: ["scad"],
- Scala: ["scala"],
- Scheme: ["scm|sm|rkt|oak|scheme"],
- SCSS: ["scss"],
- SH: ["sh|bash|^.bashrc"],
- SJS: ["sjs"],
- Smarty: ["smarty|tpl"],
- snippets: ["snippets"],
- Soy_Template:["soy"],
- Space: ["space"],
- SQL: ["sql"],
- SQLServer: ["sqlserver"],
- Stylus: ["styl|stylus"],
- SVG: ["svg"],
- Swift: ["swift"],
- Tcl: ["tcl"],
- Tex: ["tex"],
- Text: ["txt"],
- Textile: ["textile"],
- Toml: ["toml"],
- TSX: ["tsx"],
- Twig: ["twig|swig"],
- Typescript: ["ts|typescript|str"],
- Vala: ["vala"],
- VBScript: ["vbs|vb"],
- Velocity: ["vm"],
- Verilog: ["v|vh|sv|svh"],
- VHDL: ["vhd|vhdl"],
- Wollok: ["wlk|wpgm|wtest"],
- XML: ["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl|xaml"],
- XQuery: ["xq"],
- YAML: ["yaml|yml"],
- Django: ["html"]
- };
- for (var key in supportedModes) {
- if (supportedModes.hasOwnProperty(key)) {
- var thisExtension = supportedModes[key][0].split("|");
- if (thisExtension.length == 1){
- if (ext == thisExtension[0]){
- return key;
- }
- }else{
- for(var i =0; i < thisExtension.length;i++){
- if (ext == thisExtension[i]){
- return key;
- }
- }
- }
- }
- }
- }
- $(window).bind('keydown', function(event) {
- if (event.ctrlKey || event.metaKey) {
- switch (String.fromCharCode(event.which).toLowerCase()) {
- case 's':
- event.preventDefault();
- Save();
- break;
- }
- }
- });
- </script>
- </body>
- </html>
|