oxjs/source/Ox.UI/js/Core/Ox.Focus.js

54 lines
1.7 KiB
JavaScript
Raw Normal View History

2011-07-29 18:48:43 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
2011-05-16 10:49:48 +00:00
/*@
Ox.Focus <o> Basic focus handler
@*/
2011-04-22 22:03:10 +00:00
Ox.Focus = function() {
var stack = [];
return {
_print: function() {
Ox.print(stack);
},
2011-05-12 20:02:22 +00:00
_reset: function() {
$('.OxFocus').removeClass('OxFocus');
stack = [];
},
2011-05-16 10:49:48 +00:00
/*@
blur <f> blur element
(id) -> <u> blur element by id
@*/
2011-04-22 22:03:10 +00:00
blur: function(id) {
var index = stack.indexOf(id);
if (index > -1 && index == stack.length - 1) {
stack.length == 1 ? stack.pop() :
stack.splice(stack.length - 2, 0, stack.pop());
//$elements[id].removeClass('OxFocus');
$('.OxFocus').removeClass('OxFocus'); // fixme: the above is better, and should work
stack.length && Ox.UI.elements[stack[stack.length - 1]].addClass('OxFocus');
Ox.print('blur', id, stack);
}
},
2011-05-16 10:49:48 +00:00
/*@
focus <f> focus element
(id) -> <u> focus element by id
@*/
2011-04-22 22:03:10 +00:00
focus: function(id) {
var index = stack.indexOf(id);
if (index == -1 || index < stack.length - 1) {
index > -1 && stack.splice(index, 1);
stack.push(id);
$('.OxFocus').removeClass('OxFocus'); // fixme: see above
Ox.UI.elements[id].addClass('OxFocus');
Ox.print('focus', id, stack);
}
},
2011-05-16 10:49:48 +00:00
/*@
focused <f> return id of focused element, or null
() -> <s> get id of currently focused element
@*/
2011-04-22 22:03:10 +00:00
focused: function() {
return stack.length ? stack[stack.length - 1] : null;
}
};
}();