Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
🐜 🎊 Fix firefox drag and drop support for image uploading in markdown…
Browse files Browse the repository at this point in the history
… cards. (#640)

closes TryGhost/Ghost#8315
- Previously you couldn't upload images in markdown cards in firefox. Moving the drop action off of the component and onto the root editor as well as having an dragover handler which does nothing fixed the issue 🤷
  • Loading branch information
disordinary authored and kevinansfield committed Apr 13, 2017
1 parent 720b947 commit 14bbb0d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions lib/gh-koenig/addon/components/gh-koenig.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,6 @@ export default Component.extend({
editor.cursorDidChange(() => this.cursorMoved());
},

// drag and drop images onto the editor
drop(event) {
if (event.dataTransfer.files.length) {
event.preventDefault();
for (let i = 0; i < event.dataTransfer.files.length; i++) {
let file = [event.dataTransfer.files[i]];
this.editor.insertCard('card-image', {pos: 'top', file});
}
}
},

// makes sure the cursor is on screen except when selection is happening in which case the browser mostly ensures it.
// there is an issue with keyboard selection on some browsers though so the next step will be to record mouse and touch events.
cursorMoved() {
Expand Down Expand Up @@ -411,6 +400,20 @@ export default Component.extend({
},
menuIsClosed() {
this.sendAction('menuIsClosed');
},
// drag and drop images onto the editor
dropImage(event) {
if (event.dataTransfer.files.length) {
event.preventDefault();
for (let i = 0; i < event.dataTransfer.files.length; i++) {
let file = [event.dataTransfer.files[i]];
this.editor.insertCard('card-image', {pos: 'top', file});
}
}
},
dragOver(event) {
// required for drop events to fire on markdown cards in firefox.
event.preventDefault();
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/gh-koenig/addon/templates/components/gh-koenig.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{/ember-wormhole}}
{{/each}}
<div class='gh-koenig'>
<div class='surface needsclick' tabindex="{{tabindex}}"/>
<div class='surface needsclick' tabindex="{{tabindex}}" ondrop={{action "dropImage"}} ondragover={{action "dragOver"}} />
</div>

{{yield}}
Expand Down

0 comments on commit 14bbb0d

Please sign in to comment.