steal buffalo’s planner slider in mootools and css

On BuiltByBuffalo‘s Proposal Planner, we use a much-revered slider thingy that we’ve had a lot of compliments on. We recently received an email asking for a little tutorial on how to put this all together. The main brief is actually pretty esoteric, and you probably won’t be working with designers of the calibre of Jason Reynolds, but this should show you how to put such a thing together.

First off, you need 3 elements. I’ve gone for divs because they’re fairly non-descript and semantically pretty viable for use here. I’ve gone for the following structure:

<div id="scale" class="m1" rel="6">
  <div id="full">
    <div id="marker"></div>
  </div>
</div>

The rel on this div refers to the maximum number of positions on the slider. Unless you shamelessly steal all my source images, you might need to change this! The class refers to a CSS class that denotes the width of the guage element (#full), defined thus:

#scale.m1 #full {
  width: 43px;
}

Because the marker element (#marker) is floated right, it will always stay to the right side of the guage div, so there’s no need for any more CSS than this.

Now that we have our layout and have defined our images (I won’t insult you by teaching you how to set a background image. If you really don’t know that, the declarations are in the source!), we need a method of getting between them. In the actual planner, we do a bunch of ajax-y stuff between stages that’s not relevant here, so here’s a simple breakdown. We’ve got 2 links, next and previous. We, therefore, need 2 event methods to handle input.

In our Marker class, the initialize method deals with identifying the container, marker and guage elements so that we don’t need to keep traversing the DOM to get them. It also sets the current state of the marker and gleans the capacity from the rel attribute (even though it shouldn’t really – you can hardcode it if you want!). We then have our next and previous methods, which just check that their respective states are valid (we don’t want the marker trying to go to 0 or 7, so we stop it from happening).

The method do_morph is where all the legwork is done. We construct the class to Fx.Morph to (mootools requires the whole CSS declaration, not just the element) then define some other options for the morph (namely the duration and a method to run when it’s completed). The completed function calculates the background position needed on the marker image so that we display the correct state.

I’m not great at explaining things, but hopefully that’s done a little to make it clearer for the person who asked for this post, and easy to steal for the people who are that way inclined!

Enjoy the demo:

Oh crap, I accidentally deleted the demo. I’ll put it back when I’ve got some time. In the mean-time; check out the real thing

Taking responsibility for your web content

A new website for a business is an amazing investment, and can be an incredible tool for generating revenue. A CMS is an excellent way for non-technical users to have a website that they can maintain and perpetuate without technical intervention, saving time and money.

For compatibility and future-proofing, it is important that the content of a website keeps to certain standards. In some cases these standards are a legal requirement, further accentuating their pertinence.

Regex-matching the contents of an HTML tag

I have a folder in my Mail.app client dedicated to code snippets that I’ve emailed to myself. It’s usually stuff that I don’t use a whole lot, or stuff that I did at the end of a day that I know I won’t remember tomorrow. There’s a whole load of mod_rewrite and shell stuff in there! A blog seems like a pretty sensible place to keep this sort of thing, so every time I get something I might need, I’ll add it here as a pastebin type thing. I could always use pastebin, but that’s just one more site to keep track of!

So, the following matches the value of the href attribute in an a tag:

<a(?!href).*href=["']{1}([^"']*)["']{1}[^>]*>

Obviously if you wanted to match the src attribute of an img tag, you’d change it up in the following way:

<img(?!src).*src=["']{1}([^"']*)["']{1}[^>]*>

The former matches the href value in the following tags:

<a href="awesome">
<a class="brilliant" href="awesome">
<a href="awesome" id="excellent">
<a class="brilliant" href="awesome" id="excellent">
<a href='awesome'>
<a href=''>

Being awesome on each row, except for the last row, which is an empty string.

This revelation is inspired by the following post on statiksoft. I really needed this the other day!

IE6 and PNG transparency

I personally don’t believe that technology and techniques that benefit both the user and the developer should be shunned just because the lion-share of users are still relying on older technology. PNG gives far better quality images, usually at a greatly reduced file size. It seems like a no-brainer. Except for the fact that IE6 doesn’t support transparency in PNGs.

There is an IE6 PNG fix on TwinHelix that I can only get to do half the job, which is really irritating. The technique makes the image render with transparency, but makes it expand to a somtimes arbitrary size with the dreaded red cross in the corner. Another problem with this is that it doesn’t allow you do position the image. I’m currently using a relatively verbose alternative, which essentially involves you emulating an img tag, but allows you to position your element. Hopefully some will find this helpful as I was racking my brains for something like this on my last project.