]> source.dussan.org Git - jquery-ui.git/commitdiff
accordion: added test for headers with descendants; replaced while-loop to find heade...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Sat, 21 Jun 2008 16:16:59 +0000 (16:16 +0000)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Sat, 21 Jun 2008 16:16:59 +0000 (16:16 +0000)
tests/accordion.html
tests/accordion.js
tests/all.html
ui/ui.accordion.js

index 194b130b2e1d9db14d3a334647cfc990f26bbd88..275ebe0e7127a4d3b0ddbaa75263b0c8c99b1adf 100644 (file)
 
 <div id="main" style="position:absolute;top:-2000000px;">
 
-       <fieldset>
-               <legend>Standard, container is a div, header is h3 and content p</legend>
+       <div id="list1">
+               <a>There is one obvious advantage:</a>
+               <div>
+                       <p>
+                               You've seen it coming!<br/>
+                               Buy now and get nothing for free!<br/>
+                               Well, at least no free beer. Perhaps a bear, if you can afford it.
+                       </p>
+               </div>
+               <a>Now that you've got...</a>
+               <div>
+                       <p>
+                               your bear, you have to admit it!<br/>
+                               No, we aren't selling bears.
+                       </p>
+                       <p>
+                               We could talk about renting one.
+                       </p>
+               </div>
+               <a>Rent one bear, ...</a>
+               <div>
+                       <p>
+                               get two for three beer.
+                       </p>
+                       <p>
+                               And now, for something completely different.
+                       </p>
+               </div>
+       </div>
 
-               <div id="list1">
-                       <a>There is one obvious advantage:</a>
-                       <div>
-                               <p>
-                                       You've seen it coming!<br/>
-                                       Buy now and get nothing for free!<br/>
-                                       Well, at least no free beer. Perhaps a bear, if you can afford it.
-                               </p>
-                       </div>
-                       <a>Now that you've got...</a>
-                       <div>
-                               <p>
-                                       your bear, you have to admit it!<br/>
-                                       No, we aren't selling bears.
-                               </p>
-                               <p>
-                                       We could talk about renting one.
-                               </p>
-                       </div>
-                       <a>Rent one bear, ...</a>
+       <ul id="navigation">
+               <li>
+                       <a class="head" href="?p=1.1.1">Guitar</a>
+                       <ul>
+                               <li><a href="?p=1.1.1.1">Electric</a></li>
+                               <li><a href="?p=1.1.1.2">Acoustic</a></li>
+                               <li><a href="?p=1.1.1.3">Amps</a></li>
+                               <li><a href="?p=1.1.1.4">Effects</a></li>
+                               <li><a href="?p=1.1.1.5">Accessories</a></li>
+                       </ul> 
+               </li>
+               <li>
+                       <a class="head" href="?p=1.1.2"><span>Bass</span></a>
+                       <ul>
+                               <li><a href="?p=1.1.2.1">Electric</a></li>
+                               <li><a href="?p=1.1.2.2">Acoustic</a></li>
+                               <li><a href="?p=1.1.2.3">Amps</a></li>
+                               <li><a href="?p=1.1.2.4">Effects</a></li>
+                               <li><a href="?p=1.1.2.5">Accessories</a></li>
+                               <li><a href="?p=1.1.2.5">Accessories</a></li>
+                               <li><a href="?p=1.1.2.5">Accessories</a></li>
+                       </ul> 
+               </li>
+               <li>
+                       <a class="head" href="?p=1.1.3">Drums</a>
+                       <ul>
+                               <li><a href="?p=1.1.3.2">Acoustic Drums</a></li>
+                               <li><a href="?p=1.1.3.3">Electronic Drums</a></li>
+                               <li><a href="?p=1.1.3.6">Accessories</a></li>
+                       </ul> 
+               </li>
+       </ul>
+       <dl id="list2">
+               <dt class="red">Red</dt>
+               <dd>
+                       Fancy stuff about red thingies.
+               </dd>
+               <dt class="green selected">Green</dt>
+               <dd>
+                       Green! Green! Green!
+               </dd>
+               <dt class="blue">Blue</dt>
+               <dd>
+                       Cool kids are blue.
+               </dd>
+       </dl>
+       
+       <div id="list3">
+               <div>
+                       <div class="title">Tennis</div>
                        <div>
