Include to favorites
Log in Logout Register
Start Login Contact Help Photos What's new
Avanced Search
FAQ
RESULTS IN: TEXT IMAGES

Hello, Guest
Login  Register
Online: 89 visitors

Blogging (2)
Business (1)
Educational (2)
Gadgets (1)
Games (2)
High Tech News (1)
Internet (0)
PC (1)
PDA (0)
Photography (0)
Science (1)
Software (1)
Wireless (1)


Browse by date

<< October 2008 >>
MonTueWedThrFriSatSun
12345
6789101112
13141516171819
20212223242526
2728293031




Recent searches

Popular searches

Hot this month

Weblogs Archive


GADGETS AND GAMES DIRECTORY :: > Software Register Weblog >  Software Tech Weblogs - WEEKLYBITS.COM GADGETS AND GAMES DIRECTORY
Yahoo User Interface Blog
generated by http://wordpress.org/?v=2.3.3  en Blogger
SEND A FRIEND
Suscribing to  please login first
User: Login

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications.
News and Articles about Designing and Developing wiht Yahoo! Libraries.Visit Yahoo! User Interface Blog
Address URLhttp://yuiblog.com/blog    Registered: 26-Apr-2008
Ads:

Send to email
Visit ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids in Development
By Christian Heilmann
el 25-Jun-2008

I love YUI Grids. I know my CSS and I know how to work around different problems of browsers, but I am also very much bored about having to fix and test and create these workarounds over and over again. While YUI Grids might not be perfect for all cases of web development out there, I am happy to take a pragmatic approach and just create sites that can be done with them (now you also know why I am not a designer).

One problem I keep having when I put some YUI Grids-based sites live is that people complain about me expecting a certain screen resolution or viewport size. YUI grids can either be 100% wide, which can be pretty silly on high resolutions, or optimized for resolutions of either 800×600 or 1024×768. When you optimize for 800 pixels people on higher resolutions will complain about the length of the page and when you go for 1024 people will say they have to scroll to see your side-bar on 800×600. You can’t win.

Or can you? CSS is not dynamic — it has a fixed state and you can only hope that the browser does the right thing with what you give it (well, there are conditional comments for IE, but technically they are HTML, and of course there are media queries in CSS3 and other goodies, but for the sake of the argument let’s say supporting IE6 is a base). JavaScript, on the other hand, is very dynamic and you can read out and check what is happening to the browser currently in use and react to it.

Putting this feature of JavaScript to good use you can create a YUI-Grids-based layout that remains flexible and changes according to needs. All you need to do is use some YUI Dom magic and change IDs and classes accordingly.

YUI Grids come in several flavours of overall width, defined by the ID on the container DIV:

  • #doc - 750px centered (good for 800×600)
  • #doc2 - 950px centered (good for 1024×768)
  • #doc3 - 100% fluid (good for everybody)
  • #doc4 - 974px fluid (good for 1024×768)
  • #doc-custom - custom width

One thing to remember here is that even doc3 has a minimum width of 750 pixels, which is why for a fully flexible grid you need to override that:

#doc3{
  min-width:0;
}

Inside the container DIV you can have two blocks, and their width and the position of the side bar is defined by the class on the container DIV:

  • .yui-t1 - Two columns, narrow on left, 160px
  • .yui-t2 - Two columns, narrow on left, 180px
  • .yui-t3 - Two columns, narrow on left, 300px
  • .yui-t4 - Two columns, narrow on right, 180px
  • .yui-t5 - Two columns, narrow on right, 240px
  • .yui-t6 - Two columns, narrow on right, 300px

Putting these together you can create a plan for your flexible grid:

  • When the available screen space is larger than 950 pixels, use doc2 and the widest sidebar — either left or right
  • If you have less than 950 pixels, use doc and the medium size sidebars
  • If you have less than 760 pixels, use doc3 and the smallest sidebars
  • If you have even less — say 600 pixels — at your disposal, show the side bar below the main content

The script to allow for this is not really rocket science. All it needs to do is read out the grids settings, the width of the available browser window and then change the IDs and classes accordingly.

