Here are a couple prototype functions that extend the Mootools Accordion to open a section from a link with an anchor. eg..
http://www.liquidnexus.com/index.php#ANCHOR
In the mootools 1.1 days, it was a subclass, but something changed that was far too evil to deal with right now, so I consolidated it into two functions that you can use with the existing Accordion class.
Array.prototype.findIndex = function(value){
var ctr = "";
for (var i=0; i < this.length; i++) {
// use === to check for Matches. ie., identical (===), ;
if (this[i] == value) {
return i;
}
}
return ctr;
};
Accordion.prototype.displayAnchoredSection = function(wrapperElement){
var displaySection = 0;
var anchor = window.location.href.split('#')[1];
if(anchor){
var sections = $$(wrapperElement);
var items = new Array();
for (var i=0; i < sections.length; i++) {
items[i]=sections[i].getElementsByTagName(’a')[0].getAttribute(”name”);
};
displaySection = items.findIndex(anchor);
};
this.display(displaySection);
}
The first function is a prototype to return the index of an item in an array, the second function pulls the anchor from the location url, and tells the accordion to display that section. There are a few caveats to using this, as I just threw it together for my own personal use. First, you have to wrap each section of your accordion in wrapper class, and then in your domready event, create your accordion, and then tell it which section to open.
var accordion = new Accordion($$('\*toggler\*'), $$('\*content\*'));
accordion.displayAnchoredSection('\*wrapperClass\*');
I’m not feeling very articulate as I’m writing this, so if I’m talking in circles, you’ll have to excuse me. If you have any issues, just tweet me @bdelcamp on twitter, or email me.


















