mirror of
https://github.com/transmission/transmission
synced 2024-12-26 01:27:28 +00:00
(trunk web) make Transmission.js' keyDown() function more efficient & a little more readable
This commit is contained in:
parent
f1d91b1ff8
commit
d42973b607
1 changed files with 30 additions and 32 deletions
|
@ -475,22 +475,23 @@ Transmission.prototype =
|
||||||
Prefs.setValue( key, val );
|
Prefs.setValue( key, val );
|
||||||
},
|
},
|
||||||
|
|
||||||
scrollToElement: function( e )
|
scrollToRow: function(row)
|
||||||
{
|
{
|
||||||
if( iPhone )
|
if( iPhone ) // FIXME: why?
|
||||||
return;
|
return
|
||||||
|
|
||||||
var container = $('#torrent_container');
|
var list = $('#torrent_container')
|
||||||
var scrollTop = container.scrollTop( );
|
var scrollTop = list.scrollTop()
|
||||||
var innerHeight = container.innerHeight( );
|
var innerHeight = list.innerHeight()
|
||||||
|
|
||||||
var offsetTop = e.offsetTop;
|
var e = $(row.getElement())
|
||||||
var offsetHeight = $(e).outerHeight( );
|
var offsetTop = e[0].offsetTop
|
||||||
|
var offsetHeight = e.outerHeight()
|
||||||
|
|
||||||
if( offsetTop < scrollTop )
|
if( offsetTop < scrollTop )
|
||||||
container.scrollTop( offsetTop );
|
list.scrollTop( offsetTop );
|
||||||
else if( innerHeight + scrollTop < offsetTop + offsetHeight )
|
else if( innerHeight + scrollTop < offsetTop + offsetHeight )
|
||||||
container.scrollTop( offsetTop + offsetHeight - innerHeight );
|
list.scrollTop( offsetTop + offsetHeight - innerHeight );
|
||||||
},
|
},
|
||||||
|
|
||||||
seedRatioLimit: function(){
|
seedRatioLimit: function(){
|
||||||
|
@ -582,32 +583,29 @@ Transmission.prototype =
|
||||||
/*
|
/*
|
||||||
* Process key event
|
* Process key event
|
||||||
*/
|
*/
|
||||||
keyDown: function(event)
|
keyDown: function(ev)
|
||||||
{
|
{
|
||||||
var tr = this;
|
var up = ev.keyCode === 38 // up key pressed
|
||||||
var sel = tr.getSelectedRows( );
|
var dn = ev.keyCode === 40 // down key pressed
|
||||||
var rows = tr.getVisibleRows( );
|
|
||||||
var i = -1;
|
|
||||||
|
|
||||||
if( event.keyCode == 40 ) // down arrow
|
if(up || dn)
|
||||||
{
|
{
|
||||||
var r = sel.length ? sel[sel.length-1] : null;
|
var rows = this.getVisibleRows()
|
||||||
i = r==null ? null : tr.getRowIndex(rows,r)+1;
|
|
||||||
if( i == rows.length || i == null )
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
else if( event.keyCode == 38 ) // up arrow
|
|
||||||
{
|
|
||||||
var r = sel.length ? sel[0] : null
|
|
||||||
i = r==null ? null : tr.getRowIndex(rows,r)-1;
|
|
||||||
if( i == -1 || i == null )
|
|
||||||
i = rows.length - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( 0<=i && i<rows.length ) {
|
// find the first selected row
|
||||||
tr.deselectAll( );
|
for(var i=0, row; row=rows[i]; ++i)
|
||||||
tr.selectRow( tr._rows[i], true );
|
if(row.isSelected())
|
||||||
tr.scrollToElement( tr._rows[i] );
|
break
|
||||||
|
|
||||||
|
if(i == rows.length) // no selection yet
|
||||||
|
i = 0
|
||||||
|
else if(dn)
|
||||||
|
i = (i+1) % rows.length
|
||||||
|
else if(up)
|
||||||
|
i = (i || rows.length) - 1
|
||||||
|
|
||||||
|
this.setSelectedRow(rows[i])
|
||||||
|
this.scrollToRow(rows[i])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue