First try at a jQuery plugin for event adding

First try at a jQuery plugin for event adding

Hi all,

Just after some guidance or suggestions as to weather I am on the right track, style etc.

I wanted to be able to insert an event at the top of an event stack in the new jQuery-1.4.2 special event handler.

I have written the following which accomplishes this for me, but want to know if I'm "doing it right".

  1. (function(jQuery){
  2.     function modalEventAdd( obj ) {
  3.         obj.origType = obj.type;
  4.         if (obj.type.indexOf('modal') != -1) {
  5.             obj.type = obj.type.split('modal')[1]
  6.         } else {
  7.             throw obj.type + ' is not modal supported';
  8.         }

  9.         var events = jQuery.data(this, "events");
  10.         if (events[ obj.type ]) events[ obj.type ].reverse();

  11.         jQuery.event.add( this, obj.type, obj, obj.data );

  12.         if (events[ obj.type ]) events[ obj.type ].reverse();
  13.     }

  14.     jQuery.extend(jQuery.event.special, {
  15.         modalkeydown  : { add: modalEventAdd },
  16.         modalkeypress : { add: modalEventAdd },
  17.         modalkeyup    : { add: modalEventAdd },
  18.     })

  19. })(jQuery)
Now to add an event at the top of the event stack I can use something like the following:

  1. $(document).bind('modalkeydown', function(event){event.stopImmediatePropagation()});

Suggestions?
Should I do more error handling around line 10 for fetching data?
Should I cache events[ obj.type ] for reversing again after adding?
Should I not do this at all because of event handler position tracking?