[Note to self: next time use Firebug to see how things work]
OK. The hack (rev.3?) really should have been
element.getChildren('.morphtabs_defaulthide').setStyle({
height: '0px',
visibility: 'hidden',
opacity: '0'
});
to properly mimic the Accordion hiding a section.
-----
OK. I just read your last message while writing this. Here's the
explanation before I get further. As defined in HTML-4.01, an element
can have multiple classes, so if you have:
<div id="oneDiv" class="element"> [...] </div>
you can also have:
<div id="myDiv" class="element another_class"> [...] </div>
without it causing any problems. It's expected to be valid. This means
the element with id "myDiv" will receive all styles defined for the
class "element" as well as all styles defined for the class
"another_class". Now this last div (with id "myDiv") is seen as having
both the class 'element' and the class 'another_class'. And this even
if one or any of the classes don't have any styles defined (i.e. isn't
defined in CSS's <style> tags). It serves as another mean to select
elements (hence the usefulness of CSS selectors) using only the id or
just *one* single class. So if, with MooTools, you do
var elemArray1 = $$('div.element'); // an array of div elements with
class 'element'
var elemArray2 = $$('div.another_class'); // an array of div elements
with class 'another_class'
both elemArray1 and elemArray2 arrays will contain the div
"myDiv" (along with all other matching elements). It also means that
var bool1 = $('myDiv').hasClass('element'); // sets bool1 to true
var bool2 = $('myDiv').hasClass('another_class'); // sets bool2 to
true
will both return true. So you can use classes to 'flag' elements,
without causing widget/script to break by changing the one class or
id.
So the hack really involved (1) adding the class
"morphtabs_defaulthide" to all your <div class="element">, without
anything breaking, to get something like this:
<p class="toggler">City + Region</p>
<div class="element morphtabs_defaulthide">- <a href="[..]">[..]</a>
- <a href="[..]">[..]</a>
- <a href="[..]">[..]</a>
[..]
</div>
<p class="toggler">Civic</p>
<div class="element morphtabs_defaulthide">- <a href="[..]">[..]</a>
- <a href="[..]">[..]</a>
- <a href="[..]">[..]</a>
[..]
</div>
and so on; and (2) changing the fill() function within Morphtabs.js to
fill: function(element, contents) {
if(this.options.useAjax) {
this.getContent();
} else {
element.set('html', contents);
var children = element.getChildren('.morphtabs_defaulthide');
if (children) {
children.setStyles({
height: '0px',
visibility: 'hidden',
opacity: '0'
});
}
}
},
so as to support resetting your <div class="element
morphtabs_defaulthide"> (which contain the accordion sections) to a
hidden state, as set by the Accordion plugin when first run.
-----
OK. But even with the hack, it still won't work. Aactually, the hack
is useless!
Why? Because (of course! it's clear now...) Morphtabs breaks the
Accordion: upon initialization, Morphtabs removes from the DOM and
stores away content of the panels (except for the first one) and
injects/replaces it in a wrapper only when needed (i.e. when a tab is
clicked). So by the time you switch to another panel (after the first
one), elements have in fact just been created & injected and thus
don't have any event attached to handlers of the Accordion previously
created. So clicking on the togglers doesn't do anything.
Now I don't really see an easy fix to this. It wouldn't be a problem
if Morphtabs was hiding panels instead or destructing/re-injecting
them. Here are the options I see:
- Use another plugin for that tabs functionality (not ideal, I know)
- Modify heavily Morphtabs to work around it's incompatibility with
Accordion (event worse)
- Somehow re-create the accordion after each tab/panel switch (does
Morphtabs raise events?)
- Create a wrapper class around Morphtabs and overide the fill()
function to re-attach event handlers to togglers after injection.
(that would be my best bet)
But first look around to see if anybody stumbled upon the same problem
and if any fix has been found.
Oh, wait, I may have something working...
Jonathan