IFrame.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.form.uploader.plugins.IFrame"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.form.uploader.plugins.IFrame"] = true;
  8. dojo.provide("dojox.form.uploader.plugins.IFrame");
  9. dojo.require("dojox.form.uploader.plugins.HTML5");
  10. dojo.require("dojo.io.iframe");
  11. dojo.declare("dojox.form.uploader.plugins.IFrame", [], {
  12. //
  13. // Version: 1.6
  14. //
  15. // summary:
  16. // A plugin for dojox.form.Uploader that adds Ajax upload capabilities.
  17. //
  18. // description:
  19. // Only supported by IE, due to the specifc iFrame hack used. The
  20. // dojox.form.uploader.plugins.HTML5 plugin should be used along with this to add HTML5
  21. // capabilities to browsers that support them. Progress events are not supported.
  22. // Inherits all properties from dojox.form.Uploader and dojox.form.uploader.plugins.HTML5.
  23. //
  24. force:"",
  25. postMixInProperties: function(){
  26. this.inherited(arguments);
  27. if(!this.supports("multiple")){
  28. this.uploadType = "iframe";
  29. }
  30. },
  31. upload: function(/*Object ? */data){
  32. // summary:
  33. // See: dojox.form.Uploader.upload
  34. //
  35. if(!this.supports("multiple") || this.force =="iframe"){
  36. this.uploadIFrame(data);
  37. dojo.stopEvent(data);
  38. return;
  39. }
  40. },
  41. uploadIFrame: function(){
  42. // summary:
  43. // Internal. You could use this, but you should use upload() or submit();
  44. // which can also handle the post data.
  45. //
  46. var url = this.getUrl();
  47. var dfd = dojo.io.iframe.send({
  48. url: this.getUrl(),
  49. form: this.form,
  50. handleAs: "json",
  51. error: dojo.hitch(this, function(err){
  52. console.error("HTML Upload Error:" + err.message);
  53. }),
  54. load: dojo.hitch(this, function(data, ioArgs, widgetRef){
  55. this.onComplete(data);
  56. })
  57. });
  58. }
  59. });
  60. dojox.form.addUploaderPlugin(dojox.form.uploader.plugins.IFrame);
  61. }