diff --git a/web/javascript/torrent.js b/web/javascript/torrent.js index ada9ed7da..c1f5627b9 100644 --- a/web/javascript/torrent.js +++ b/web/javascript/torrent.js @@ -40,10 +40,9 @@ Torrent.prototype = this._file_view = [ ]; // Create a new
  • element - var top_e = document.createElement( 'li' ); - top_e.className = 'torrent'; - top_e.id = 'torrent_' + data.id; - var element = $(top_e); + var element = document.createElement( 'li' ); + element.className = 'torrent'; + element.id = 'torrent_' + data.id; element._torrent = this; this._element = element; this._controller = controller; @@ -52,27 +51,27 @@ Torrent.prototype = // Create the 'name'
    var e = document.createElement( 'div' ); e.className = 'torrent_name'; - top_e.appendChild( e ); + element.appendChild( e ); element._name_container = e; // Create the 'progress details'
    e = document.createElement( 'div' ); e.className = 'torrent_progress_details'; - top_e.appendChild( e ); + element.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%'; - top_e.appendChild( e ); + element.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'; - top_e.appendChild( e ); + element.appendChild( e ); element._progress_incomplete_container = e; // Add the pause/resume button - don't specify the @@ -82,20 +81,15 @@ Torrent.prototype = image.className = 'torrent_pause'; e = document.createElement( 'a' ); e.appendChild( image ); - top_e.appendChild( e ); + element.appendChild( e ); element._pause_resume_button_image = image; - if (!iPhone) $(e).bind('click', {element: element}, this.clickPauseResumeButton); // Create the 'peer details'
    e = document.createElement( 'div' ); e.className = 'torrent_peer_details'; - top_e.appendChild( e ); + element.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
  • 's in straight html, but adding through the DOM gets a bit odd. if ($.browser.safari) @@ -118,7 +112,7 @@ Torrent.prototype = this.refresh(data); // insert the element - transferListParent.appendChild(top_e); + transferListParent.appendChild(element); }, initializeTorrentFilesInspectorGroup: function( fileListParent ) { @@ -201,88 +195,6 @@ 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 @@ -499,7 +411,7 @@ Torrent.prototype = * Return true if this torrent is selected */ isSelected: function() { - return this.element()[0].className.indexOf('selected') != -1; + return this.element().className.indexOf('selected') != -1; }, /** diff --git a/web/javascript/transmission.js b/web/javascript/transmission.js index 5da1a1f66..be0099a7f 100644 --- a/web/javascript/transmission.js +++ b/web/javascript/transmission.js @@ -60,12 +60,15 @@ 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); }); @@ -288,7 +291,11 @@ Transmission.prototype = shadow: false, boundingElement: $('div#torrent_container'), boundingRightPad: 20, - boundingBottomPad: 5 + boundingBottomPad: 5, + onContextMenu: function(e) { + tr.setSelectedElement( $(e.target).closest('.torrent')[0], true ); + return true; + } }); }, @@ -323,7 +330,7 @@ Transmission.prototype = { var torrents = [ ]; for( var i=0, row; row=this._rows[i]; ++i ) - if( row._torrent && ( row[0].style.display != 'none' ) ) + if( row._torrent && ( row.style.display != 'none' ) ) torrents.push( row._torrent ); return torrents; }, @@ -353,7 +360,7 @@ Transmission.prototype = { var rows = [ ]; for( var i=0, row; row=this._rows[i]; ++i ) - if( row[0].style.display != 'none' ) + if( row.style.display != 'none' ) rows.push( row ); return rows; }, @@ -374,20 +381,20 @@ Transmission.prototype = scrollToElement: function( e ) { - if( iPhone ) - return; + if( !iPhone ) + { + var container = $('#torrent_container'); + var scrollTop = container.scrollTop( ); + var innerHeight = container.innerHeight( ); - var container = $('#torrent_container'); - var scrollTop = container.scrollTop( ); - var innerHeight = container.innerHeight( ); + var offsetTop = e.offsetTop; + var offsetHeight = $(e).outerHeight( ); - 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 ); + if( offsetTop < scrollTop ) + container.scrollTop( offsetTop ); + else if( innerHeight + scrollTop < offsetTop + offsetHeight ) + container.scrollTop( offsetTop + offsetHeight - innerHeight ); + } }, /*-------------------------------------------- @@ -396,35 +403,23 @@ Transmission.prototype = * *--------------------------------------------*/ - setSelectedTorrent: function( torrent, doUpdate ) { + setSelectedElement: function( element, doUpdate ) { this.deselectAll( ); - this.selectTorrent( torrent, doUpdate ); + this.selectElement( element, 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[0], 'selected' ); + $.className.remove( e, 'selected' ); if( doUpdate ) this.selectionChanged( ); }, - deselectTorrent: function( torrent, doUpdate ) { - if( torrent._element ) - this.deselectElement( torrent._element, doUpdate ); - }, selectAll: function( doUpdate ) { var tr = this; @@ -437,7 +432,7 @@ Transmission.prototype = var tr = this; for( var i=0, row; row=tr._rows[i]; ++i ) tr.deselectElement( row ); - tr._last_torrent_clicked = null; + tr._last_element_clicked = null; if( doUpdate ) tr.selectionChanged( ); }, @@ -445,21 +440,17 @@ Transmission.prototype = /* * Select a range from this torrent to the last clicked torrent */ - selectRange: function( torrent, doUpdate ) + selectRange: function( element, doUpdate ) { - 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( !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( doUpdate ) @@ -503,10 +494,8 @@ Transmission.prototype = i = rows.length - 1; } - if( 0<=i && i