-                               <p>
-                                       get two for three beer.
-                               </p>
-                               <p>
-                                       And now, for something completely different.
-                               </p>
+                               One ball, two players. Lots of fun.
                        </div>
                </div>
-
-       </fieldset>
-       
-       <fieldset>
-               <legend>Navigation - Unordered List with anchors and nested lists.</legend>
-               <p>The first item is cloned to allow the user to select it. The
-               active element is choosen based on location.hash: Open Drums and click
-               the first item ('Drums'), then reload the page.</p>
-
-               <ul id="navigation">
-                       <li>
-                               <a class="head" href="?p=1.1.1">Guitar</a>
-                               <ul>
-                                       <li><a href="?p=1.1.1.1">Electric</a></li>
-                                       <li><a href="?p=1.1.1.2">Acoustic</a></li>
-                                       <li><a href="?p=1.1.1.3">Amps</a></li>
-                                       <li><a href="?p=1.1.1.4">Effects</a></li>
-                                       <li><a href="?p=1.1.1.5">Accessories</a></li>
-                               </ul> 
-                       </li>
-                       <li>
-                               <a class="head" href="?p=1.1.2">Bass</a>
-                               <ul>
-                                       <li><a href="?p=1.1.2.1">Electric</a></li>
-                                       <li><a href="?p=1.1.2.2">Acoustic</a></li>
-                                       <li><a href="?p=1.1.2.3">Amps</a></li>
-                                       <li><a href="?p=1.1.2.4">Effects</a></li>
-                                       <li><a href="?p=1.1.2.5">Accessories</a></li>
-                                       <li><a href="?p=1.1.2.5">Accessories</a></li>
-                                       <li><a href="?p=1.1.2.5">Accessories</a></li>
-                               </ul> 
-                       </li>
-                       <li>
-                               <a class="head" href="?p=1.1.3">Drums</a>
-                               <ul>
-                                       <li><a href="?p=1.1.3.2">Acoustic Drums</a></li>
-                                       <li><a href="?p=1.1.3.3">Electronic Drums</a></li>
-                                       <li><a href="?p=1.1.3.6">Accessories</a></li>
-                               </ul> 
-                       </li>
-               </ul>
-
-       </fieldset>
-
-       <fieldset>
-               <legend>With options, container is a definition list, header dt, content dd</legend>
-               
-               <dl id="list2">
-                       <dt class="red">Red</dt>
-                       <dd>
-                               Fancy stuff about red thingies.
-                       </dd>
-                       <dt class="green selected">Green</dt>
-                       <dd>
-                               Green! Green! Green!
-                       </dd>
-                       <dt class="blue">Blue</dt>
-                       <dd>
-                               Cool kids are blue.
-                       </dd>
-               </dl>
-               
-       </fieldset>
-
-       <fieldset>
-               <legend>Divitus structure, div container, div header (class title), div
-               content, no active on startup and can be completely closed</legend>
-
-               <div id="list3">
+               <div>
+                       <div class="title">Soccer</div>
                        <div>
-                               <div class="title">Tennis</div>
-                               <div>
-                                       One ball, two players. Lots of fun.
-                               </div>
+                               One ball, 22 players. Lots of fun.
                        </div>
+               </div>
+               <div>
+                       <div class="title">Baseball</div>
                        <div>
-                               <div class="title">Soccer</div>
-                               <div>
-                                       One ball, 22 players. Lots of fun.
-                               </div>
+                               Well, one ball, some guys running around, some guys hitting others with a stick.<br/>
+                               Sounds like fun, doesn't it?
                        </div>
                        <div>
