DataTables/KeyTable — Issue #6: loose focus - optional
Author: matzke
Created: 2011-12-09 09:06:49+00:00
State: open

Sometimes you don't want to loose focus, when the user clickes outside the table so make this optional ;-) I would commit the code myself, but I'm still using SVN ...

* put code in separate function

```javascript
/*
* Function: _fnLooseFocus
* Purpose: Loose table focus when click outside the table
* Returns: -
*/
function _fnLooseFocus()
{
jQuery(document).click( function(e) {
var nTarget = e.target;
var bTableClick = false;
while ( nTarget )
{
if ( nTarget == oInit.table )
{
bTableClick = true;
break;
}
nTarget = nTarget.parentNode;
}
if ( !bTableClick )
{
_fnBlur();
}
} );
}
```
* in function _fnInit add

```javascript
if ( typeof oInit.looseFocus == 'undefined' ) {
oInit.looseFocus = true;
}

if ( oInit.looseFocus == true ) {
_fnLooseFocus();
}
```