MooTools Tips extension: Tips.Glossary

This is just a little something I whipped up because I found it useful. Tips.Glossary is used for helpful tool-tips that gracefully degrade when JavaScript is not available for whatever reason. The basic idea is that you include an HTML glossary in the page, and if Tips.Glossary is available, the tips will come up however you specify, if not, they are simply anchors to their entries in the HTML.

This probably works with most MooTools stuff post 1.2, you are smart and will figure it out.

Check it out here.

Download the example.

or have a look at the code:

Selectors.Pseudo.hash = function(hash){
	if(!$chk(hash))
		return this.get('href').contains('#');
	var currentHash = this.get('href').split('#')[1];
	return currentHash === hash;
}
 
 
Tips.Glossary = new Class({
 
	Extends: Tips,
 
	options: {
		'anchorClass':	false,
		'hideGlossary':	true
	},
 
	initialize: function(glossary, options){
		this.parent(options);
		this.glossary = $(glossary);
		if(!$chk(this.glossary))
			throw "Glossary not found / defined, quitting";
		if(this.options.hideGlossary)
			this.glossary.setStyle('display', 'none');
		this.indexGlossary();
		return this;
	},
 
	indexGlossary: function(){
		this.items = this.glossary.getElements('*[id]');
		this.anchors = new Elements();
		this.items.each(function(e){
			var anchor = $(document.body).getElement('a:hash('+e.get('id')+')');
			if($chk(anchor)){
				if(this.options.hideGlossary);
				anchor.addEvent('click', function(event){
					new Event(event).stop();
				});
				this.setTipContent(anchor, e);
				this.anchors.push(anchor);
			}
			if(this.options.anchorClass)
				this.anchors.addClass(this.options.anchorClass);
			this.attach(this.anchors);
		}, this);
	},
 
	setTipContent: function(anchor, target){
		anchor.store('tip:title', target.get('title'));
		anchor.store('tip:text', target.get('html'));
		this.fireEvent('settingContent', [anchor, target]);
	}
 
});

On a side note, notice the psuedo selector being added. This has been added because for whatever reason, the following CSS3 selector is goofy:

$(document.body).getElements('a[href="http://trickeries.com"]'); // works
$(document.body).getElements('a[href="#glossary-username"]');    // does not work

Anyone have any idea why?

trackback

Tags: , , , 1 response »
  1. khela's gravatar

    Nice work :)

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.

Pixler: a transparent PNG pixel generator

I made a weensy little script for the theme I recently made (which I still have not named or prepared for distribution) which will generate single pixel transparent pngs to use as tiled background images in css.

demonstration toy

<?php    
 
	$p = imagecreatetruecolor(1, 1);
	imagesavealpha($p, true);
	$o = (100 - (int) $_GET['o']) * 1.27;
	$c = imagecolorallocatealpha($p, (int) $_GET['r'], (int) $_GET['g'], (int) $_GET['b'], $o);
	imagefill($p, 0, 0, $c);
	header("Content-type: image/png");
	imagepng($p);
 
?>

usage / parameters:

r
how much red to include: r=[0-255]
g
how much green to include: g=[0-255]
b
how much blue to include: b=[0-255]
o
how opaque the pixel should be: o=[0(fully transparent)-100(fully opaque)]

so…

pixler.php?r=255&g=255&b=255&o=50
will make a white pixel that is 50% visible.
pixler.php?r=255&o=100
will make a red pixel that is fully visible.
pixler.php
calling the script with no parameters will create an invisible black pixel (…).

trackback

Tags: , , , , 10 responses »
  1. Jorge's gravatar

    awesome script! i’ve been looking for exactly this script!!!!! kudos!

  2. atom's gravatar

    @Jorge

    this is one i made more recently, which is a tad better, and does gradients too:

    http://github.com/re5et/trickyInc/blob/master/images/trickyImg.php

  3. DouG Molidor's gravatar

    Pretty frikkin cool. Works like a charm.
    Do you have examples for JPG and GIF too?

    Thanks.

  4. atom's gravatar

    @DouG Molidor

    i suspect that you are slightly confused. Neither JPG or GIF support alpha channel transparency.

  5. Jorge's gravatar

    @atom i’ll try that out, thanks!

  6. The Sheraz's gravatar

    Nice snippit! We are using it on our splash page for a new project coming up. Cheers!

  7. 女性人体艺术's gravatar

    博客写的很好,有很多值得学习的地方,给博主留个言,记得回访哦。

  8. 人体艺术图片's gravatar

    博主写的真的很好,在这里给你留个言了,我的网站比较前卫,博主不要介意啊,以后多多关照。

  9. Guy's gravatar

    Great code, thanks!

  10. 青岛卓众信息科技有限公司'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.

Queuing ajax requests with MooTools 1.2

UPDATE: This might be sorta useless. Please see this comment.

There have been a variety of occasions where I only want one instance of the Request object, but want to make sure that every request I attempt gets run without canceling another, or screwing around with onCompletes.  The following is a rather simple implement that takes care of this problem:

Request.implement({
    queue: function(sendArg){
        if(!$defined(this.queued))
            this.queued = [];
        this.queued.push(sendArg);
        this.processQueue();
    },
    processQueue: function(){
		if(this.timer)
			$clear(this.timer);
		if (!this.check())
			this.timer = this.processQueue.delay(250, this);
		else {
			if ($defined(this.queued[0])) {
				this.send(this.queued.shift());
				this.processQueue();
			}
			else
				this.fireEvent('onQueueEmpty');
		}
    }
});

This will basically stack requests and send them in the order received. If there is no stack, the request will be sent immediately.

The usage is the same as the normal Request send method, however there is now an onQueueEmpty event to tell when all requests in the queue have been sent.

example

download w/the example

