Skip to content
This repository has been archived by the owner on Mar 8, 2019. It is now read-only.

Getting Started

huangyaping edited this page Oct 31, 2014 · 4 revisions

1. Include scriptswefweff

<!-- wysihtml5 parser rules -->
<script src="/path-to-wysihtml5/parser_rules/advanced.js"></script>
<!-- Library -->
<script src="/path-to-wysihtml5/dist/wysihtml5-0.3.0.min.js"></script>

2. Create a textarea

<form><textarea id="wysihtml5-textarea" placeholder="Enter your text ..." autofocus></textarea></form>

wysihtml5 takes a textarea and transforms it into a rich text editor. The textarea acts as a fallback for unsupported browsers (eg. IE < 8). Make sure the textarea element has an id, so we can later access it easily from javascript. The resulting rich text editor will much behave and look like the textarea since behavior (placeholder, autofocus, ...) and css styles will be copied over.

Please note: The textarea will always hold the editor's generated markup. Therefore wysihtml5 integrates smoothly with forms.

3. Create a toolbar

<div id="wysihtml5-toolbar" style="display: none;">
  <a data-wysihtml5-command="bold">bold</a>
  <a data-wysihtml5-command="italic">italic</a>
  
  <!-- Some wysihtml5 commands require extra parameters -->
  <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="red">red</a>
  <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="green">green</a>
  <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="blue">blue</a>
  
  <!-- Some wysihtml5 commands like 'createLink' require extra paramaters specified by the user (eg. href) -->
  <a data-wysihtml5-command="createLink">insert link</a>
  <div data-wysihtml5-dialog="createLink" style="display: none;">
    <label>
      Link:
      <input data-wysihtml5-dialog-field="href" value="http://" class="text">
    </label>
    <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
  </div>
</div>

The toolbar contains the formatting options. Make sure the toolbar element has an id and has display: none.

Please note: wysihtml5 supports many more formatting commands. Check the "advanced demo":https://github.com/xing/wysihtml5/blob/master/examples/advanced.html or find a full list of "all supported commands here":https://github.com/xing/wysihtml5/wiki/Supported-Commands.

4. Initialize wysihtml5

<script>
var editor = new wysihtml5.Editor("wysihtml5-textarea", { // id of textarea element
  toolbar:      "wysihtml5-toolbar", // id of toolbar element
  parserRules:  wysihtml5ParserRules // defined in parser rules set 
});
</script>

Make sure you place the <script> at the end of the document, before the

Clone this wiki locally