Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/core/behavior-global-drag-and-drop.js
/** | /** | ||||
* @provides javelin-behavior-global-drag-and-drop | * @provides javelin-behavior-global-drag-and-drop | ||||
* @requires javelin-behavior | * @requires javelin-behavior | ||||
* javelin-dom | * javelin-dom | ||||
* javelin-uri | * javelin-uri | ||||
* javelin-mask | * javelin-mask | ||||
* phabricator-drag-and-drop-file-upload | * phabricator-drag-and-drop-file-upload | ||||
*/ | */ | ||||
JX.behavior('global-drag-and-drop', function(config) { | JX.behavior('global-drag-and-drop', function(config, statics) { | ||||
if (!JX.PhabricatorDragAndDropFileUpload.isSupported()) { | if (!JX.PhabricatorDragAndDropFileUpload.isSupported()) { | ||||
return; | return; | ||||
} | } | ||||
var pending = 0; | function init() { | ||||
var files = []; | statics.pending = 0; | ||||
var errors = false; | statics.files = []; | ||||
statics.errors = false; | |||||
statics.enabled = true; | |||||
if (config.ifSupported) { | if (config.ifSupported) { | ||||
JX.$(config.ifSupported).style.display = ''; | JX.$(config.ifSupported).style.display = ''; | ||||
} | } | ||||
var page = JX.$('phabricator-standard-page'); | var page = JX.$('phabricator-standard-page'); | ||||
var drop = new JX.PhabricatorDragAndDropFileUpload(page) | statics.drop = new JX.PhabricatorDragAndDropFileUpload(page) | ||||
.setURI(config.uploadURI) | .setURI(config.uploadURI) | ||||
.setViewPolicy(config.viewPolicy) | .setViewPolicy(config.viewPolicy) | ||||
.setChunkThreshold(config.chunkThreshold); | .setChunkThreshold(config.chunkThreshold); | ||||
drop.listen('didBeginDrag', function() { | install_extra_listeners(); | ||||
statics.drop.start(); | |||||
return true; | |||||
} | |||||
btrahan: As far as I can tell, this doesn't actually do anything? The data only gets set on the file… | |||||
Not Done Inline ActionsThe div is initially hidden for me, at least -- this hides it on my system: PhabricatorFileUploadController.php 40 ->setControlStyle('display: none') That said, it would probably be fine to kill it; every reasonable browser supports this now. epriestley: The div is initially hidden for me, at least -- this hides it on my system… | |||||
function install_extra_listeners() { | |||||
statics.drop.listen('didBeginDrag', function() { | |||||
if (!statics.enabled) { | |||||
return; | |||||
} | |||||
JX.Mask.show('global-upload-mask'); | JX.Mask.show('global-upload-mask'); | ||||
JX.DOM.show(JX.$(config.instructions)); | JX.DOM.show(JX.$(config.instructions)); | ||||
}); | }); | ||||
drop.listen('didEndDrag', function() { | statics.drop.listen('didEndDrag', function() { | ||||
if (!statics.enabled) { | |||||
return; | |||||
} | |||||
JX.Mask.hide('global-upload-mask'); | JX.Mask.hide('global-upload-mask'); | ||||
JX.DOM.hide(JX.$(config.instructions)); | JX.DOM.hide(JX.$(config.instructions)); | ||||
}); | }); | ||||
drop.listen('willUpload', function() { | statics.drop.listen('willUpload', function() { | ||||
pending++; | if (!statics.enabled) { | ||||
return; | |||||
} | |||||
statics.pending++; | |||||
}); | }); | ||||
drop.listen('didUpload', function(f) { | statics.drop.listen('didUpload', function(f) { | ||||
files.push(f); | if (!statics.enabled) { | ||||
return; | |||||
} | |||||
statics.files.push(f); | |||||
pending--; | statics.pending--; | ||||
if (pending === 0 && !errors) { | if (statics.pending === 0 && !statics.errors) { | ||||
// If whatever the user dropped in has finished uploading, send them to | // If whatever the user dropped in has finished uploading, send them to | ||||
// their uploads. | // their uploads. | ||||
var uri; | var uri; | ||||
uri = JX.$U(config.browseURI); | uri = JX.$U(config.browseURI); | ||||
var ids = []; | var ids = []; | ||||
for (var ii = 0; ii < files.length; ii++) { | for (var ii = 0; ii < statics.files.length; ii++) { | ||||
ids.push(files[ii].getID()); | ids.push(statics.files[ii].getID()); | ||||
} | } | ||||
uri.setQueryParam('h', ids.join(',')); | uri.setQueryParam('h', ids.join(',')); | ||||
files = []; | statics.files = []; | ||||
uri.go(); | uri.go(); | ||||
} | } | ||||
}); | }); | ||||
drop.listen('didError', function() { | statics.drop.listen('didError', function() { | ||||
pending--; | if (!statics.enabled) { | ||||
errors = true; | return; | ||||
} | |||||
statics.pending--; | |||||
statics.errors = true; | |||||
}); | }); | ||||
} | |||||
drop.start(); | statics.init = statics.init || init(); | ||||
JX.Stratcom.listen( | |||||
'quicksand-redraw', | |||||
null, | |||||
function (e) { | |||||
e.kill(); | |||||
var data = e.getData(); | |||||
var toggle = data.newResponse.globalDragAndDrop; | |||||
statics.enabled = toggle; | |||||
statics.drop.setIsEnabled(toggle); | |||||
}); | |||||
}); | }); | ||||
Not Done Inline ActionsAnother approach would be to just make this do: statics.drop.setEnabled(data.newResponse.globalDragAndDrop); ...and all the listeners in DragAndDropFileUpload just did something like: if (!this.getEnabled()) { return; } I'm not sure if that would actually be any smaller in this case, but it usually seems to end up a bit cleaner than trying to uninstall/reinstall listeners. epriestley: Another approach would be to just make this do:
statics.drop.setEnabled(data.newResponse. |
As far as I can tell, this doesn't actually do anything? The data only gets set on the file upload controller and the pertinent div is not hidden to begin with... Safe to kill or did this break or?