-                               <div class="title">Baseball</div>
-                               <div>
-                                       Well, one ball, some guys running around, some guys hitting others with a stick.<br/>
-                                       Sounds like fun, doesn't it?
-                               </div>
-                               <div>
-                                       Well, apart from the running part.
-                               </div>
+                               Well, apart from the running part.
                        </div>
                </div>
-               
-       </fieldset>
-               
-       <div id="switch">
-               <select>
-                       <option>Switch to...</option>
-                       <option value="1">1</option>
-                       <option value="2">2</option>
-                       <option value="3">3</option>
-               </select>
-               <button id="close">Close all</button>
-               Activate via selector, eg. ':first' or 'a:first': <input id="switch2" />
        </div>
-
-       <div id="log"><div><strong>Log of the 2nd accordion</strong></div></div>
+               
 </div>
 
 </body>
index 1fbd1e20c743ae7e8ace6e3ad90fa6bac08b5aae..e957acd431be7fec2a96a01ae9b74beb237a128b 100644 (file)
@@ -10,10 +10,14 @@ jQuery.ui.accordion.defaults.animated = false;
 function state(accordion) {
        var args = $.makeArray(arguments).slice(1);
        $.each(args, function(i, n) {
-               equals(n, accordion.find("div").eq(i).is(":visible"));
+               equals(accordion.find("div").eq(i).is(":visible"), n);
        });
 }
 
+$.fn.triggerEvent = function(type, target) {
+       return this.triggerHandler(type, [jQuery.event.fix({ type: type, target: target })]);
+}
+
 test("basics", function() {
        state($('#list1').accordion(), 1, 0, 0);
 });
@@ -82,4 +86,17 @@ test("activate, jQuery or DOM element", function() {
        state(ac, 0, 1, 0);
 });
 
+function state2(accordion) {
+       var args = $.makeArray(arguments).slice(1);
+       $.each(args, function(i, n) {
+               equals(accordion.find("ul").eq(i).is(":visible"), n);
+       });
+}
+
+test("handle click on header-descendant", function() {
+       var ac = $('#navigation').accordion({ header: '.head', autoHeight: false })
+       ac.triggerEvent("click", $('#navigation span:contains(Bass)')[0]);
+       state2(ac, 0, 1, 0);
+});
+
 })(jQuery);
index ad46f8729ed644e9d6d757d690a8c539f2d42529..e5f85a27c2fd96c7b96134dd5b0070943db824ed 100644 (file)
                <div class="ui-slider-handle" style="position: absolute; height: 21px; left: 0px; bottom: 0px; width: 17px; background-image: url(http://developer.yahoo.com/yui/examples/slider/assets/thumb-n.gif);"></div>
        </div>
 
-       <fieldset>
-               <legend>Standard, container is a div, header is h3 and content p</legend>
+       <div id="list1">
+               <a>There is one obvious advantage:</a>
+               <div>
+                       <p>
+                               You've seen it coming!<br/>
+                               Buy now and get nothing for free!<br/>
+                               Well, at least no free beer. Perhaps a bear, if you can afford it.
+                       </p>
+               </div>
+               <a>Now that you've got...</a>
+               <div>
+                       <p>
+                               your bear, you have to admit it!<br/>
+                               No, we aren't selling bears.
+                       </p>
+                       <p>
+                               We could talk about renting one.
+                       </p>
+               </div>
+               <a>Rent one bear, ...</a>
+               <div>
+                       <p>
+                               get two for three beer.
+                       </p>
+                       <p>
+                               And now, for something completely different.
+                       </p>
+               </div>
+       </div>
 
