# Overview
Bootstrap-wysihtml5 is a javascript plugin that makes it easy to create simple, beautiful wysiwyg editors with the help of [wysihtml5](https://github.com/xing/wysihtml5) and [Twitter Bootstrap](http://twitter.github.com/bootstrap/).
## About this fork
This fork provides the same functionality as the original by [jhollingworth](https://github.com/jhollingworth/bootstrap-wysihtml5) but skips bootstrap 2 support and adds bootstrap 3 support.
Besides it uses bower for client side dependency management.
### Why a fork again?
The old repository seems to be dead. Pull Requests are not accepted anymore since some time. The other bootstrap-wysihtml5 packages in the bower registry do NOT provide bootstrap 3 support, even if the name so suggests. They are not maintained either.
Furthermore the packages on bower do not use proper dependency management.
I will maintain this repo and I will accept pull requests.
## Dependencies
Additionally to the existing dependencies I added handlebars in version 0.2.0. You only need the handlebars.runtime.min.js. The templates are precompiled during build. This adds less than 7kB to your client (~3kB gzipped). Thus it is easier to maintain the code.
Because maintaining code requires maintainable code.
## Development
Install all development dependencies via
npm install
Additionaly you need grunt, grunt-cli and bower as global packages installed.
Also install the client dependencies via
bower install
There is a grunt task for building. Just run
grunt
on the command line and everything should build fine.
## Installation
If you are using bower use the “bootstrap3-wysihtml5-bower” package.
bower install bootstrap3-wysihtml5-bower
If using Rails, use ["bootstrap-wysihtml5-rails"](https://github.com/Nerian/bootstrap-wysihtml5-rails):
gem bootstrap-wysihtml5-rails
## Examples
- [http://waxolunist.github.io/bootstrap3-wysihtml5-bower/](http://waxolunist.github.io/bootstrap3-wysihtml5-bower/)
For use with requirejs see the examples in the repo.
### Files to reference
In the folder dist you will the plain unminified javascript files and two kinds of minified files.
**bootstrap3-wysihtml5.min.js**: This file contains the jquery plugin, the templates and the english translations. If you are referencing this file, you have to reference jquery, bootstrap jquery plugin, handlebars runtime and wysihtml.js.
**bootstrap3-wysihtml5.all.min.js**: This file contains all of the normal minified file plus the handlebars runtime and editor library. If you are referencing this file, you have to reference jquery and bootstrap jquery plugin.
**bootstrap3-wysihtml5.min.css**: This is the stylesheet for this plugin.
If you are using any other translation than english, you have to either build this plugin yourself, or reference it separately.
### Usage
#### Editable Div
This is the new style from version 0.3 on and will be supported on all browsers.
The javascript will keep the same. For example it is easier to change the content dynamically on runtime.
```javascript
$('.textarea').html('Some text dynamically set.');
```
#### Textarea
This is the old style usage and does use a sandboxed iframe, which will from version 0.3 on not work in IE.
```html
```
You can get the html generated by getting the value of the text area, e.g.
```javascript
$('#some-textarea').val();
```
#### RequireJS
From version 0.3 on, requirejs is supported.
The usage with requirejs will be the same with a slightly difference to the localisation feature. English will not be pre loaded, so translations not in the used language will not fallback to english but are just empty.
Also if using english you have to load the locale dependency.
A minimum example:
```javascript
require.config({
paths: {
'domReady': '../components/requirejs-domready/domReady',
'jquery': '../components/jquery/jquery.min',
'bootstrap': '../components/bootstrap/dist/js/bootstrap.min',
'bootstrap.wysihtml5': '../dist/amd/bootstrap3-wysihtml5.all',
'bootstrap.wysihtml5.de-DE': '../dist/locales/bootstrap-wysihtml5.de-DE'
},
shim: {
'bootstrap': {
deps: ['jquery']
}
},
deps: [
'./start'
]
});
```
```
define([
'require',
'domReady',
'jquery',
'bootstrap.wysihtml5.de-DE'
], function(require, domReady, $) {
'use strict';
domReady(function() {
$('.textarea').wysihtml5({
locale: 'de-DE'
});
});
});
```
# Advanced
## Options
An options object can be passed in to `.wysihtml5()` to configure the editor:
```javascript
$('#some-textarea').wysihtml5({someOption: 23, ...})
```
#### Buttons
To override which buttons to show, set the appropriate flags:
```javascript
$('#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
"blockquote": true, //Blockquote
"size": //default: none, other options are xs, sm, lg
});
```
Since v0.3.0 toolbar options are nested in toolbar. So use therefore following syntax:
```javascript
$('#some-textarea').wysihtml5({
toolbar: {
"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
"blockquote": true, //Blockquote
"size": //default: none, other options are xs, sm, lg
}
});
```
#### Font Awesome
To use Font Awesome for the icons of the toolbar you can use since v0.3.1 following option:
```javascript
toolbar: {
"fa": true
}
```
Don't forget to add the font awesome stylesheet in this case, which is a bower dependency since v0.3.1.
#### Custom Templates for Toolbar Buttons
see wikie: [Custom Templates](https://github.com/Waxolunist/bootstrap3-wysihtml5-bower/wiki/Custom-Templates)
##### Data Attributes
As of version 0.2.4 there are two new data attributes.
- data-wysihtml5-format-name
- Normally the inner html of the format command is used to display as current font style. This attribute overrides this value.
- data-wysihtml5-display-format-name
- Whether to show the current font style in the toolbar anyways.
#### Stylesheets
It is possible to supply a number of stylesheets for inclusion in the editor `