I am doing stuff.

Purr – a MooTools notifications / alert class.

I have written up a notifications / alert class for a recent project and thought I would share it. Too much to go into in a post, so there is a big page for it here.

Before anyone brings it up, this is not yet in the MooTools Forge, but it will be soon assuming I don’t become distracted by something else…

trackback

Tags: , , no responses »

Leave a Reply

ok to use:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

bonus!

If you want to post code, you can use:

<pre lang="[language]">[code]</pre>

Where [language] is a valid geshi language type, and where [code] is your code.

rAccordion – a MooTools 1.2 recursive accordion

So I have managed to create a recursive mootools accordion, which is something I have wanted to get done for a long time.

The secret ingredient to get this made up was some CSS3 selectors and a bit of recursion.

You basically just pass in a class for the toggles, a class for the elements, and a parent container to reference.

The usage ends up fairly simple:

new rAccordion('container', 'toggle', 'element');

In the example, container is the id of the parent that the classes are in, toggle is the class that each toggle has, and element is the class that each element has. A fourth argument can be passed, which is the options argument for the mootools Accordion class.

There are some kinks thatstill need working out. There are inherit problems with just jamming accordions inside of each other. The way mootools creates the accordion requires quite a bit of inline styles, which include defined heights. These heights become problematic when accordions inside accordions need to expand or contract, but their parent element has a defined height and overflow which will not allow the newly expanded portion to be seen.

I do have something of a solution in place, but it feels a little hacky, but I am not sure it will get any better unless I rewrite the accordion.

If anyone has any ideas on how to address this issue, please drop me a comment.

example

download w/the example

Here is the class:

var rAccordion = new Class({
 
	initialize: function(container, toggleClass, elementClass, options){
		this.container = container;
		this.tClass = toggleClass;
		this.eClass = elementClass;
		this.options = options;
		this.selector = '#' + this.container + ' > .';
		this.makeAccordion();
	},
 
	makeAccordion: function(){
		new Accordion(
			$$(this.selector+this.tClass),
			$$(this.selector+this.eClass),
			this.options
		).addEvents({
			// The onActive and onComplete events added to the stack here to
			// attempt to address some of the css issues.
			'onActive': function(toggle){
				if(toggle.getParent().getStyle('height') != 0)
					toggle.getParent().setStyle('height', '');
			},
			'onComplete': function(a){
				if ($defined(a)) {
					var height = 0;
					a.getParent().getChildren().each(function(e){
						height = height + e.offsetHeight;
					});
					if(height != a.getParent().offsetHeight && a.getParent().offsetHeight != 0)
						a.getParent().setStyle('height','');
				}
			}
		});
		this.selector += this.eClass + ' > .';
		if($defined($$(this.selector)[0]))
			this.makeAccordion();
	}
 
});

trackback