-               <div id="list1">
-                       <a>There is one obvious advantage:</a>
-                       <div>
-                               <p>
-                                       You've seen it coming!<br/>
-                                       Buy now and get nothing for free!<br/>
-                                       Well, at least no free beer. Perhaps a bear, if you can afford it.
-                               </p>
-                       </div>
-                       <a>Now that you've got...</a>
-                       <div>
-                               <p>
-                                       your bear, you have to admit it!<br/>
-                                       No, we aren't selling bears.
-                               </p>
-                               <p>
-                                       We could talk about renting one.
-                               </p>
-                       </div>
-                       <a>Rent one bear, ...</a>
+       <ul id="navigation">
+               <li>
+                       <a class="head" href="?p=1.1.1">Guitar</a>
+                       <ul>
+                               <li><a href="?p=1.1.1.1">Electric</a></li>
+                               <li><a href="?p=1.1.1.2">Acoustic</a></li>
+                               <li><a href="?p=1.1.1.3">Amps</a></li>
+                               <li><a href="?p=1.1.1.4">Effects</a></li>
+                               <li><a href="?p=1.1.1.5">Accessories</a></li>
+                       </ul> 
+               </li>
+               <li>
+                       <a class="head" href="?p=1.1.2"><span>Bass</span></a>
+                       <ul>
+                               <li><a href="?p=1.1.2.1">Electric</a></li>
+                               <li><a href="?p=1.1.2.2">Acoustic</a></li>
+                               <li><a href="?p=1.1.2.3">Amps</a></li>
+                               <li><a href="?p=1.1.2.4">Effects</a></li>
+                               <li><a href="?p=1.1.2.5">Accessories</a></li>
+                               <li><a href="?p=1.1.2.5">Accessories</a></li>
+                               <li><a href="?p=1.1.2.5">Accessories</a></li>
+                       </ul> 
+               </li>
+               <li>
+                       <a class="head" href="?p=1.1.3">Drums</a>
+                       <ul>
+                               <li><a href="?p=1.1.3.2">Acoustic Drums</a></li>
+                               <li><a href="?p=1.1.3.3">Electronic Drums</a></li>
+                               <li><a href="?p=1.1.3.6">Accessories</a></li>
+                       </ul> 
+               </li>
+       </ul>
+       <dl id="list2">
+               <dt class="red">Red</dt>
+               <dd>
+                       Fancy stuff about red thingies.
+               </dd>
+               <dt class="green selected">Green</dt>
+               <dd>
+                       Green! Green! Green!
+               </dd>
+               <dt class="blue">Blue</dt>
+               <dd>
+                       Cool kids are blue.
+               </dd>
+       </dl>
+       
+       <div id="list3">
+               <div>
+                       <div class="title">Tennis</div>
                        <div>
-                               <p>
-                                       get two for three beer.
-                               </p>
-                               <p>
-                                       And now, for something completely different.
-                               </p>
+                               One ball, two players. Lots of fun.
                        </div>
                </div>
