Clean code.

This commit is contained in:
Lars Jung 2014-08-30 18:53:16 +02:00
parent ba10f70b12
commit 8951732f3c
42 changed files with 2547 additions and 2572 deletions

View file

@ -1,4 +1,3 @@
modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/location', 'core/server'], function (_, $, allsettings, resource, event, location, server) {
var settings = _.extend({
@ -6,60 +5,60 @@ modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'co
type: 'php-tar',
packageName: 'package',
alwaysVisible: false
}, allsettings.download),
downloadBtnTemplate =
}, allsettings.download);
var downloadBtnTemplate =
'<li id="download">' +
'<a href="#">' +
'<img src="' + resource.image('download') + '" alt="download"/>' +
'<span class="l10n-download"/>' +
'</a>' +
'</li>',
'</li>';
var selectedItems = [];
selectedItems = [],
onSelection = function (items) {
function onSelection(items) {
var $download = $('#download');
var $download = $('#download');
selectedItems = items.slice(0);
if (selectedItems.length) {
$download.show();
} else if (!settings.alwaysVisible) {
$download.hide();
}
},
selectedItems = items.slice(0);
if (selectedItems.length) {
$download.show();
} else if (!settings.alwaysVisible) {
$download.hide();
}
}
onClick = function (event) {
function onClick(event) {
var type = settings.type,
extension = (type === 'shell-zip') ? 'zip' : 'tar',
query = {
action: 'download',
as: (settings.packageName || location.getItem().label) + '.' + extension,
type: type,
hrefs: _.pluck(selectedItems, 'absHref').join('|:|')
};
var type = settings.type;
var extension = (type === 'shell-zip') ? 'zip' : 'tar';
var query = {
action: 'download',
as: (settings.packageName || location.getItem().label) + '.' + extension,
type: type,
hrefs: _.pluck(selectedItems, 'absHref').join('|:|')
};
server.formRequest(query);
},
server.formRequest(query);
}
init = function () {
function init() {
if (!settings.enabled) {
return;
}
if (!settings.enabled) {
return;
}
$(downloadBtnTemplate)
.find('a').on('click', onClick).end()
.appendTo('#navbar');
$(downloadBtnTemplate)
.find('a').on('click', onClick).end()
.appendTo('#navbar');
if (settings.alwaysVisible) {
$('#download').show();
}
if (settings.alwaysVisible) {
$('#download').show();
}
event.sub('selection', onSelection);
}
event.sub('selection', onSelection);
};
init();
});