mirror of
https://github.com/transmission/transmission
synced 2025-02-20 13:16:53 +00:00
(trunk web) revert that last change
This commit is contained in:
parent
a32cbd7a91
commit
b7b8121c6e
2 changed files with 159 additions and 110 deletions
|
@ -40,9 +40,10 @@ Torrent.prototype =
|
|||
this._file_view = [ ];
|
||||
|
||||
// Create a new <li> element
|
||||
var element = document.createElement( 'li' );
|
||||
element.className = 'torrent';
|
||||
element.id = 'torrent_' + data.id;
|
||||
var top_e = document.createElement( 'li' );
|
||||
top_e.className = 'torrent';
|
||||
top_e.id = 'torrent_' + data.id;
|
||||
var element = $(top_e);
|
||||
element._torrent = this;
|
||||
this._element = element;
|
||||
this._controller = controller;
|
||||
|
@ -51,27 +52,27 @@ Torrent.prototype =
|
|||
// Create the 'name' <div>
|
||||
var e = document.createElement( 'div' );
|
||||
e.className = 'torrent_name';
|
||||
element.appendChild( e );
|
||||
top_e.appendChild( e );
|
||||
element._name_container = e;
|
||||
|
||||
// Create the 'progress details' <div>
|
||||
e = document.createElement( 'div' );
|
||||
e.className = 'torrent_progress_details';
|
||||
element.appendChild( e );
|
||||
top_e.appendChild( e );
|
||||
element._progress_details_container = e;
|
||||
|
||||
// Create the 'in progress' bar
|
||||
e = document.createElement( 'div' );
|
||||
e.className = 'torrent_progress_bar incomplete';
|
||||
e.style.width = '0%';
|
||||
element.appendChild( e );
|
||||
top_e.appendChild( e );
|
||||
element._progress_complete_container = e;
|
||||
|
||||
// Create the 'incomplete' bar (initially hidden)
|
||||
e = document.createElement( 'div' );
|
||||
e.className = 'torrent_progress_bar incomplete';
|
||||
e.style.display = 'none';
|
||||
element.appendChild( e );
|
||||
top_e.appendChild( e );
|
||||
element._progress_incomplete_container = e;
|
||||
|
||||
// Add the pause/resume button - don't specify the
|
||||
|
@ -81,15 +82,20 @@ Torrent.prototype =
|
|||
image.className = 'torrent_pause';
|
||||
e = document.createElement( 'a' );
|
||||
e.appendChild( image );
|
||||
element.appendChild( e );
|
||||
top_e.appendChild( e );
|
||||
element._pause_resume_button_image = image;
|
||||
if (!iPhone) $(e).bind('click', {element: element}, this.clickPauseResumeButton);
|
||||
|
||||
// Create the 'peer details' <div>
|
||||
e = document.createElement( 'div' );
|
||||
e.className = 'torrent_peer_details';
|
||||
element.appendChild( e );
|
||||
top_e.appendChild( e );
|
||||
element._peer_details_container = e;
|
||||
|
||||
// Set the torrent click observer
|
||||
element.bind('click', {element: element}, this.clickTorrent);
|
||||
if (!iPhone) element.bind('contextmenu', {element: element}, this.rightClickTorrent);
|
||||
|
||||
// Safari hack - first torrent needs to be moved down for some reason. Seems to be ok when
|
||||
// using <li>'s in straight html, but adding through the DOM gets a bit odd.
|
||||
if ($.browser.safari)
|
||||
|
@ -112,7 +118,7 @@ Torrent.prototype =
|
|||
this.refresh(data);
|
||||
|
||||
// insert the element
|
||||
transferListParent.appendChild(element);
|
||||
transferListParent.appendChild(top_e);
|
||||
},
|
||||
|
||||
initializeTorrentFilesInspectorGroup: function( fileListParent ) {
|
||||
|
@ -195,6 +201,88 @@ Torrent.prototype =
|
|||
},
|
||||
hideFileList: function() { this.fileList().hide(); },
|
||||
|
||||
/*--------------------------------------------
|
||||
*
|
||||
* E V E N T F U N C T I O N S
|
||||
*
|
||||
*--------------------------------------------*/
|
||||
|
||||
/*
|
||||
* Process a right-click event on this torrent
|
||||
*/
|
||||
rightClickTorrent: function(event)
|
||||
{
|
||||
// don't stop the event! need it for the right-click menu
|
||||
|
||||
var t = event.data.element._torrent;
|
||||
if ( !t.isSelected( ) )
|
||||
t._controller.setSelectedTorrent( t );
|
||||
},
|
||||
|
||||
/*
|
||||
* Process a click event on this torrent
|
||||
*/
|
||||
clickTorrent: function( event )
|
||||
{
|
||||
// Prevents click carrying to parent element
|
||||
// which deselects all on click
|
||||
event.stopPropagation();
|
||||
var torrent = event.data.element._torrent;
|
||||
|
||||
// 'Apple' button emulation on PC :
|
||||
// Need settable meta-key and ctrl-key variables for mac emulation
|
||||
var meta_key = event.metaKey;
|
||||
var ctrl_key = event.ctrlKey;
|
||||
if (event.ctrlKey && navigator.appVersion.toLowerCase().indexOf("mac") == -1) {
|
||||
meta_key = true;
|
||||
ctrl_key = false;
|
||||
}
|
||||
|
||||
// Shift-Click - Highlight a range between this torrent and the last-clicked torrent
|
||||
if (iPhone) {
|
||||
torrent._controller.setSelectedTorrent( torrent, true );
|
||||
|
||||
} else if (event.shiftKey) {
|
||||
torrent._controller.selectRange( torrent, true );
|
||||
// Need to deselect any selected text
|
||||
window.focus();
|
||||
|
||||
// Apple-Click, not selected
|
||||
} else if (!torrent.isSelected() && meta_key) {
|
||||
torrent._controller.selectTorrent( torrent, true );
|
||||
|
||||
// Regular Click, not selected
|
||||
} else if (!torrent.isSelected()) {
|
||||
torrent._controller.setSelectedTorrent( torrent, true );
|
||||
|
||||
// Apple-Click, selected
|
||||
} else if (torrent.isSelected() && meta_key) {
|
||||
torrent._controller.deselectTorrent( torrent, true );
|
||||
|
||||
// Regular Click, selected
|
||||
} else if (torrent.isSelected()) {
|
||||
torrent._controller.setSelectedTorrent( torrent, true );
|
||||
}
|
||||
|
||||
torrent._controller.setLastTorrentClicked(torrent);
|
||||
},
|
||||
|
||||
/*
|
||||
* Process a click event on the pause/resume button
|
||||
*/
|
||||
clickPauseResumeButton: function( event )
|
||||
{
|
||||
// prevent click event resulting in selection of torrent
|
||||
event.stopPropagation();
|
||||
|
||||
// either stop or start the torrent
|
||||
var torrent = event.data.element._torrent;
|
||||
if( torrent.isActive( ) )
|
||||
torrent._controller.stopTorrent( torrent );
|
||||
else
|
||||
torrent._controller.startTorrent( torrent );
|
||||
},
|
||||
|
||||
/*--------------------------------------------
|
||||
*
|
||||
* I N T E R F A C E F U N C T I O N S
|
||||
|
@ -411,7 +499,7 @@ Torrent.prototype =
|
|||
* Return true if this torrent is selected
|
||||
*/
|
||||
isSelected: function() {
|
||||
return this.element().className.indexOf('selected') != -1;
|
||||
return this.element()[0].className.indexOf('selected') != -1;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -60,15 +60,12 @@ Transmission.prototype =
|
|||
$('.inspector_tab').bind('click', function(e){ tr.inspectorTabClicked(e, this); });
|
||||
$('.file_wanted_control').live('click', function(e){ tr.fileWantedClicked(e, this); });
|
||||
$('.file_priority_control').live('click', function(e){ tr.filePriorityClicked(e, this); });
|
||||
$('.torrent_list > .torrent').live('click', function(e){ tr.torrentClicked(e, this); });
|
||||
if (iPhone) {
|
||||
$('#torrent_inspector').bind('click', function(e){ tr.hideInspector(); });
|
||||
$('#preferences_link').bind('click', function(e){ tr.releaseClutchPreferencesButton(e); });
|
||||
} else {
|
||||
$('.torrent_resume').live('click', function(e){ tr.torrentResumeClicked(e, this); });
|
||||
$('.torrent_pause').live('click', function(e){ tr.torrentPauseClicked(e, this); });
|
||||
$(document).bind('keydown', function(e){ tr.keyDown(e); });
|
||||
//$('#torrent_container').bind('click', function(e){ tr.deselectAll( true ); });
|
||||
$('#torrent_container').bind('click', function(e){ tr.deselectAll( true ); });
|
||||
$('#open_link').bind('click', function(e){ tr.openTorrentClicked(e); });
|
||||
$('#filter_toggle_link').bind('click', function(e){ tr.toggleFilterClicked(e); });
|
||||
$('#inspector_link').bind('click', function(e){ tr.toggleInspectorClicked(e); });
|
||||
|
@ -291,11 +288,7 @@ Transmission.prototype =
|
|||
shadow: false,
|
||||
boundingElement: $('div#torrent_container'),
|
||||
boundingRightPad: 20,
|
||||
boundingBottomPad: 5,
|
||||
onContextMenu: function(e) {
|
||||
tr.setSelectedElement( $(e.target).closest('.torrent')[0], true );
|
||||
return true;
|
||||
}
|
||||
boundingBottomPad: 5
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -330,7 +323,7 @@ Transmission.prototype =
|
|||
{
|
||||
var torrents = [ ];
|
||||
for( var i=0, row; row=this._rows[i]; ++i )
|
||||
if( row._torrent && ( row.style.display != 'none' ) )
|
||||
if( row._torrent && ( row[0].style.display != 'none' ) )
|
||||
torrents.push( row._torrent );
|
||||
return torrents;
|
||||
},
|
||||
|
@ -360,7 +353,7 @@ Transmission.prototype =
|
|||
{
|
||||
var rows = [ ];
|
||||
for( var i=0, row; row=this._rows[i]; ++i )
|
||||
if( row.style.display != 'none' )
|
||||
if( row[0].style.display != 'none' )
|
||||
rows.push( row );
|
||||
return rows;
|
||||
},
|
||||
|
@ -381,20 +374,20 @@ Transmission.prototype =
|
|||
|
||||
scrollToElement: function( e )
|
||||
{
|
||||
if( !iPhone )
|
||||
{
|
||||
var container = $('#torrent_container');
|
||||
var scrollTop = container.scrollTop( );
|
||||
var innerHeight = container.innerHeight( );
|
||||
if( iPhone )
|
||||
return;
|
||||
|
||||
var offsetTop = e.offsetTop;
|
||||
var offsetHeight = $(e).outerHeight( );
|
||||
var container = $('#torrent_container');
|
||||
var scrollTop = container.scrollTop( );
|
||||
var innerHeight = container.innerHeight( );
|
||||
|
||||
if( offsetTop < scrollTop )
|
||||
container.scrollTop( offsetTop );
|
||||
else if( innerHeight + scrollTop < offsetTop + offsetHeight )
|
||||
container.scrollTop( offsetTop + offsetHeight - innerHeight );
|
||||
}
|
||||
var offsetTop = e[0].offsetTop;
|
||||
var offsetHeight = e.outerHeight( );
|
||||
|
||||
if( offsetTop < scrollTop )
|
||||
container.scrollTop( offsetTop );
|
||||
else if( innerHeight + scrollTop < offsetTop + offsetHeight )
|
||||
container.scrollTop( offsetTop + offsetHeight - innerHeight );
|
||||
},
|
||||
|
||||
/*--------------------------------------------
|
||||
|
@ -403,23 +396,35 @@ Transmission.prototype =
|
|||
*
|
||||
*--------------------------------------------*/
|
||||
|
||||
setSelectedElement: function( element, doUpdate ) {
|
||||
setSelectedTorrent: function( torrent, doUpdate ) {
|
||||
this.deselectAll( );
|
||||
this.selectElement( element, doUpdate );
|
||||
this.selectTorrent( torrent, doUpdate );
|
||||
},
|
||||
|
||||
selectElement: function( e, doUpdate ) {
|
||||
$.className.add( e[0], 'selected' );
|
||||
this.scrollToElement( e );
|
||||
$.className.add( e, 'selected' );
|
||||
if( doUpdate )
|
||||
this.selectionChanged( );
|
||||
$.className.add( e[0], 'selected' );
|
||||
},
|
||||
selectRow: function( rowIndex, doUpdate ) {
|
||||
this.selectElement( this._rows[rowIndex], doUpdate );
|
||||
},
|
||||
selectTorrent: function( torrent, doUpdate ) {
|
||||
if( torrent._element )
|
||||
this.selectElement( torrent._element, doUpdate );
|
||||
},
|
||||
|
||||
deselectElement: function( e, doUpdate ) {
|
||||
$.className.remove( e, 'selected' );
|
||||
$.className.remove( e[0], 'selected' );
|
||||
if( doUpdate )
|
||||
this.selectionChanged( );
|
||||
},
|
||||
deselectTorrent: function( torrent, doUpdate ) {
|
||||
if( torrent._element )
|
||||
this.deselectElement( torrent._element, doUpdate );
|
||||
},
|
||||
|
||||
selectAll: function( doUpdate ) {
|
||||
var tr = this;
|
||||
|
@ -432,7 +437,7 @@ Transmission.prototype =
|
|||
var tr = this;
|
||||
for( var i=0, row; row=tr._rows[i]; ++i )
|
||||
tr.deselectElement( row );
|
||||
tr._last_element_clicked = null;
|
||||
tr._last_torrent_clicked = null;
|
||||
if( doUpdate )
|
||||
tr.selectionChanged( );
|
||||
},
|
||||
|
@ -440,17 +445,21 @@ Transmission.prototype =
|
|||
/*
|
||||
* Select a range from this torrent to the last clicked torrent
|
||||
*/
|
||||
selectRange: function( element, doUpdate )
|
||||
selectRange: function( torrent, doUpdate )
|
||||
{
|
||||
if( !this._last_element_clicked )
|
||||
this.selectElement( element );
|
||||
else { // select the range between the prevous & current
|
||||
var a = this._rows.indexOf( this._last_element_clicked );
|
||||
var b = this._rows.indexOf( element );
|
||||
var begin = a < b ? a : b;
|
||||
var end = a > b ? a : b;
|
||||
for( var i=begin; i<=end; ++i )
|
||||
this.selectElement( this._rows[i] );
|
||||
if( !this._last_torrent_clicked )
|
||||
{
|
||||
this.selectTorrent( torrent );
|
||||
}
|
||||
else // select the range between the prevous & current
|
||||
{
|
||||
var rows = this.getVisibleRows( );
|
||||
var i = this.getTorrentIndex( rows, this._last_torrent_clicked );
|
||||
var end = this.getTorrentIndex( rows, torrent );
|
||||
var step = i < end ? 1 : -1;
|
||||
for( ; i!=end; i+=step )
|
||||
this.selectRow( i );
|
||||
this.selectRow( i );
|
||||
}
|
||||
|
||||
if( doUpdate )
|
||||
|
@ -494,8 +503,10 @@ Transmission.prototype =
|
|||
i = rows.length - 1;
|
||||
}
|
||||
|
||||
if( 0<=i && i<rows.length )
|
||||
this.setSelectedElement (this._rows[i]);
|
||||
if( 0<=i && i<rows.length ) {
|
||||
tr.deselectAll( );
|
||||
tr.selectRow( i, true );
|
||||
}
|
||||
},
|
||||
|
||||
isButtonEnabled: function(e) {
|
||||
|
@ -640,61 +651,6 @@ Transmission.prototype =
|
|||
this.updateVisibleFileLists();
|
||||
},
|
||||
|
||||
torrentClicked: function(event, element)
|
||||
{
|
||||
var torrent = element._torrent;
|
||||
var isSelected = element.className.indexOf('selected') != -1;
|
||||
|
||||
|
||||
//console.log ('torrent clicked. meta ' + event.metaKey + ' ctrl ' + event.ctrlKey + ' shift ' + event.shiftKey );
|
||||
// 'Apple' button emulation on PC:
|
||||
// TODO: Need settable meta-key and ctrl-key variables for mac emulation
|
||||
var meta_key = event.metaKey;
|
||||
var ctrl_key = event.ctrlKey;
|
||||
if (event.ctrlKey && navigator.appVersion.toLowerCase().indexOf("mac") == -1) {
|
||||
meta_key = true;
|
||||
ctrl_key = false;
|
||||
}
|
||||
|
||||
// Shift-Click - Highlight a range between this torrent and the last-clicked torrent
|
||||
if (iPhone) {
|
||||
this.setSelectedElement( element, true );
|
||||
} else if (event.shiftKey) {
|
||||
this.selectRange( element, true );
|
||||
// Need to deselect any selected text
|
||||
window.focus();
|
||||
|
||||
} else if (!isSelected && meta_key) { // Apple-Click, not selected
|
||||
this.selectElement( element, true );
|
||||
} else if (!isSelected) { // Regular Click, not selected
|
||||
this.setSelectedElement( element, true );
|
||||
} else if (isSelected && meta_key) { // Apple-Click, selected
|
||||
this.deselectElement( element, true );
|
||||
} else if (isSelected) { // Regular Click, selected
|
||||
this.setSelectedElement( element, true );
|
||||
}
|
||||
|
||||
this._last_element_clicked = element;
|
||||
|
||||
// Prevents click carrying to parent element
|
||||
// which deselects all on click
|
||||
event.stopPropagation();
|
||||
},
|
||||
|
||||
torrentPauseClicked: function (event, element) {
|
||||
var row = element.parentNode.parentNode;
|
||||
console.log ('pause clicked');
|
||||
this.stopTorrent (row._torrent);
|
||||
event.stopPropagation ();
|
||||
},
|
||||
|
||||
torrentResumeClicked: function (event, element) {
|
||||
var row = element.parentNode.parentNode;
|
||||
console.log ('resume clicked');
|
||||
this.startTorrent (row._torrent);
|
||||
event.stopPropagation ();
|
||||
},
|
||||
|
||||
fileWantedClicked: function(event, element){
|
||||
this.extractFileFromElement(element).fileWantedControlClicked(event);
|
||||
},
|
||||
|
@ -944,6 +900,11 @@ Transmission.prototype =
|
|||
return false; // to prevent the event from bubbling up
|
||||
},
|
||||
|
||||
setLastTorrentClicked: function( torrent )
|
||||
{
|
||||
this._last_torrent_clicked = torrent;
|
||||
},
|
||||
|
||||
/*
|
||||
* Update the inspector with the latest data for the selected torrents
|
||||
*/
|
||||
|
@ -1288,10 +1249,10 @@ Transmission.prototype =
|
|||
{
|
||||
var rows = this.getVisibleRows( );
|
||||
for( var i=0, row; row=rows[i]; ++i ) {
|
||||
var wasEven = row.className.indexOf('even') != -1;
|
||||
var wasEven = row[0].className.indexOf('even') != -1;
|
||||
var isEven = ((i+1) % 2 == 0);
|
||||
if( wasEven != isEven )
|
||||
$(row).toggleClass('even', isEven);
|
||||
row.toggleClass('even', isEven);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -1496,14 +1457,14 @@ Transmission.prototype =
|
|||
// hide the ones we're not keeping
|
||||
for( var i=keep.length, e; e=this._rows[i]; ++i ) {
|
||||
delete e._torrent;
|
||||
e.style.display = 'none';
|
||||
e[0].style.display = 'none';
|
||||
}
|
||||
|
||||
// show the ones we're keeping
|
||||
sel.sort( Torrent.compareById );
|
||||
for( var i=0, len=keep.length; i<len; ++i ) {
|
||||
var e = this._rows[i];
|
||||
e.style.display = 'block';
|
||||
e[0].style.display = 'block';
|
||||
var t = keep[i];
|
||||
t.setElement( e );
|
||||
if( Torrent.indexOf( sel, t.id() ) != -1 )
|
||||
|
|
Loading…
Reference in a new issue