Getting instance of a jQuery plugin

1.2k views Asked by At

I'm using SCEditor and am loading it as such:

$(document).ready(function() {

    // Create var to store emoticons
    var emoticons = false;

    $.getJSON('../../images/emoticons/default/emoticons.json')
    .done(function(response) {
        emoticons = response;
    })
    .always(function() {
        // always initialize sceditor
        $(".sceditor").sceditor({
            // Options here...
        });
    });

})

Now, I'm wondering how I go about getting the instance of this plugin so I can later pass it in if I want to reference it via a user action on the page.

For example, they have an API of which, what I would like to do is be able to get the value of the editor when the user clicks a preview button, it appears you can do that with this method.

My problem is, I'm not sure how I go about referencing the instance created?

I know how I could get it if I was running the code on the same request of when it was created, but not afterwards via a user action.

1

There are 1 answers

1
Rudi On BEST ANSWER

This is how you get the instance of a specific editor:

var instance = $('.sceditor:first').sceditor('instance');

Then you get the current value, possibly filtered by plugins, like so:

var value = instance.val();

If you want the rendered HTML value, do this:

var value = instance.getWysiwygEditorValue(false);