root / trunk / web / dojo / dojox / editor / plugins / UploadImage.js
History | View | Annotate | Download (2.2 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, 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 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.editor.plugins.UploadImage"]){ |
9 |
dojo._hasResource["dojox.editor.plugins.UploadImage"]=true; |
10 |
dojo.provide("dojox.editor.plugins.UploadImage");
|
11 |
dojo.require("dijit._editor._Plugin");
|
12 |
dojo.require("dojox.form.FileUploader");
|
13 |
dojo.experimental("dojox.editor.plugins.UploadImage");
|
14 |
dojo.declare("dojox.editor.plugins.UploadImage",dijit._editor._Plugin,{tempImageUrl:"",iconClassPrefix:"editorIcon",useDefaultCommand:false,uploadUrl:"",button:null,label:"Upload",setToolbar:function(_1){ |
15 |
this.button.destroy();
|
16 |
this.createFileInput();
|
17 |
_1.addChild(this.button);
|
18 |
},_initButton:function(){ |
19 |
this.command="uploadImage"; |
20 |
this.editor.commands[this.command]="Upload Image"; |
21 |
this.inherited("_initButton",arguments); |
22 |
delete this.command; |
23 |
},createFileInput:function(){ |
24 |
var _2=dojo.create("span",{innerHTML:"."},document.body); |
25 |
dojo.style(_2,{width:"40px",height:"20px",paddingLeft:"8px",paddingRight:"8px"}); |
26 |
this.button=new dojox.form.FileUploader({isDebug:true,uploadUrl:this.uploadUrl,uploadOnChange:true,selectMultipleFiles:false,baseClass:"dojoxEditorUploadNorm",hoverClass:"dojoxEditorUploadHover",activeClass:"dojoxEditorUploadActive",disabledClass:"dojoxEditorUploadDisabled"},_2); |
27 |
this.connect(this.button,"onChange","insertTempImage"); |
28 |
this.connect(this.button,"onComplete","onComplete"); |
29 |
},onComplete:function(_3,_4,_5){ |
30 |
_3=_3[0];
|
31 |
var _6=dojo.withGlobal(this.editor.window,"byId",dojo,[this.currentImageId]); |
32 |
var _7;
|
33 |
if(this.downloadPath){ |
34 |
_7=this.downloadPath+_3.name;
|
35 |
}else{
|
36 |
_7=_3.file; |
37 |
} |
38 |
_6.src=_7; |
39 |
dojo.attr(_6,"_djrealurl",_7);
|
40 |
if(_3.width){
|
41 |
_6.width=_3.width; |
42 |
_6.height=_3.height; |
43 |
} |
44 |
},insertTempImage:function(){ |
45 |
this.currentImageId="img_"+(new Date().getTime()); |
46 |
var _8="<img id=\""+this.currentImageId+"\" src=\""+this.tempImageUrl+"\" width=\"32\" height=\"32\"/>"; |
47 |
this.editor.execCommand("inserthtml",_8); |
48 |
}}); |
49 |
dojo.subscribe(dijit._scopeName+".Editor.getPlugin",null,function(o){ |
50 |
if(o.plugin){
|
51 |
return;
|
52 |
} |
53 |
switch(o.args.name){
|
54 |
case "uploadImage": |
55 |
o.plugin=new dojox.editor.plugins.UploadImage({url:o.args.url}); |
56 |
} |
57 |
}); |
58 |
} |