bind globally instead of to each individual file

this brings us from 35 down to 8 function calls per file initalization
This commit is contained in:
Kevin Glowacz 2009-05-25 04:07:48 +00:00
parent 8c9fb12e82
commit 231110f747
2 changed files with 28 additions and 13 deletions

View File

@ -663,6 +663,7 @@ TorrentFile.prototype = {
this.readAttributes(file_data);
var li = document.createElement('li');
li.id = 't' + this._torrent.id() + 'f' + this._index;
li.classNameConst = 'inspector_torrent_file_list_entry ' + ((this._index%2)?'odd':'even');
li.className = li.classNameConst;
@ -688,9 +689,6 @@ TorrentFile.prototype = {
this._element = li;
this._priority_control = pri_div;
this._progress = $(prog_div);
$(wanted_div).bind('click', { file: this }, this.fileWantedControlClicked);
$(pri_div).bind('click', { file: this }, this.filePriorityControlClicked);
},
update: function(file_data) {
@ -803,21 +801,20 @@ TorrentFile.prototype = {
},
fileWantedControlClicked: function(event) {
event.data.file.toggleWanted();
this.toggleWanted();
},
filePriorityControlClicked: function(event) {
filePriorityControlClicked: function(event, element) {
var x = event.pageX;
var target = this;
while (target !== null) {
x = x - target.offsetLeft;
target = target.offsetParent;
while (element !== null) {
x = x - element.offsetLeft;
element = element.offsetParent;
}
var file = event.data.file
var prio;
if( x < 12 ) prio = -1;
else if( x < 23 ) prio = 0;
else prio = 1;
file.setPriority( prio );
this.setPriority( prio );
}
};

View File

@ -58,6 +58,8 @@ Transmission.prototype =
$('#prefs_save_button').bind('click', function(e) { tr.savePrefsClicked(e); return false;});
$('#prefs_cancel_button').bind('click', function(e){ tr.cancelPrefsClicked(e); return false; });
$('.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); });
if (iPhone) {
$('#torrent_inspector').bind('click', function(e){ tr.hideInspector(); });
$('#preferences_link').bind('click', function(e){ tr.releaseClutchPreferencesButton(e); });
@ -648,7 +650,23 @@ Transmission.prototype =
this.updateVisibleFileLists();
},
fileWantedClicked: function(event, element){
this.extractFileFromElement(element).fileWantedControlClicked(event);
},
filePriorityClicked: function(event, element){
this.extractFileFromElement(element).filePriorityControlClicked(event, element);
},
extractFileFromElement: function(element) {
var match = $(element).closest('.inspector_torrent_file_list_entry').attr('id').match(/^t(\d+)f(\d+)$/);
var torrent_id = match[1];
var file_id = match[2];
var torrent = Torrent.lookup( this._torrents, torrent_id );
return torrent._file_view[file_id];
},
toggleFilterClicked: function(event) {
if (this.isButtonEnabled(event))
this.toggleFilter();
@ -1400,7 +1418,7 @@ Transmission.prototype =
changeFileCommand: function(command, torrent, file) {
this.remote.changeFileCommand(command, torrent, file)
},
hideiPhoneAddressbar: function(timeInSeconds) {
if( iPhone ) {
var delayLength = timeInSeconds ? timeInSeconds*1000 : 150;