New User? Register here - Existing Users: Username: Password: [Advanced Login]

 

 

Current Poll

Your preferred Interactive shell?









( 1341 votes ~ 14 comments )

 

Weblog entry #116 for simonw

TextArea to WYSIWYG Editor the Dojo way
Posted by simonw on Tue 12 Dec 2006 at 18:47
Tags: none.

Task: Turn a form with a text area into a hypertext editor on the example.com website.

Note square brackets replace angle brackets in the HTML examples because I can't decipher Steve's escaping scheme, if he has one. A simple editor that encoded the markup correctly for me would help.

Dojo is a Javascript library, and toolkit, that covers a whole range of common (and no so common) tasks, of which the editor is just a small component. It aims to provide a browser independent environment, where one can just do things the Dojo way, whilst providing graceful degradation where possible.

Dojo uses a build system to minimize the size and number of downloads the browser must make to include key components. Components included in the build in this compressed way are referred to as baked in. Get the dojo distro with the Editor2 widget "baked in" for best performance.

wget http://download.dojotoolkit.org/release-0.4.1/dojo-0.4.1-editor.tar.gz
tar xvzf dojo-0.4.1-editor.tar.gz

Test it basically works with the old Editor demo, otherwise fiddle with your webserver settings as required.
http://www.example.com/dojo-0.4.1-editor/demos/widget/Editor.html

Now change the head section of your form page to include;

[script type="text/javascript" src="/dojo-0.4.1-editor/dojo.js"][/script]
[script]
     dojo.require("dojo.widget.Editor2");
[/script]

The second of these "script" tags is not strictly necessary for this dojo build, but will save you going mad when you replace it with another dojo build.

Find the "[TEXTAREA ...]" tags and add dojoType="Editor2" to them so '[TEXTAREA dojoType="Editor2" ... ]'

The editor can be customized, and other form elements can be modified in similar simple fashion, but I just wanted to document this specific case as I needed it today, and it serves as a good example of how simple adding Dojo widgets can be. You probably also want to have a clean-up at this point, zip file, demos directory, etc.

 

Comments on this Entry

Posted by Steve (62.30.xx.xx) on Tue 12 Dec 2006 at 18:53
[ Send Message | View Steve's Scratchpad | View Weblogs ]

Note square brackets replace angle brackets in the HTML examples because I can't decipher Steve's escaping scheme, if he has one. A simple editor that encoded the markup correctly for me would help.

If you choose "Plain Text" you should be able to insert literal < + > characters without side-effects.

If you choose HTML you should use entities.

Bugs will be fixed if they are reported ..

Steve

[ Parent | Reply to this comment ]

 

 

Flattr