71 lines
2.3 KiB
JavaScript
71 lines
2.3 KiB
JavaScript
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
|
'use strict';
|
|
/*@
|
|
Ox.Focus <o> Basic focus handler
|
|
@*/
|
|
|
|
Ox.Focus = (function() {
|
|
var stack = [];
|
|
return {
|
|
_print: function() {
|
|
Ox.Log('Core', stack);
|
|
},
|
|
_reset: function() {
|
|
$('.OxFocus').removeClass('OxFocus');
|
|
stack = [];
|
|
},
|
|
/*@
|
|
blur <f> blur element
|
|
(id) -> <u> 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());
|
|
Ox.UI.elements[id]
|
|
.removeClass('OxFocus')
|
|
.triggerEvent('losefocus');
|
|
if (stack.length) {
|
|
Ox.UI.elements[stack[stack.length - 1]]
|
|
.addClass('OxFocus')
|
|
.triggerEvent('gainfocus')
|
|
}
|
|
Ox.Log('Core', 'blur', id, stack);
|
|
}
|
|
},
|
|
/*@
|
|
focus <f> focus element
|
|
(id) -> <u> 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);
|
|
if (stack.length > 1) {
|
|
Ox.print('...', Object.keys(Ox.UI.elements[stack[stack.length - 2]]))
|
|
Ox.UI.elements[stack[stack.length - 2]]
|
|
.removeClass('OxFocus')
|
|
.triggerEvent('losefocus')
|
|
}
|
|
Ox.UI.elements[id]
|
|
.addClass('OxFocus')
|
|
.triggerEvent('gainfocus');
|
|
Ox.Log('Core', 'focus', id, stack);
|
|
}
|
|
},
|
|
/*@
|
|
focused <f> return id of focused element, or null
|
|
() -> <s> get id of currently focused element
|
|
@*/
|
|
focused: function() {
|
|
return stack.length ? stack[stack.length - 1] : null;
|
|
},
|
|
remove: function(id) {
|
|
var index = stack.indexOf(id);
|
|
index > -1 && stack.splice(index, 1);
|
|
}
|
|
};
|
|
}());
|