in uima-ducc-web/src/main/webapp/root/opensources/DataTables-1.10.1/extensions/KeyTable/js/dataTables.keyTable.js [419:580]
function _fnSetFocus( nTarget, bAutoScroll )
{
/* If node already has focus, just ignore this call */
if ( _nOldFocus == nTarget )
{
return;
}
if ( typeof bAutoScroll == 'undefined' )
{
bAutoScroll = true;
}
/* Remove old focus (with blur event if needed) */
if ( _nOldFocus !== null )
{
_fnRemoveFocus( _nOldFocus );
}
/* Add the new class to highlight the focused cell */
$(nTarget).addClass( _sFocusClass );
$(nTarget).parent().addClass( _sFocusClass );
/* If it's a DataTable then we need to jump the paging to the relevant page */
var oSettings;
if ( _oDatatable )
{
oSettings = _oDatatable;
var iRow = _fnFindDtCell( nTarget )[1];
var bKeyCaptureCache = _bKeyCapture;
/* Page forwards */
while ( iRow >= oSettings.fnDisplayEnd() )
{
if ( oSettings._iDisplayLength >= 0 )
{
/* Make sure we are not over running the display array */
if ( oSettings._iDisplayStart + oSettings._iDisplayLength < oSettings.fnRecordsDisplay() )
{
oSettings._iDisplayStart += oSettings._iDisplayLength;
}
}
else
{
oSettings._iDisplayStart = 0;
}
_oDatatable.oApi._fnCalculateEnd( oSettings );
}
/* Page backwards */
while ( iRow < oSettings._iDisplayStart )
{
oSettings._iDisplayStart = oSettings._iDisplayLength>=0 ?
oSettings._iDisplayStart - oSettings._iDisplayLength :
0;
if ( oSettings._iDisplayStart < 0 )
{
oSettings._iDisplayStart = 0;
}
_oDatatable.oApi._fnCalculateEnd( oSettings );
}
/* Re-draw the table */
_oDatatable.oApi._fnDraw( oSettings );
/* Restore the key capture */
_bKeyCapture = bKeyCaptureCache;
}
/* Cache the information that we are interested in */
var aNewPos = _fnCoordsFromCell( nTarget );
_nOldFocus = nTarget;
_iOldX = aNewPos[0];
_iOldY = aNewPos[1];
var iViewportHeight, iViewportWidth, iScrollTop, iScrollLeft, iHeight, iWidth, aiPos;
if ( bAutoScroll )
{
/* Scroll the viewport such that the new cell is fully visible in the rendered window */
iViewportHeight = $(window).height();
iViewportWidth = $(window).width();
iScrollTop = $(document).scrollTop();
iScrollLeft = $(document).scrollLeft();
iHeight = nTarget.offsetHeight;
iWidth = nTarget.offsetWidth;
aiPos = _fnGetPos( nTarget );
/* Take account of scrolling in DataTables 1.7 - remove scrolling since that would add to
* the positioning calculation
*/
if ( _oDatatable && typeof oSettings.oScroll != 'undefined' &&
(oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "") )
{
aiPos[1] -= $(oSettings.nTable.parentNode).scrollTop();
aiPos[0] -= $(oSettings.nTable.parentNode).scrollLeft();
}
/* Correct viewport positioning for vertical scrolling */
if ( aiPos[1]+iHeight > iScrollTop+iViewportHeight )
{
/* Displayed element if off the bottom of the viewport */
_fnSetScrollTop( aiPos[1]+iHeight - iViewportHeight );
}
else if ( aiPos[1] < iScrollTop )
{
/* Displayed element if off the top of the viewport */
_fnSetScrollTop( aiPos[1] );
}
/* Correct viewport positioning for horizontal scrolling */
if ( aiPos[0]+iWidth > iScrollLeft+iViewportWidth )
{
/* Displayed element is off the bottom of the viewport */
_fnSetScrollLeft( aiPos[0]+iWidth - iViewportWidth );
}
else if ( aiPos[0] < iScrollLeft )
{
/* Displayed element if off the Left of the viewport */
_fnSetScrollLeft( aiPos[0] );
}
}
/* Take account of scrolling in DataTables 1.7 */
if ( _oDatatable && typeof oSettings.oScroll != 'undefined' &&
(oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "") )
{
var dtScrollBody = oSettings.nTable.parentNode;
iViewportHeight = dtScrollBody.clientHeight;
iViewportWidth = dtScrollBody.clientWidth;
iScrollTop = dtScrollBody.scrollTop;
iScrollLeft = dtScrollBody.scrollLeft;
iHeight = nTarget.offsetHeight;
iWidth = nTarget.offsetWidth;
/* Correct for vertical scrolling */
if ( nTarget.offsetTop + iHeight > iViewportHeight+iScrollTop )
{
dtScrollBody.scrollTop = (nTarget.offsetTop + iHeight) - iViewportHeight;
}
else if ( nTarget.offsetTop < iScrollTop )
{
dtScrollBody.scrollTop = nTarget.offsetTop;
}
/* Correct for horizontal scrolling */
if ( nTarget.offsetLeft + iWidth > iViewportWidth+iScrollLeft )
{
dtScrollBody.scrollLeft = (nTarget.offsetLeft + iWidth) - iViewportWidth;
}
else if ( nTarget.offsetLeft < iScrollLeft )
{
dtScrollBody.scrollLeft = nTarget.offsetLeft;
}
}
/* Focused - so we want to capture the keys */
_fnCaptureKeys();
/* Fire of the focus event if there is one */
_fnEventFire( "focus", _iOldX, _iOldY );
}