-               
-       </fieldset>
-       
-       <fieldset>
-               <legend>Navigation - Unordered List with anchors and nested lists.</legend>
-               <p>The first item is cloned to allow the user to select it. The
-               active element is choosen based on location.hash: Open Drums and click
-               the first item ('Drums'), then reload the page.</p>
-
-               <ul id="navigation">
-                       <li>
-                               <a class="head" href="?p=1.1.1">Guitar</a>
-                               <ul>
-                                       <li><a href="?p=1.1.1.1">Electric</a></li>
-                                       <li><a href="?p=1.1.1.2">Acoustic</a></li>
-                                       <li><a href="?p=1.1.1.3">Amps</a></li>
-                                       <li><a href="?p=1.1.1.4">Effects</a></li>
-                                       <li><a href="?p=1.1.1.5">Accessories</a></li>
-                               </ul> 
-                       </li>
-                       <li>
-                               <a class="head" href="?p=1.1.2">Bass</a>
-                               <ul>
-                                       <li><a href="?p=1.1.2.1">Electric</a></li>
-                                       <li><a href="?p=1.1.2.2">Acoustic</a></li>
-                                       <li><a href="?p=1.1.2.3">Amps</a></li>
-                                       <li><a href="?p=1.1.2.4">Effects</a></li>
-                                       <li><a href="?p=1.1.2.5">Accessories</a></li>
-                                       <li><a href="?p=1.1.2.5">Accessories</a></li>
-                                       <li><a href="?p=1.1.2.5">Accessories</a></li>
-                               </ul> 
-                       </li>
-                       <li>
-                               <a class="head" href="?p=1.1.3">Drums</a>
-                               <ul>
-                                       <li><a href="?p=1.1.3.2">Acoustic Drums</a></li>
-                                       <li><a href="?p=1.1.3.3">Electronic Drums</a></li>
-                                       <li><a href="?p=1.1.3.6">Accessories</a></li>
-                               </ul> 
-                       </li>
-               </ul>
-               
-       </fieldset>
-
-       <fieldset>
-               <legend>With options, container is a definition list, header dt, content dd</legend>
-               
-               <dl id="list2">
-                       <dt class="red">Red</dt>
-                       <dd>
-                               Fancy stuff about red thingies.
-                       </dd>
-                       <dt class="green selected">Green</dt>
-                       <dd>
-                               Green! Green! Green!
-                       </dd>
-                       <dt class="blue">Blue</dt>
-                       <dd>
-                               Cool kids are blue.
-                       </dd>
-               </dl>
-               
-       </fieldset>
-
-       <fieldset>
-               <legend>Divitus structure, div container, div header (class title), div
-               content, no active on startup and can be completely closed</legend>
-
-               <div id="list3">
+               <div>
+                       <div class="title">Soccer</div>
                        <div>
-                               <div class="title">Tennis</div>
-                               <div>
-                                       One ball, two players. Lots of fun.
-                               </div>
+                               One ball, 22 players. Lots of fun.
                        </div>
+               </div>
+               <div>
+                       <div class="title">Baseball</div>
                        <div>
-                               <div class="title">Soccer</div>
-                               <div>
-                                       One ball, 22 players. Lots of fun.
-                               </div>
+                               Well, one ball, some guys running around, some guys hitting others with a stick.<br/>
+                               Sounds like fun, doesn't it?
                        </div>
                        <div>
-                               <div class="title">Baseball</div>
-                               <div>
-                                       Well, one ball, some guys running around, some guys hitting others with a stick.<br/>
-                                       Sounds like fun, doesn't it?
-                               </div>
-                               <div>
-                                       Well, apart from the running part.
-                               </div>
+                               Well, apart from the running part.
                        </div>
                </div>
-               
-       </fieldset>
-               
-               <div id="switch">
-                       <select>
-                               <option>Switch to...</option>
-                               <option value="1">1</option>
-                               <option value="2">2</option>
-                               <option value="3">3</option>
-                       </select>
-                       <button id="close">Close all</button>
-                       Activate via selector, eg. ':first' or 'a:first': <input id="switch2" />
-               </div>
-
-               <div id="log"><div><strong>Log of the 2nd accordion</strong></div></div>
+       </div>
 
        <div id="resizable1" style="background: green; width: 100px; height: 100px;">I'm a resizable.</div>
        <img src="images/test.jpg" id="resizable2" style="width: 100px; height: 100px;"/>
index 00a660c0b5ab582221f7b4c9e545cebcfad87b87..c7828cd9dc34b55ca3c37031d88fd91d33039ea2 100644 (file)
@@ -180,9 +180,7 @@ function clickHandler(event) {
        // due to the event delegation model, we have to check if one
        // of the parent elements is our actual header, and find that
        if ( clicked.parents(options.header).length ) {
-               while ( !clicked.is(options.header) ) {
-                       clicked = clicked.parent();
-               }
+               clicked = clicked.parents(options.header + ":first");
        }
        
        var clickedActive = clicked[0] == options.active[0];