refactory-id / bootstrap-markdown

Bootstrap plugin for markdown editing
Apache License 2.0
1.99k stars 371 forks source link

Trigger events from outside (external save button) #59

Closed Maltretieren closed 10 years ago

Maltretieren commented 10 years ago

I want to build an external "Save" button. Is it possible to trigger an event (save) from outside, so the onSave hook gets fired?

lodev09 commented 10 years ago

You can do it like this:

$('#md').markdown({
    onShow: function(e) {
        var $md = e;
        $('#external-btn').on('click', function(e) {
            // trigger the hook
            $md.$options.onSave($md);
        });
    },
    onSave: function(e) {
        console.log('saving ...');
    }
});

Let me know if that works for you. :)

baldwinSPC commented 10 years ago

@lodev09 Just an FYI. I had the same requirement and used the sample provided and it works great. Thanks!

lodev09 commented 10 years ago

No problem @baldwinSPC . @toopay , I think you need to close this one. :)