0

I need to create a fake input so that i can change the content to be html elements.

Like in Desmos app you can type something like : a^b and it will change to ab witch in html is:a<sup>b</sup.

Also see the Monaco Editor that does syntax highlighting, autocomplete, etc.

I am familiar with contenteditable attribute but in Demos they don't use it.

in both of these applications they implementing a fake input without using text area , hidden input, or contenteditable attribute.

So my question is how to achieve that behavior and implement a fake input with fake oninput, onblur, oncopy etc handler functions.

kfir2142
  • 19
  • 3
  • It looks as if they have an onfocus of the element which then kicks of a onkeyup function which will read your keystrokes and depending on what you press, they add attributes to a span (which in turn must populate the html) – Pete Oct 11 '17 at 14:32

1 Answers1

0

You can use keydown/keyup/keypress events for edit content in your fake-field. Something like this:

$(document).click(function (e) {
    if($(e.target).is("#your_editor")) {
        // editor area focused
        if($(this).hasClass("focused")) {
            return;
        }
        $(this).addClass("focused");
    } else {
        // editor area is not focused
        $("#your_editor").removeClass("focused");
    }
});

$(document).keydown(function (e) {
    // some key are pressed
    if($("#your_editor").hasClass("focused")) {
        // do something with e.keyCode
    }
});
Sergey
  • 1
  • 1