mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-03-19 12:00:01 +01:00
Dropbox feature nearly done.
This commit is contained in:
parent
f915bdea3b
commit
14960af036
@ -1,8 +1,10 @@
|
||||
|
||||
modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry'], function (_, $, allsettings, entry) {
|
||||
modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry', 'core/resource'], function (_, $, allsettings, entry, resource) {
|
||||
|
||||
var defaults = {
|
||||
enabled: true
|
||||
enabled: false,
|
||||
maxfiles: 5,
|
||||
maxfilesize: 20
|
||||
},
|
||||
|
||||
settings = _.extend({}, defaults, allsettings.dropbox),
|
||||
@ -11,8 +13,8 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry'], functi
|
||||
|
||||
uploadTemplate = '<li class="upload clearfix">' +
|
||||
'<span class="name"></span>' +
|
||||
'<div class="progress"><div class="bar"></div></div>' +
|
||||
'<span class="size"></span>' +
|
||||
'<div class="progress"><div class="bar"></div></div>' +
|
||||
'</li>',
|
||||
|
||||
init = function () {
|
||||
@ -23,16 +25,34 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry'], functi
|
||||
|
||||
var $dropbox = $(template).appendTo('#content');
|
||||
|
||||
var uploads = {};
|
||||
var uploads = {},
|
||||
afterUpload = function (err, file, timeout) {
|
||||
|
||||
$dropbox.filedrop({
|
||||
timeout = timeout || 5000;
|
||||
|
||||
if (file) {
|
||||
uploads[file.name]
|
||||
.addClass(err ? 'error' : 'finished')
|
||||
.find('.progress').replaceWith(err ? '<span class="error">' + err + '</span>' : '<span class="finished">okay</span>');
|
||||
|
||||
setTimeout(function () {
|
||||
uploads[file.name].slideUp(400, function () {
|
||||
|
||||
uploads[file.name].remove();
|
||||
delete uploads[file.name];
|
||||
});
|
||||
}, timeout);
|
||||
}
|
||||
};
|
||||
|
||||
// $dropbox.filedrop({
|
||||
$('html').filedrop({
|
||||
|
||||
// The name of the $_FILES entry:
|
||||
paramname: 'userfile',
|
||||
|
||||
maxfiles: 24,
|
||||
maxfilesize: 1024,
|
||||
url: allsettings.h5aiAbsHref + 'php/api.php',
|
||||
maxfiles: settings.maxfiles,
|
||||
maxfilesize: settings.maxfilesize,
|
||||
url: resource.api(),
|
||||
data: {
|
||||
action: 'upload',
|
||||
href: entry.absHref
|
||||
@ -48,19 +68,9 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry'], functi
|
||||
$dropbox.removeClass('match');
|
||||
},
|
||||
|
||||
docOver: function () {
|
||||
|
||||
$dropbox.addClass('hint');
|
||||
},
|
||||
|
||||
docLeave: function () {
|
||||
|
||||
$dropbox.removeClass('hint');
|
||||
},
|
||||
|
||||
drop: function () {
|
||||
|
||||
$dropbox.removeClass('match hint');
|
||||
$dropbox.removeClass('match');
|
||||
},
|
||||
|
||||
|
||||
@ -70,69 +80,23 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry'], functi
|
||||
.find('.name').text(file.name).end()
|
||||
.find('.size').text(file.size).end()
|
||||
.find('.progress .bar').css('width', 0).end();
|
||||
|
||||
console.log('beforeEach', file);
|
||||
},
|
||||
|
||||
uploadStarted: function (i, file, len) {
|
||||
|
||||
console.log('uploadStarted', i, file, len);
|
||||
},
|
||||
|
||||
progressUpdated: function (i, file, progress) {
|
||||
|
||||
uploads[file.name]
|
||||
.find('.progress .bar').css('width', '' + progress + '%');
|
||||
console.log('progressUpdated', i, file, progress);
|
||||
uploads[file.name].find('.progress .bar').css('width', '' + progress + '%');
|
||||
},
|
||||
|
||||
uploadFinished: function (i, file, response) {
|
||||
|
||||
uploads[file.name].addClass(response.code ? 'error' : 'finished');
|
||||
setTimeout(function () {
|
||||
uploads[file.name].slideUp(400, function () {
|
||||
|
||||
uploads[file.name].remove();
|
||||
});
|
||||
}, 5000);
|
||||
console.log('uploadFinished', i, file, response);
|
||||
afterUpload(response.code && response.msg, file);
|
||||
},
|
||||
|
||||
afterAll: function () {
|
||||
|
||||
// $('#uploads .upload').remove();
|
||||
},
|
||||
|
||||
|
||||
error: function (err, file) {
|
||||
|
||||
uploads[file.name].addClass('error');
|
||||
setTimeout(function () {
|
||||
uploads[file.name].slideUp(400, function () {
|
||||
|
||||
uploads[file.name].remove();
|
||||
});
|
||||
}, 5000);
|
||||
switch (err) {
|
||||
case 'BrowserNotSupported':
|
||||
console.log('ERROR', 'Your browser does not support HTML5 file uploads!');
|
||||
break;
|
||||
case 'TooManyFiles':
|
||||
console.log('ERROR', 'Too many files! Please select 5 at most! (configurable)');
|
||||
break;
|
||||
case 'FileTooLarge':
|
||||
console.log('ERROR', file.name + ' is too large! Please upload files up to 2mb (configurable).');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
console.log('error', err, file);
|
||||
afterUpload(err, file);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
init();
|
||||
|
Loading…
x
Reference in New Issue
Block a user