// vim: et:ts=4:sw=4:sts=4:ft=javascript /*@ Ox.Focus Basic focus handler @*/ Ox.Focus = (function() { var stack = []; return { _print: function() { Ox.print(stack); }, _reset: function() { $('.OxFocus').removeClass('OxFocus'); stack = []; }, /*@ blur blur element (id) -> blur element by id @*/ 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); } }, /*@ focus focus element (id) -> focus element by id @*/ 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); Ox.UI.elements[id].addClass('OxFocus'); } }, /*@ focused return id of focused element, or null () -> get id of currently focused element @*/ focused: function() { return stack.length ? stack[stack.length - 1] : null; } }; }());