JavaScript DHTML/Rico/Accordion

Материал из Web эксперт
Перейти к: навигация, поиск

Accordion panel with controls

   <source lang="html4strict">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Accordion</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <link href="rico21/examples/client/css/phokus/phokus.css" media="screen" rel="Stylesheet" type="text/css">


<script src="rico21/src/rico.js" type="text/javascript"></script> <script type="text/javascript"> Rico.loadModule("Accordion"); Rico.onLoad( function() {

 new Rico.Accordion( $$("div.panelheader"), $$("div.panelContent"), 
                     {panelHeight:200, selectPanelIndex: 0, stepping: Rico.Stepping.ease_in });

}); </script> <style type="text/css"> .panel {

   width: 175px;
   padding: 0pt 15px 15px;
   background: transparent url(examples/client/images/phokus/sb-bottom.gif) no-repeat scroll 0pt 100%;

} .panel h3, label{

    margin: 0pt 0pt 5px -15px;
    padding: 15px 34px 0pt 15px;
    width: 150px;
    background: transparent url("rico21/examples/client/images/phokus/sb-top.gif") no-repeat scroll 0%;
    color: #FFFFFF;
    display: block;
    font-family: "Lucida Grande",Verdana,Arial,Helvetica,sans-serif;
    font-size: 1em;
    font-weight: bold;
    position: relative;
    text-transform: uppercase;
    cursor: pointer;
}

.panelContent {

  width:170px;

} </style> </head> <body>

openRico 2.0 Demos!

<a href="javascript:void(0)" onclick="Rico.animate({fadeOut:$("post-caption")})">Posted by BB</a> Fri, 24 Mar 2006 12:17:00 GMT

More openRico updates soon! Ross Lawley

Posted in <a href="#examples" rel="tag">example</a> | Tags <a href="#example" rel="tag">blog</a>, <a href="#example" rel="tag">blah</a> | <a href="#comments">261 comments</a> | <a href="#trackbacks">99 trackbacks</a>

</body> </html>

 </source>
   
  


Nested accordion panel

   <source lang="html4strict">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > <title>Rico</title> <script src="rico21/src/rico.js" type="text/javascript"></script> <script type="text/javascript"> Rico.loadModule("Accordion"); Rico.onLoad( function() {

 new Rico.Accordion( $$("div.panelHeader"), $$("div.panelContent"),
     {panelHeight:200,
      hoverClass: "panelHover",
      selectedClass: "panelSelected",
      clickedClass: "panelClicked",
      selectedIndex: 1
     });
 new Rico.Accordion( $$("div.nestedPanelHeader"), $$("div.nestedPanelContent"),
     {panelHeight:100,
      hoverClass: "panelHover",
      selectedClass: "panelSelected",
      clickedClass: "panelClicked"
     }); 

}); </script> <style type="text/css"> body, p {

 font-family : Trebuchet MS, Arial, Helvetica, sans-serif;

} h1 { font-size: 16pt; }

  1. accordionExample {
 border : 1px solid #4f4f4f;
 width: 650px;

} .panelHeader, .nestedPanelHeader{

 background-image: url("rico21/examples/client/images/example1_panelBG.png");
 height: 22px;
 color : #ECECEC;
 font-weight : normal;
 padding-left: 5px;
 white-space: nowrap;

} .panelHover {

 background-image: url("rico21/examples/client/images/example1_panelBGHover.png");
 height: 22px;
 color : #ffffff;
 padding-left: 5px;

} .panelClicked {

  background-image: url("rico21/examples/client/images/example1_panelBGClick.png");
  height: 22px;
  color : #ffffff;
  padding-left: 5px;

} .panelSelected {

 background-image: url("rico21/examples/client/images/example1_panelBGSelected.png");
 height: 22px;
 color : #494949;
 font-weight : bold;
 padding-left: 5px;

} .panelContent, .nestedPanelContent {

 background-image: url("rico21/examples/client/images/example1_contentBG");
 background: #f8f8f8;
 overflow: auto;

}

  1. nestedaccordionExample {
 margin-top: 20px;
 margin-left:75px;
 width: 350px;
 border : 1px solid #4f4f4f;
 overflow: hidden;

} </style> </head> <body>

Rico Nested Accordions

Note that this example defaults to opening the second panel of the accordion. This is done by setting options.selectedIndex=1.

       Overview
      
This example illustrates how to use the Rico.Accordion behavior to transform a set of divs into a first class accordion component.

The Rico.Accordion behavior makes use of the Effect.AccordionSize which is an effect that simultaneously grows the height of one element while shrinking the height of another. The Rico.Accordion behavior adds the necessary event handlers on the respective divs to handle the visual aspects of expanding, collapsing and hovering.
       More Info (nested accordion)
                        Overview of ContentTransition base component 
                     The Accordion now derives from a base component that applies and manages
                     behaviors and effects.  The effects can be defined at the extended class.  
                     This approach results in a very flexible way of managing 
                           Alternative HTML
                       Since the accordion does not parse the html, it can be constructed much looser
                       than in previous versions.  The base ContentTransition can be used to quicly build 
                       components such as tabs, master details, and many application specific behaviors.
                       We will be providing examples of building your own soon.
                           Alternative effects
                   We will be discussing alternative transition effects here.  
                   Should be interesting.
          Rico Code
        
To attach the accordion behavior to the accordion container div, construct a Rico.Accordion object and pass the panel titles and contents to it. This is a bit different than the previous version, but allows a lot more flexibilitiy. With the new Prototype Selector class it is still very easy.
new Rico.Accordion( $$("div.panelheader"), $$("div.panelContent") );
      -or-
     new Rico.Accordion( $$("div.panelheader"), $$("div.panelContent"), 
                     {panelHeight:200, 
                      hoverClass: "mdHover",
                      selectedClass: "mdSelected"}} );
        The second example specifies the height of the accordion panels and the css classes that can be associated 
        with the accordion behaviors.  
       There are many other configuration parameters that can be specified to modify various visual aspects of the
        accordion. The panelHeight is the attribute that is most commonly overridden.
         Important Note
       
The accordion is very flexible now and can handle scrollbars on firefox through the use of some new features in Rico. However, you do have to make sure the header and content elements passed in to the Accordion constructor have the same elements and match up in the order they are passed. The new Accordion requires far less html attributes than Rico"s previous versions.

</body></html>

 </source>
   
  


Put a grid control into a accordion

   <source lang="html4strict">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > <title>Rico Accordion & Grid</title> <script src="rico21/src/rico.js" type="text/javascript"></script> <script type="text/javascript"> Rico.loadModule("Accordion"); Rico.loadModule("LiveGrid","LiveGridMenu","greenHdg.css"); Rico.onLoad( function() {

 var myData = [
   [1,"Cell 1:2","Cell 1:3","Cell 1:4","Cell 1:5"],
   [2,"Cell 2:2","Cell 2:3","Cell 2:4","Cell 2:5"],
   [3,"Cell 3:2","Cell 3:3","Cell 3:4","Cell 3:5"],
   [4,"Cell 4:2","Cell 4:3","Cell 4:4","Cell 4:5"],
   [5,"Cell 5:2","Cell 5:3","Cell 5:4","Cell 5:5"],
   [6,"Cell 6:2","Cell 6:3","Cell 6:4","Cell 6:5"]
 ];
 for (var i=1; i<=3; i++) {
   var opts = {  
     useUnformattedColWidth: false,
     defaultWidth : 90,
     frozenColumns: 1,
     windowResize : false,
     visibleRows  : -4,
     columnSpecs  : [{Hdg:"Column 1",type:"number", decPlaces:0, ClassName:"alignright"},
                     {Hdg:"Column 2"},
                     {Hdg:"Column 3"},
                     {Hdg:"Column 4"},
                     {Hdg:"Column 5"}]
   };
   var buffer=new Rico.Buffer.Base();
   buffer.loadRowsFromArray(myData);
   var grid=new Rico.LiveGrid ("ex"+i, buffer, opts);
   grid.menu=new Rico.GridMenu();
 }
 alert("The grids have been sized, so now initialize the accordion");
 new Rico.Accordion( $$("div.panelheader"), $$("div.panelContent"),
                     {panelHeight:200, hoverClass: "mdHover", selectedClass: "mdSelected"});

}); </script> <style type="text/css"> body, p {

 font-family : Trebuchet MS, Arial, Helvetica, sans-serif;

} h1 { font-size: 16pt; } .panelheader {

 background-color : #6b79a5;
 height: 26px;
 color : #ced7ef;
 font-weight : normal;
 border-bottom:1px solid #182052;
 border-top:1px solid #BDC7E7;
 font-weight : normal;
 padding-left: 5px;

} .mdHover {

 background-color : #63699c;
 color : #ffffff;

} .mdSelected {

 background-color : #63699c;
 color : #ffffff;
 font-weight : bold;
 

} .panelContent {

 border : 1px solid #1f669b;
 border-top-width    : 0px;
 border-bottom-width : 0px;
 font-size: smaller;
 overflow: auto;
 height: 200px; /* allow grids to size during initialization */

}

  1. accordionExample {
 margin-top : 6px;
 border : 1px solid #4f4f4f;
 width: 500px;

} </style> </head>

