Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

105
LINES

< > BotCompany Repo | #1009208 // Ace Editor Test [syntax-enhanced editor for web pages, WORKS]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (10959L/76K/234K).

1  
!7
2  
3  
static S text, title;
4  
5  
concept Text {
6  
  S conceptID;
7  
  S title;
8  
  S text;
9  
  S by;
10  
}
11  
12  
p {
13  
  db();
14  
  indexConceptField(Text, 'conceptID);
15  
  indexConceptField(Text, 'by);
16  
  load("text");
17  
  load("title");
18  
  if (isMainProgram()) serveHttpAndOpenBrowser();
19  
}
20  
21  
synchronized html {
22  
  uri = dropPrefix("/", uri);
23  
  
24  
  if (possibleGlobalID(uri)) {
25  
    S id = uri;
26  
    Text t = findConcept(Text, conceptID := id);
27  
    ret t == null ? "Text with ID " + id + " not found" : 
28  
      p(ahref(botLink(), "&lt;&lt; back"))
29  
      + h3(t.conceptID + " - " + dynamize(or2(t.title, "Untitled")))
30  
      + textFormat(t.text)
31  
      + p("by " + t.by);
32  
  }
33  
  
34  
  S newTitle = params.get("title");
35  
  if (newTitle != null) {
36  
    title = newTitle;
37  
    save("title");
38  
  }
39  
  
40  
  S newText = params.get("text");
41  
  if (newText != null) {
42  
    text = newText;
43  
    save("text");
44  
  }
45  
  
46  
  S user = cookieConcept();
47  
  S msg = "";
48  
  
49  
  if (nempty(params.get("publish"))) {
50  
    Text t = uniq_sync(Text, +title, +text, by := user);
51  
    if (empty(t.conceptID)) cset(t, conceptID := aGlobalID());
52  
    msg = "Published as: " + t.conceptID;
53  
  }
54  
  
55  
  S list = p("Published texts: " + join(", ", map(func(Text t) {
56  
    ahref(selfLink(t.conceptID), t.conceptID) }, list(Text))));
57  
  
58  
  ret
59  
    (empty(msg) ? "" : p(msg))
60  
    + list
61  
    + p("You are: " + or2(user, "?"))
62  
    + hpostform([[
63  
<style type="text/css" media="screen">
64  
    #editor { 
65  
        width: 600px;
66  
        height: 350px;
67  
    }
68  
</style>
69  
<table><tr><td>
70  
</td></tr>
71  
Title: <input type="text" name="title" value="#TITLE#<>">
72  
<tr><td>
73  
      <div id="editor">#TEXT#<></div>
74  
    <script src="http://tinybrain.de:8080/ace-builds/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
75  
    <script src="http://tinybrain.de:8080/ace-builds/src-noconflict/ext-language_tools.js" type="text/javascript" charset="utf-8"></script>
76  
    <script>
77  
        ace.require("ace/ext/language_tools");
78  
        var editor = ace.edit("editor");
79  
        editor.setTheme("ace/theme/ambience");
80  
        //editor.getSession().setMode("ace/mode/lua");
81  
        editor.getSession().setTabSize(2);
82  
        editor.getSession().setUseSoftTabs(true);
83  
        editor.getSession().setUseWrapMode(true);
84  
        document.getElementById('editor').style.fontSize='15px';
85  
        editor.setOptions({
86  
          enableBasicAutocompletion: true
87  
        });
88  
        editor.focus();
89  
    </script>
90  
   <input type="hidden" name="text" value="">
91  
 </td></tr>
92  
 <tr><td>
93  
 <input type="submit" value="Save">
94  
 <br><br>
95  
 <input type="submit" name="publish" value="Publish this text">
96  
 </td></tr></table>
97  
  ]].replace("#TITLE#<>", htmlencode(title))
98  
    .replace("#TEXT#<>", htmlencode(text)),
99  
    onSubmit := "if (editor) text.value = editor.getValue(); return true;");
100  
}
101  
102  
sS textFormat(S text) {
103  
  ret div(pre(dynamize(text)),
104  
    style := "padding-left: 1em; padding-top: 0.5em; padding-bottom: 0.5em; background-color: #EEEEEE; border-style: solid; border-color: #666666; border-width: 1px 0px 1px 0px;");
105  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009208
Snippet name: Ace Editor Test [syntax-enhanced editor for web pages, WORKS]
Eternal ID of this version: #1009208/24
Text MD5: 69bb6aa539d78fb43a38f00046d0cba7
Transpilation MD5: 820d9124544357107a727c7c29983642
Author: stefan
Category: javax / html
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-17 00:34:12
Source code size: 3091 bytes / 105 lines
Pitched / IR pitched: No / No
Views / Downloads: 520 / 775
Version history: 23 change(s)
Referenced in: [show references]