BLOG ARCHIVES
GEEK STUFF

Digg This Site! AddThis Social Bookmark Button
Creative Commons License

-->

Article: Preparing For Widescreen

March 28th, 2006

I wrote an article called โ€œPreparing for Widescreenโ€ for Digital-Web. Please read it!

One thing to note โ€“ the D-W staff accidentally published an outdated version of my JavaScript, so the code referenced in my article is not the same script I used in my demo. I’ve outlined the differences on below, so come back here and read the details after you get through the article.

Here’s the code from my demo:

First, determine screen width, using a conditional operator (basically a condensed if..else statement), via document.body.clientWidth (IE, Firefox) or innerWidth (Opera, Firefox, Netscape).

var screenW = (document.all) ? document.body.clientWidth : innerWidth

Next, again using a conditional operator, I set a variable to tell which stylesheet should be active. It is crucial to give this variable a name that is consistent with what each stylesheet has been named, as later it will be used within the indexOf command.

var theStyle = (screenW > 1200) ? 'huge' : (screenW > 1000) ? 'big' : 'small';

Once that variable is set, use it within a for loop that enables the correct stylesheet and disables the others.

var i, a;
for (i = 0; a = document.getElementsByTagName(’link’)[i]; i++) {
 if (a.getAttribute(’href’).indexOf(theStyle) != -1) {
   a.disabled = false;
 } else {
   a.disabled = true;
 }
}

The three previous snippets of code need to be placed into a function, which I’ve called dynamicStyle(). Once this is created, the following command is placed within the script tag (outside of the function), in order for the content to adjust when the page is loaded or when a user resizes their browser:

window.onload = window.onresize = dynamicStyle;

Same basic idea, but a slightly smoother solution.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit
  • MisterWong

2 Responses to “Article: Preparing For Widescreen”

  1. Douglas Clifton Says:

    For the DWM article, the JavaScript code took some extra massaging. Keep in mind this is for the “mini” demo–not the full blown technique.

    function miniStyle(z) {
    
     var i, l, t, v;
     for (i = 0; l = document.getElementsByTagName('link')[i]; i++) {
      if (l.getAttribute('rel').indexOf('stylesheet') != -1) {
       t = l.getAttribute('title');
       if (t && t.indexOf('Mini') != -1) {
        if (l.getAttribute('href').indexOf(z) != -1) l.disabled = false;
        else l.disabled = true;
       }
      }
     }
     switch(z) {
      case 'minihuge':
       v = '1280x1024 and up';
       break;
      case 'minibig':
       v = '1024x768';
       break;
      default:
       v = '800x600';
     }
     document.getElementById('minisize').innerHTML = v;
     return false;
    }
    
    function addLoadEvent(f) {
     var o = window.onload;
     if (typeof window.onload != 'function') window.onload = f;
     else {
      window.onload = function() {
       o();
       f();
      }
     }
    }
    
  2. Progettare un layout a prova di Widescreen - Laburno Says:

    […] Preparing for Widescreen - Mike Mandaio. Sul blog dell’autore c’รจ una correzione successiva riguardo al javascript utilizzato. […]

Leave a Reply