/*
 * jQuery Behavior Plugin: Define rich behaviors that include both event 
 * handlers and (un)transformations on DOM elements.
 * 
 * Copyright (c) 2011 Florian Schäfer (florian.schaefer@gmail.com)
 * Dual licensed under the MIT (MIT_LICENSE.txt)
 * and GPL Version 2 (GPL_LICENSE.txt) licenses.
 *
 * Version: 1.1
 * Requires: jQuery 1.4.2+ and Live Query 1.1+.
 * 
 */

(function($, attr) {
    
    // jQuery supports getData, setData and changeData,
    // support getAttr, setAttr, changeAttr too.
    $.attr = function (elem, name, value) { 
        var current = attr (elem, name), // read current value.
        retval = current;
        
        if (!value) {
            // we are getting a value.
            $.event.trigger ('getAttr', {
                attribute: name,
                from: current,
                to: value
            }, elem);
        } else { // writing
            // we are setting a value.
            $.event.trigger ('setAttr', {
                attribute: name,
                from: current,
                to: value
            }, elem);
            
            retval = attr.apply (this, arguments); // call original.
            
            // value or type changed.
            if (current !== value) {
                $.event.trigger ('changeAttr', {
                    attribute: name,
                    from: current,
                    to: value
                }, elem);
            }
        }
        return retval; // return original 
    };
    
})(jQuery, jQuery.attr);

(function($, undefined) {
    
    if (!$.fn.livequery) {
        throw "jquery.behavior.js: jQuery Plugin: Live Query not loaded.";
    }
    
    $.behavior = function (metabehaviors, context) {
        
        context = context || window.document;
        
        // Handle $.behavior (""), $.behavior (null), or $.behavior (undefined).
        if (!metabehaviors) {
            return this;
        }
        
        // Handle $.behavior ([{ ... }, { ... }, ... ], [context]).
        if ($.isArray (metabehaviors)) {
            return $.each (metabehaviors, function () {
                $.behavior (this, context);
            });
        }
        
        // Handle $.behavior ({ ... }, [context]).
        return $.each (metabehaviors, function (selector, metabehavior) {
            
            metabehavior = $.extend ({
                options: {
                    expire: false
                },
                transform: $.noop,
                untransform: $.noop
            }, metabehavior);
            
            // Cache element.
            var $element = $(selector, context);
            
            if (metabehavior.options.expire) {
                $element.expire ();
            }
            
            // Transform DOM element.
            $element.livequery (metabehavior.transform, metabehavior.untransform);
            
            // Bind all events.
            for (var event in metabehavior) {
                switch (event) {
                    case 'transform':
                    case 'untransform':
                    case 'options':
                        // Don't handle these here.
                        continue;
                    
                    default:
                        $element.livequery (event, metabehavior[event]);
                        break;
                }
            }
            
        });
    };
    
    $.fn.behavior = function (metabehaviors) {
        return this.each (function () {
            $.behavior (metabehaviors, this);
        });
    };
    
})(jQuery);

@@ -309,17 +309,17 @@
 sion: 1.
-1
+2
 %0A * Requ
@@ -1573,19 +1573,16 @@
  if (!$.
-fn.
 livequer
@@ -2613,16 +2613,25 @@
 $element
+InContext
  = $(sel
@@ -2637,33 +2637,33 @@
 lector, context)
-;
+,
 %0A            %0A  
@@ -2663,105 +2663,34 @@
     
-%0A  
     
-      if (metabehavior.options.expire) %7B%0A                $eleme
+$context = $(co
 nt
-.
 ex
-pire ();%0A            %7D
+t);
 %0A   
@@ -2749,32 +2749,41 @@
         $element
+InContext
 .livequery (meta
@@ -2936,16 +2936,116 @@
         
+%0A                if (metabehavior.hasOwnProperty(event)) %7B%0A                    %0A                    
 switch (
@@ -3049,24 +3049,28 @@
 h (event) %7B%0A
+    
             
@@ -3111,24 +3111,28 @@
             
+    
 case 'untran
@@ -3131,32 +3131,36 @@
  'untransform':%0A
+    
                 
@@ -3203,16 +3203,20 @@
         
+    
 // Don't
@@ -3235,16 +3235,20 @@
 e here.%0A
+    
         
@@ -3297,69 +3297,1538 @@
     
-%0A                    default:%0A                        $elemen
+    %0A                        case 'blur': %0A                        case 'focus': %0A                        case 'focusin': %0A                        case 'focusout': %0A                        case 'load': %0A                        case 'resize': %0A                        case 'scroll': %0A                        case 'unload': %0A                        case 'click': %0A                        case 'dblclick': %0A                        case 'mousedown': %0A                        case 'mouseup': %0A                        case 'mousemove': %0A                        case 'mouseover': %0A                        case 'mouseout': %0A                        case 'mouseenter': %0A                        case 'mouseleave': %0A                        case 'change': %0A                        case 'select': %0A                        case 'submit': %0A                        case 'keydown': %0A                        case 'keypress': %0A                        case 'keyup': %0A                        case 'error':%0A                            if (metabehavior.options.expire) %7B%0A                                $context.undelegate (selector, event);%0A                            %7D%0A                            $context.delegate (selector, event, metabehavior%5Bevent%5D);%0A                            break;%0A                        %0A                        default:%0A                            if (metabehavior.options.expire) %7B%0A                                $elementInContext.expire (event);%0A                            %7D%0A                            $elementInContex
 t.li
@@ -4881,32 +4881,36 @@
                 
+    
 break;%0A         
@@ -4908,33 +4908,93 @@
                 
-%7D
+    %7D%0A                    %0A                %7D%0A                
 %0A            %7D%0A 

Use jquery delegates for events: blur, focus, focusin, focusout, load, resize, scroll, unload, click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, mouseenter, mouseleave, change, select, submit, keydown, keypress, keyup, error.