123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- define("dojox/form/uploader/plugins/Flash", [
- "dojo/dom-form",
- "dojo/dom-style",
- "dojo/dom-construct",
- "dojo/dom-attr",
- "dojo/_base/declare",
- "dojo/_base/config",
- "dojo/_base/connect",
- "dojo/_base/lang",
- "dojo/_base/array",
- "dojox/form/uploader/plugins/HTML5",
- "dojox/embed/Flash"
- ],function(domForm, domStyle, domConstruct, domAttr, declare, config, connect, lang, array, formUploaderPluginsHTML5, embedFlash){
- var pluginsFlash = declare("dojox.form.uploader.plugins.Flash", [], {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- swfPath:config.uploaderPath || require.toUrl("dojox/form/resources/uploader.swf"),
-
-
-
-
-
-
- skipServerCheck:true,
-
-
-
-
-
-
- serverTimeout: 2000,
-
-
-
-
- isDebug:false,
-
-
-
- devMode:false,
-
-
-
-
-
-
-
-
-
- deferredUploading:0,
-
-
-
-
- force:"",
- postMixInProperties: function(){
- if(!this.supports("multiple")){
-
- this.uploadType = "flash";
- this._files = [];
- this._fileMap = {};
- this._createInput = this._createFlashUploader;
- this.getFileList = this.getFlashFileList;
- this.reset = this.flashReset;
- this.upload = this.uploadFlash;
- this.fieldname = "flashUploadFiles";
- }
- this.inherited(arguments);
- },
-
- onReady: function(/* dojox.form.FileUploader */ uploader){
-
-
-
-
- },
- onLoad: function(/* dojox.form.FileUploader */ uploader){
-
-
- },
- onFileChange: function(fileArray){
-
-
-
-
- },
- onFileProgress: function(fileArray){
-
-
-
- },
-
- getFlashFileList: function(){
-
-
- return this._files;
- },
- flashReset: function(){
- this.flashMovie.reset();
- this._files = [];
- },
-
- uploadFlash: function(/*Object ? */formData){
-
-
-
-
- this.onBegin(this.getFileList());
- this.flashMovie.doUpload(formData);
- },
- _change: function(fileArray){
- this._files = this._files.concat(fileArray);
- array.forEach(fileArray, function(f){
- f.bytesLoaded = 0;
- f.bytesTotal = f.size;
- this._fileMap[f.name+"_"+f.size] = f;
- }, this);
- this.onChange(this._files);
- this.onFileChange(fileArray);
- },
- _complete: function(fileArray){
- var o = this._getCustomEvent();
- o.type = "load";
- this.onComplete(fileArray);
- },
- _progress: function(f){
- this._fileMap[f.name+"_"+f.bytesTotal].bytesLoaded = f.bytesLoaded;
- var o = this._getCustomEvent();
- this.onFileProgress(f);
- this.onProgress(o);
- },
- _error: function(err){
- this.onError(err);
- },
- _onFlashBlur: function(fileArray){
-
- },
- _getCustomEvent: function(){
- var o = {
- bytesLoaded:0,
- bytesTotal:0,
- type:"progress",
- timeStamp:new Date().getTime()
- };
- for(var nm in this._fileMap){
- o.bytesTotal += this._fileMap[nm].bytesTotal;
- o.bytesLoaded += this._fileMap[nm].bytesLoaded;
- }
- o.decimal = o.bytesLoaded / o.bytesTotal;
- o.percent = Math.ceil((o.bytesLoaded / o.bytesTotal)*100)+"%";
- return o;
- },
- _connectFlash: function(){
-
-
-
-
-
-
-
-
- this._subs = [];
- this._cons = [];
- var doSub = lang.hitch(this, function(s, funcStr){
- this._subs.push(connect.subscribe(this.id + s, this, funcStr));
- });
- doSub("/filesSelected", "_change");
- doSub("/filesUploaded", "_complete");
- doSub("/filesProgress", "_progress");
- doSub("/filesError", "_error");
- doSub("/filesCanceled", "onCancel");
- doSub("/stageBlur", "_onFlashBlur");
- this.connect(this.domNode, "focus", function(){
-
-
- this.flashMovie.focus();
- this.flashMovie.doFocus();
- });
- if(this.tabIndex>=0){
- domAttr.set(this.domNode, "tabIndex", this.tabIndex);
- }
- },
- _createFlashUploader: function(){
-
-
-
- var url = this.getUrl();
- if(url){
- if(url.toLowerCase().indexOf("http")<0 && url.indexOf("/")!=0){
-
-
-
-
- var loc = window.location.href.split("/");
- loc.pop();
- loc = loc.join("/")+"/";
- url = loc+url;
- }
- }else{
- console.warn("Warning: no uploadUrl provided.");
- }
- this.inputNode = domConstruct.create("div", {className:"dojoxFlashNode"}, this.domNode, "first");
- domStyle.set(this.inputNode, {
- position:"absolute",
- top:"-2px",
- width:this.btnSize.w+"px",
- height:this.btnSize.h+"px",
- opacity:0
- });
- var w = this.btnSize.w;
- var h = this.btnSize.h;
- var args = {
- expressInstall:true,
- path: (this.swfPath.uri || this.swfPath) + "?cb_" + (new Date().getTime()),
- width: w,
- height: h,
- allowScriptAccess:"always",
- allowNetworking:"all",
- vars: {
- uploadDataFieldName: this.flashFieldName || this.name+"Flash",
- uploadUrl: url,
- uploadOnSelect: this.uploadOnSelect,
- deferredUploading:this.deferredUploading || 0,
- selectMultipleFiles: this.multiple,
- id: this.id,
- isDebug: this.isDebug,
- noReturnCheck: this.skipServerCheck,
- serverTimeout:this.serverTimeout
- },
- params: {
- scale:"noscale",
- wmode:"transparent",
- wmode:"opaque",
- allowScriptAccess:"always",
- allowNetworking:"all"
- }
- };
- this.flashObject = new embedFlash(args, this.inputNode);
- this.flashObject.onError = lang.hitch(function(msg){
- console.error("Flash Error: " + msg);
- });
- this.flashObject.onReady = lang.hitch(this, function(){
- this.onReady(this);
- });
- this.flashObject.onLoad = lang.hitch(this, function(mov){
- this.flashMovie = mov;
- this.flashReady = true;
- this.onLoad(this);
- });
- this._connectFlash();
- }
- });
- dojox.form.addUploaderPlugin(pluginsFlash);
- return pluginsFlash;
- });
|