Style Sheets
  Home arrow Style Sheets arrow Page 2 - Customizing styles: User-Controlled Style ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Customizing styles: User-Controlled Style Sheets – Part III
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 10
    2005-04-20

    Table of Contents:
  • Customizing styles: User-Controlled Style Sheets – Part III
  • Breaking the "changeStyle()" function into pieces
  • Listing the complete source code
  • Making the big change: multiple style sheets and persistence
  • Defining the HTML markup and Style Sheets
  • Putting the pieces together

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Customizing styles: User-Controlled Style Sheets – Part III - Breaking the "changeStyle()" function into pieces


    (Page 2 of 6 )

    As you can see, the function is pretty similar to the previous version. However, we’ve added to it the handy capability to change both style sheets in a reversible way. In the first place, when the user clicks on the switcher link, the code grabs the corresponding style sheets, accessing them by their ID attribute, with the lines listed below:

    // get style sheets

    var defaultSheet=document.getElementById('default');

    if(!defaultSheet){return;}

    var newSheet=document.getElementById('accessible');

    if(!newSheet){return;}

    Once the style sheets have been accessed, the process of swapping them is extremely simple, as you’ll see in a moment. The function checks to see which style sheet is currently active. For whichever style sheet is enabled, the script simply disables it and activates the other one.

    Otherwise, the reverse process occurs. If a particular style sheet is disabled, the code activates it again and disables its counterpart. The link is really working as a real reversible style switcher, but don’t forget that it’s changing entire style sheets. The reversible swapping process is performed with the following lines, assigning the corresponding Boolean values to each style sheet:

    if(newSheet.disabled){

         // disable previous active style sheet

         defaultSheet.disabled=true;

         newSheet.disabled=false;

    }

    else {

         // enable new style sheet

         newSheet.disabled=true;

         defaultSheet.disabled=false;

    }

    Definitely, the function has been greatly improved. Happily, we’ve reached our first goal, which was to make the style change completely reversible for users. Finally, the function should be called when the document has been loaded, usually using the "onload" event handler:

    // execute code when page is loaded

    window.onload=function(){

         if(document.getElementById){

              changeStyle();

         }

    }

    The main advantage of this method is that it is fairly straightforward. If you’re pretty familiar with DHTML, the approach is easy to follow.

    So far, this version of the "changeStyle()" function isn’t very different from our earlier implementation, described in Part II of this article series. But just by adding a few lines of code, we’ve created a more powerful model, establishing the basics for further improvements.  

    Since we want to be kind and allow many Web developers to add new features to the current script, let’s show the full code for this approach. I will also include the proper style sheets used in the example. 

    More Style Sheets Articles
    More By Alejandro Gervasio


       · Is adding all the stylesheets as rel="stylesheet". All but one should be...
       · Yes, you're correct about the usage of the "alternate" attribute. Thanks for...
       · We added the changes to the article.
       · Thanks so much for the correction in the article.Best Regards
     

    STYLE SHEETS ARTICLES

    - Image Replacement CSS Techniques
    - Using BlueTrip`s Success, Notice and Error C...
    - More Uses for the Thin and Caps CSS Classes ...
    - Styling Definition Lists with the BlueTrip C...
    - Styling Unordered and Ordered HTML Lists wit...
    - Using the BlueTrip CSS Framework`s Thin and ...
    - Adding Borders to Web Page Columns with Blue...
    - Introducing the BlueTrip CSS Framework
    - Using a Background Grid to Assist Web Page L...
    - Extending the Rule Of Thirds for Web Page La...
    - A Two-Column Web Page Layout Based on the Ru...
    - Using the Rule Of Thirds for Web Page Layout
    - Swapping Columns Using the Divine Ratio for ...
    - Using the Golden Ratio in Liquid Web Page De...
    - Fundamental Design Principles for Web Page L...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek