If a node is loaded via an ajax call, and injected into an already rendered page, syntax highlighter is not applied to any new content. I think you need to look at using drupal behaviours to ensure that the syntax highlighter is attached to any injected content.

Comments

mattyoung’s picture

would you like to make a patch?

mattyoung’s picture

Status: Active » Needs review

in the latest dev release, I added Drupal.behaviors.syntaxhighlighter() for AJAX support, please test. I don't have any AJAX setup to test this so I need your help.

If you report back this works, then I'll make a release.

Thanks!

mrfelton’s picture

Status: Needs review » Needs work

Unfortunately not... for an example:

1. http://www.kirkdesigns.co.uk/projects
1. click on the blue 'Drupal modules' button at the top,
2. Select Path Filter from the left - That is loading http://www.kirkdesigns.co.uk/project/pathfilter onto the page using ajax, but the syntax highlighter is missing.

mattyoung’s picture

I misspelled behviors instead of behaviors

I've checked in the fix, please try again.

Hope I didn't waste too much of your time. This is what I get when I don't have the right setup to test things myself. I'll buy you a bear if you go to Drupalcon next year for this mix up.

Let me know how it goes and make sure you get the latest 'dev' version after the release bot get to it.

You can be sure it's the latest if the version string in syntaxhighlighter.module is:

// $Id: syntaxhighlighter.module,v 1.31 2009/12/04 22:46:01 mattyoung Exp $
mattyoung’s picture

Status: Needs work » Needs review

~

mrfelton’s picture

Status: Needs review » Needs work

I think your javascript could do with some work! I'm cleaning it up now, I'll have a patch shortly... Fancy giving me co-maintainership?

mrfelton’s picture

Status: Needs work » Needs review
StatusFileSize
new4.3 KB

OK, the attached patch works for me. Sorry, but I couldn't work with all that inline JavaScript, so I reworked it to use an external javascript file. Much more readable... Please check it trough and let me know what you think.

Tom

mattyoung’s picture

>Fancy giving me co-maintainership?

How do I do this? I've given you CVS access. What else do I do to make you co-maintainer?

mrfelton’s picture

That's it. I'm now a co-maintainer of the project and am happy to provide my help where I can :)

Can you give the syntax highlighter a quick test with my patch applied to ensure that I didn't break anything else in the process... seems to all be working to me, but maybe you know something I don't...

mattyoung’s picture

StatusFileSize
new5.01 KB

On page load, highlight doesn't happen because there is no page load ready handler in the new syntaxhighlighter.js file, I add one and took out the 'defer' flag but it's not working. Can you see why it's not working? I had to go to a meeting now and cannot debug it at the moment.

/**
 * Page ready handler
 */
jQuery(function($) {
	alert("I'm ready");
  SyntaxHighlighter.highlight();
  if (Drupal.settings.syntaxhighlighter.legacy_mode) {
    dp.SyntaxHighlighter.HighlightAll('code');
  }
  
});

also, when everything is working, minify the js file and use that instead.

Thx!

mrfelton’s picture

Status: Needs review » Needs work

You don't need an onload event. behaviors fire onload, as well as whenever new elements are inserted into the doc. It was working well for me, so strange that it wasn't for you... I'll have a look and see what I can do.

mrfelton’s picture

What browser/os are you using?

mrfelton’s picture

Status: Needs work » Fixed

Should be good now. Committed. I also minified the JS and committed that too.

mattyoung’s picture

Status: Fixed » Active

It doesn't work for me.

see http://hddigitalworks.com/syntax-highlighter

no highlighting...

tried on chrome, firefox, opera and safari.

mrfelton’s picture

StatusFileSize
new1.8 KB

please try this patch.

mrfelton’s picture

StatusFileSize
new2.74 KB

Actually, this version may be better:

mattyoung’s picture

still not working :(

see http://hddigitalworks.com/syntax-highlighter

Until everything is working, don't use the minify js file yet for better debugging (maybe the minify version is different?). Put 'alert("....")' in there to see if it's actually running?

Also, don't use the '$' variable in syntaxhighlighter.js, use 'jQuery' instead. This is the recommended way in D7 actually for better compatibility with other js lib because they might be defining the '$' at the global level.

mrfelton’s picture

can you try just altering the .module to use the non-minified version? I actually forgot to redo the minification, so probably didn't even see the new code with either of those patches.

Problem for me is that this works on all my test sites, but not on your one - difficult for me to test.

mrfelton’s picture

StatusFileSize
new2.77 KB

Attached is the altered patch to use the non minified version.

mrfelton’s picture

This version uses the D7 jQuery style (at least, this is what has been used throughout the D7 codebase).

mattyoung’s picture

Tom: it works!

See: http://hddigitalworks.com/syntax-highlighter

You are a js wizard :). My head spins just looking at your beautiful code.

mrfelton’s picture

Status: Active » Fixed

Good news, re-minified the js and committed. thanks for testing.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.