views:

41

answers:

2

I'm a little curious about how the editing of Google Docs works. How did they implement an editor within the DOM? It does not really looks like a form with a textarea, but rather a normal document body with an additional cursor. I guess it is some javascript technique behind.

Is there any free library that I can use for achieving this kind of functionality, or how can I implement it myself?

A: 

For mee it looks like any HTML editor. They just coded their own JavaScript HTML editor. Even the HTML edit view doesn't have any magic.

A good and free HTML editor is TinyMCE but there are many others out there, even some very powerfull proprietary like CuteEditor which is available for PHP and ASP.NET.

BTW: The content of the document (in Google Docs) is placed in an iframe, just as it is in CuteEditor (and probably also in TinyMCE).

Kau-Boy
I am more interested in a library to handle input events within a document model rather than a complete text editor like TinyMCE. Or, if there is no such library, I want information on how this kind of user interface can be implemented.
Johan
+2  A: 

It uses editing functionality built into all modern desktop browsers, accessed at document level via setting the designMode property of the document to "on", or at an element level by adding a contenteditable attribute with value "true" (also triggered by setting the contentEditable property of an element to the string "true").

A very common strategy for editing a piece of content in a web page is to include an iframe whose document has designMode turned on.

Coupled with this is document.execCommand, which in an editable document can be used to apply various kinds of formatting. For example:

 document.execCommand("bold", false, null);

... will toggle whether the selected text is bold. There is a pool of common commands between browsers but there are some discrepancies as to exactly how some are implemented. More info can be found here at MSDN for IE and here at MDC for Firefox. Can't seem to find documentation for WebKit.

Tim Down
Thanks! This is what I am looking for.
Johan