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-10-29 10:01:28 +00:00
|
|
|
Ox.Focus = (function() {
|
2011-04-22 22:03:10 +00:00
|
|
|
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.print('focus', id, stack);
|
2011-08-15 12:18:14 +00:00
|
|
|
Ox.UI.elements[id].addClass('OxFocus');
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
},
|
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;
|
|
|
|
}
|
|
|
|
};
|
2011-10-29 10:01:28 +00:00
|
|
|
}());
|