Bootstrap-wysihtml5 is a javascript plugin that makes it easy to create simple, beautiful wysiwyg editors with the help of wysihtml5 and Twitter Bootstrap.
If you are using rails use the bootstrap-wysihtml5-rails gem.
gem install bootstrap-wysihtml5-rails
Otherwise, download the latest version of bootstrap-wysihtml5.
<link rel="stylesheet" type="text/css" href="/css/bootstrap-wysihtml5.css"></link> <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css"></link> <script src="js/wysihtml5-0.3.0.js"></script> <script src="js/jquery-1.7.2.min.js"></script> <script src="js/bootstrap.min.js"></script> <script src="js/bootstrap-wysihtml5.js"></script>
<textarea id="some-textarea" placeholder="Enter text ..."></textarea> <script type="text/javascript"> $('#some-textarea').wysihtml5(); </script>
You can get the html generated by getting the value of the text area, e.g.
$('#some-textarea').val();
An options object can be passed in to .wysihtml5() to configure the editor:
$('#some-textarea').wysihtml5({someOption: 23, ...})
To override which buttons to show, set the appropriate flags:
$('#some-textarea').wysihtml5({ "font-styles": true, //Font styling, e.g. h1, h2, etc. Default true "emphasis": true, //Italics, bold, etc. Default true "lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true "html": false, //Button which allows you to edit the generated HTML. Default false "link": true, //Button to insert a link. Default true "image": true, //Button to insert an image. Default true, "color": false //Button to change color of font });
To define custom templates for buttons, you can submit a customTemplates hash with the new definitions. Each entry should be a function which expects ‘locale’ to manage the translations.
For example, the default template used for the editHtml mode button looks like this
<li> <div class='btn-group'> <a class='btn' data-wysihtml5-action='change_view' title='" + locale.html.edit + "'><i class='icon-pencil'></i></a>" </div> </li>
You can change it to not use the pencil icon (for example) by defining the custom template like this:
var myCustomTemplates = { html : function(locale) { return "<li>" + "<div class='btn-group'>" + "<a class='btn' data-wysihtml5-action='change_view' title='" + locale.html.edit + "'>HTML</a>" + "</div>" + "</li>"; } } // pass in your custom templates on init $('#some-textarea').wysihtml5({ customTemplates: myCustomTemplates });
This will override only the toolbar template for html, and all others will use the default.
It is possible to supply a number of stylesheets for inclusion in the editor ``:</p>
<pre>