With jQuery is very simple make new event plugins. This is a sample plugin that I made
for my organisation: (sorry comments in spanish :$)

/**
* @fileoverview
* Crea nuevos eventos para la pulsación de las teclas:
* INTRO, DELETE, ARROWS, PAGINA arriba y abajo
*
* @author ATICA
* @version 0.1
* @requires jQuery.js
*/

jQuery.fn.extend({
   /**
    * Evento para la pulsación de la tecla Intro
    * @param {function} función a ejecutar en el evento
    */
   intropress: function(f){
       $(this).bind("intropress",f);
       $(this).keydown(function(e){
           if(e.keyCode==13){ $(this).trigger("intropress");}
       });
       return this;
   },
   /**
    * Evento para la pulsación de la tecla Suprimir
    * @param {function} función a ejecutar en el evento
    */
   deletepress: function(f){
       $(this).bind("deletepress",f);
       $(this).keydown(function(e){
           if(e.keyCode==46){ $(this).trigger("deletepress");}
       });
       return this;
   },
   /**
    * Evento para la pulsación de la tecla flecha izquierda
    * @param {function} función a ejecutar en el evento
    */
   leftpress: function(f){
       $(this).bind("leftpress",f);
       $(this).keydown(function(e){
           if(e.keyCode==37){ $(this).trigger("leftpress");}
       });
       return this;
   },
   /**
    * Evento para la pulsación de la tecla flecha derecha
    * @param {function} función a ejecutar en el evento
    */
   rightpress: function(f){
       $(this).bind("rightpress",f);
       $(this).keydown(function(e){
           if(e.keyCode==39){ $(this).trigger("rightpress");}
       });
       return this;
   },
   /**
    * Evento para la pulsación de la tecla flecha arriba
    * @param {function} función a ejecutar en el evento
    */
   uppress: function(f){
       $(this).bind("uppress",f);
       $(this).keydown(function(e){
           if(e.keyCode==38){ $(this).trigger("uppress");}
       });
       return this;
   },
   /**
    * Evento para la pulsación de la tecla flecha abajo
    * @param {function} función a ejecutar en el evento
    */
   downpress: function(f){
       $(this).bind("downpress",f);
       $(this).keydown(function(e){
           if(e.keyCode==40){ $(this).trigger("downpress");}
       });
       return this;
   },
   /**
    * Evento para la pulsación de la tecla página abajo
    * @param {function} función a ejecutar en el evento
    */
   pagedownpress: function(f){
       $(this).bind("pagedownpress",f);
       $(this).keydown(function(e){
           if(e.keyCode==34){ $(this).trigger("pagedownpress");}
       });
       return this;
   },    /**
    * Evento para la pulsación de la tecla página arriba
    * @param {function} función a ejecutar en el evento
    */
   pageuppress: function(f){
       $(this).bind("pageuppress",f);
       $(this).keydown(function(e){
           if(e.keyCode==33){ $(this).trigger("pageuppress");}
       });
       return this;
   },
});

Brandon Aaron escribió:
I recently created an plugin/extension for jQuery to use the following syntax for binding events.

$('input').bind('mouseover focus', fn);

So you can bind multiple event types to the same function quickly. It also applies to .one and .unbind.

However, this got me thinking about writing a plugin that would allow us to add new event types ... like mouseenter and mouseleave. So instead of using .hover, you could do this:

$(...).bind('mouseenter', fn);

or

$(...).bind('mouseenter', fn1).bind('mouseenter', fn2);

or

$(...).unbind('mouseenter', fn1);

or

$(...).trigger('mouseenter');

etc...


So I'm curious about what the jQuery community thinks about this idea? I've built out a proof-of-concept but it is by no means production ready. You can see it in action here: http://www.brandonaaron.net/jquery/plugins/events_extension/test/test.html

We could also hook up the mousewheel event in the same way.

$(...).bind('mousewheel', fn);

Are there other events that could be added/normalized with this plugin?



BTW ... Here is the blog post about binding multiple event types: http://blog.brandonaaron.net/2007/06/05/bind-multiple-events-simultaneously-with-jquery/ <http://blog.brandonaaron.net/2007/06/05/bind-multiple-events-simultaneously-with-jquery/>

--
Brandon Aaron



--
Best Regards,
José Francisco Rives Lirola <sevir1ATgmail.com>

SeViR CW · Computer Design
http://www.sevir.org
Murcia - Spain

Reply via email to