mirror of
https://we.phorge.it/source/phorge.git
synced 2024-09-19 16:58:48 +02:00
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
This commit is contained in:
parent
a97968b9ff
commit
c73e888ad4
4 changed files with 26 additions and 78 deletions
|
@ -33,7 +33,6 @@ $package_spec = array(
|
||||||
'javelin-behavior-refresh-csrf',
|
'javelin-behavior-refresh-csrf',
|
||||||
'javelin-behavior-phabricator-watch-anchor',
|
'javelin-behavior-phabricator-watch-anchor',
|
||||||
'javelin-behavior-phabricator-autofocus',
|
'javelin-behavior-phabricator-autofocus',
|
||||||
'phabricator-paste-file-upload',
|
|
||||||
'phabricator-menu-item',
|
'phabricator-menu-item',
|
||||||
'phabricator-dropdown-menu',
|
'phabricator-dropdown-menu',
|
||||||
'javelin-behavior-phabricator-oncopy',
|
'javelin-behavior-phabricator-oncopy',
|
||||||
|
|
|
@ -28,6 +28,11 @@ JX.install('PhabricatorDragAndDropFileUpload', {
|
||||||
// TODO: Is there a better capability test for this? This seems okay in
|
// TODO: Is there a better capability test for this? This seems okay in
|
||||||
// Safari, Firefox and Chrome.
|
// Safari, Firefox and Chrome.
|
||||||
|
|
||||||
|
return !!window.FileList;
|
||||||
|
},
|
||||||
|
isPasteSupported : function() {
|
||||||
|
// TODO: Needs to check if event.clipboardData is available.
|
||||||
|
// Works in Chrome, doesn't work in Firefox 10.
|
||||||
return !!window.FileList;
|
return !!window.FileList;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -109,6 +114,27 @@ JX.install('PhabricatorDragAndDropFileUpload', {
|
||||||
// Force depth to 0.
|
// Force depth to 0.
|
||||||
this._updateDepth(-this._depth);
|
this._updateDepth(-this._depth);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
if (JX.PhabricatorDragAndDropFileUpload.isPasteSupported()) {
|
||||||
|
JX.DOM.listen(
|
||||||
|
this._node,
|
||||||
|
'paste',
|
||||||
|
null,
|
||||||
|
JX.bind(this, function(e) {
|
||||||
|
var clipboardData = e.getRawEvent().clipboardData;
|
||||||
|
if (!clipboardData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var ii = 0; ii < clipboardData.items.length; ii++) {
|
||||||
|
var item = clipboardData.items[ii];
|
||||||
|
if (!/^image\//.test(item.type)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
this._sendRequest(item.getAsFile());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_sendRequest : function(spec) {
|
_sendRequest : function(spec) {
|
||||||
var file = new JX.PhabricatorFileUpload()
|
var file = new JX.PhabricatorFileUpload()
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
/**
|
|
||||||
* @requires javelin-install
|
|
||||||
* javelin-util
|
|
||||||
* javelin-request
|
|
||||||
* javelin-dom
|
|
||||||
* javelin-uri
|
|
||||||
* @provides phabricator-paste-file-upload
|
|
||||||
* @javelin
|
|
||||||
*/
|
|
||||||
|
|
||||||
JX.install('PhabricatorPasteFileUpload', {
|
|
||||||
|
|
||||||
construct : function(node) {
|
|
||||||
this._node = node;
|
|
||||||
},
|
|
||||||
|
|
||||||
events : ['willUpload', 'didUpload'],
|
|
||||||
|
|
||||||
statics : {
|
|
||||||
isSupported : function() {
|
|
||||||
// TODO: Needs to check if event.clipboardData is available.
|
|
||||||
// Works in Chrome, doesn't work in Firefox 10.
|
|
||||||
return !!window.FileList;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
members : {
|
|
||||||
_node : null,
|
|
||||||
|
|
||||||
start : function() {
|
|
||||||
JX.DOM.listen(
|
|
||||||
this._node,
|
|
||||||
'paste',
|
|
||||||
null,
|
|
||||||
JX.bind(this, function(e) {
|
|
||||||
var clipboardData = e.getRawEvent().clipboardData;
|
|
||||||
if (!clipboardData) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (var ii = 0; ii < clipboardData.types.length; ii++) {
|
|
||||||
if (/^image\//.test(clipboardData.types[ii])) {
|
|
||||||
var file = clipboardData.items[ii].getAsFile();
|
|
||||||
|
|
||||||
this.invoke('willUpload', file);
|
|
||||||
|
|
||||||
var up_uri = JX.$U(this.getURI())
|
|
||||||
.setQueryParam('name', 'clipboard.png')
|
|
||||||
.setQueryParam('__upload__', 1)
|
|
||||||
.toString();
|
|
||||||
|
|
||||||
new JX.Request(up_uri, JX.bind(this, function(r) {
|
|
||||||
this.invoke('didUpload', r);
|
|
||||||
}))
|
|
||||||
.setRawData(file)
|
|
||||||
.send();
|
|
||||||
|
|
||||||
e.kill();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
properties: {
|
|
||||||
URI : null
|
|
||||||
}
|
|
||||||
});
|
|
|
@ -3,7 +3,6 @@
|
||||||
* @requires javelin-behavior
|
* @requires javelin-behavior
|
||||||
* javelin-dom
|
* javelin-dom
|
||||||
* phabricator-drag-and-drop-file-upload
|
* phabricator-drag-and-drop-file-upload
|
||||||
* phabricator-paste-file-upload
|
|
||||||
* phabricator-textareautils
|
* phabricator-textareautils
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -39,12 +38,5 @@ JX.behavior('aphront-drag-and-drop-textarea', function(config) {
|
||||||
drop.start();
|
drop.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (JX.PhabricatorPasteFileUpload.isSupported()) {
|
|
||||||
var paste = new JX.PhabricatorPasteFileUpload(target)
|
|
||||||
.setURI(config.uri);
|
|
||||||
paste.listen('didUpload', onupload);
|
|
||||||
paste.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue