Thursday 25 July 2013

Sweeeeeeeeeeeeeep

It seems that lately I only ever do blogs when I have some open tabs in my browser that I want to get rid of but keep a record of somewhere.

The first one is this parody of jQuery love on Stack Overflow.

Next up, I was trying to get the current page in a menu highlighted for a WP theme I am working on. WP automatically tags the current page in the menu with css class of 'current-menu-item'. So easy, right? Well the problem is that if you use fragment (hash) urls, WP will ignore the fragment / hash.

So if you were viewing page.html, and in the nav you had links to page.html, page.html#hash1, and page.html#hash2, then all three of those entries would have a class of 'current-menu-item'. I can certainly understand the logic of this, but for my purposes I only wanted the current page hash highlighted.

So this required js to read the current url and then apply a class (I used 'current-menu-item-real') to the anchor that matched the current url. I decided I'd like it also to update if someone clicks to go to another hash / fragment on the same page. Looking for how to do this I found there is a popstate event.

However, old IEs don't support popstate, and in IE10 the popstate event does not fire when the fragment / hash changes. So I had to revert to listening for the hashchange event instead.

I found a nice blog of photos of little model people interacting with the full size world: The Little People Project. According their FAQ they use figures designed for use with train sets. They modify them by cutting them up, reposing, and sometimes adding extra bits with modelling clay. Then they paint them. Very creative and well executed.

No comments: