2011-07-29 18:48:43 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
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() {
|
2011-11-04 15:54:28 +00:00
|
|
|
Ox.Log('Core', stack);
|
2011-04-22 22:03:10 +00:00
|
|
|
},
|
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) {
|
2011-11-01 19:56:11 +00:00
|
|
|
stack.length == 1
|
|
|
|
? stack.pop()
|
|
|
|
: stack.splice(stack.length - 2, 0, stack.pop());
|
2011-04-22 22:03:10 +00:00
|
|
|
//$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');
|
2011-11-04 15:54:28 +00:00
|
|
|
Ox.Log('Core', 'blur', id, stack);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
},
|
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
|
2011-11-04 15:54:28 +00:00
|
|
|
Ox.Log('Core', '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-11-01 19:56:11 +00:00
|
|
|
},
|
|
|
|
remove: function(id) {
|
|
|
|
var index = stack.indexOf(id);
|
|
|
|
index > -1 && stack.splice(index, 1);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
};
|
2011-10-29 10:01:28 +00:00
|
|
|
}());
|