-
-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
160 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div :class="'drag-n-drop ' + (receiving ? 'receiving' : '')" @drop.prevent="fileReceived"> | ||
<div class="label"> | ||
<slot></slot> | ||
</div> | ||
|
||
<div class="inner-border"></div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,51 @@ | ||
/* | ||
Manages a drag-and-drop-target on a component. When a file is dragged onto it, | ||
this component dispatches a `file-drag-n-drop` event to its parent. | ||
*/ | ||
|
||
const Vue = require('vue'); | ||
const { default: { on, off } } = require('oui-dom-events'); | ||
const domEvents = require('../../vue/mixins/dom-events'); | ||
|
||
module.exports = Vue.extend({ | ||
template: | ||
`<div :class="'drag-n-drop ' + (dragover ? 'dragover' : '')"> | ||
<div class='label'> | ||
<slot></slot> | ||
</div> | ||
<div class='inner-border'></div> | ||
</div>`, | ||
template: require('./index.html'), | ||
|
||
data: () => ({ | ||
dragover: false, | ||
/* Whether the user has a file dragged onto this component. */ | ||
|
||
receiving: false | ||
}), | ||
|
||
ready() { | ||
const {$el, $parent:{$el:parentEl}} = this; | ||
const parentEl = this.$parent.$el; | ||
|
||
on(parentEl, 'dragenter.file-drag-n-drop', () => { | ||
this.dragover = true; | ||
}); | ||
/* | ||
Make ourselves visible when the user drags a file onto us. | ||
*/ | ||
|
||
on(parentEl, 'dragexit.file-drag-n-drop', () => { | ||
this.dragover = false; | ||
this.on(parentEl, 'dragenter', () => { | ||
this.receiving = true; | ||
}); | ||
// The below is necessary to prevent the browser from | ||
// opening the file directly, on drop. | ||
on(parentEl, 'dragover.file-drag-n-drop', e => { | ||
e.preventDefault(); | ||
|
||
this.on(parentEl, 'dragexit', () => { | ||
this.receiving = false; | ||
}); | ||
on($el, 'drop', e => { | ||
|
||
/* | ||
The below is necessary to prevent the browser from opening the file | ||
directly after the user drops a file on us. | ||
*/ | ||
|
||
this.on(parentEl, 'dragover', e => { | ||
e.preventDefault(); | ||
this.$dispatch('file-drag-n-drop', e.dataTransfer.files); | ||
this.dragover = false; | ||
}); | ||
}, | ||
|
||
beforeDestroy() { | ||
off(this.$parent.$el, '.file-drag-n-drop'); | ||
methods: { | ||
fileReceived(e) { | ||
this.$dispatch('file-drag-n-drop', e.dataTransfer.files); | ||
this.receiving = false; | ||
} | ||
}, | ||
|
||
mixins: [domEvents] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.