Archive for the 'Javascript' Category


Bookmarklet For YUI Logger 4

During development using javascript I have always felt that it would be useful to be able to easily add and remove YUI Logger without having to deal with manually adding and removing the related javascript and css from the source files.

I resolved this problem by writing a bookmarklet which will allow you to do that easily. The details are available here. This has been tested on firefox 2.x, safari 3.1 and IE 6/7. Please post any bugs that you find. If you do the view source of the file you can see the code as well.

yui - custom event 0

Note to self on how to setup custom even.
Step 1: Define a custom event

1
var onCustomEvent1 = new YAHOO.util.CustomEvent('onCustomEvent');

Step 2: Make methods subscribe to the event

1
2
onCustomEvent1.subscribe(method1);
onCustomEvent1.subscribe(method2);

etc.You can also pass arguments to the subscribe method, which can be accessed by the subscribed method, as explained below.

Step 3: Whenever that event is supposed to be triggerd, cause the event to be executed

onCustomEvent1.fire();

You can also pass arguments to the fire method, these arguments can then be accessed in the subscribe method explained below.

1
2
onCustomEvent1.fire({action:'fire'});
function method1(event, arguments, obj) {}
  • event returns the name of the custom event
  • arguments is the set of arguments that are passed in the fire event
  • obj is the argument that is passed in the subscribe method.

Calling the fire() method causes all the listener methods to get fired. Simple stuff, amazing uses as well, maybe its just me but i am sure i wont remember this the second time i have look at it.