May 06, 2008

New jQuery UI release 1.5b4

One more step closer to being out of beta; and a new site to boot. Check it out at http://ui.jquery.com

April 19, 2008

Adobe Illustrator Wireframe Symbols

A basic library of symbols for wireframing in Adobe Illustrator.  I originally created these for the City of Jacksonville for internal wireframing.  [link to come]

April 07, 2008

Expand with JavaScript; Link without JavaScript

Over at GodBit, someone needed to show a div when a heading was clicked, but if the user didn’t have javascript, the heading was a link to a detail page. This sounded like an interesting idea, so I poked around and here is what I ended up with:


$(document).ready(function(){
 $("h3 a").parent().next("div").hide();
 $("h3 a").click(function() {
  $("h3 a").parent().next("div").slideToggle();
  return false;
 })
});

The key here is return false;—that stops the click from triggering the link.

March 25, 2008

Implementing IE min-width with Javascript

min-width works in Firefox and Safari, and even IE 7, but not IE 6 -- big surprise. However, we can fake it fairly well. With a little jQuery fun, we can read the min-width value, and then implement it using javascript fairly nicely.

First off, we know we have to attach this to the resize of the browser. IE seems to execute the resize event many, many times during an actual window resize1 -- almost as if it were trying to execute it once every pixel resized (just a guess).

Enter the wresize jQuery plugin. This plugin tries to catch when the resize starts, and more importantly, when it finishes, and then executes a function. The one downside to this plugin is that we cant execute a function that requires us to pass any variables to it. Luckily, we don't need to for this.

Here are the things we need to do:

  1. Get the min-width value; if it's not set then we'll default to 760px.
  2. jQuery will give us the value text, so it will return "960px" or the like. We need to strip out the text to convert it from a string to a number.
  3. Then, we need to calculate what size the browser window should be before we invoke the min-width.
  4. Then, we wait. Wait for the browser to be just the right size.
  5. Set the min-width on the first div inside the body element.
  6. Un-set the min-width when the browser window widens.

Simple, right? Here's the actual min-width function:


function minwidth() {
  if ( (jQuery.browser.msie) && (jQuery.browser.version==6) ) {
    var cssprop = jQuery("body div").css("min-width");
    if ( cssprop == null ) {
      cssprop = 760; //No min-width; default to min-width of 760
    } else {
      cssprop = parseInt(cssprop); //Convert value to numeric;
    };
    
    //get document margin to figure browser width to look for
    var margin = parseInt( jQuery("body").css("margin-left") ) + parseInt( jQuery("body").css("margin-right") );

    //21px is the width of the scroll bar.
    if (clientwidth() < (cssprop + margin + 21)) {
      jQuery(document.body).width(cssprop); //Set fixed-width
    } else {
      jQuery(document.body).width("auto"); //Un-set fixed-width
    };
  };
};

Now that's just the function; we haven't used it yet. We need to execute this function on page load, and use the wresize plugin to execute the same function on resize. Luckily, that's simple too.


$(document).ready(function(){
  minwidth(); //call IE minwidth on page load
  $( window ).wresize( minwidth ); //IE Resize event - resize for min-width
});

We didn't cover the clientwidth() function -- that's how we're getting the browser's window size. Check out the example page for the final result.

1http://snook.ca/archives/javascript/ie6_fires_onresize/

3 of 4 « FirstP  <  1 2 3 4 >

Who?

Howdy. I'm Richard W. Baker - a designer based in Jacksonville, Florida with a passion for information architecture and usable interfaces. At my day job, I work for the City of Jacksonville as a User Interface Designer.

If you still have questions, or you're interested in hiring me for your next project, .

Active ingredients: XHTML + CSS + Expression Engine
Page rendered in 0.2324 seconds  |  52 SQL queries total