YAHOO.example.autoGrid = function(){
  var container = YAHOO.util.Dom.get('doc') ||
                  YAHOO.util.Dom.get('doc2') ||
                  YAHOO.util.Dom.get('doc4') ||
                  YAHOO.util.Dom.get('doc3') ||
                  YAHOO.util.Dom.get('doc-custom');
  if(container){
    var sidebar = null;
    var classes = container.className;
    if(classes.match(/yui-t[1-3]|yui-left/)){
       var sidebar = 'left';
    }
    if(classes.match(/yui-t[4-6]|yui-right/)){
       var sidebar = 'right';
    }
    function switchGrid(){
      var currentWidth = YAHOO.util.Dom.getViewportWidth();
      if(currentWidth > 950){
        container.id = 'doc2';
        if(sidebar){
          container.className = sidebar === 'left' ? 'yui-t3' : 'yui-t6';
        }
      }
      if(currentWidth < 950){
        container.id = 'doc';
        if(sidebar){
          container.className = sidebar === 'left' ? 'yui-t2' : 'yui-t5';
        }
      }
      if(currentWidth < 760){
        container.id = 'doc3';
        if(sidebar){
          container.className = sidebar === 'left' ? 'yui-t1' : 'yui-t4';
        }
      }
      if(currentWidth < 600){
        container.id = 'doc3';
        container.className = '';
      }
    };
    switchGrid();
    /*
      Throttle by Nicholas Zakas to work around MSIE's resize nasties.
      http://www.nczonline.net/blog/2007/11/30/the_throttle_function
    */
    function throttle(method, scope) {
      clearTimeout(method._tId);
        method._tId= setTimeout(function(){
        method.call(scope);
      }, 100);
    };
    YAHOO.util.Event.on(window,'resize',function(){
      throttle(YAHOO.example.autoGrid.switch,window);
    });

  };
  return {
    switch:switchGrid
  };
}();

Let’s go through it step by step:

YAHOO.example.autoGrid = function(){
  var container = YAHOO.util.Dom.get('doc') ||
                  YAHOO.util.Dom.get('doc2') ||
                  YAHOO.util.Dom.get('doc4') ||
                  YAHOO.util.Dom.get('doc3') ||
                  YAHOO.util.Dom.get('doc-custom');
  if(container){

First we check if there is actually a YUI Grid in the current document, by testing for the presence of the correct IDs. If there is, we execute the rest of the code.

    var sidebar = null;
    var classes = container.className;
    if(classes.match(/yui-t[1-3]|yui-left/)){
       var sidebar = 'left';
    }
    if(classes.match(/yui-t[4-6]|yui-right/)){
       var sidebar = 'right';
    }

We define sidebar as null, retrieve the class name of the container element and check if there was a column structure defined. In addition to the preset YUI Grids classes we also defined yui-left and yui-right here. These styles allow you to not have a sidebar without the script functionality but to get one once the script determines that there is enough space for one.

    function switchGrid(){
      var currentWidth = YAHOO.util.Dom.getViewportWidth();
      if(currentWidth > 950){
        container.id = 'doc2';
        if(sidebar){
          container.className = sidebar === 'left' ? 'yui-t3' : 'yui-t6';
        }
      }
      if(currentWidth < 950){
        container.id = 'doc';
        if(sidebar){
          container.className = sidebar === 'left' ? 'yui-t2' : 'yui-t5';
        }
      }
      if(currentWidth < 760){
        container.id = 'doc3';
        if(sidebar){
          container.className = sidebar === 'left' ? 'yui-t1' : 'yui-t4';
        }
      }
      if(currentWidth < 600){
        container.id = 'doc3';
        container.className = '';
      }
    };
    switchGrid();

The method switchGrid() does all the work we defined. We set up the different cases for applying IDs and classes and call the method immediately after it’s been defined.

    /*
      Throttle by Nicholas Zakas to work around MSIE's resize nasties.
      http://www.nczonline.net/blog/2007/11/30/the_throttle_function
    */
    function throttle(method, scope) {
      clearTimeout(method._tId);
        method._tId= setTimeout(function(){
        method.call(scope);
      }, 100);
    };
    YAHOO.util.Event.on(window,'resize',function(){
      throttle(YAHOO.example.autoGrid.switch,window);
    });

For full flexibility, we also apply an event listener that re-checks the grid specifications when the user resizes the browser. As Internet Explorer has a nasty habit of firing the resize event while the user resizes the window, we need to throttle the execution of switchGrid(). This is explained in detail on Nicholas Zakas’ blog.

  };
  return {
    switch:switchGrid
  };
}();

As the throttle method needs a public method to call from setTimeout() we return a pointer to switchGrid.

That’s all. You can try out the effect on the demonstration page. If you define your sidebar independent of size, you can create some wonderfully dynamic and flexible sites with this little script.



Read 5 times

Suscribing to  please login first
?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids -  Tech Weblogs - WEEKLYBITS.COM  Blogger Is a collection of i

Photologs

Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
I love YUI Grids. I know my CSS and I know how to work around different problems of browsers, but I am also very much bored about having to fix and test and create these workarounds over and over again. While YUI Grids might not be perfect for all cases of web development out there, [...] [..] Read complete article
Subscribe to ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
Published 25-Jun-2008 by Christian Heilmann in Development
Read 5 times. More hits in More articles ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids Images about ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

