Skip to content

Instantly share code, notes, and snippets.

@natecavanaugh
Created January 9, 2013 22:47
Show Gist options
  • Save natecavanaugh/4497719 to your computer and use it in GitHub Desktop.
Save natecavanaugh/4497719 to your computer and use it in GitHub Desktop.
Native handling of focus delegation (probably won't need, just ignore IE6 in the css for :focus)
addInputFocus: function() {
var handleFocus = function(event) {
var target = event.target;
var tagName = target.tagName;
if (tagName) {
tagName = tagName.toLowerCase();
}
var nodeType = target.type;
if (((tagName == 'input') && (/text|password/).test(nodeType)) ||
(tagName == 'textarea')) {
var className = target.className;
if (/^focus(?:in)?$/.test(event.type)) {
if (!REGEX_CSS_FOCUS.test(className)) {
target.className += ' focus';
}
}
else {
target.className = className.replace(REGEX_CSS_FOCUS, '');
}
}
};
var body = document.body;
var addEvent = AUI.Env.add;
var blur = 'blur';
var focus = 'focus';
if (body.attachEvent) {
blur = 'focusout';
focus = 'focusin';
}
addEvent(body, blur, handleFocus, true);
addEvent(body, focus, handleFocus, true);
//A.on('focus', handleFocus, document);
//A.on('blur', handleFocus, document);
//A.use(
// 'aui-base',
// function(A) {
// var handleFocus = function(event) {
// var target = event.target;
// var tagName = target.get('tagName');
// if (tagName) {
// tagName = tagName.toLowerCase();
// }
// var nodeType = target.get('type');
// if (((tagName == 'input') && (/text|password/).test(nodeType)) ||
// (tagName == 'textarea')) {
// var action = 'addClass';
// if (/blur|focusout/.test(event.type)) {
// action = 'removeClass';
// }
// target[action]('focus');
// }
// };
// A.on('focus', handleFocus, document);
// A.on('blur', handleFocus, document);
// }
//);
Util.addInputFocus = function(){};
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment