r1793 - branches/experimental/a11y
Author: a.farkas.pm
Date: Sun Jan 25 12:29:37 2009
New Revision: 1793
Added:
branches/experimental/a11y/ui.a11y.ext.js
Modified:
branches/experimental/a11y/getID.js
Log:
Some ideas for an a11y extension
Modified: branches/experimental/a11y/getID.js
==============================================================================
--- branches/experimental/a11y/getID.js (original)
+++ branches/experimental/a11y/getID.js Sun Jan 25 12:29:37 2009
@@ -1,13 +1,16 @@
-jQuery.fn.getID = function(){
- var id = '';
- if(this[0]){
- var elem = $(this[0]);
- id = elem.attr('id');
- if(!id){
- id = 'ID-'+ new Date().getTime();
- elem.attr({'id': id});
+(function($){
+ var uId = new Date().getTime();
+ $.fn.getID = function(){
+ var id = '';
+ if(this[0]){
+ var elem = $(this[0]);
+ id = elem.attr('id');
+ if(!id){
+ id = 'ID-' + (uId++);
+ elem.attr({'id': id});
+ }
}
- }
-
- return id;
-};
+ return id;
+ };
+})(jQuery);
+
Added: branches/experimental/a11y/ui.a11y.ext.js
==============================================================================
--- (empty file)
+++ branches/experimental/a11y/ui.a11y.ext.js Sun Jan 25 12:29:37 2009
@@ -0,0 +1,214 @@
+/**
+ * @author alexander.farkas
+ */
+(function($){
+ $.ui = $.ui ||
+ {};
+ /*
+ * HCM-Detection
+ */
+ $.ui.userMode = (function(){
+ var userBg,
+ timer,
+ testDiv,
+ boundEvents = 0;
+
+ function testBg(){
+ testDiv = testDiv || $('<div></div>').css({position: 'absolute',
left: '-999em', top: '-999px', width: '0px',
height: '0px'}).appendTo('body');
+ var black = $.curCSS(
testDiv.css({backgroundColor: '#000000'})[0], 'backgroundColor', true),
+ white = $.curCSS(
testDiv.css({backgroundColor: '#ffffff'})[0], 'backgroundColor', true),
+ newBgStatus = (black === white || white === 'transparent');
+ if(newBgStatus != userBg){
+ userBg = newBgStatus;
+ $.event.trigger('_internalusermode');
+ }
+ return userBg;
+ }
+
+ function init(){
+ testBg();
+ timer = setInterval(testBg, 3000);
+ }
+
+ function stop(){
+ clearInterval(timer);
+ (testDiv && testDiv.remove());
+ testDiv = null;
+ }
+
+ $.event.special.usermode = {
+ setup: function(){
+ (!boundEvents && init());
+ boundEvents++;
+ var jElem = $(this)
+ .bind('_internalusermode', $.event.special.usermode.handler);
+ //always trigger
+ setTimeout(function(){
+ jElem.triggerHandler('_internalusermode');
+ }, 1);
+ return true;
+ },
+ teardown: function(){
+ boundEvents--;
+ (!boundEvents && stop());
+ $(this).unbind('_internalusermode', $.event.special.usermode.handler);
+ return true;
+ },
+ handler: function(e){
+ e.type = 'usermode';
+ e.disabled = !userBg;
+ e.enabled = userBg;
+ return jQuery.event.handle.apply(this, arguments);
+ }
+ };
+
+ return {
+ get: testBg
+ };
+
+ })();
+
+ $.fn.userMode = function(fn){
+ return this[(fn) ? 'bind' : 'trigger']('usermode', fn);
+ };
+
+ $(function(){
+ $('html').userMode(function(e){
+ $('html')[e.enabled ? 'addClass' : 'removeClass']('hcm');
+ });
+ });
+
+ /*
+ * SR-Update
+ */
+ $.ui.SR = (function(){
+ var input, val = 0;
+
+ function init(){
+ input = $('<input type="hidden" value="'+val+'" />')
+ .css({display: 'none'})
+ .appendTo('body')
+ .ajaxComplete(update);
+ }
+
+ function update(){
+ if(input){
+ setTimeout(function(){
+ input.val(++val);
+ }, 1);
+ }
+ }
+ return {
+ update: update,
+ init: init
+ };
+ })();
+ $($.ui.SR.init);
+
+ /*
+ * getID-Exts
+ */
+
+ if(!$.fn.getID){
+ var uId = new Date().getTime();
+ $.fn.getID = function(){
+ var id = '';
+ if(this[0]){
+ var elem = $(this[0]);
+ id = elem.attr('id');
+ if(!id){
+ id = 'ID-' + (uId++);
+ elem.attr({'id': id});
+ }
+ }
+ return id;
+ };
+ }
+
+ $.each({
+ labelWith: 'aria-labelledby',
+ describeWith: 'aria-describedby',
+ ownsThis: 'aria-owns'
+ }, 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($){
+ 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);
+ });
+
+ $.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);
+ });
+ };
+
+ $.fn.inOut.defaults = {
+ mouseDelay: 0,
+ keyDelay: 1,
+ bothOut: false
+ };
+ })(jQuery);
+
+
+})(jQuery);
\ No newline at end of file