A YUI Grids-based WordPress Theme ? YUI Autogrid Minimal
As I had to upgrade my personal blog to the newest WordPress version (and my old theme had been hacked to death), I chose to start from scratch with a WordPress theme. [You can download the new theme here.] As I am a lazy person and I think blogging is first and foremost about content and availability, [...] [..] Read complete article
Subscribe to ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
Published 02-Jul-2008 by Christian Heilmann in Development
Read 7 times. More hits in More articles A YUI Grids-based WordPress Theme ? YUI Autogrid Minimal Images about A YUI Grids-based WordPress Theme ? YUI Autogrid Minimal
Nerdblog Blogger

Provides news about hardware, software, notebooks, laptops, PCs, Mac, PDAs
Nerdblog.Net

JavaScript 2's new direction (InfoWorld)
InfoWorld - Standardization efforts for the next version of JavaScript have taken a sharp turn this month, with some key changes in the Web scripting technology's direction. JavaScript creator Brendan Eich, CTO of Mozilla, has helped forge a consensus on how to proceed with the direction for JavaScript's improvements. “JavaScript was sitting still. It was [...] [..] Read complete article
Subscribe to ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
Published 26-Aug-2008 by Nerdblog in General
Read 1 times. More hits in More articles JavaScript 2's new direction 
    (InfoWorld) Images about JavaScript 2's new direction 
    (InfoWorld)
Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

Non-blocking JavaScript Downloads
Stoyan Stefanov. - Non-blocking JavaScript Downloads About the Author: Stoyan Stefanov is a Yahoo! web developer working for the Exceptional Performance team and leading the development of the YSlow performance tool. He also an open-source contributor, conference speaker and technical writer: his latest book is called Object-Oriented JavaScript. External JavaScript files block downloads and hurt your page performance, but there is an [...] [..] Read complete article
Subscribe to ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
Published 22-Jul-2008 by Stoyan Stefanov in DevelopmentPerformance
Read 3 times. More hits in More articles Non-blocking JavaScript Downloads Images about Non-blocking JavaScript Downloads
Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

Free Chapter from Douglas Crockford?s ?JavaScript: The Good Parts?
Click through to read Ch. 5 of Douglas The #2 book on Amazon’s JavaScript shelf this morning is Douglas Crockford’s forthcoming Javascript: The Good Parts (currently available for preorder and due for release later this month). In this volume, Douglas articulates a philosophy of coding in JavaScript that builds up on and extends the content of his popular video series and articles. [...] [..] Read complete article
Subscribe to ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
Published 05-May-2008 by Eric Miraglia in Development
Read 9 times. More hits in More articles Free Chapter from Douglas Crockford?s ?JavaScript: The Good Parts? Images about Free Chapter from Douglas Crockford?s ?JavaScript: The Good Parts?
Kotaku`s The Gamers Guide Blogger

XBOX 360 Gamers Weblog Gossip, news and leaks for obsessive gamers Kotaku As if you don't waste enough of your time in a gamer's haze, here's Kotaku: a gamer's guide that goes beyond the press release. Gossip, cheats, criticism, design, nostalgia, pred

E3 Gate Crasher: Ghetto Vader - Let Him In? [E308]
Ghetto Vader here came all the way from The Bronx to crash E3 even though he doesn't have an invite. Should we let him in? Gawker Media polls require Javascript; if you're viewing this in an RSS reader, click through to view in your Javascript-enabled web browser. [..] Read complete article
Subscribe to ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
Published 16-Jul-2008 by Noah R in e308 Cosplay E3 08 Gatecrasher Ghetto vader Project 420 Rap
Read 3 times. More hits in More articles  E3 Gate Crasher: Ghetto Vader - Let Him In? [E308] Images about  E3 Gate Crasher: Ghetto Vader - Let Him In? [E308]
Kotaku`s The Gamers Guide Blogger

XBOX 360 Gamers Weblog Gossip, news and leaks for obsessive gamers Kotaku As if you don't waste enough of your time in a gamer's haze, here's Kotaku: a gamer's guide that goes beyond the press release. Gossip, cheats, criticism, design, nostalgia, pred

Super Mario Bros. In 14 Kilobytes Of Javascript [Nintendo]
It may be lacking in Koopas, power ups and an underworld—not to mention the dreaded embedded MIDI soundtrack—but this Super Mario Bros. clone packed into 14 KB of Javascript is still [..] Read complete article
Subscribe to ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
Published 09-Apr-2008 by Michael McWhertor in NesNintendoRetroSuper Mario Bros.
Read 8 times. More hits in More articles Super Mario Bros. In 14 Kilobytes Of Javascript [Nintendo] Images about Super Mario Bros. In 14 Kilobytes Of Javascript [Nintendo]
Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

