Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Are there javascript callbacks I can hook into after submitting comments?

edited May 2011 in Vanilla 2.0 - 2.8
I'd like to run the syntaxhighlighter.all() after comments are edited to convert pre tags to highlighted code.

Is there something I can hook into? I'd rather not go down the setTimeout (hack) route.



  • Options
    edited May 2011
    Hmm... I borrowed the code from this post, which works:

    But I still consider it a bit hacky, as my solution was this:
    $ButtonOptions = array('class' => 'Button CommentButton', 'onclick' =>"setTimeout(SyntaxHighlighter.update, 500)");
    SyntaxHighlighter.update() is a wrapper function I added to SyntaxHighlighter with some jQuery initialization code to go through all page pre tags and get them ready for syntax highlighting.

    Is there a way in vanilla to add global hooks? I'd rather add the following to all pages, which is clientside so no need to extend multiple PHP files, and will attach itself to any new form elements created on clicks and so forth:
    jQuery('#Form_Body').live('submit', SyntaxHighlighter.update);
  • Options
    Hmm.... so I added the live() code to SyntaxHighlighter's init() code, but weirdly, live() doesn't seem to work inside vanilla. Not sure why that is.
  • Options
    ToddTodd Chief Product Officer Vanilla Staff
    edited May 2011
    Iive doesn't work with everything, not just Vanilla. Even if it does work you need the highlighter to work after the form has returned, not before the data is submitted.

    Calling livequery() will most always work and you can ensure the js query is included in the page with:
  • Options
    Wow, I didn't know about livequery - it does exactly what I want!
    Any time I preview, or update a comment, the syntax highlighting is updated as soon as the pre is created.

  • Options
    ToddTodd Chief Product Officer Vanilla Staff
    Cool. Not sure, but if SyntaxHighlighter.update updates all pre tags then it is a tad inefficient with livequery. I do believe livequery changes the this reference to tell you what item was just added so you can just call the highlighter on $(this).
  • Options
    Nice tip, I'll check that out.

    SyntaxHighlighter.highlight(); does just the one pre.
Sign In or Register to comment.