trackback

Tags: , , , , , 9 responses »
  1. keif's gravatar

    Very, very useful, I was working on something similar.

  2. atom's gravatar

    @keif: i agree =)

    I am pretty surprised that something like this hasn’t made its way into the core yet.

  3. adamnfish's gravatar
    adamnfish Says:

    The request class in mootools 1.2 already includes chaining!

    The check method allows you to queue, cancel or ignore requests while there is already a request running (identical to the Fx classes) depending on the option you provide. (look at the source!)

    So to do this, you don’t need to add any code (ie @atom, it is already in the core…)

    Simply provide {link: ‘ignore’ | ‘chain’ | ‘cancel’} as required. The default is ignore, so you won’t have seen it and I’ve no doubt it’s not documented yet…
    *rolls eyes

    Honestly, since the forums were shut this sort of thing seems to be happening a lot.

    To implement ‘onChainComplete’ (like you did for the queue), just add an event to onSuccess that checks the length of the chain ;)

    ps. I *Adore* your design…

  4. atom's gravatar

    @adamnfish you are absolutely correct =)

    My implement is indeed useless. It is not in the documentation, but setting ‘link’:'chain’ does work to chain/queue requests.

    After testing I think I have either discovered a MooTools bug, or a Firebug bug, or some other manner of oddity. When using ‘link’:'chain’, I am not seeing a response logged in Firebug, however the response does exist, as I can still use it when passing to the onSuccess function.

    So, uh, someone look into that or something.

  5. paddo's gravatar

    “When using ‘link’:’chain’, I am not seeing a response logged in Firebug, however the response does exist, as I can still use it when passing to the onSuccess function.”

    Same here, firebug doesn’t show the request until it’s already done. And when it’s done, it tells me that it only took 1ms (which can’t be true, I’ve put a sleep(2) in my php). Odd, odd, odd… link: ‘chain’ however works like a charm! I hope they’ll update the docs soon.

  6. atom's gravatar

    it looks like someone else thought thinks queueing needs a little help, however his is mroe useful and doesn’t just stack, which you can already apparently do:

    http://www.clientcide.com/code-snippets/ajax/new-plugin-requestqueue/

  7. diancitie's gravatar

    Great article.Thanks.

  8. evaniaward's gravatar

    present past cap

  9. danonharde's gravatar

    studies article projections

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.

Sortable Slideable Saveable – a Mootools 1.2 class

Sortable Slideable Saveable (sss) is a class I wrote up that allows you to have a list of elements that can be sorted, toggled, and the state of each will be saved each time a change is made, either using a cookie or a couple of ajax / json calls.

It can be seen in action in my sidebar to the right. You can drag / sort them by dragging the icons, and you can toggle them by clicking on the title of each. Any changes you make will be stored in a cookie, you can reload the page and they should be in the state you left them in.

I will probably update this and provide some detailed documentation shortly. If anyone has any questions, let me know. Also if anyone has any input on how to make it better, let me know.

another example

download w/the example

trackback

Tags: , , , , 13 responses »
  1. keif's gravatar

    Your side bar isn’t working for me (OS X, FF3.0.1) but your other example works flawlessly.

    Very cool script, and I love that it’s default state works with JS off.

  2. atom's gravatar

    hmm, i guess someone is going to have to let me borrow a mac :p

  3. links for 2008-07-30 | iKeif – mootools, jquery, social media and a ton of links's gravatar

    [...] Guide to Earning Six Figures: Changing Your Mind 13 hours agoInformation about going free lance.trickeries! » Blog Archive » Sortable Slideable Saveable – a Mootools 1.2 class 14 hours agoVery cool mootools 1.2 class for slideable sortables that are savable via cookies!The [...]

  4. keif's gravatar

    WEEELLL I could play around with it a bit and see if I can figure it out (or if it’s just FF# acting buggy).

  5. atom's gravatar

    It is a little odd that there is a difference in FF between systems, I would like to assume the engines in use would be exactly the same, however I have already seen stupid differences in the rendering of styles between the two. My assumption is that it is just a goofy issue with CSS.

  6. Tyler's gravatar

    brilliantly executed, as usual.

  7. atom's gravatar

    ^ _ ^

  8. electronbender's gravatar
    electronbender Says:

    Chief,
    Can you add a nested ability to this thing? That would realyyyyy be nice…

  9. Rob C's gravatar

    Hi,

    The ’savable’ side of things doesn’t seem to work on your example (the one linked here, and the one downloaded).

    I can see the PHP code at the top, but how does one implement the save?

    Thanks!

  10. atom's gravatar

    @Rob, What I have there in the example is just a quick and dirty example using sessions. In order to have this saved in any meaningful sense you are going to need to write / read the state to and from somewhere.

  11. dakota's gravatar

    Could this be modified to support dragging to multiple columns?

  12. dakota's gravatar

    How can I style the drop areas to have a dotted border? by this I mean when dragging one, how can I get the areas I can release it to to have a border… I’ve been trying to have it add a class, but can’t figure out where in the sss code to add it.

  13. Guillem's gravatar

    Hi,

    I there a way to use your amazing script with multiple list in order to mix them together?
    I tried to do this that way:
    window.addEvent(‘domready’, function(){
    new sss(‘#list, #list2′, ‘.toggle’, ‘.box-content’);
    });

    But mootools return an error at line 115 in sss.js.
    Do you think you can fix that? If you want I can give you some bucks for it (using paypal)

    Thanks a lot.

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.

dancing kirby javascript bookmarklet

I made this because i figured it was just what everyone needed (because everyone is grumpy all the time).  It is a simple javascript function you can store in a bookmark that will add a sweet dancing kirby to any page you are on.

(>^ – ^)> fire him up <(^ – ^<)

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.