Sanskrit > Usage

Sanskrit replaces normal textareas with an IFrame that has been set to "design mode". This allows us to edit the XHTML inside it and retrieve it. When the form is submitted, the XHTML is transformed into Textile.

JavaScript

Sanskrit will automatically look for textareas with the class name "sanskrit" and turn them into iframes. You can do this manually by creating a new Sanskrit object and passing it the textarea:

new Sanskrit(aTextarea);

The Sanskrit constructor takes an optional options parameter, which is an object containing various values that will affect the way the editor works.

new Sanskrit(aTextarea, {
  className: 'prakrit',
  onSubmit: function(){ alert(this.getContents()); },
  toolbar: {
    onEm: function(){ alert('Italic text will be, my master') },
    actions: {'strong': 'strong', 'em': 'em', 'ins': 'ins', 'del': 'del', 'link': 'link', 'unlink': 'unlink'}
  }
});

XHTML

The DOM structure that replaces the textarea looks something like this:

<div class="sanskrit">
  <ul>
    <li class="em"><a href="">em</a></li>
    <li class="strong"><a href="">strong</a></li>
    <!-- Etc. -->
  </ul>
  <iframe />
</div>

The class name for the container is the one from the options object, or "sanskrit" if not set.