This project is archived and is in readonly mode.

#42 ✓resolved
Thomas Aylott

Accordion addSection Method doesn't allow insertion into last position

Reported by Thomas Aylott | May 28th, 2008 @ 10:05 AM

Originally posted on Trac by VirtuosiMedia

Original Trac Ticket

Description

The addSection Method for the Accordion class does not allow insertion of a new section into the last position of the array. In an array of 2 , [0, 1], either 0 or 1 may be passed as arguments to add a third section, but not 2. If no argument is passed, the new section defaults to the second to last position rather than the last. I was able to fix this in v1.11 by changing:

		if (len && (!test || pos)){
			pos = $pick(pos, len - 1);
			toggler.injectBefore(this.togglers[pos]);
			element.injectAfter(toggler);
		} else if (this.container && !test){
			toggler.inject(this.container);
			element.inject(this.container);
		}

to:

		if (len && (!test || pos)){
			pos = $pick(pos, len - 1);
			toggler.injectAfter(this.elements[pos]);
			element.injectAfter(toggler);
		} else if (this.container && !test){
			toggler.inject(this.container);
			element.inject(this.container);
		}

However, simply changing 'before' to 'after' in version 1.2b2 does not work. Here is an example of my code:


window.addEvent('domready', function() {
	var menu = new Accordion('.toggle', '.element', {
		display: 1,
		fixedHeight: 300,
		alwaysHide: true,
		duration: 2500,
		onActive: function(toggler, element){
			toggler.setStyle('color', '#CCC');
		},
	 
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#000');
		}
	  }
	);

	var thirdMenuToggler = new Element('div', {'class': 'toggle'}).setHTML('Menu 3');

	var thirdMenuElement = new Element('div', {'class': 'element'}).setHTML('Link 6Link 7');

	menu.addSection(thirdMenuToggler, thirdMenuElement);
	
});

	Menu 1

			Link 1
			Link 2

	Menu 2

			Link 3
			Link 4
			Link 5			

Trac Attachments

Trac Comments

Changed 1 month ago by knownwanderer


        
I changed the following to get it to work, but this probably isn't the best idea. 

toggler.inject(this.togglers[pos].getNext(), 'after');
//toggler.inject(this.togglers[pos], 'before');

      

Comments and changes to this ticket

  • Adam

    Adam July 17th, 2008 @ 10:43 PM

    • Tag set to accordion, defect, major, plugins

    Please consider updating the aforementioned code block to:

    if (len && (!test || pos)){
    		    var injectPoint = 'before';
    			if (!$defined(pos) || pos >= len){
    			    injectPoint = 'after';
    			    pos = len - 1;
    			}
    			pos = $pick(pos, len - 1);
    			toggler.inject(this.togglers[pos], injectPoint);
    			element.inject(toggler, 'after');
    		} else if (this.container && !test){
    			toggler.inject(this.container);
    			element.inject(this.container);
    		}
    

    This code keeps all the functionality the same as it is now except that when the index is not specified or is greater than the current number of elements it will append the new section at the end.

  • Adam

    Adam July 17th, 2008 @ 09:27 PM

    I made a mistake with the last post, the following code works right:

    if (len && (!test || pos)){
    			if (!$defined(pos) || pos >= len){
    			    pos = len - 1;
    			    toggler.inject(this.elements[pos], 'after');
    			} else {
    			    pos = $pick(pos, len - 1);
    			    toggler.inject(this.togglers[pos], 'before');
    			}
    			element.inject(toggler, 'after');
    		} else if (this.container && !test){
    			toggler.inject(this.container);
    			element.inject(this.container);
    		}
    		var idx = this.togglers.indexOf(toggler);
    
  • Aaron Newton

    Aaron Newton February 19th, 2009 @ 12:10 AM

    • Assigned user changed from “Valerio” to “Aaron Newton”
    • Tag changed from accordion, defect, major, plugins to accordion, defect
    • Milestone cleared.
  • fakedarren

    fakedarren February 8th, 2010 @ 03:25 PM

    • State changed from “new” to “open”
    • Assigned user changed from “Aaron Newton” to “fakedarren”
  • fakedarren

    fakedarren February 13th, 2010 @ 12:18 PM

    • State changed from “open” to “resolved”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Pages