
/*
* jQuery AssignEnterKey Plug-in
*
* Summary       This plug-in will attach a click/blur event to all input elements inside a parent container,  
*                        the events will add and remove a class to the parent container that is used to associate  
*                        the enter key with the a button or submit button.  
*                
* Notes             Using the options, you can target a different controls for both triggering the focus and the target to be executed.
*
* Example         $("FIELDSET").AssignEnterKey();
*
* Developed by  Zachary.Hunter@gmail.com
* Date                2009-05-29 23:05
*/
(function($) {
    $.fn.AssignEnterKey = function(options) {

        var defaults = {
            triggerExp: ":input,:a",
            targetExp: ":submit,:button,:href"
        };

        var options = $.extend(defaults, options);

        $(document).keypress(function(e) {
            if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                $(".EnterKeyAssigned")
					.find(options.targetExp)
					.click();
                return false;
            }
			else if((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                $(".EnterKeyAssigned")
				 .click();
                return false;
			}
        });

        return this.each(function() {
            var obj = $(this);

            obj.find(options.triggerExp)
                    .click(function() { obj.addClass("EnterKeyAssigned"); })
                    .blur(function() { obj.removeClass("EnterKeyAssigned"); });
        });
    };
})(jQuery); 


