Answer the question
In order to leave comments, you need to log in
How to do WYSIWYG with jQuery?
Explain on your fingers how to make a simple vizivig editor like TinyMCE or CKEditor. I am interested in the idea without all the subtleties. Thank you.
Answer the question
In order to leave comments, you need to log in
You need to use the designMode document property. You can open a document in designMode in an iframe.
Something like this:
in the code, the parser eats "<" and ">" (
I once wrote WYSIWYG from scratch, if necessary I can look for the source code.
document.writeln(' iframe id="' + editor + '" /iframe ');
var edit = document.getElementById(editor).contentWindow.document;
edit.designMode = "On";
There was an idea to write a short article, presenting the simplest editor in 2 KB using jQuery, but then I scored (the editor itself is, too lazy to design). If you are interested, I will give the code in a personal correspondence.
When I was tinkering with this, I didn’t really like the designMode option - an abundance of left tags, difficulties with their overlap, and the like. I end up leaning towards creating and positioning various inputs and styling them to match the element being edited.
And Googledocs, as far as I remember, simply catch the events of pressing the keyboard keys, substituting them with javascript in the place where the cursor is set. The cursor, by the way, is also drawn there manually - it is not native.
Have a look at imperavi . Maybe you don't need to write anything. And if necessary, the license is open there, you can see the implementation and finish it or make your own with blackjack.
+1 for imperavi. Most understandable code. Best for studying.
But the idea of writing CKEditor is obviously unhealthy - you will drown in cross-browser.
The same imperavi has to be finished
I wrote my own WYSIWYG though it doesn't fully work in IE yet, but it's enough for my purposes.
github.com/un1t/pencil
The code is small, easy to understand. It’s hard to write, visivig yourself, but to finish someone else’s is even more difficult. If you fix a couple of broken moments in IE, then you can use it quite normally.
If you want, you can help me finish it.
nicEdit. You can select the elements that will be displayed on the panel. If you still want to reinvent the wheel, look at its sorts and write in jquery (although the option is not very good, jquery as an additional dependency ...)
Here's an article to get you started: blog.whatwg.org/the-road-to-html-5-contenteditable
If you are interested in seeing the source code, you can dig into our monster github.com/Studio-42/elRTE
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question