From ef27211d2da36667608d854ff578f30da1e5132e Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Fri, 12 Dec 2008 13:20:34 +0000 Subject: Accordion: Fixed #3646 - Update markup to new UI CSS Framework specs; Added visual test and updated tests to markup changes --- tests/accordion.html | 108 ++++++++++++++++---------------------------- tests/accordion.js | 10 ++-- tests/visual/accordion.html | 55 ++++++++++++++++++++++ ui/ui.accordion.js | 52 ++++++++++----------- 4 files changed, 125 insertions(+), 100 deletions(-) create mode 100644 tests/visual/accordion.html diff --git a/tests/accordion.html b/tests/accordion.html index 13079e1f2..a0459937d 100644 --- a/tests/accordion.html +++ b/tests/accordion.html @@ -19,38 +19,47 @@
- There is one obvious advantage: -
-

- You've seen it coming!
- Buy now and get nothing for free!
- Well, at least no free beer. Perhaps a bear, if you can afford it. -

-
- Now that you've got... -
-

- your bear, you have to admit it!
- No, we aren't selling bears. -

-

- We could talk about renting one. -

-
- Rent one bear, ... -
-

- get two for three beer. -

-

- And now, for something completely different. -

-
+
+ There is one obvious advantage: +
+

+ You've seen it coming! +
+ Buy now and get nothing for free! +
+ Well, at least no free beer. Perhaps a bear, if you can afford it. +

+
+
+
+ Now that you've got... +
+

+ your bear, you have to admit it! +
+ No, we aren't selling bears. +

+

+ We could talk about renting one. +

+
+
+
+ Rent one bear, ... +
+

+ get two for three beer. +

+

+ And now, for something completely different. +

