Skip to content

Commit c73e888

Browse files
author
epriestley
committed
Consolidate file pasting code
Summary: Fixes T2861. This used to work but I think I broke it when I made the notification popup thing work. Merge it into the drag-and-drop since 90% of the code is the same anyway. Test Plan: Pasted files into Chrome and got uploads. This doesn't work in Safari and Firefox; as far as I know it isn't supported in those browers. Reviewers: blc, btrahan, chad Reviewed By: btrahan CC: aran Maniphest Tasks: T2861 Differential Revision: https://secure.phabricator.com/D5530
1 parent a97968b commit c73e888

File tree

4 files changed

+26
-78
lines changed

4 files changed

+26
-78
lines changed

scripts/celerity_mapper.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
'javelin-behavior-refresh-csrf',
3434
'javelin-behavior-phabricator-watch-anchor',
3535
'javelin-behavior-phabricator-autofocus',
36-
'phabricator-paste-file-upload',
3736
'phabricator-menu-item',
3837
'phabricator-dropdown-menu',
3938
'javelin-behavior-phabricator-oncopy',

webroot/rsrc/js/application/core/DragAndDropFileUpload.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ JX.install('PhabricatorDragAndDropFileUpload', {
2828
// TODO: Is there a better capability test for this? This seems okay in
2929
// Safari, Firefox and Chrome.
3030

31+
return !!window.FileList;
32+
},
33+
isPasteSupported : function() {
34+
// TODO: Needs to check if event.clipboardData is available.
35+
// Works in Chrome, doesn't work in Firefox 10.
3136
return !!window.FileList;
3237
}
3338
},
@@ -109,6 +114,27 @@ JX.install('PhabricatorDragAndDropFileUpload', {
109114
// Force depth to 0.
110115
this._updateDepth(-this._depth);
111116
}));
117+
118+
if (JX.PhabricatorDragAndDropFileUpload.isPasteSupported()) {
119+
JX.DOM.listen(
120+
this._node,
121+
'paste',
122+
null,
123+
JX.bind(this, function(e) {
124+
var clipboardData = e.getRawEvent().clipboardData;
125+
if (!clipboardData) {
126+
return;
127+
}
128+
129+
for (var ii = 0; ii < clipboardData.items.length; ii++) {
130+
var item = clipboardData.items[ii];
131+
if (!/^image\//.test(item.type)) {
132+
continue;
133+
}
134+
this._sendRequest(item.getAsFile());
135+
}
136+
}));
137+
}
112138
},
113139
_sendRequest : function(spec) {
114140
var file = new JX.PhabricatorFileUpload()

webroot/rsrc/js/application/core/PasteFileUpload.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

webroot/rsrc/js/application/core/behavior-drag-and-drop-textarea.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @requires javelin-behavior
44
* javelin-dom
55
* phabricator-drag-and-drop-file-upload
6-
* phabricator-paste-file-upload
76
* phabricator-textareautils
87
*/
98

@@ -39,12 +38,5 @@ JX.behavior('aphront-drag-and-drop-textarea', function(config) {
3938
drop.start();
4039
}
4140

42-
if (JX.PhabricatorPasteFileUpload.isSupported()) {
43-
var paste = new JX.PhabricatorPasteFileUpload(target)
44-
.setURI(config.uri);
45-
paste.listen('didUpload', onupload);
46-
paste.start();
47-
}
48-
4941
});
5042

0 commit comments

Comments
 (0)