JavaScript
  Home arrow JavaScript arrow Page 5 - Useful Web Widgets
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? 
JAVASCRIPT

Useful Web Widgets
By: Chris Root
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2006-01-18

    Table of Contents:
  • Useful Web Widgets
  • Getting Down With Father Time
  • The Function in Depth
  • A Calendar Engine
  • The Interface Code

  • 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


    Useful Web Widgets - The Interface Code


    (Page 5 of 5 )

    As I mentioned before the calendar object can be used in a lot of environments. The following function is browser DOM specific and shown here as just an example of how to use the data generated. It's been tested in Firefox and Safari, but may work fine in most if not all browsers. This script does not provide a table above for display of the name of the days or a display of the month. All that is up to you. I have the calendar engine code in a separate document and embed it using a "<script>" tag. If you are trying to put together a complete solution you may want to put all the code in a separate document.

    We first get a reference to the table which will house the calendar, and then get a calendar object. We also need to get together a few DOM objects to clone while constructing the rows of days. Make sure to set class, align and other attributes you may need to massage the appearance of the table at this point.

    function getCalendarMonth(data,selectedYear,selectedMonth)
    {
                var table = document.getElementById("calendarTable");
                var cal = new calendar(selectedYear,selectedYear);
                var month = cal.years[selectedYear].monthObjects
    [selectedMonth];
                var len = month.dayObjects.length;
                var trow = document.createElement("tr");
                trow.setAttribute("class","calRow");
                var tcell = document.createElement("td");
                tcell.setAttribute("valign","top");
                var temprow = trow.cloneNode(true);
                var eventContainer = document.createElement("div");

    Now it's time to loop through the days of the month, adding the event information and constructing the table markup. Depending on how big you want to make the calendar you may want to simply put links in each day pane that produce a popup containing the day's events.

    var tempCell = null;
    var counter = 0;
    var dnum;
    for(var c = 0;c < len;c++)
    {
        if(counter == 7)
        {
            //we've put seven cells in the current row lets start again.
            counter = 0;
        }
        if(counter == 0)
        {
           
    //new row
            temprow = trow.cloneNode(true);
        }
        //new cell
        tempCell = tcell.cloneNode(true);
        dobj = month.dayObjects[c];
        //event information
        if(typeof data[dobj.displayNumber] != "undefined")
        {
            var devent = data[dobj.displayNumber];
        }
        else
        {
            var devent = "";
        }
        temptxt = document.createTextNode(dobj.displayNumber);
        eventText = document.createTextNode(devent);
        container = eventContainer.cloneNode(false);
        container.appendChild(eventText);
        tempCell.appendChild(temptxt);
        tempCell.appendChild(container);
        if(dobj.displayNumber == "")
        {
            //make a blank cell and set a CSS selector

        tempCell.setAttribute("class","blankcell");
            }
            else
            {
                //put the day number in and set a CSS selector
                tempCell.setAttribute("class","daycell");
            }
            //add the new cell to the current row
            temprow.appendChild(tempCell);
            // if we're done inserting all the cells in the row, add it to the table.
            if(counter == 6)
            {
                table.appendChild(temprow);
            }
            counter++;
        }
    }

    Your Time is up

    These three scripts should give you a good start or be a useful addition to an already established library of JavaScript functions. Each can be modified and expanded to fit more situations. If you have any ideas on mods please share them.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Thank you for reading the article. Comments are welcome.
     

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT