Skip to main content

Search and Top Navigation

Ticket #4222: accordion-4222.patch


File accordion-4222.patch, 2.8 KB (added by jzaefferer, May 08, 2009 12:57PM UTC)
Index: tests/unit/accordion/accordion_options.js
===================================================================
--- tests/unit/accordion/accordion_options.js	(revision 2502)
+++ tests/unit/accordion/accordion_options.js	(working copy)
@@ -119,6 +119,20 @@
 	ok(false, 'missing test - untested code is broken code');
 });
 
+test("{ icons: false }", function() {
+	function icons(on) {
+		same($("#list1 span.ui-icon:visible").length, on ? 3 : 0);
+	} 
+	$("#list1").accordion({
+		icons: false
+	});
+	icons(false);
+	$("#list1").accordion("option", "icons", $.ui.accordion.defaults.icons);
+	icons(true);
+	$("#list1").accordion("option", "icons", false);
+	icons(false);
+});
+
 test("{ navigation: false }, default", function() {
 	ok(false, 'missing test - untested code is broken code');
 });
Index: ui/ui.accordion.js
===================================================================
--- ui/ui.accordion.js	(revision 2502)
+++ ui/ui.accordion.js	(working copy)
@@ -60,8 +60,7 @@
 		this.active.next().addClass('ui-accordion-content-active');
 
 		//Append icon elements
-		$("").addClass("ui-icon " + o.icons.header).prependTo(this.headers);
-		this.active.find(".ui-icon").toggleClass(o.icons.header).toggleClass(o.icons.headerSelected);
+		this._createIcons();
 
 		// IE7-/Win - Extra vertical space in lists fixed
 		if ($.browser.msie) {
@@ -104,6 +103,18 @@
 		}
 
 	},
+	
+	_createIcons: function() {
+		var o = this.options;
+		if (o.icons) {
+			$("").addClass("ui-icon " + o.icons.header).prependTo(this.headers);
+			this.active.find(".ui-icon").toggleClass(o.icons.header).toggleClass(o.icons.headerSelected);
+		}
+	},
+	
+	_destroyIcons: function() {
+		this.headers.children(".ui-icon").remove();
+	},
 
 	destroy: function() {
 		var o = this.options;
@@ -120,7 +131,7 @@
 			.removeAttr("role").removeAttr("aria-expanded").removeAttr("tabindex");
 
 		this.headers.find("a").removeAttr("tabindex");
-		this.headers.children(".ui-icon").remove();
+		this._destroyIcons();
 		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", "");
@@ -130,8 +141,18 @@
 	},
 	
 	_setData: function(key, value) {
-		if(key == 'alwaysOpen') { key = 'collapsible'; value = !value; }
-		$.widget.prototype._setData.apply(this, arguments);	
+		// alwaysOpen is deprecated
+		if(key == 'alwaysOpen'){ key = 'collapsible'; value = !value; }
+		
+		$.widget.prototype._setData.apply(this, arguments);
+			
+		if (key == "icons") {
+			this._destroyIcons();
+			if (value) {
+				this._createIcons();
+			}
+		}
+		
 	},
 
 	_keydown: function(event) {

Download in other formats:

Original Format