From f60ea86825714d17055efd78e4b54a3b4c82a4ff Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 4 Mar 2011 11:37:34 +0100 Subject: [PATCH 1/2] Modified accordion to have a default index --- src/ui/controls/accordion.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/ui/controls/accordion.js b/src/ui/controls/accordion.js index 8edbbc3..af7c321 100644 --- a/src/ui/controls/accordion.js +++ b/src/ui/controls/accordion.js @@ -10,7 +10,9 @@ Object.extend(Event, { * Applies "accordion menu" behavior to an element and its contents. * * ##### Options - * + * + * * `defaultIndex` (Integer): Determines which content element should be + * open by default. * * `multiple` (Boolean): Whether multiple panels can be open at once. * Defaults to `false`. * * `headerSelector` (String): A CSS selector that identifies the @@ -56,7 +58,7 @@ Object.extend(Event, { UI.addBehavior(this.headers, [UI.Behavior.Hover, UI.Behavior.Focus]); // The next sibling of each header is its corresponding content element. - this.content = this.headers.map( function(h) { return h.next(); }); + this.content = this.headers.map( function(h) {return h.next();}); UI.addClassNames(this.content, 'ui-accordion-content ui-helper-reset ' + 'ui-widget-content ui-corner-bottom'); @@ -65,12 +67,17 @@ Object.extend(Event, { this.headers.each( function(header) { var icon = new Element('span'); UI.addClassNames(icon, 'ui-icon ' + opt.icons.header); - header.insert({ top: icon }); + header.insert({top: icon}); }); - // If the user specified an active header, mark it as active. + // If the user specified a default index, mark it as active. // Otherwise, the first one is active by default. - this._markActive(opt.active || this.headers.first(), false); + this.content.each(function(element, i){ + if(opt.defaultIndex != i) { + element.hide(); + } + }); + this._markActive(this.headers[opt.defaultIndex] || this.headers.first(), false); // ARIA. this.element.writeAttribute({ @@ -80,7 +87,7 @@ Object.extend(Event, { this.headers.invoke('writeAttribute', 'role', 'tab'); this.content.invoke('writeAttribute', 'role', 'tabpanel'); - var links = this.headers.map( function(h) { return h.down('a'); }); + var links = this.headers.map( function(h) {return h.down('a');}); links.invoke('observe', 'click', function(event) { event.preventDefault(); }); @@ -153,7 +160,7 @@ Object.extend(Event, { } header = this.headers[index]; } - (function() { header.down('a').focus(); }).defer(); + (function() {header.down('a').focus();}).defer(); }, _toggleActive: function(header) { @@ -223,6 +230,7 @@ Object.extend(Event, { Object.extend(UI.Accordion, { DEFAULT_OPTIONS: { + defaultIndex: 0, multiple: false, /* whether more than one pane can be open at once */ headerSelector: 'h3', From e05e3d6c9052dfc8035f77c503c16dc8998a0247 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 4 Mar 2011 11:37:34 +0100 Subject: [PATCH 2/2] Added defaultIndex option to S2.UI.Accordion and fixed initialization behaviour Signed-off-by: Eirik Ottesen --- src/ui/controls/accordion.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ui/controls/accordion.js b/src/ui/controls/accordion.js index 8edbbc3..a90bb35 100644 --- a/src/ui/controls/accordion.js +++ b/src/ui/controls/accordion.js @@ -10,7 +10,9 @@ Object.extend(Event, { * Applies "accordion menu" behavior to an element and its contents. * * ##### Options - * + * + * * `defaultIndex` (Integer): Determines which content element should be + * open by default. * * `multiple` (Boolean): Whether multiple panels can be open at once. * Defaults to `false`. * * `headerSelector` (String): A CSS selector that identifies the @@ -68,9 +70,13 @@ Object.extend(Event, { header.insert({ top: icon }); }); - // If the user specified an active header, mark it as active. + // If the user specified a default index, mark it as active. // Otherwise, the first one is active by default. - this._markActive(opt.active || this.headers.first(), false); + this.content.each(function(element, i){ + if(opt.defaultIndex != i) { + element.hide(); + } + }); // ARIA. this.element.writeAttribute({ @@ -223,6 +229,7 @@ Object.extend(Event, { Object.extend(UI.Accordion, { DEFAULT_OPTIONS: { + defaultIndex: 0, multiple: false, /* whether more than one pane can be open at once */ headerSelector: 'h3',