#5944: Unify indentation style and strip trailing whitespaces across JS code, no functional changes (patch by xzcvczx + a lot more)

This commit is contained in:
Mike Gelfand
2015-05-05 19:12:48 +00:00
parent 5de8bbe6d8
commit 7177d43ba1
11 changed files with 1180 additions and 1178 deletions

View File

@@ -45,11 +45,11 @@ function FileRow(torrent, depth, name, indices, even)
{
var pct = 100 * (fields.size ? (fields.have / fields.size) : 1.0),
c = [ Transmission.fmt.size(fields.have),
' of ',
Transmission.fmt.size(fields.size),
' (',
Transmission.fmt.percentString(pct),
'%)' ].join('');
' of ',
Transmission.fmt.size(fields.size),
' (',
Transmission.fmt.percentString(pct),
'%)' ].join('');
setTextContent(elements.progress, c);
},
refreshImpl = function() {

File diff suppressed because it is too large Load Diff

View File

@@ -1,17 +1,17 @@
var Notifications = {};
$(document).ready(function () {
if (!window.webkitNotifications) {
return;
}
if (!window.webkitNotifications) {
return;
}
var notificationsEnabled = (window.webkitNotifications.checkPermission() === 0),
toggle = $('#toggle_notifications');
var notificationsEnabled = (window.webkitNotifications.checkPermission() === 0),
toggle = $('#toggle_notifications');
toggle.show();
updateMenuTitle();
$(transmission).bind('downloadComplete seedingComplete', function (event, torrent) {
if (notificationsEnabled) {
toggle.show();
updateMenuTitle();
$(transmission).bind('downloadComplete seedingComplete', function (event, torrent) {
if (notificationsEnabled) {
var title = (event.type == 'downloadComplete' ? 'Download' : 'Seeding') + ' complete',
content = torrent.getName(),
notification;
@@ -22,21 +22,21 @@ $(document).ready(function () {
notification.cancel();
}, 5000);
};
});
});
function updateMenuTitle() {
toggle.html((notificationsEnabled ? 'Disable' : 'Enable') + ' Notifications');
}
function updateMenuTitle() {
toggle.html((notificationsEnabled ? 'Disable' : 'Enable') + ' Notifications');
}
Notifications.toggle = function () {
if (window.webkitNotifications.checkPermission() !== 0) {
window.webkitNotifications.requestPermission(function () {
notificationsEnabled = (window.webkitNotifications.checkPermission() === 0);
updateMenuTitle();
});
} else {
notificationsEnabled = !notificationsEnabled;
updateMenuTitle();
}
};
Notifications.toggle = function () {
if (window.webkitNotifications.checkPermission() !== 0) {
window.webkitNotifications.requestPermission(function () {
notificationsEnabled = (window.webkitNotifications.checkPermission() === 0);
updateMenuTitle();
});
} else {
notificationsEnabled = !notificationsEnabled;
updateMenuTitle();
}
};
});

View File

@@ -7,312 +7,312 @@
function PrefsDialog(remote) {
var data = {
dialog: null,
remote: null,
elements: { },
var data = {
dialog: null,
remote: null,
elements: { },
// all the RPC session keys that we have gui controls for
keys: [
'alt-speed-down',
'alt-speed-time-begin',
'alt-speed-time-day',
'alt-speed-time-enabled',
'alt-speed-time-end',
'alt-speed-up',
'blocklist-enabled',
'blocklist-size',
'blocklist-url',
'dht-enabled',
'download-dir',
'encryption',
'idle-seeding-limit',
'idle-seeding-limit-enabled',
'lpd-enabled',
'peer-limit-global',
'peer-limit-per-torrent',
'peer-port',
'peer-port-random-on-start',
'pex-enabled',
'port-forwarding-enabled',
'rename-partial-files',
'seedRatioLimit',
'seedRatioLimited',
'speed-limit-down',
'speed-limit-down-enabled',
'speed-limit-up',
'speed-limit-up-enabled',
'start-added-torrents',
'utp-enabled'
],
// all the RPC session keys that we have gui controls for
keys: [
'alt-speed-down',
'alt-speed-time-begin',
'alt-speed-time-day',
'alt-speed-time-enabled',
'alt-speed-time-end',
'alt-speed-up',
'blocklist-enabled',
'blocklist-size',
'blocklist-url',
'dht-enabled',
'download-dir',
'encryption',
'idle-seeding-limit',
'idle-seeding-limit-enabled',
'lpd-enabled',
'peer-limit-global',
'peer-limit-per-torrent',
'peer-port',
'peer-port-random-on-start',
'pex-enabled',
'port-forwarding-enabled',
'rename-partial-files',
'seedRatioLimit',
'seedRatioLimited',
'speed-limit-down',
'speed-limit-down-enabled',
'speed-limit-up',
'speed-limit-up-enabled',
'start-added-torrents',
'utp-enabled'
],
// map of keys that are enabled only if a 'parent' key is enabled
groups: {
'alt-speed-time-enabled': ['alt-speed-time-begin',
'alt-speed-time-day',
'alt-speed-time-end' ],
'blocklist-enabled': ['blocklist-url',
'blocklist-update-button' ],
'idle-seeding-limit-enabled': [ 'idle-seeding-limit' ],
'seedRatioLimited': [ 'seedRatioLimit' ],
'speed-limit-down-enabled': [ 'speed-limit-down' ],
'speed-limit-up-enabled': [ 'speed-limit-up' ]
}
},
// map of keys that are enabled only if a 'parent' key is enabled
groups: {
'alt-speed-time-enabled': ['alt-speed-time-begin',
'alt-speed-time-day',
'alt-speed-time-end' ],
'blocklist-enabled': ['blocklist-url',
'blocklist-update-button' ],
'idle-seeding-limit-enabled': [ 'idle-seeding-limit' ],
'seedRatioLimited': [ 'seedRatioLimit' ],
'speed-limit-down-enabled': [ 'speed-limit-down' ],
'speed-limit-up-enabled': [ 'speed-limit-up' ]
}
},
initTimeDropDown = function(e)
{
var i, hour, mins, value, content;
initTimeDropDown = function(e)
{
var i, hour, mins, value, content;
for (i=0; i<24*4; ++i) {
hour = parseInt(i/4, 10);
mins = ((i%4) * 15);
value = i * 15;
content = hour + ':' + (mins || '00');
e.options[i] = new Option(content, value);
}
},
for (i=0; i<24*4; ++i) {
hour = parseInt(i/4, 10);
mins = ((i%4) * 15);
value = i * 15;
content = hour + ':' + (mins || '00');
e.options[i] = new Option(content, value);
}
},
onPortChecked = function(response)
{
var is_open = response['arguments']['port-is-open'],
text = 'Port is <b>' + (is_open ? 'Open' : 'Closed') + '</b>',
e = data.elements.root.find('#port-label');
setInnerHTML(e[0],text);
},
onPortChecked = function(response)
{
var is_open = response['arguments']['port-is-open'],
text = 'Port is <b>' + (is_open ? 'Open' : 'Closed') + '</b>',
e = data.elements.root.find('#port-label');
setInnerHTML(e[0],text);
},
setGroupEnabled = function(parent_key, enabled)
{
var i, key, keys, root;
setGroupEnabled = function(parent_key, enabled)
{
var i, key, keys, root;
if (parent_key in data.groups)
{
root = data.elements.root,
keys = data.groups[parent_key];
if (parent_key in data.groups)
{
root = data.elements.root,
keys = data.groups[parent_key];
for (i=0; key=keys[i]; ++i)
root.find('#'+key).attr('disabled',!enabled);
}
},
for (i=0; key=keys[i]; ++i)
root.find('#'+key).attr('disabled',!enabled);
}
},
onBlocklistUpdateClicked = function ()
{
data.remote.updateBlocklist();
setBlocklistButtonEnabled(false);
},
setBlocklistButtonEnabled = function(b)
{
var e = data.elements.blocklist_button;
e.attr('disabled',!b);
e.val(b ? 'Update' : 'Updating...');
},
onBlocklistUpdateClicked = function ()
{
data.remote.updateBlocklist();
setBlocklistButtonEnabled(false);
},
setBlocklistButtonEnabled = function(b)
{
var e = data.elements.blocklist_button;
e.attr('disabled',!b);
e.val(b ? 'Update' : 'Updating...');
},
getValue = function(e)
{
var str;
getValue = function(e)
{
var str;
switch (e[0].type)
{
case 'checkbox':
case 'radio':
return e.prop('checked');
switch (e[0].type)
{
case 'checkbox':
case 'radio':
return e.prop('checked');
case 'text':
case 'url':
case 'email':
case 'number':
case 'search':
case 'select-one':
str = e.val();
if( parseInt(str,10).toString() === str)
return parseInt(str,10);
if( parseFloat(str).toString() === str)
return parseFloat(str);
return str;
case 'text':
case 'url':
case 'email':
case 'number':
case 'search':
case 'select-one':
str = e.val();
if( parseInt(str,10).toString() === str)
return parseInt(str,10);
if( parseFloat(str).toString() === str)
return parseFloat(str);
return str;
default:
return null;
}
},
default:
return null;
}
},
/* this callback is for controls whose changes can be applied
immediately, like checkboxs, radioboxes, and selects */
onControlChanged = function(ev)
{
var o = {};
o[ev.target.id] = getValue($(ev.target));
data.remote.savePrefs(o);
},
/* this callback is for controls whose changes can be applied
immediately, like checkboxs, radioboxes, and selects */
onControlChanged = function(ev)
{
var o = {};
o[ev.target.id] = getValue($(ev.target));
data.remote.savePrefs(o);
},
/* these two callbacks are for controls whose changes can't be applied
immediately -- like a text entry field -- because it takes many
change events for the user to get to the desired result */
onControlFocused = function(ev)
{
data.oldValue = getValue($(ev.target));
},
onControlBlurred = function(ev)
{
var newValue = getValue($(ev.target));
if (newValue !== data.oldValue)
{
var o = {};
o[ev.target.id] = newValue;
data.remote.savePrefs(o);
delete data.oldValue;
}
},
/* these two callbacks are for controls whose changes can't be applied
immediately -- like a text entry field -- because it takes many
change events for the user to get to the desired result */
onControlFocused = function(ev)
{
data.oldValue = getValue($(ev.target));
},
onControlBlurred = function(ev)
{
var newValue = getValue($(ev.target));
if (newValue !== data.oldValue)
{
var o = {};
o[ev.target.id] = newValue;
data.remote.savePrefs(o);
delete data.oldValue;
}
},
getDefaultMobileOptions = function()
{
return {
width: $(window).width(),
height: $(window).height(),
position: [ 'left', 'top' ]
};
},
getDefaultMobileOptions = function()
{
return {
width: $(window).width(),
height: $(window).height(),
position: [ 'left', 'top' ]
};
},
initialize = function (remote)
{
var i, key, e, o;
initialize = function (remote)
{
var i, key, e, o;
data.remote = remote;
data.remote = remote;
e = $('#prefs-dialog');
data.elements.root = e;
e = $('#prefs-dialog');
data.elements.root = e;
initTimeDropDown(e.find('#alt-speed-time-begin')[0]);
initTimeDropDown(e.find('#alt-speed-time-end')[0]);
initTimeDropDown(e.find('#alt-speed-time-begin')[0]);
initTimeDropDown(e.find('#alt-speed-time-end')[0]);
o = isMobileDevice
? getDefaultMobileOptions()
: { width: 350, height: 400 };
o.autoOpen = false;
o.show = o.hide = 'fade';
o.close = onDialogClosed;
e.tabbedDialog(o);
o = isMobileDevice
? getDefaultMobileOptions()
: { width: 350, height: 400 };
o.autoOpen = false;
o.show = o.hide = 'fade';
o.close = onDialogClosed;
e.tabbedDialog(o);
e = e.find('#blocklist-update-button');
data.elements.blocklist_button = e;
e.click(onBlocklistUpdateClicked);
e = e.find('#blocklist-update-button');
data.elements.blocklist_button = e;
e.click(onBlocklistUpdateClicked);
// listen for user input
for (i=0; key=data.keys[i]; ++i)
{
e = data.elements.root.find('#'+key);
switch (e[0].type)
{
case 'checkbox':
case 'radio':
case 'select-one':
e.change(onControlChanged);
break;
// listen for user input
for (i=0; key=data.keys[i]; ++i)
{
e = data.elements.root.find('#'+key);
switch (e[0].type)
{
case 'checkbox':
case 'radio':
case 'select-one':
e.change(onControlChanged);
break;
case 'text':
case 'url':
case 'email':
case 'number':
case 'search':
e.focus(onControlFocused);
e.blur(onControlBlurred);
case 'text':
case 'url':
case 'email':
case 'number':
case 'search':
e.focus(onControlFocused);
e.blur(onControlBlurred);
default:
break;
}
}
},
default:
break;
}
}
},
getValues = function()
{
var i, key, val, o={},
keys = data.keys,
root = data.elements.root;
getValues = function()
{
var i, key, val, o={},
keys = data.keys,
root = data.elements.root;
for (i=0; key=keys[i]; ++i) {
val = getValue(root.find('#'+key));
if (val !== null)
o[key] = val;
}
for (i=0; key=keys[i]; ++i) {
val = getValue(root.find('#'+key));
if (val !== null)
o[key] = val;
}
return o;
},
return o;
},
onDialogClosed = function()
{
transmission.hideMobileAddressbar();
onDialogClosed = function()
{
transmission.hideMobileAddressbar();
$(data.dialog).trigger('closed', getValues());
};
$(data.dialog).trigger('closed', getValues());
};
/****
***** PUBLIC FUNCTIONS
****/
/****
***** PUBLIC FUNCTIONS
****/
// update the dialog's controls
this.set = function (o)
{
var e, i, key, val, option,
keys = data.keys,
root = data.elements.root;
// update the dialog's controls
this.set = function (o)
{
var e, i, key, val, option,
keys = data.keys,
root = data.elements.root;
setBlocklistButtonEnabled(true);
setBlocklistButtonEnabled(true);
for (i=0; key=keys[i]; ++i)
{
val = o[key];
e = root.find('#'+key);
for (i=0; key=keys[i]; ++i)
{
val = o[key];
e = root.find('#'+key);
if (key === 'blocklist-size')
{
// special case -- regular text area
e.text('' + val.toStringWithCommas());
}
else switch (e[0].type)
{
case 'checkbox':
case 'radio':
e.prop('checked', val);
setGroupEnabled(key, val);
break;
case 'text':
case 'url':
case 'email':
case 'number':
case 'search':
// don't change the text if the user's editing it.
// it's very annoying when that happens!
if (e[0] !== document.activeElement)
e.val(val);
break;
case 'select-one':
e.val(val);
break;
default:
break;
}
}
};
if (key === 'blocklist-size')
{
// special case -- regular text area
e.text('' + val.toStringWithCommas());
}
else switch (e[0].type)
{
case 'checkbox':
case 'radio':
e.prop('checked', val);
setGroupEnabled(key, val);
break;
case 'text':
case 'url':
case 'email':
case 'number':
case 'search':
// don't change the text if the user's editing it.
// it's very annoying when that happens!
if (e[0] !== document.activeElement)
e.val(val);
break;
case 'select-one':
e.val(val);
break;
default:
break;
}
}
};
this.show = function ()
{
transmission.hideMobileAddressbar();
this.show = function ()
{
transmission.hideMobileAddressbar();
setBlocklistButtonEnabled(true);
data.remote.checkPort(onPortChecked,this);
data.elements.root.dialog('open');
};
setBlocklistButtonEnabled(true);
data.remote.checkPort(onPortChecked,this);
data.elements.root.dialog('open');
};
this.close = function ()
{
transmission.hideMobileAddressbar();
data.elements.root.dialog('close');
},
this.close = function ()
{
transmission.hideMobileAddressbar();
data.elements.root.dialog('close');
},
this.shouldAddedTorrentsStart = function()
{
return data.elements.root.find('#start-added-torrents')[0].checked;
};
this.shouldAddedTorrentsStart = function()
{
return data.elements.root.find('#start-added-torrents')[0].checked;
};
data.dialog = this;
initialize (remote);
data.dialog = this;
initialize (remote);
};

View File

@@ -54,8 +54,8 @@ TransmissionRemote.prototype =
}
remote._error = request.responseText
? request.responseText.trim().replace(/(<([^>]+)>)/ig,"")
: "";
? request.responseText.trim().replace(/(<([^>]+)>)/ig,"")
: "";
if (!remote._error.length)
remote._error = 'Server not responding';
@@ -108,10 +108,13 @@ TransmissionRemote.prototype =
},
renameTorrent: function(torrentIds, oldpath, newname, callback, context) {
var o = { method: 'torrent-rename-path',
arguments: { 'ids': torrentIds,
'path': oldpath,
'name': newname }
var o = {
method: 'torrent-rename-path',
arguments: {
'ids': torrentIds,
'path': oldpath,
'name': newname
}
};
this.sendRequest(o, callback, context);
},
@@ -124,7 +127,7 @@ TransmissionRemote.prototype =
updateTorrents: function(torrentIds, fields, callback, context) {
var o = {
method: 'torrent-get',
'arguments': {
arguments: {
'fields': fields
}
};

View File

@@ -239,10 +239,10 @@ TorrentRendererFull.prototype =
' (', t.getPercentDoneStr(), '%)' ];
// append UL stats: ', uploaded 8.59 GiB (Ratio: 12.3)'
c.push(', uploaded ',
Transmission.fmt.size(t.getUploadedEver()),
' (Ratio ',
Transmission.fmt.ratioString(t.getUploadRatio()),
')');
Transmission.fmt.size(t.getUploadedEver()),
' (Ratio ',
Transmission.fmt.ratioString(t.getUploadRatio()),
')');
} else { // not done yet
c = [ Transmission.fmt.size(sizeWhenDone - t.getLeftUntilDone()),
' of ', Transmission.fmt.size(sizeWhenDone),
@@ -257,7 +257,7 @@ TorrentRendererFull.prototype =
c.push('remaining time unknown');
else
c.push(Transmission.fmt.timeInterval(t.getETA()),
' remaining');
' remaining');
}
return c.join('');

