]> source.dussan.org Git - jquery-ui.git/commitdiff
accordion: fix for the previous commit; event triggering still somewhat crippled...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Fri, 30 Jan 2009 16:49:40 +0000 (16:49 +0000)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Fri, 30 Jan 2009 16:49:40 +0000 (16:49 +0000)
tests/visual/accordion/accordion.html
ui/ui.accordion.js

index b5322391ab0f9017b9b6ddadaffc894165ea0dfe..bdea21248fd24201156ed561567b983a5743a485 100644 (file)
@@ -10,7 +10,7 @@
        <script type="text/javascript">
                $(function() {
                        function on() {
-                               $("#accordion").accordion({ header: "h3" });
+                               $("#accordion").accordion();
                        }
                        function off() {
                                $("#accordion").accordion("destroy");
index 0ecbfeb24a0baa2385fc64943a02faa44333dd2c..da1712dccd1761e5d83bbd25383bf5a8e8a08a4b 100644 (file)
@@ -85,12 +85,13 @@ $.widget("ui.accordion", {
                        this.headers.find('a').attr('tabIndex','-1');
 
                if (o.event) {
-                       this.element.bind((o.event) + ".accordion", function(event) { return self._clickHandler.call(self, event); });
+                       this.headers.bind((o.event) + ".accordion", function(event) { return self._clickHandler.call(self, event, this); });
                }
 
        },
 
        destroy: function() {
+               var o = this.options;
 
                this.element
                        .removeClass("ui-accordion ui-widget ui-helper-reset")
@@ -105,8 +106,10 @@ $.widget("ui.accordion", {
 
                this.headers.find("a").removeAttr("tabindex");
                this.headers.children(".ui-icon").remove();
-               this.headers.next().removeClass("ui-accordion-content ui-accordion-content-active");
-
+               var contents = this.headers.next().css("display", "").removeAttr("role").removeClass("ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content ui-accordion-content-active");
+               if (o.autoHeight || o.fillHeight) {
+                       contents.css("height", "");
+               }
        },
 
        _keydown: function(event) {
@@ -131,7 +134,7 @@ $.widget("ui.accordion", {
                                break;
                        case keyCode.SPACE:
                        case keyCode.ENTER:
-                               return this._clickHandler({ target: event.target });
+                               return this._clickHandler({ target: event.target }, event.target);
                }
 
                if (toFocus) {
@@ -176,7 +179,8 @@ $.widget("ui.accordion", {
 
        activate: function(index) {
                // call clickHandler with custom event
-               this._clickHandler({ target: this._findActive(index)[0] });
+               var active = this._findActive(index)[0];
+               this._clickHandler({ target: active }, active);
        },
 
        _findActive: function(selector) {
@@ -189,7 +193,7 @@ $.widget("ui.accordion", {
                                : this.headers.filter(":eq(0)");
        },
 
-       _clickHandler: function(event) {
+       _clickHandler: function(event, target) {
 
                var o = this.options;
                if (o.disabled) return false;
@@ -213,21 +217,13 @@ $.widget("ui.accordion", {
                }
 
                // get the click target
-               var clicked = $(event.target);
-
-               // due to the event delegation model, we have to check if one
-               // of the parent elements is our actual header, and find that
-               // otherwise stick with the initial target
-               clicked = $( clicked.parents(o.header)[0] || clicked );
+               var clicked = $(event.currentTarget || target);
                var clickedIsActive = clicked[0] == this.active[0];
 
                // if animations are still active, or the active header is the target, ignore click
                if (this.running || (o.alwaysOpen && clickedIsActive)) {
                        return false;
                }
-               if (!clicked.is(o.header)) {
-                       return;
-               }
 
                // switch classes
                this.active.removeClass("ui-state-active ui-corner-top").addClass("ui-state-default ui-corner-all")
@@ -373,7 +369,7 @@ $.extend($.ui.accordion, {
                clearStyle: false,
                event: "click",
                fillSpace: false,
-               header: "> li :first,> :not(li):odd",
+               header: "> li :first,> :not(li):even",
                icons: {
                        header: "ui-icon-triangle-1-e",
                        headerSelected: "ui-icon-triangle-1-s"