summaryrefslogtreecommitdiff
path: root/js/dojo-1.6/dojox/form/uploader/plugins/IFrame.js
blob: 98a69a4d66d17eb801e2c924a47e0892b644e92f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


if(!dojo._hasResource["dojox.form.uploader.plugins.IFrame"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.form.uploader.plugins.IFrame"] = true;
dojo.provide("dojox.form.uploader.plugins.IFrame");

dojo.require("dojox.form.uploader.plugins.HTML5");
dojo.require("dojo.io.iframe");

dojo.declare("dojox.form.uploader.plugins.IFrame", [], {
	//
	// Version: 1.6
	//
	// summary:
	//		A plugin for dojox.form.Uploader that adds Ajax upload capabilities.
	//
	//	description:
	//		Only supported by IE, due to the specifc iFrame hack used. The
	//		dojox.form.uploader.plugins.HTML5 plugin should be used along with this to add HTML5
	//		capabilities to browsers that support them. Progress events are not supported.
	//		Inherits all properties from dojox.form.Uploader and dojox.form.uploader.plugins.HTML5.
	//

	force:"",

	postMixInProperties: function(){
		this.inherited(arguments);
		if(!this.supports("multiple")){
			this.uploadType = "iframe";
		}
	},

	upload: function(/*Object ? */data){
		// summary:
		//		See: dojox.form.Uploader.upload
		//
		if(!this.supports("multiple") || this.force =="iframe"){
			this.uploadIFrame(data);
			dojo.stopEvent(data);
			return;
		}
	},

	uploadIFrame: function(){
		// summary:
		//		Internal. You could use this, but you should use upload() or submit();
		//		which can also handle the post data.
		//
		var url = this.getUrl();
		var dfd = dojo.io.iframe.send({
			url: this.getUrl(),
			form: this.form,
			handleAs: "json",
			error: dojo.hitch(this, function(err){
				console.error("HTML Upload Error:" + err.message);
			}),
			load: dojo.hitch(this, function(data, ioArgs, widgetRef){
				this.onComplete(data);
			})
		});
	}
});

dojox.form.addUploaderPlugin(dojox.form.uploader.plugins.IFrame);

}