View File

@@ -420,14 +420,13 @@ Torrent.compareByProgress = function(ta, tb)
return (a - b) || Torrent.compareByRatio(ta, tb);
};
Torrent.compareBySize = function(ta, tb)
{
var a = ta.getTotalSize(),
b = tb.getTotalSize();
var a = ta.getTotalSize(),
b = tb.getTotalSize();
return (a - b) || Torrent.compareByName(ta, tb);
}
return (a - b) || Torrent.compareByName(ta, tb);
};
Torrent.compareTorrents = function(a, b, sortMethod, sortDirection)
{
@@ -447,9 +446,9 @@ Torrent.compareTorrents = function(a, b, sortMethod, sortDirection)
case Prefs._SortByProgress:
i = Torrent.compareByProgress(a,b);
break;
case Prefs._SortBySize:
i = Torrent.compareBySize(a,b);
break;
case Prefs._SortBySize:
i = Torrent.compareBySize(a,b);
break;
case Prefs._SortByState:
i = Torrent.compareByState(a,b);
break;
@@ -488,9 +487,9 @@ Torrent.sortTorrents = function(torrents, sortMethod, sortDirection)
case Prefs._SortByProgress:
torrents.sort(this.compareByProgress);
break;
case Prefs._SortBySize:
torrents.sort(this.compareBySize);
break;
case Prefs._SortBySize:
torrents.sort(this.compareBySize);
break;
case Prefs._SortByState:
torrents.sort(this.compareByState);
break;

View File

@@ -606,7 +606,7 @@ Transmission.prototype =
clearInterval(this.sessionInterval);
delete this.sessionInterval;
if (enabled) {
var callback = $.proxy(this.loadDaemonPrefs,this),
var callback = $.proxy(this.loadDaemonPrefs,this),
msec = 8000;
this.sessionInterval = setInterval(callback, msec);
}
@@ -1199,8 +1199,8 @@ Transmission.prototype =
updateGuiFromSession: function(o)
{
var limit, limited, e, b, text,
fmt = Transmission.fmt,
menu = $('#footer_super_menu');
fmt = Transmission.fmt,
menu = $('#footer_super_menu');
this.serverVersion = o.version;
@@ -1227,10 +1227,10 @@ Transmission.prototype =
limited = o[RPC._DownSpeedLimited];
e = menu.find('#limited_download_rate');
e.html('Limit (' + fmt.speed(limit) + ')');
e.html('Limit (' + fmt.speed(limit) + ')');
if (!limited)
e = menu.find('#unlimited_download_rate');
if (!limited)
e = menu.find('#unlimited_download_rate');
e.selectMenuItem();
}
@@ -1241,10 +1241,10 @@ Transmission.prototype =
limited = o[RPC._UpSpeedLimited];
e = menu.find('#limited_upload_rate');
e.html('Limit (' + fmt.speed(limit) + ')');
e.html('Limit (' + fmt.speed(limit) + ')');
if (!limited)
e = menu.find('#unlimited_upload_rate');
if (!limited)
e = menu.find('#unlimited_upload_rate');
e.selectMenuItem();
}
},
@@ -1680,7 +1680,7 @@ Transmission.prototype =
delete this.statsInterval;
if (enabled) {
var callback = $.proxy(this.loadDaemonStats,this),
msec = 5000;
msec = 5000;
this.statsInterval = setInterval(callback, msec);
}
},