<body>

Rico Accordion & Grid

         Overview

This example illustrates how to include LiveGrids in an Accordion.

One key is the following grid options:

windowResize : false, /* don"t resize grids if window is resized */
visibleRows  : -4,    /* size grid to parent element */

combined with the following css:

.panelContent {
  height: 200px; /* allow grids to size during initialization */
}
         Grid 1

 

         Grid 2

 

         Grid 3

 

</body></html>

 </source>
   
  


Rico Accordion with Memory

   <source lang="html4strict">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > <title>Rico</title> <script src="rico21/src/rico.js" type="text/javascript"></script> <script type="text/javascript"> Rico.loadModule("Accordion"); Rico.onLoad( function() {

 new Rico.Accordion( $$("div.panelheader"), $$("div.panelContent"),
                     {panelHeight:200, hoverClass: "panelHover", selectedClass: "panelSelected", cookieName: "Rico.AccCookie"});

}); </script> <style type="text/css"> body, p {

 font-family : Trebuchet MS, Arial, Helvetica, sans-serif;

} h1 { font-size: 16pt; }

  1. accordionExample {
   border : 1px solid #4f4f4f;
   width: 650px;

} .panelheader{

 background-image: url("rico21/examples/client/images/example1_panelBG.png");
 height: 22px;
 color : #ECECEC;
 font-weight : normal;
 padding-left: 5px;

} .panelHover {

 background-image: url("rico21/examples/client/images/example1_panelBGHover.png");
 height: 22px;
 color : #ffffff;
 padding-left: 5px;

} .panelClicked {

  background-image: url("rico21/examples/client/images/example1_panelBGClick.png");
  height: 22px;
  color : #ffffff;
  padding-left: 5px;

} .panelSelected {

 background-image: url("rico21/examples/client/images/example1_panelBGSelected.png");
 height: 22px;
 color : #494949;
 font-weight : bold;
 padding-left: 5px;

} .panelContent {

   background-image: url("rico21/examples/client/images/example1_contentBG");
   background: #f8f8f8;
   overflow: auto;

} </style> </head> <body>

Rico Accordion with Memory

This example remembers the panel you had open the last time you visited. Simply provide a value for options.cookieName. This option also applies to tabbed panels. By default, the cookie value is only remembered for the current session. To have it persist longer, also set options.cookieDays.

            Overview
           
This example illustrates how to use the Rico.Accordion behavior to transform a set of divs into a first class accordion component.

The Rico.Accordion is actually a very simple component built off of Rico behaviors and effects. It adds the necessary event handlers on the respective divs to handle the visual aspects of expanding, collapsing and hovering.
            HTML Code
          
The example HTML structure is an outer div that holds all of the panels. Then, each panel is just a couple of DIVs (one for the header and one for the content) wrapped in an outer DIV. You can actually use elements other than divs.
  <div id="accordionDiv">
          <div id="overviewPanel">
            <div id="overviewHeader">
              Overview
             </div>
             <div id="panel1Content">
              ... content text ...
             </div>
          </div>
       </div>
       
            Rico Code
          
