IFrame.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. define("dojox/form/uploader/plugins/IFrame", [
  2. "dojo/dom-construct",
  3. "dojo/_base/declare",
  4. "dojo/_base/lang",
  5. "dojo/_base/array",
  6. "dojo/io/iframe",
  7. "dojox/form/uploader/plugins/HTML5"
  8. ],function(domConstruct, declare, lang, array, ioIframe, formUploaderPluginsHTML5){
  9. var pluginsIFrame = declare("dojox.form.uploader.plugins.IFrame", [], {
  10. //
  11. // Version: 1.6
  12. //
  13. // summary:
  14. // A plugin for dojox.form.Uploader that adds Ajax upload capabilities.
  15. //
  16. // description:
  17. // Only supported by IE, due to the specifc iFrame hack used. The
  18. // formUploaderPluginsHTML5 plugin should be used along with this to add HTML5
  19. // capabilities to browsers that support them. Progress events are not supported.
  20. // Inherits all properties from dojox.form.Uploader and formUploaderPluginsHTML5.
  21. //
  22. force:"",
  23. postMixInProperties: function(){
  24. this.inherited(arguments);
  25. if(!this.supports("multiple") || this.force =="iframe"){
  26. this.uploadType = "iframe";
  27. this.upload = this.uploadIFrame;
  28. }
  29. },
  30. uploadIFrame: function(data){
  31. // summary:
  32. // Internal. You could use this, but you should use upload() or submit();
  33. // which can also handle the post data.
  34. //
  35. var form, destroyAfter = false;
  36. if(!this.getForm()){
  37. //enctype can't be changed once a form element is created
  38. form = domConstruct.place('<form enctype="multipart/form-data" method="post"></form>', this.domNode);
  39. array.forEach(this._inputs, function(n, i){
  40. if(n.value) form.appendChild(n);
  41. }, this);
  42. destroyAfter = true;
  43. }else{
  44. form = this.form;
  45. }
  46. var url = this.getUrl();
  47. var dfd = ioIframe.send({
  48. url: url,
  49. form: form,
  50. handleAs: "json",
  51. content: data,
  52. error: lang.hitch(this, function(err){
  53. if(destroyAfter){ domConstruct.destroy(form); }
  54. this.onError(err);
  55. }),
  56. load: lang.hitch(this, function(data, ioArgs, widgetRef){
  57. if(destroyAfter){ domConstruct.destroy(form); }
  58. if(data["ERROR"] || data["error"]){
  59. this.onError(data);
  60. }else{
  61. this.onComplete(data);
  62. }
  63. })
  64. });
  65. }
  66. });
  67. dojox.form.addUploaderPlugin(pluginsIFrame);
  68. return pluginsIFrame;
  69. });