Tags: , , , , , 19 responses »
  1. Daniel Buchner's gravatar
    Daniel Buchner Says:

    I think a cure for you overflow ailment with slide/accordion might lie in an ‘extend’ of the class. This is a great way to let Fx.Slide do overflow auto (it is set to hidden automatically too, annoying!), for refrence:

    http://we.designandco.de/2008/06/10/mootools-fxslide-flicker-bug/
    http://we.designandco.de/2008/06/20/mootools-fxslide-flicker-bug-ii/

    I am not sure if internally Accordion is dependent on Slide for its actions, but anyhow, ‘extend’ use could give you the option I believe that you desire without actually rewriting the Accordion class.

    This script is well done, I’ll be using it in the next few days, thanks!

    - Daniel

  2. atom's gravatar

    @Daniel, the accordion class does not use Fx.Slide, but rather is extending the Fx class directly. I read it over and I think there are some clues to how to fix this, so I will be investigation those further.

  3. @atom's gravatar

    Hi atom, thanks for this great script.
    I’m trying to save the active state via cookie, but I don’t get it to work.

    Is it possible to make the menu stay open at a certain place when invoked? (ie. if you opened the first nest and clicked an item, when you went to its page, the menu would stay open at that item)

    This would really help for knowing where you are on a website if this menu was used on it

  4. atom's gravatar

    My first though is no, mostly because this is intended to work with however many accordions you have.

    However, it can probably be done without too much work, so I will probably have a look at it and see what I can do without making this too complicated.

  5. Thorsten's gravatar

    Hi there, just a little short question: what would a piece of extra code look like, to use a mouseover event for the accordion instaead of a click??

  6. atom's gravatar

    @Thorsten,

    It wouldn’t be too difficult really, but you would have to work with the actual Accordion class that this is utilizing.

    After creating the accordions, you would need to add a mouseover event to each toggler bound to the accordion’s display function, and remove the click events.

  7. Thorsten's gravatar

    @atom,

    well, I’m not so good with js but a friend helped me out. Last question: do I have to change your js in order to use plain list elements (ul li)?? I tried that with the same names for the classes but nothing was working. Maybe I’m too stupid. Could you help me out?

  8. Janies's gravatar

    Hi there, I’m learning to work with mootools and This example is exactly what I have tried to achieve for the past 1 week but to no avail! Thanks for sharing this!

    There are two problems that I’ve encountered while working with the script.

    1. The expanding and collapsing is not consistent. sometimes the whole menu collapse and sometimes it doesn’t.

    2. changing the css style of the 2nd class of toggle. For eg.

    Toggle 1
    > Toggle 2
    > element 3
    > Toggle 2a

    I have tried to play around with the script but i can’t change the style of Toggle 2 or Toggle 2a.

    Any idea if question 2 can be fixed?

    Thanks!

  9. Janies's gravatar

    Toggle 1
    >> Toggle 2
    >>>> Element 3
    >> Toggle 2.a
    >>>> Element 4

    After posting the above post, i realised the indent is omited. To prevent confusion, here is what i meant of the toggle 2.

  10. liv's gravatar

    hi atom thanks for the great script.

    I am also trying to get the menu to stay open when invoked. has this been developed? I have been trying out some if statements within the raccordion definition (creating a class “current” and then having the display option depend on it) without any luck.

  11. yolanda's gravatar

    Hi, I’m also trying to get the menu to stay open. Has anyone had any luck?
    Also can’t change the active style of the second level.
    Thanks

  12. Justino A. Arciga Jr.'s gravatar

    Hi,
    I have some problem with the height. When it firts load the page the height of the first accordion did not wrapped exactly with the content it hide it. what is the solution or workaroud can i do with this problem.

    Thanks for any help!

    jR.

  13. Alex K's gravatar

    @atom, thank you very much for this! I am in dire need to get the active state working! Please email me if you have implemented it. Thank you!

  14. NAD*'s gravatar

    @with script to close all sub-levels

    var rAccordion = new Class({
     
    	initialize: function(container, toggleClass, elementClass, options){
    		this.container = container;
    		this.tClass = toggleClass;
    		this.eClass = elementClass;
    		this.options = options;
    		this.selector = '#' + this.container + ' &gt; .';
    		this.list_acc = new Array();
    		this.acc_index = 0;
    		this.h = (window.ie6) ? "100%" : '';
    		this.makeAccordion();
     
    	},
     
    	makeAccordion: function(){
    		this.list_acc[this.acc_index] = new Accordion(
    			$$(this.selector+this.tClass),
    			$$(this.selector+this.eClass),
    			this.options 
    		)
     
    		this.list_acc[this.acc_index].list_acc = this.list_acc;
    		this.list_acc[this.acc_index].acc_index = this.acc_index;
    		this.list_acc[this.acc_index++].addEvents({
    			// The onActive and onComplete events added to the stack here to
    			// attempt to address some of the css issues.
    			'onActive': function(toggle){
    				for(i=this.acc_index+1; i  .';
    		if($defined($$(this.selector)[0]))
    			this.makeAccordion();
    	}
     
    });
  15. NAD*'s gravatar

    @sorry…

    - this.h = (window.ie6) ?100%:;
    + this.h = (window.ie6) ?100%: "";
  16. NAD*'s gravatar

    @v1.0.545 – lol

    ok… the code are not completed.

    the difference are:

    /* on initialize and before this.makeAccordion */
    this.list_acc = new Array(); /* list of accordion levels */
    this.acc_index = 0; /* accordion level index */
    this.h = (window.ie6)?"100%":""  /* bug ie6 */
     
     
    /* at makeAccordion, put list_acc and acc_index into accordion scope */
    this.list_acc[this.acc_index] = new Accordion(...);
    this.list_acc[this.acc_index].list_acc = this.list_acc;
    this.list_acc[this.acc_index].acc_index = this.acc_index;
    this.list_acc[this.acc_index++].addEvent(
       onActive: (...)
       onComplete: function(a){
          (...)
          for(i=this.acc_index+1; i &lt; this.list_acc.length; i++)
             this.list_acc[i].display(-1,true);
       }
    });

    Good work!

  17. TMG's gravatar

    Very slick looking. Is it possible to have more than one element per toggle? It’s breaking it when I try.

  18. 济南二手房's gravatar

    济南二手房(esf.jnol.cn)网来博客参观过了,呵呵,有空多多交流哈。

  19. 小区's gravatar

    很不错的博客哦,来过踩踩,欢迎回访~

Leave a Reply

ok to use:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

bonus!

If you want to post code, you can use:

<pre lang="[language]">[code]</pre>

Where [language] is a valid geshi language type, and where [code] is your code.

mlurl (my little url): a personal url shortener

mlurl - my little url

A friend (and boss) of mine thought that this would be a good idea, and not being foolish/strange enough to be a coder himself, I decided to make it because it could be useful.

It is a drop in php script that allows you to host your own url shortener / redirector like snurl or tinyurl. Only you will be able to add / remove url’s from it.  This would allow you to essentially brand the url’s you send, or just simplify the linking process on your site or elsewhere.

If you have any trouble, check out the README.txt included, or leave a comment here.

download

trackback

Tags: , , , , , , 4 responses »
  1. julfo's gravatar

    Hi,

    This is great, but i have one suggestion, or even a request. I feel that mlurl would be improved if you made it so that you didn’t have to log in to create urls. Of course there could still be an admin area, but not necessary to log in to create links. If you did that then this would be perfect. Perhaps you could creat Mlurl v.2?

    Thanks,
    Julfo

  2. atom's gravatar

    I am working on another version between other things. It will most likely be released on this site when I am done.

  3. diancitie's gravatar

    Great article.Thanks.

  4. 青岛卓众's gravatar

    青岛卓众(www.chinajoyzone.com)给博主拜年来了,恭祝新的一年事事顺心,万事如意。

Leave a Reply

ok to use:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

bonus!

If you want to post code, you can use:

<pre lang="[language]">[code]</pre>

Where [language] is a valid geshi language type, and where [code] is your code.

COMPLETED: current project: recursive mootools accordion

All done, go here

For some time I have wanted to create a truly recursive mootools accordion class that could, with properly formatted xhtml, be limitlessly recursive. I have attempted this on several occasions, however have yet to be successful.

I am looking forward to trying again with the advent of mootools 1.2, it will most likely be much easier to complete. Most of the problems that have been encountered have been with how flexible I have tried to make it. I have achieved the desired, however it would only apply to one parent and it’s descendents, however I would still like it to be able to apply to all of the said parents siblings.

Updates will follow.

trackback

Tags: , , 2 responses »
  1. Daniel Buchner's gravatar

    This has been a want of mine for a looooong time. Kudos to your effort, I can wait to see the trickeried-out endless accordion!

  2. atom's gravatar

    I have actually had this on the mind very recently, and have an almost complete version ready to go, stay tuned.

Leave a Reply

ok to use:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

bonus!

If you want to post code, you can use:

<pre lang="[language]">[code]</pre>

Where [language] is a valid geshi language type, and where [code] is your code.