Notoptimal Dev?s New YUI-Based Accordion Menu
Visit Notoptimal Dev Juan I. Leon at Notoptimal Dev went looking for the perfect Accordion Menu recently, but the search was not a success. The criteria: be lightweight use unobtrusive Javascript techniques (ie not have scattered Javascript all over the markup) use simple CSS to make it look nice needed to support both single and multiple sections opened at [...] [..] Read complete article
Subscribe to ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
Published 07-Jun-2008 by Eric Miraglia in Development
Read 8 times. More hits in More articles Notoptimal Dev?s New YUI-Based Accordion Menu Images about Notoptimal Dev?s New YUI-Based Accordion Menu
Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

Production JavaScript Debugging
Setting up Firefox You know the scenario. A bug is filed for a JavaScript issue in production. You update your development server to the same files (allegedly) that are in production but you can’t reproduce the issue. Debugging your JavaScript code is horrifically difficult, if not impossible, because you’re following best practices and crunching the file using the YUI Compressor. You start [...] [..] Read complete article
Subscribe to ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
Published 27-Jun-2008 by Nicholas C. Zakas in Development
Read 10 times. More hits in More articles Production JavaScript Debugging Images about Production JavaScript Debugging
Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

Free Chapter: ?Coding and Design Patterns? from Stoyan Stefanov?s Object-Oriented JavaScript
Stoyan Stefanov Stoyan Stefanov is a member of Yahoo’s Exceptional Performance team; he’s worked on a variety of performance-related projects at Yahoo, including the popular YSlow plugin for Firebug. He’s also a contributing author here on YUIBlog. Stoyan’s latest project is Object Oriented JavaScript, a new book from Packt whose simple goal is to help you learn [...] [..] Read complete article
Subscribe to ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
Published 26-Sep-2008 by Eric Miraglia in Development
Read 2 times. More hits in More articles Free Chapter: ?Coding and Design Patterns? from Stoyan Stefanov?s Object-Oriented JavaScript Images about Free Chapter: ?Coding and Design Patterns? from Stoyan Stefanov?s Object-Oriented JavaScript
Kotaku`s The Gamers Guide Blogger

XBOX 360 Gamers Weblog Gossip, news and leaks for obsessive gamers Kotaku As if you don't waste enough of your time in a gamer's haze, here's Kotaku: a gamer's guide that goes beyond the press release. Gossip, cheats, criticism, design, nostalgia, pred

When Spore PS3 Controller Creatures Rumble! [Forget Dicks]
Spore can be used to re-create 360 controllers. Yay. Spore can be used to re-create Wii-motes. Yay. But did you know that Spore has the raw power to re-create PS3 controllers? It can even do that boomerang-looking proto-type controller. This all comes f [..] Read complete article
Subscribe to ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
Published 26-Jun-2008 by StephenTotilo in Forget dicks PS3 Spore
Read 4 times. More hits in More articles  When Spore PS3 Controller Creatures Rumble! [Forget Dicks] Images about  When Spore PS3 Controller Creatures Rumble! [Forget Dicks]
Kotaku`s The Gamers Guide Blogger

XBOX 360 Gamers Weblog Gossip, news and leaks for obsessive gamers Kotaku As if you don't waste enough of your time in a gamer's haze, here's Kotaku: a gamer's guide that goes beyond the press release. Gossip, cheats, criticism, design, nostalgia, pred

Sporelebrity Contest Kicks Off [Charity Contest]
Last month Electronic Arts contacted me to see if I would be willing to create a Spore creature for charity. The idea was that 70 handpicked "celebrities" from the Internets and meatspace would create a creature and send them to EA, which would in turn allow the public to vote on the best creati [..] Read complete article
Subscribe to ?AutoGrid? for YUI Grids ? Using JavaScript to Create Adaptive Grids
Published 01-Jul-2008 by Brian Crecente in Charity contest Child's Play creature creator jennifer ann's group Original Spore Top
Read 1 times. More hits in More articles  Sporelebrity Contest Kicks Off [Charity Contest] Images about  Sporelebrity Contest Kicks Off [Charity Contest]

Warning We are not responsible of information posted from external feeds. Use this website at your own risk. Notice: We will not be liable for any direct or indirect loss or damage arising under this disclaimer or in connection with our website, whether arising in tort, contract, or otherwise.


Your Site here Your Site here Your site here Your site here Your site here