78dd776426
Initially a lot of code was copied from another project. This lead to confusing naming conventions.
48 lines
1.4 KiB
HTML
48 lines
1.4 KiB
HTML
<link rel="import" href="file-selection-behavior.html">
|
|
<script>
|
|
'use strict';
|
|
window.Snapdrop = window.Snapdrop || {};
|
|
Snapdrop.FileDropBehaviorImpl = {
|
|
attached: function() {
|
|
var dropZone = this;
|
|
|
|
dropZone.addEventListener('dragover', function(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
e.dataTransfer.dropEffect = 'copy';
|
|
dropZone.style.transform = 'scale(1.2)';
|
|
}, false);
|
|
|
|
var dragEnd = function() {
|
|
dropZone.style.transform = 'scale(1)';
|
|
};
|
|
|
|
dropZone.addEventListener('dragleave', dragEnd, false);
|
|
dropZone.addEventListener('dragexit', dragEnd, false);
|
|
dropZone.addEventListener('dragend', dragEnd, false);
|
|
|
|
// Get file data on drop
|
|
dropZone.addEventListener('drop', function(event) {
|
|
event.stopPropagation();
|
|
event.preventDefault();
|
|
|
|
//drop is a dragend
|
|
dragEnd();
|
|
|
|
// Get files
|
|
var files = event.dataTransfer.files;
|
|
// Notify Selection
|
|
this.notifyFilesSelection(files);
|
|
});
|
|
}
|
|
};
|
|
document.body.addEventListener('dragover', function(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
}, false);
|
|
document.body.addEventListener('drop', function(event) {
|
|
event.stopPropagation();
|
|
event.preventDefault();
|
|
});
|
|
Snapdrop.FileDropBehavior = [Snapdrop.FileDropBehaviorImpl, Snapdrop.FileSelectionBehavior];
|
|
</script>
|