[JS] Rich Text Editors. Whats the basic principle?
Chris Baron
Ranch Hand
Joined: Mar 21, 2003
Posts: 1015
posted
0
Hi,
just for interest: whats the basic principle of Rich Text Editors like CKEditor, TinyMCE, etc?
I assume you build a iframe and bind eventhandlers for onkeydown and onkeyup to them.
But then, how is the cursor realised? Range selection? And, and, and...
Does somebody know?
Thanks cb
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
Have you considered just looking at the source code for one? They're generally just glorified textareas./
Chris Baron
Ranch Hand
Joined: Mar 21, 2003
Posts: 1015
posted
0
Yes, i searched for the smallest one i could find (punymce), but the source code is very hard to read. There are very few comments and the variables names are usually just one letter. It would be much easier to understand, if someone who knows how it's working, would list the basic steps.
Here you see that it's more than just a pimped up textarea. They build up a dom representation and bind events to the iframe. But i really wonder how the cursor is realised and how navigation within the text is done (e.g. arrow key). And of course the selection of ranges.
This message was edited 2 times. Last update was at by Chris Baron
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
Well, all the examples on the site start with a textarea. So look at one that's coded more clearly, rather than focusing on the "smallest" one?
Chris Baron
Ranch Hand
Joined: Mar 21, 2003
Posts: 1015
posted
0
David,
you are a real nice guy, but why do feel challenged to answer to this thread at any price?
Sorry, but i'm looking for someone who knows how it works and is willing to share his knowledge in a short summary.
And if there's nobody here i wouldn't be disappointed.
cb
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
So basically you want a walkthrough of 1500 lines of JavaScript code? I mean, I'm not really sure what you're looking for. It's a text area--that's how selections are handled. It binds keys, that's how keystrokes are handled. It has some buttons that work on selections, they're just buttons.
This message was edited 1 time. Last update was at by David Newton
Chris Baron
Ranch Hand
Joined: Mar 21, 2003
Posts: 1015
posted
0
Ok,
so you are typing into a hidden textarea but what you see is html in an iframe right?
The cursor and the selection range still remain a mystery for me.
It's only ~300 lines, and having jQuery abstract some of the nuts and bolts might give you a better starting point.
Getting selected text is a normal window function, IIRC.
Chris Baron
Ranch Hand
Joined: Mar 21, 2003
Posts: 1015
posted
0
Cool thanks!
so iframe.contentWindow.document.selection resp. iframe.contentWindow.getSelection() seem to be the key to selection.
I didn't know that it exists in JS. I've got to experiment with that.
Could be that i come back for the cursor but in the meanwhile: thanks again!
cb
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
No sweat; feel free to follow up with specific questions, or if you discover something cool :)
Chris Baron
Ranch Hand
Joined: Mar 21, 2003
Posts: 1015
posted
0
I think now i've got it The cursor is a selection with nothing selected. Hehe.
subject: [JS] Rich Text Editors. Whats the basic principle?