support drag and drop
This commit is contained in:
parent
2cbcc9e7dd
commit
25c24d6f20
4 changed files with 121 additions and 2 deletions
|
|
@ -93,6 +93,25 @@
|
|||
Ox.$window.on({
|
||||
resize: oml.resizeWindow
|
||||
});
|
||||
Ox.$document.on({
|
||||
dragenter: function(event) {
|
||||
event.preventDefault();
|
||||
},
|
||||
dragover: function(event) {
|
||||
event.preventDefault();
|
||||
},
|
||||
drop: function(event) {
|
||||
if (event.originalEvent.dataTransfer.files) {
|
||||
event.preventDefault();
|
||||
oml.upload(event.originalEvent.dataTransfer.files, function(response) {
|
||||
setTimeout(function() {
|
||||
oml.UI.set({listSelection: response.data.ids});
|
||||
oml.reloadList();
|
||||
}, 50);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
oml.$ui.appPanel = oml.ui.appPanel().appendTo(Ox.$body);
|
||||
oml.$ui.loadingIcon.updateElement(Ox.Request.requests());
|
||||
Ox.Request.bindEvent({
|
||||
|
|
|
|||
|
|
@ -999,3 +999,33 @@ oml.updateDebugMenu = function() {
|
|||
});
|
||||
oml.user.ui.showDebugMenu ? menu.show() : menu.hide();
|
||||
};
|
||||
|
||||
oml.supportedExtensions = ['pdf', 'epub', 'cbr', 'cbz'];
|
||||
oml.upload = function(files, callback) {
|
||||
var request = new XMLHttpRequest(),
|
||||
url = '/api/upload/';
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState == 4) {
|
||||
if (request.status == 200) {
|
||||
callback(JSON.parse(request.responseText), null);
|
||||
} else {
|
||||
callback(null, {
|
||||
code: request.status,
|
||||
text: request.statusText
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
var formData = new FormData();
|
||||
for (var i=0; i < files.length; i++) {
|
||||
var extension = Ox.last(files[i].name.split('.'));
|
||||
if (Ox.contains(oml.supportedExtensions, extension)) {
|
||||
formData.append('files', files[i]);
|
||||
}
|
||||
}
|
||||
if (oml.user.ui._list[0] == ':' && oml.user.ui._list.length > 1) {
|
||||
formData.append('list', oml.user.ui._list.slice(1));
|
||||
}
|
||||
request.open('post', url, true);
|
||||
request.send(formData);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue