2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
2012-05-21 10:38:18 +00:00
|
|
|
|
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) {
|
2012-01-21 11:30:16 +00:00
|
|
|
Ox.GarbageCollection();
|
2011-04-22 22:03:10 +00:00
|
|
|
var index = stack.indexOf(id);
|
|
|
|
if (index > -1 && index == stack.length - 1) {
|
2011-11-01 19:56:11 +00:00
|
|
|
stack.length == 1
|
2012-05-24 17:13:46 +00:00
|
|
|
// empty stack
|
2011-11-01 19:56:11 +00:00
|
|
|
? stack.pop()
|
2012-05-24 17:13:46 +00:00
|
|
|
// swap the two last stack items
|
2011-11-01 19:56:11 +00:00
|
|
|
: stack.splice(stack.length - 2, 0, stack.pop());
|
2012-01-27 14:29:11 +00:00
|
|
|
Ox.UI.elements[id]
|
|
|
|
.removeClass('OxFocus')
|
|
|
|
.triggerEvent('losefocus');
|
|
|
|
if (stack.length) {
|
|
|
|
Ox.UI.elements[stack[stack.length - 1]]
|
|
|
|
.addClass('OxFocus')
|
|
|
|
.triggerEvent('gainfocus')
|
|
|
|
}
|
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) {
|
2012-01-21 11:30:16 +00:00
|
|
|
Ox.GarbageCollection();
|
2011-04-22 22:03:10 +00:00
|
|
|
var index = stack.indexOf(id);
|
|
|
|
if (index == -1 || index < stack.length - 1) {
|
2012-05-24 17:13:46 +00:00
|
|
|
// move the item to the end of the stack
|
2011-04-22 22:03:10 +00:00
|
|
|
index > -1 && stack.splice(index, 1);
|
|
|
|
stack.push(id);
|
2012-01-27 14:29:11 +00:00
|
|
|
if (stack.length > 1) {
|
|
|
|
Ox.UI.elements[stack[stack.length - 2]]
|
|
|
|
.removeClass('OxFocus')
|
2012-01-21 11:30:16 +00:00
|
|
|
.triggerEvent('losefocus');
|
2012-01-27 14:29:11 +00:00
|
|
|
}
|
2011-11-07 18:17:16 +00:00
|
|
|
Ox.UI.elements[id]
|
2012-01-27 14:29:11 +00:00
|
|
|
.addClass('OxFocus')
|
|
|
|
.triggerEvent('gainfocus');
|
|
|
|
Ox.Log('Core', 'focus', id, stack);
|
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
|
|
|
},
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
remove <f> remove
|
|
|
|
(id) -> <u>
|
|
|
|
@*/
|
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
|
|
|
}());
|