Changeset 12819


Ignore:
Timestamp:
Aug 31, 2011, 2:24:35 PM (12 years ago)
Author:
jordan
Message:

(trunk web) minor code cleanup -- fixing comments, grouping argument lists, etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/javascript/transmission.js

    r12817 r12819  
    4545                $('#remove_link').click(function(e) { tr.removeClicked(e); });
    4646                $('#prefs_save_button').click(function(e) { tr.savePrefsClicked(e); return false;});
    47                 $('#prefs_cancel_button').click(function(e) { tr.hidePrefsDialog(); return false; });
    48                 $('#block_update_button').click(function(e) { tr.remote.updateBlocklist(); return false; });
    49                 $('#stats_close_button').click(function(e) { tr.hideStatsDialog(); return false; });
     47                $('#prefs_cancel_button').click(function() { tr.hidePrefsDialog(); return false; });
     48                $('#block_update_button').click(function() { tr.remote.updateBlocklist(); return false; });
     49                $('#stats_close_button').click(function() { tr.hideStatsDialog(); return false; });
    5050                $('.inspector_tab').click(function(e) { tr.inspectorTabClicked(e, this); });
    5151                $('#files_select_all').live('click', function(e) { tr.filesSelectAllClicked(e, this); });
     
    5353                $('#open_link').click(function(e) { tr.openTorrentClicked(e); });
    5454                $('#upload_confirm_button').click(function(e) { tr.confirmUploadClicked(e); return false;});
    55                 $('#upload_cancel_button').click(function(e) { tr.hideUploadDialog(); return false; });
     55                $('#upload_cancel_button').click(function() { tr.hideUploadDialog(); return false; });
    5656                $('#turtle-button').click(function() { tr.toggleTurtleClicked(); });
    5757                $('#compact-button').click(function() { tr.toggleCompactClicked(); });
     
    6868
    6969                $(document).delegate('#torrent_list > li', 'click', function(ev) {tr.onRowClicked(ev,ev.currentTarget.row);});
    70                 $(document).delegate('#torrent_list > li', 'dblclick', function(e) {tr.toggleInspector();});
     70                $(document).delegate('#torrent_list > li', 'dblclick', function() {tr.toggleInspector();});
    7171       
    7272                $('#torrent_upload_form').submit(function() { $('#upload_confirm_button').click(); return false; });
     
    360360
    361361        seedRatioLimit: function() {
    362                 if (this._prefs && this._prefs['seedRatioLimited'])
    363                         return this._prefs['seedRatioLimit'];
     362                var p = this._prefs;
     363                if (p && p.seedRatioLimited)
     364                        return p.seedRatioLimit;
    364365                return -1;
    365366        },
     
    382383
    383384        getSelectedTorrents: function() {
    384                 return $.map(this.getSelectedRows(),function(r) {return r.getTorrent();});
     385                return $.map(this.getSelectedRows(),function(r) {
     386                        return r.getTorrent();
     387                });
    385388        },
    386389
    387390        getSelectedTorrentIds: function() {
    388                 return $.map(this.getSelectedRows(),function(r) {return r.getTorrentId();});
     391                return $.map(this.getSelectedRows(),function(r) {
     392                        return r.getTorrentId();
     393                });
    389394        },
    390395
     
    455460        {
    456461                if (!this.selectionChangedTimer)
    457                         this.selectionChangedTimer = setTimeout($.proxy(this.selectionChanged,this),200);
     462                        this.selectionChangedTimer =
     463                                setTimeout($.proxy(this.selectionChanged,this),200);
    458464        },
    459465
     
    470476        {
    471477                var handled = false,
    472                         rows = this._rows,
     478                    rows = this._rows,
    473479                    up = ev.keyCode === 38; // up key pressed
    474480                    dn = ev.keyCode === 40, // down key pressed
     
    493499                        if (anchor >= 0)
    494500                        {
    495                                 // user is extending the selection with the shift + arrow keys...
     501                                // user is extending the selection
     502                                // with the shift + arrow keys...
    496503                                if (   ((anchor <= last) && (last < i))
    497504                                    || ((anchor >= last) && (last > i)))
     
    530537        },
    531538
    532         isButtonEnabled: function(e) {
    533                 var p = e.target ? e.target.parentNode : e.srcElement.parentNode;
    534                 return p.className!='disabled' && p.parentNode.className!='disabled';
     539        isButtonEnabled: function(ev) {
     540                var p = (ev.target || ev.srcElement).parentNode;
     541                return p.className!=='disabled'
     542                    && p.parentNode.className!=='disabled';
    535543        },
    536544
     
    704712        /* Turn the periodic ajax session refresh on & off */
    705713        togglePeriodicSessionRefresh: function(enabled) {
    706                 clearInterval(this._periodic_session_refresh);
    707                 delete this._periodic_session_refresh;
     714                clearInterval(this.sessionInterval);
     715                delete this.sessionInterval;
    708716                if (enabled) {
    709717                        var msec = this.getIntervalMsec(Prefs._SessionRefreshRate, 5);
    710                         this._periodic_session_refresh = setInterval($.proxy(this.loadDaemonPrefs,this), msec);
     718                        this.sessionInterval = setInterval($.proxy(this.loadDaemonPrefs,this), msec);
    711719                }
    712720        },
     
    714722        /* Turn the periodic ajax stats refresh on & off */
    715723        togglePeriodicStatsRefresh: function(enabled) {
    716                 clearInterval(this._periodic_stats_refresh);
    717                 delete this._periodic_stats_refresh;
     724                clearInterval(this.statsInterval);
     725                delete this.statsInterval;
    718726                if (enabled) {
    719727                        var msec = this.getIntervalMsec(Prefs._SessionRefreshRate, 5);
    720                         this._periodic_stats_refresh = setInterval($.proxy(this.loadDaemonStats,this), msec);
     728                        this.statsInterval = setInterval($.proxy(this.loadDaemonStats,this), msec);
    721729                }
    722730        },
     
    9981006        onTorrentChanged: function(tor)
    9991007        {
    1000                 var id = tor.getId();
    1001 
    10021008                // update our dirty fields
    1003                 this.dirtyTorrents[id] = true;
     1009                this.dirtyTorrents[ tor.getId() ] = true;
    10041010
    10051011                // enqueue ui refreshes
     
    10101016        updateFromTorrentGet: function(updates, removed_ids)
    10111017        {
    1012                 var i, o, t, id, needed, needs,
    1013                     needinfo = [];
     1018                var i, o, t, id, needed, needinfo = [];
    10141019
    10151020                for (i=0; o=updates[i]; ++i)
     
    10201025                                needed = t.needsMetaData();
    10211026                                t.refresh(o);
    1022                                 needs = t.needsMetaData();
    1023                                 if (needed && !needs)
     1027                                if (needed && !t.needsMetaData())
    10241028                                        needinfo.push(id);
    10251029                        }
     
    10621066        initializeTorrents: function()
    10631067        {
    1064                 // to bootstrap, we only need to ask for the servers's torrents' ids.
    1065                 // updateFromTorrentGet() automatically asks for the rest of the info when it gets a new id.
    1066                 var fields = ['id'].concat(Torrent.Fields.Metadata, Torrent.Fields.Stats);
    1067                 this.remote.updateTorrents(null, fields, this.updateFromTorrentGet, this);
     1068                var fields = ['id'].concat(Torrent.Fields.Metadata,
     1069                                           Torrent.Fields.Stats);
     1070                this.remote.updateTorrents(null, fields,
     1071                                          this.updateFromTorrentGet, this);
    10681072        },
    10691073
     
    10801084        },
    10811085
     1086        // Load the torrent fields which are only used by the inspector
    10821087        refreshInspectorTorrents: function(full)
    10831088        {
    1084                 // some torrent fields are only used by the inspector, so we defer loading them
    1085                 // until the user is viewing the torrent in the inspector.
    1086                 if (this.inspectorIsVisible()) {
    1087                         var ids = this.getSelectedTorrentIds();
    1088                         if (ids && ids.length) {
    1089                                 var fields = ['id'].concat(Torrent.Fields.StatsExtra);
    1090                                 if (this.needsExtraInfo(ids))
    1091                                         fields = fields.concat(Torrent.Fields.InfoExtra);
    1092                                 this.remote.updateTorrents(ids, fields, this.updateFromTorrentGet, this);
    1093                         }
     1089                var fields, ids=null;
     1090
     1091                if (this.inspectorIsVisible())
     1092                        ids = this.getSelectedTorrentIds();
     1093
     1094                if (ids && ids.length) {
     1095                        fields = ['id'].concat(Torrent.Fields.StatsExtra);
     1096                        if (this.needsExtraInfo(ids))
     1097                                $.merge(fields, Torrent.Fields.InfoExtra);
     1098                        this.remote.updateTorrents(
     1099                                ids, fields, this.updateFromTorrentGet, this);
    10941100                }
    10951101        },
     
    11661172        updateStatusbar: function()
    11671173        {
     1174                var i, row,
     1175                    u=0, d=0,
     1176                    fmt = Transmission.fmt,
     1177                    torrents = this.getAllTorrents();
     1178
    11681179                this.refreshFilterButton();
    11691180
    11701181                // up/down speed
    1171                 var u=0, d=0;
    1172                 var torrents = this.getAllTorrents();
    1173                 for (var i=0, row; row=torrents[i]; ++i) {
     1182                for (i=0; row=torrents[i]; ++i) {
    11741183                        u += row.getUploadSpeed();
    11751184                        d += row.getDownloadSpeed();
    11761185                }
    11771186
    1178                 var fmt = Transmission.fmt;
    11791187                setInnerHTML($('#statusbar #speed-up-label')[0], u ? '&uarr; ' + fmt.speedBps(u) : '');
    11801188                setInnerHTML($('#statusbar #speed-dn-label')[0], d ? '&darr; ' + fmt.speedBps(d) : '');
     
    13221330        },
    13231331
    1324         hideMobileAddressbar: function(timeInSeconds) {
     1332        hideMobileAddressbar: function(delaySecs) {
    13251333                if (isMobileDevice && !scroll_timeout) {
    1326                         var delayLength = timeInSeconds ? timeInSeconds*1000 : 150;
    1327                         scroll_timeout = setTimeout($.proxy(this.doToolbarHide,this), delayLength);
     1334                        var delayMsec = delaySecs*1000 || 150;
     1335                        scroll_timeout = setTimeout($.proxy(this.doToolbarHide,this), delayMsec);
    13281336                }
    13291337        },
Note: See TracChangeset for help on using the changeset viewer.