Topics: Controls
Sep 22, 2011 at 1:17 AM

Hi Ruslan

Not sure if the comments are working over at, so if you don't mind I'll ask a quick question here.

Started using your PrettyPhoto extension, but I only want to load the JavaScript and CSS on demand.

Here's what I went with (PrettyPhoto2.cs):

static void ItemServing(object sender, ServingEventArgs e)
//make sure we are safe to go
            if (e.Location != ServingLocation.PostList && e.Location != ServingLocation.SinglePost && e.Location != ServingLocation.SinglePage)
// Use pattern to check if prettyPhoto exists in page as part of a link and if so, load baggage           
            if (HttpContext.Current.CurrentHandler is BlogBasePage && Regex.IsMatch(e.Body, @"<a\s[^>]+?prettyPhoto", RegexOptions.IgnoreCase))
                (HttpContext.Current.CurrentHandler as BlogBasePage).LoadComplete += BasePageLoadComplete;
I appreciate that once everything loads it will be cached by the browser anyway, but I'd like to spread the load and add support only when needed.
Anyway, it seems to work fine, but I'm thinking there has to be a better way, any thoughts?

Sep 22, 2011 at 5:02 AM

Hm, accidentally just committed code doing similar to syntax highlighter. I think you can slightly simplify and make faster avoiding regex all together, something like:


Sep 22, 2011 at 1:06 PM
Edited Sep 23, 2011 at 12:47 AM

Much better, I was covering the bases with regex for varying tag markup (extra space, single quotes, upper case, etc) - but not necessary, after a quick check I see that the Tiny editor takes care of all that, so even if you put in something like REL  =  'prettyPhoto' it gets changed back to rel="prettyPhoto" on update. Cheers.

Edit for general info:

Just noticed that photo galleries were not working, galleries are in format rel="prettyPhoto[gallery]" so it's just a slight mod to the above.

//omit the escaped quote mark from the end of the Contains arg

As a side note, the Tiny editor can be a bit of a minefield in HTML mode.

Type in something like rel='prettyPhoto" (mixing single and double quotes) and your content disappears when Tiny auto cleans the markup.

Another reason to use Windows Live Writer, might have to think about a Tiny plugin for this, good to have options.