To attach the accordion behavior to the accordion container div, construct a Rico.Accordion object and pass the panel titles and contents to it. This is a bit different than the previous version, but allows a lot more flexibilitiy. With the new Prototype Selector class it is still very easy.
new Rico.Accordion( $$("div.panelheader"), $$("div.panelContent") );
        -or-
       new Rico.Accordion( $$("div.panelheader"), $$("div.panelContent"), 
                       {panelHeight:200, 
                        hoverClass: "mdHover",
                        selectedClass: "mdSelected"}} );
          The second example specifies the height of the accordion panels and the css classes that can be associated 
          with the accordion behaviors.  
         There are many other configuration parameters that can be specified to modify various visual aspects of the
          accordion. The panelHeight is the attribute that is most commonly overridden.
           Important Note
         
The accordion is very flexible now and can handle scrollbars on firefox through the use of some new features in Rico. However, you do have to make sure the header and content elements passed in to the Accordion constructor have the same elements and match up in the order they are passed. The new Accordion requires far less html attributes than Rico"s previous versions.


</body></html>

 </source>
   
  


Rico Basic Accordion

   <source lang="html4strict">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > <title>Rico</title> <script src="rico21/src/rico.js" type="text/javascript"></script> <script type="text/javascript"> Rico.loadModule("Accordion"); Rico.onLoad( function() {

 new Rico.Accordion( $$("div.panelheader"), $$("div.panelContent"),
                     {panelHeight:200, hoverClass: "mdHover", selectedClass: "mdSelected"});

}); </script> <style type="text/css"> body, p {

 font-family : Trebuchet MS, Arial, Helvetica, sans-serif;

} h1 { font-size: 16pt; } .panelheader {

 background-color : #6b79a5;
 height: 26px;
 color : #ced7ef;
 font-weight : normal;
 border-bottom:1px solid #182052;
 border-top:1px solid #BDC7E7;
 font-weight : normal;
 padding-left: 5px;

} .mdHover {

 background-color : #63699c;
 color : #ffffff;

} .mdSelected {

 background-color : #63699c;
 color : #ffffff;
 font-weight : bold;
 

} .panelContent {

 border : 1px solid #1f669b;
 border-top-width    : 0px;
 border-bottom-width : 0px;
 font-size: smaller;
 overflow: auto;

}

  1. accordionExample {
 margin-top : 6px;
 border : 1px solid #4f4f4f;
 width: 500px;

} </style> </head>

<body>

Rico Basic Accordion

<a href="http://validator.w3.org/check?uri=referer"><img style="border:none;" src="examples/client/images/valid-html401.png" alt="Valid HTML 4.01 Strict" height="31" width="88"></a>

         Overview
        
This example illustrates how to use the Rico.Accordion behavior to transform a set of divs into a first class accordion component.

The Rico.Accordion is actually a very simple component built off of Rico behaviors and effects. It adds the necessary event handlers on the respective divs to handle the visual aspects of expanding, collapsing and hovering.
         HTML Code
       
The example HTML structure is an outer div that holds all of the panels. Then, each panel is just a couple of DIVs (one for the header and one for the content) wrapped in an outer DIV. You can actually use elements other than divs.
 <div id="accordionDiv">
       <div id="overviewPanel">
         <div id="overviewHeader">
           Overview
          </div>
          <div id="panel1Content">
           ... content text ...
          </div>
       </div>
    </div>
    
         Rico Code
       
To attach the accordion behavior to the accordion container div, construct a Rico.Accordion object and pass the panel titles and contents to it. This is a bit different than the previous version, but allows a lot more flexibilitiy. With the new Prototype Selector class it is still very easy.
    new Rico.Accordion( $$("div.panelheader"), $$("div.panelContent") );
     -or-
    new Rico.Accordion( $$("div.panelheader"), $$("div.panelContent"), 
                        {panelHeight:200, 
                         hoverClass: "mdHover",
                         selectedClass: "mdSelected"}} );
       The second example specifies the height of the accordion panels and the css classes that can be associated 
       with the accordion behaviors.  
       There are many other configuration parameters that can be specified to modify various visual aspects of the
       accordion. The panelHeight is the attribute that is most commonly overridden.
         Important Note
       
The accordion is very flexible now and can handle scrollbars on firefox through the use of some new features in Rico. However, you do have to make sure the header and content elements passed in to the Accordion constructor have the same elements and match up in the order they are passed. The new Accordion requires far less html attributes than Rico"s previous versions.

</body></html>

 </source>

Навигация