+
+
-
-
Red
-
- Fancy stuff about red thingies. -
-
Green
-
- Green! Green! Green! -
-
Blue
-
- Cool kids are blue. -
-
- -
-
-
Tennis
-
- One ball, two players. Lots of fun. -
-
-
-
Soccer
-
- One ball, 22 players. Lots of fun. -
-
-
-
Baseball
-
- Well, one ball, some guys running around, some guys hitting others with a stick.
- Sounds like fun, doesn't it? -
-
- Well, apart from the running part. -
-
-
diff --git a/tests/accordion.js b/tests/accordion.js index 5ac24fd9d..99a368c37 100644 --- a/tests/accordion.js +++ b/tests/accordion.js @@ -10,7 +10,7 @@ jQuery.ui.accordion.defaults.animated = false; function state(accordion) { var args = $.makeArray(arguments).slice(1); $.each(args, function(i, n) { - equals(accordion.find("div").eq(i).is(":visible"), n); + equals(accordion.find(".ui-accordion-content").eq(i).is(":visible"), n); }); } @@ -23,11 +23,11 @@ test("basics", function() { }); test("autoheight", function() { - $('#navigation').accordion({ header: '.head', autoHeight: false }); + $('#navigation').accordion({ autoHeight: false }); equals( 90, $('#navigation ul:first').height() ); equals( 126, $('#navigation ul:eq(1)').height() ); equals( 54, $('#navigation ul:last').height() ); - $('#navigation').accordion("destroy").accordion({ header: '.head', autoHeight: true }); + $('#navigation').accordion("destroy").accordion({ autoHeight: true }); equals( 126, $('#navigation ul:first').height() ); equals( 126, $('#navigation ul:eq(1)').height() ); equals( 126, $('#navigation ul:last').height() ); @@ -67,7 +67,7 @@ test("activate, boolean, alwaysOpen:true", function() { }); test("activate, string expression", function() { - var ac = $('#list1').accordion({ active: ":last" }); + var ac = $('#list1').accordion({ active: "a:last" }); state(ac, 0, 0, 1); ac.accordion("activate", ":first"); state(ac, 1, 0, 0); @@ -94,7 +94,7 @@ function state2(accordion) { } test("handle click on header-descendant", function() { - var ac = $('#navigation').accordion({ header: '.head', autoHeight: false }) + var ac = $('#navigation').accordion({ autoHeight: false }) ac.triggerEvent("click", $('#navigation span:contains(Bass)')[0]); state2(ac, 0, 1, 0); }); diff --git a/tests/visual/accordion.html b/tests/visual/accordion.html new file mode 100644 index 000000000..e1e2d5433 --- /dev/null +++ b/tests/visual/accordion.html @@ -0,0 +1,55 @@ + + + + jQuery UI Accordion Visual Test + + + + + + + + + + + + + +
+
+

Test 1

+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit +
+
+
+

Test 2

+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit +
+
+
+

Test 3

+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit +
+
+
+ + + + + diff --git a/ui/ui.accordion.js b/ui/ui.accordion.js index d30bd9217..eebf321d0 100644 --- a/ui/ui.accordion.js +++ b/ui/ui.accordion.js @@ -28,23 +28,22 @@ $.widget("ui.accordion", { } } } - - // calculate active if not specified, using the first header - options.headers = this.element.find(options.header); - options.active = findActive(options.headers, options.active); + + this.element.addClass("ui-accordion ui-widget ui-helper-reset"); + var groups = this.element.children().addClass("ui-accordion-group"); + var headers = options.headers = groups.find("> :first-child").addClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all"); + headers.next().addClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom"); + + var active = options.active = findActive(headers, options.active).toggleClass("ui-state-default").toggleClass("ui-state-active").toggleClass("ui-corner-all").toggleClass("ui-corner-top"); + active.parent().addClass("selected"); + $("").addClass("ui-icon ui-icon-circle-plus").prependTo(headers); + active.find(".ui-icon").toggleClass("ui-icon-circle-plus").toggleClass("ui-icon-circle-minus"); // IE7-/Win - Extra vertical space in Lists fixed if ($.browser.msie) { this.element.find('a').css('zoom', '1'); } - if (!this.element.hasClass("ui-accordion")) { - this.element.addClass("ui-accordion"); - $('').insertBefore(options.headers); - $('').appendTo(options.headers); - options.headers.addClass("ui-accordion-header"); - } - var maxHeight; if ( options.fillSpace ) { maxHeight = this.element.parent().height(); @@ -84,8 +83,7 @@ $.widget("ui.accordion", { } else { options.active .attr('aria-expanded','true') - .attr("tabIndex", "0") - .parent().andSelf().addClass(options.selectedClass); + .attr("tabIndex", "0"); } // only need links in taborder for Safari @@ -98,16 +96,15 @@ $.widget("ui.accordion", { }, destroy: function() { - this.options.headers.parent().andSelf().removeClass(this.options.selectedClass); - this.options.headers.prev(".ui-accordion-left").remove(); - this.options.headers.children(".ui-accordion-right").remove(); - this.options.headers.next().css("display", ""); - if ( this.options.fillSpace || this.options.autoHeight ) { - this.options.headers.next().css("height", ""); - } + this.element.removeClass("ui-accordion ui-widget ui-helper-reset").removeAttr("role").unbind(".accordion"); $.removeData(this.element[0], "accordion"); - - this.element.removeClass("ui-accordion").unbind(".accordion"); + var groups = this.element.children().removeClass("ui-accordion-group selected"); + var headers = this.options.headers.removeClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-state-active ui-corner-top") + .removeAttr("role").removeAttr("aria-expanded").removeAttr("tabindex"); + headers.find("a").removeAttr("tabindex"); + headers.next().removeClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom") + .removeAttr("role").css({display: "", height: "", overflow: "", marginTop:"", marginBottom:""}); + headers.children(".ui-icon").remove(); }, _keydown: function(event) { @@ -260,10 +257,9 @@ function clickHandler(event) { if (options.disabled) { return false; } - // called only when using activate(false) to close all parts programmatically if ( !event.target && !options.alwaysOpen ) { - options.active.parent().andSelf().toggleClass(options.selectedClass); + options.active.parent().toggleClass(options.selectedClass); var toHide = options.active.next(), data = { options: options, @@ -295,9 +291,13 @@ function clickHandler(event) { } // switch classes - options.active.parent().andSelf().toggleClass(options.selectedClass); + options.active.parent().toggleClass(options.selectedClass); + options.active.removeClass("ui-state-active ui-corner-top").addClass("ui-state-default ui-corner-all") + .find(".ui-icon").removeClass("ui-icon-circle-minus").addClass("ui-icon-circle-plus"); if ( !clickedActive ) { - clicked.parent().andSelf().addClass(options.selectedClass); + clicked.parent().addClass(options.selectedClass); + clicked.removeClass("ui-state-default ui-corner-all").addClass("ui-state-active ui-corner-top") + .find(".ui-icon").removeClass("ui-icon-circle-plus").addClass("ui-icon-circle-minus"); } // find elements to show and hide -- cgit v1.2.3