]> source.dussan.org Git - jquery-ui.git/commitdiff
Fixed accordion option active getter and setter. Normalized getter to number, 0-based...
authorRichard Worth <rdworth@gmail.com>
Tue, 11 Aug 2009 00:45:01 +0000 (00:45 +0000)
committerRichard Worth <rdworth@gmail.com>
Tue, 11 Aug 2009 00:45:01 +0000 (00:45 +0000)
tests/unit/accordion/accordion_options.js
ui/ui.accordion.js

index bb844f83805da6a759f45276438498932cdcaa23..00b3dbb8c523303339528c5487327e19dd5be703 100644 (file)
@@ -38,7 +38,20 @@ test("{ active: false }", function() {
 });
 
 test("{ active: Number }", function() {
-       ok(false, 'missing test - untested code is broken code');
+       expect(4);
+       $("#list1").accordion({
+               active: 0
+       });
+       equals( $("#list1").accordion('option', 'active'), 0);
+
+       $("#list1").accordion('option', 'active', 1);
+       equals( $("#list1").accordion('option', 'active'), 1);
+
+       $('.ui-accordion-header:eq(2)', '#list1').click();
+       equals( $("#list1").accordion('option', 'active'), 2);
+
+       $("#list1").accordion('activate', 0);
+       equals( $("#list1").accordion('option', 'active'), 0);
 });
 
 test("{ animated: false }, default", function() {
index f05a3b1a5b3df632b201a3cef6cf15944d2d3566..1b8337547b13142484cbc0be699230942d7aaa53 100644 (file)
@@ -153,6 +153,9 @@ $.widget("ui.accordion", {
                
                $.widget.prototype._setData.apply(this, arguments);
                        
+               if (key == "active") {
+                       this.activate(value);
+               }
                if (key == "icons") {
                        this._destroyIcons();
                        if (value) {
@@ -230,6 +233,7 @@ $.widget("ui.accordion", {
        },
 
        activate: function(index) {
+               this.options.active = index;
                // call clickHandler with custom event
                var active = this._findActive(index)[0];
                this._clickHandler({ target: active }, active);
@@ -273,6 +277,8 @@ $.widget("ui.accordion", {
                // get the click target
                var clicked = $(event.currentTarget || target);
                var clickedIsActive = clicked[0] == this.active[0];
+               
+               o.active = $('.ui-accordion-header', this.element).index(clicked);
 
                // if animations are still active, or the active header is the target, ignore click
                if (this.running || (!o.collapsible && clickedIsActive)) {