mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 12:34:47 -04:00
Updates download.
This commit is contained in:
parent
b8503b6f03
commit
580653a1ad
3 changed files with 27 additions and 34 deletions
|
@ -23,6 +23,22 @@ modulejs.define('core/server', ['$', '_', 'config', 'core/location'], function (
|
||||||
} else {
|
} else {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
formRequest: function (data) {
|
||||||
|
|
||||||
|
var $form = $('<form method="post" style="display:none;"/>')
|
||||||
|
.attr('action', location.getAbsHref());
|
||||||
|
|
||||||
|
_.each(data, function (val, key) {
|
||||||
|
|
||||||
|
$('<input type="hidden"/>')
|
||||||
|
.attr('name', key)
|
||||||
|
.attr('value', val)
|
||||||
|
.appendTo($form);
|
||||||
|
});
|
||||||
|
|
||||||
|
$form.appendTo('body').submit().remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/server', 'core/location'], function (_, $, allsettings, resource, event, server, location) {
|
modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/location', 'core/server'], function (_, $, allsettings, resource, event, location, server) {
|
||||||
|
|
||||||
var settings = _.extend({
|
var settings = _.extend({
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -7,8 +7,6 @@ modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'co
|
||||||
packageName: 'package'
|
packageName: 'package'
|
||||||
}, allsettings.download),
|
}, allsettings.download),
|
||||||
|
|
||||||
// formats = ['tar', 'zip'],
|
|
||||||
|
|
||||||
downloadBtnTemplate = '<li id="download">' +
|
downloadBtnTemplate = '<li id="download">' +
|
||||||
'<a href="#">' +
|
'<a href="#">' +
|
||||||
'<img src="' + resource.image('download') + '" alt="download"/>' +
|
'<img src="' + resource.image('download') + '" alt="download"/>' +
|
||||||
|
@ -16,25 +14,14 @@ modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'co
|
||||||
'</a>' +
|
'</a>' +
|
||||||
'</li>',
|
'</li>',
|
||||||
|
|
||||||
selectedHrefsStr = '',
|
selectedItems = [],
|
||||||
$download, $img,
|
|
||||||
|
|
||||||
failed = function () {
|
|
||||||
|
|
||||||
$download.addClass('failed');
|
|
||||||
setTimeout(function () {
|
|
||||||
$download.removeClass('failed');
|
|
||||||
}, 1000);
|
|
||||||
},
|
|
||||||
|
|
||||||
onSelection = function (items) {
|
onSelection = function (items) {
|
||||||
|
|
||||||
selectedHrefsStr = '';
|
var $download = $('#download');
|
||||||
if (items.length) {
|
|
||||||
selectedHrefsStr = _.map(items, function (item) {
|
|
||||||
|
|
||||||
return item.absHref;
|
selectedItems = items.slice(0);
|
||||||
}).join('|:|');
|
if (selectedItems.length) {
|
||||||
$download.appendTo('#navbar').show();
|
$download.appendTo('#navbar').show();
|
||||||
} else {
|
} else {
|
||||||
$download.hide();
|
$download.hide();
|
||||||
|
@ -49,31 +36,21 @@ modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'co
|
||||||
action: 'download',
|
action: 'download',
|
||||||
as: (settings.packageName || location.getItem().label) + '.' + extension,
|
as: (settings.packageName || location.getItem().label) + '.' + extension,
|
||||||
type: type,
|
type: type,
|
||||||
hrefs: selectedHrefsStr
|
hrefs: _.pluck(selectedItems, 'absHref').join('|:|')
|
||||||
},
|
};
|
||||||
$form = $('<form action="#" method="post" style="display:none;"/>');
|
|
||||||
|
|
||||||
_.each(query, function (val, key) {
|
server.formRequest(query);
|
||||||
|
|
||||||
$('<input type="hidden"/>')
|
|
||||||
.attr('name', key)
|
|
||||||
.attr('value', val)
|
|
||||||
.appendTo($form);
|
|
||||||
});
|
|
||||||
|
|
||||||
$form.appendTo('body').submit().remove();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
init = function () {
|
init = function () {
|
||||||
|
|
||||||
if (!settings.enabled || !server.api) {
|
if (!settings.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$download = $(downloadBtnTemplate)
|
$(downloadBtnTemplate)
|
||||||
.find('a').on('click', onClick).end()
|
.find('a').on('click', onClick).end()
|
||||||
.appendTo('#navbar');
|
.appendTo('#navbar');
|
||||||
$img = $download.find('img');
|
|
||||||
|
|
||||||
event.sub('selection', onSelection);
|
event.sub('selection', onSelection);
|
||||||
};
|
};
|
||||||
|
|
|
@ -92,7 +92,7 @@ Options
|
||||||
Allow file deletion.
|
Allow file deletion.
|
||||||
*/
|
*/
|
||||||
"delete": {
|
"delete": {
|
||||||
"enabled": true
|
"enabled": false
|
||||||
},
|
},
|
||||||
|
|
||||||
/* [EXPERIMENTAL]
|
/* [EXPERIMENTAL]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue