Untested, I just threw this together before going to work, but this is
the basic idea of extending a class.
Fx.Accordion.Fli7e = new Class({
Extends: Fx.Accordion,
options: {
// just need the new options here
activeID: false
},
initialize: function(togglers, elements, options){
// calls the parent initialize function
this.parent(togglers,elements,options);
},
// add in your new methods
getActiveID: function(){
return this.options.activeID;
},
// override parent methods, or use parent(display) to just call the
parent's version
display: function(index, useFx){
useFx = $pick(useFx, true);
index = ($type(index) == 'element') ? this.elements.indexOf(index) :
index;
if ((this.timer && this.options.wait) || (index === this.previous
&& !this.options.alwaysHide)) return this;
this.previous = index;
var obj = {};
this.elements.each(function(el, i){
obj[i] = {};
var hide = (i != index) || (this.options.alwaysHide &&
(el.offsetHeight > 0));
this.fireEvent(hide ? 'background' : 'active', [this.togglers[i],
el]);
for (var fx in this.effects) obj[i][fx] = hide ? 0 :
el[this.effects[fx]];
this.options.activeID = hide ? this.options.activeID :
i;
}, this);
return useFx ? this.start(obj) : this.set(obj);
}
});
On Sep 8, 2009, at 3:12 AM, Fli7e wrote:
Hi there,
i am rather new at posting in this group and i have a question /
enhancement für the MooTools More Accordion Class.
I added a Class-Function to return the actual displayed Accordion
Element because i needed this function to store the actual active
Accordion Element in a Cookie / Session and re-use it after page
reloads.
For this this work i modified the Class ( var Accordion = Fx.Accordion
= new Class({}); ) like this:
Added option key:
------------------
options: { activeID : false }
Added function:
------------------
getActiveID: function(){ return this.options.activeID;},
Added in "display" function @ inner for loop:
------------------
this.options.activeID = hide ? this.options.activeID : i;
This way i could easily call the getActiveID() function and the active
accordion ID (0-xx) will be returned.
I have no idea if this could be done without modifing the original
code of More, so my question is:
Could i achieve this without modifing the original Code or should i
submit this small addition to some lighthouse list or is someone of
the dev's maybe doing this?
A "just a test" could be seen over here:
http://www.artness.de/area/
the Accordion to the left will auto-scale it's height to fit the CSS-
Frame height at window resize and will be redrawn using the active
element stay open.
I know, the test environment over there is not perfect code but i am
experimenting with dynamic scaling "CSS Frames" without heavy overuse
of javascript (atm only the accordion is javascript).
Opera users take care: Opera won't actually scale the Accordion as
supposed ... no clue why atm ...