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

39
LINES

< > BotCompany Repo | #1030234 // hAceEditor [WORKS]

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3236L/21K).

1  
// TODO: works only once on a page
2  
// requires JQuery
3  
sS hAceEditor(S text, O... _) {
4  
  //_ = html_massageAutofocusParam(_);
5  
  optPar S name = "text";
6  
  S id = "ace_" + name;
7  
  
8  
  ret div(htmlEncode2(text), params_stylePlus("display: none", paramsPlus(_, +id)))
9  
    + hscriptsrc("https://botcompany.de/ace-builds/src-noconflict/ace.js")
10  
    + hscriptsrc("https://botcompany.de/ace-builds/src-noconflict/ext-language_tools.js")
11  
    + hhiddenWithIDAndName(name)
12  
    + hscript(replaceDollarVars([[ {
13  
      ace.require("ace/ext/language_tools");
14  
      var editor = ace.edit($id);
15  
      editor.setTheme("ace/theme/ambience");
16  
      editor.getSession().setTabSize(2);
17  
      editor.getSession().setUseSoftTabs(true);
18  
      editor.getSession().setUseWrapMode(true);
19  
      document.getElementById($id).style.fontSize='15px';
20  
      editor.setOptions({
21  
        enableBasicAutocompletion: true
22  
      });
23  
      
24  
      var hiddenVal = document.getElementById($name);
25  
      function updateHidden() {
26  
        //hiddenVal.value = editor.getValue();
27  
        var newVal = editor.getValue();
28  
        if (hiddenVal.value != newVal)
29  
          $(hiddenVal).val(newVal).trigger('change');
30  
      }
31  
      updateHidden();
32  
      
33  
      editor.session.on('change', updateHidden);
34  
35  
      var div = $("#" + $id);
36  
      div.show();
37  
      //editor.focus();
38  
    } ]], id := jsQuote(id), name := jsQuote(name));
39  
}

Author comment

Began life as a copy of #1009277

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030234
Snippet name: hAceEditor [WORKS]
Eternal ID of this version: #1030234/18
Text MD5: 7ce8f0ae592146348d36ef08a0550507
Transpilation MD5: 6616af22ea478d50b62e6ed25237abe8
Author: stefan
Category: javax / html
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-20 12:57:40
Source code size: 1416 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 201 / 312
Version history: 17 change(s)
Referenced in: [show references]