toopay/bootstrap-markdown — pull request #61 by lodev09 (2014-05-15 02:03:51+00:00)
Title: Few Options and events

I've added some options, methods and events that fixes some issues submitted by other users and also enhances the plugin.

**Added events:**

- ***onChange*** - This will trigger every time you typed in anything on the ```textarea```. The event is triggered by ```keyup```, ```callbacks``` from each menu buttons and native ```textarea.on('change', ... )``` event

**Added methods:**

- *** hideButtons(name)*** - Completely hide the specified ```buttons``` by name. Using ```hidden``` class in boostrap.
- *** showButtons(name)*** - Opposite to ```hideButtons()```
- *** parseContent()*** - Parsing the content is now separated, so you can always call this function to parse the ```textarea``` content.

**Enhancement:**

- On ```showButtons```, ```hideButtons```, ```disableButtons``` and ```enableButtons``` methods, the ```name``` parameter can now be either an ```array``` or ```string```

**Fixes:**

- I've noticed on the current version, ```keyup``` is triggering ***3x*** because of ```keypress``` and ```keydown``` events. I've commented these lines to avoid redundancy of ```keyup``` trigger.

**Sample Implementation:**

This code will output the preview in a separate ```div``` instead of the native ```preview``` button
```javascript
// get the preview div
var $previewContainer = $('#post-md-preview');

// hide first
$previewContainer.hide();

// init
$("#post-md").markdown({
autofocus: false,
resize: 'vertical',
height: 200,
onShow: function(e) {
e.hideButtons('cmdPreview');

// in case you have default value
e.change(e);
},
onChange: function(e) {
// parse and get the parsed content
var content = e.parseContent();

// display preview :)
if (content === '') $previewContainer.hide();
else $previewContainer.show().html(content);
}
});
```