Skip to content

Conversation

@nud
Copy link

@nud nud commented Oct 28, 2014

This makes it possible to perform asynchronous operations while in the
onPreview() callback, for instance using an AJAX request:

$("#form_content").markdown({
  onPreview: function(editor, callback) {
    jQuery.ajax({
      type: "POST",
      url: "/render-markdown",
      data: { content: editor.$textarea.val() },
      success: callback
    });
  }
});

A default implementation of onPreview() is provided, using an updated
parseContent() method which doesn't call the onPreview() callback
anymore.

This effectively adds a parameter to the onPreview() callback, but
backward compatibility is retained by checking the onPreview() callback
return value and using it if it exists.

This makes it possible to perform asynchronous operations while in the
onPreview() callback, for instance using an AJAX request:

    $("#form_content").markdown({
      onPreview: function(editor, callback) {
        jQuery.ajax({
          type: "POST",
          url: "/render-markdown",
          data: { content: editor.$textarea.val() },
          success: callback
        });
      }
    });

A default implementation of onPreview() is provided, using an updated
parseContent() method which doesn't call the onPreview() callback
anymore.

This effectively adds a parameter to the onPreview() callback, but
backward compatibility is retained by checking the onPreview() callback
return value and using it if it exists.
@nud nud mentioned this pull request Oct 28, 2014
@toopay
Copy link
Member

toopay commented Nov 3, 2014

Hey @nud Can you give me an edge-case whereas we need the onPreview loaded asynchronuously?

@nud
Copy link
Author

nud commented Nov 4, 2014

Well the case is in the pull request: you need an async callback if you want to do the markdown rendering server-side, which is needed if you want to do fancy stuff in the markdown rendering.

Doing a synchronous ajax call as two downsides:

  1. it is deprecated
  2. it can freeze the browser if the server takes some time to respond.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants