mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-29 22:45:14 -04:00
Dropbox feature nearly done.
This commit is contained in:
parent
f915bdea3b
commit
14960af036
1 changed files with 33 additions and 69 deletions
|
@ -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 = {
|
var defaults = {
|
||||||
enabled: true
|
enabled: false,
|
||||||
|
maxfiles: 5,
|
||||||
|
maxfilesize: 20
|
||||||
},
|
},
|
||||||
|
|
||||||
settings = _.extend({}, defaults, allsettings.dropbox),
|
settings = _.extend({}, defaults, allsettings.dropbox),
|
||||||
|
@ -11,8 +13,8 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry'], functi
|
||||||
|
|
||||||
uploadTemplate = '<li class="upload clearfix">' +
|
uploadTemplate = '<li class="upload clearfix">' +
|
||||||
'<span class="name"></span>' +
|
'<span class="name"></span>' +
|
||||||
'<div class="progress"><div class="bar"></div></div>' +
|
|
||||||
'<span class="size"></span>' +
|
'<span class="size"></span>' +
|
||||||
|
'<div class="progress"><div class="bar"></div></div>' +
|
||||||
'</li>',
|
'</li>',
|
||||||
|
|
||||||
init = function () {
|
init = function () {
|
||||||
|
@ -23,16 +25,34 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry'], functi
|
||||||
|
|
||||||
var $dropbox = $(template).appendTo('#content');
|
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',
|
paramname: 'userfile',
|
||||||
|
|
||||||
maxfiles: 24,
|
maxfiles: settings.maxfiles,
|
||||||
maxfilesize: 1024,
|
maxfilesize: settings.maxfilesize,
|
||||||
url: allsettings.h5aiAbsHref + 'php/api.php',
|
url: resource.api(),
|
||||||
data: {
|
data: {
|
||||||
action: 'upload',
|
action: 'upload',
|
||||||
href: entry.absHref
|
href: entry.absHref
|
||||||
|
@ -48,19 +68,9 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry'], functi
|
||||||
$dropbox.removeClass('match');
|
$dropbox.removeClass('match');
|
||||||
},
|
},
|
||||||
|
|
||||||
docOver: function () {
|
|
||||||
|
|
||||||
$dropbox.addClass('hint');
|
|
||||||
},
|
|
||||||
|
|
||||||
docLeave: function () {
|
|
||||||
|
|
||||||
$dropbox.removeClass('hint');
|
|
||||||
},
|
|
||||||
|
|
||||||
drop: function () {
|
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('.name').text(file.name).end()
|
||||||
.find('.size').text(file.size).end()
|
.find('.size').text(file.size).end()
|
||||||
.find('.progress .bar').css('width', 0).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) {
|
progressUpdated: function (i, file, progress) {
|
||||||
|
|
||||||
uploads[file.name]
|
uploads[file.name].find('.progress .bar').css('width', '' + progress + '%');
|
||||||
.find('.progress .bar').css('width', '' + progress + '%');
|
|
||||||
console.log('progressUpdated', i, file, progress);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
uploadFinished: function (i, file, response) {
|
uploadFinished: function (i, file, response) {
|
||||||
|
|
||||||
uploads[file.name].addClass(response.code ? 'error' : 'finished');
|
afterUpload(response.code && response.msg, file);
|
||||||
setTimeout(function () {
|
|
||||||
uploads[file.name].slideUp(400, function () {
|
|
||||||
|
|
||||||
uploads[file.name].remove();
|
|
||||||
});
|
|
||||||
}, 5000);
|
|
||||||
console.log('uploadFinished', i, file, response);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
afterAll: function () {
|
|
||||||
|
|
||||||
// $('#uploads .upload').remove();
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
error: function (err, file) {
|
error: function (err, file) {
|
||||||
|
|
||||||
uploads[file.name].addClass('error');
|
afterUpload(err, file);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue