r2455 - added activedescendant-helper and em-change-event

r2455 - added activedescendant-helper and em-change-event

Author: a.farkas.pm
Date: Wed Apr 15 06:21:47 2009
New Revision: 2455
Modified:
branches/experimental/a11y/ui.a11y.ext.js
Log:
added activedescendant-helper and em-change-event
Modified: branches/experimental/a11y/ui.a11y.ext.js
==============================================================================
--- branches/experimental/a11y/ui.a11y.ext.js    (original)
+++ branches/experimental/a11y/ui.a11y.ext.js    Wed Apr 15 06:21:47 2009
@@ -79,6 +79,85 @@
    });
    
    /*
+     * EM-Change
+     */
+    $.testEm = (function(){
+        var emElem = $('<div style="width: 1em; position: absolute; left:
-999em; visibility: hidden;" />'),
+            timer,
+            emPx = 0,
+            oldVal = 0,
+            boundEvents = 0;
+        
+        function init(){
+            timer = setInterval(test, 999);
+        }
+        
+        function test(){
+            var width = emElem.width();
+            
+            if(emPx && emPx !== width){
+                emPx = width;
+                $.event.trigger('_internalemchange');
+            }
+            oldVal = width;
+            emPx = width;
+        }
+            
+        $.event.special.emchange ={
+            setup: function(){
+                (!boundEvents && init());
+                boundEvents++;
+                
+                $(this)
+                    .bind('_internalemchange', $.event.special.emchange.handler);
+                
+ return true;
+ },
+            teardown: function(){
+ boundEvents--;
+                (!boundEvents && clearInterval(timer));
+                $(this).unbind('_internalemchange', $.event.special.emchange.handler);
+ return true;
+ },
+ handler: function(e){
+ e.type = 'emchange';
+                e.emPx = emPx;
+                e.oldEmPx = oldVal;
+ return jQuery.event.handle.apply(this, arguments);
+ }
+        };
+        
+        $(function(){
+            emElem
+                .appendTo('body');
+            test();
+        });
+        return test;
+    })();
+    
+    /*
+     * Aria-Click
+     */
+    
+    $.event.special.ariaClick = {
+            setup: function(){
+                $(this)
+                    .bind('_internalemchange', $.event.special.emchange.handler);
+ return true;
+ },
+            teardown: function(){
+
+                $(this).unbind('_internalemchange', $.event.special.emchange.handler);
+ return true;
+ },
+ handler: function(e){
+ e.type = 'emchange';
+                e.emPx = emPx;
+                e.oldEmPx = oldVal;
+ return jQuery.event.handle.apply(this, arguments);
+ }
+        };
+    /*
     * SR-Update
     */
    $.ui.SR = (function(){
@@ -86,7 +165,6 @@
        
        function init(){
            input = $('<input type="hidden" value="'+val+'" />')
-                .css({display: 'none'})
                .appendTo('body')
                .ajaxComplete(update);
        }
@@ -128,86 +206,102 @@
    $.each({
        labelWith: 'aria-labelledby',
        describeWith: 'aria-describedby',
-        ownsThis: 'aria-owns'
+        ownsThis: 'aria-owns',
+        activateDescendant: 'aria-activedescendant'
    }, function(name, prop){
        $.fn[name] = function(elem){
            return this.attr(prop, $(elem).getID());
        };
    });
        
-    /*
-    *    focusin/focusout tyken form j�rn z�fferer�s delegate plugin
-    *     Copyright (c) 2007 J�rn Zaefferer
-    */
-    $.each({
-        focus: 'focusin',
-        blur: 'focusout'    
-    }, function( original, fix ){
-        $.event.special[fix] = {
-            setup:function() {
-                if ( $.browser.msie ) return false;
-                this.addEventListener( original, $.event.special[fix].handler, true );
-            },
-            teardown:function() {
-                if ( $.browser.msie ) return false;
-                this.removeEventListener( original,
-                $.event.special[fix].handler, true );
-            },
-            handler: function(e) {
-                arguments[0] = $.event.fix(e);
-                arguments[0].type = fix;
-                return $.event.handle.apply(this, arguments);
-            }
-        };
-    });
    
-    /*
-    * inout
-     * hover = focusblur
-     */
+    
+    
    (function($){
+        /*
+        *    focusin/focusout tyken form j�rn z�fferer�s delegate plugin
+        *     Copyright (c) 2007 Jörn Zaefferer
+        */
+        $.each({
+            focus: 'focusin',
+            blur: 'focusout'    
+        }, function( original, fix ){
+            $.event.special[fix] = {
+                setup:function() {
+                    if ( $.browser.msie ) return false;
+                    this.addEventListener( original, $.event.special[fix].handler, true );
+                },
+                teardown:function() {
+                    if ( $.browser.msie ) return false;
+                    this.removeEventListener( original,
+                    $.event.special[fix].handler, true );
+                },
+                handler: function(e) {
+                    arguments[0] = $.event.fix(e);
+                    arguments[0].type = fix;
+                    return $.event.handle.apply(this, arguments);
+                }
+            };
+        });
+        
+        /*
+        * inout
+        * hover = focusblur
+        */
+        
        var handler = {};
        $.each({enter: [1, 'in', true], out: [-1, 'out', false]},
function(handle, params){
-            handler[handle] = (function(inAddition, type, inOutState){
-                return function(e){
-                    var fn = e.data[0],
-                        o = e.data[1],
-                        elem = this,
-                        inEvents = Math.max($.data(elem, 'inEvents') + inAddition, 0);
-                        
-                    clearTimeout($.data(this, 'inOutTimer'));
-                    $.data(elem, 'inEvents', inEvents);
-                    $.data(elem, 'inOutTimer', setTimeout(function(){
-                        if((inOutState != $.data(elem, 'inOutState')) &&
-                                (inOutState || !o.bothOut || !inEvents)){
-                            $.data(elem, 'inOutState', inOutState);
-                            e.type = type;
-                            fn.call(elem, e);
-                        }
-                    }, /focus/.test(e.type) ? o.keyDelay : o.mouseDelay));
-                };
-            }).apply(this, params);
+            handler[handle] = function(e){
+                var fn = e.data[0],
+                    o = e.data[1],
+                    inOutData = e.data[2],
+                    elem = this
+                ;
+                    
+                clearTimeout(inOutData.inOutTimer);
+                inOutData.inEvents = Math.max(inOutData.inEvents + params[0], 0);
+                inOutData.inOutTimer = setTimeout(function(){
+                    if(params[2] != inOutData.inOutState &&
+                            (params[2] || !o.bothOut || !inOutData.inEvents)){
+                        inOutData.inOutState = params[2];
+                        e.type = params[1];
+                        fn.call(elem, e);
+                    }
+                }, /focus/.test(e.type) ? o.keyDelay : o.mouseDelay);
+            };
        });
+    
        
        $.fn.inOut = function(enter, out, opts){
-                
            opts = $.extend({}, $.fn.inOut.defaults, opts);
-            opts.keyDelay = opts.keyDelay ||
-                1;
            
-            return this.each(function(){
-                $(this)
-                    .data('inEvents', 0)
-                    .bind('mouseenter focusin', [enter, opts], handler.enter)
-                    .bind('mouseleave focusout', [out, opts], handler.out);
-            });
+            var inEvents = 'mouseenter focusin',
+                outEvents = 'mouseleave focusout'
+            ;
+            if(opts.useEventTypes === 'mouse'){
+                inEvents = 'mouseenter';
+                outEvents = 'mouseleave';
+            } else if(opts.useEventTypes === 'focus'){
+                inEvents = 'focusin';
+                outEvents = 'focusout';
+            }
+            
+            return this
+                .each(function(){
+                    var inOutData = {inEvents: 0};
+                    $(this)
+                        .bind(inEvents, [enter, opts, inOutData], handler.enter)
+                        .bind(outEvents, [out, opts, inOutData], handler.out);
+                });
        };
        
        $.fn.inOut.defaults = {
            mouseDelay: 0,
            keyDelay: 1,
-            bothOut: false
+            bothOut: false,
+            useEventTypes: 'both' // both || mouse || focus
        };
+
    })(jQuery);