The name says it all. This Javascript file can be added to any HTML page to turn textarea elements into a WYSIWYG editor.
This script uses the Microsoft designMode DOM extension and is written in ECMAScript edition 3. It has been tested and works in Internet Explorer 5.5+ and Mozilla 1.3+ based browsers (including Firefox and Camino) but should also work in any browser that support designMode.
Adding the control to your HTML form is easy:
Include the Javascript file into your HTML.
<script type="text/javascript" src="wysiwyg.js"></script>
Include the stylesheet into your HTML (optional).
<link rel="stylesheet" type="text/css" href="wysiwyg.css" />
Give your textarea a class of "wysiwyg".
<textarea name="mytextarea" class="wysiwyg"></textarea>
Give your textarea another class of the name of the HTML file to use as the default HTML for the WYSIWYG control (optional).
<textarea name="mytextarea" class="wysiwyg wysiwyg.html"></textarea>
The top of the JS file defines two arrays, wysiwyg_toolbarButtons and wysiwyg_elementMap, these can be overridden or changed to adjust the way the control works.
This defines the buttons and toolbars to be added to the control, and the actions to perform. The actions are the commands for execCommand, a full list of which can be found here.
This defines regular expressions to run on the HTML generated by the browsers designMode to convert it into tidier (X)HTML.
This constant should be set to true if you want the toolbar buttons to be generated as input button elements rather than standard inline HTML elements.
wysiwyg-0.2.tar.gz (12kb)
You can see the WYSIWYG control in action.