Debian Codegraph @

dojox/editor/plugins/UploadImage.js

raw symbols SCIP
1 define([
2 "dojo",
3 "dijit",
4 "dojox",
5 "dijit/_editor/_Plugin",
6 "dojo/_base/connect",
7 "dojo/_base/declare",
8 "dojox/form/FileUploader",
9 "dijit/_editor/_Plugin"
10 ], function(dojo, dijit, dojox, _Plugin) {
11
12 dojo.experimental("dojox.editor.plugins.UploadImage");
13
14 var UploadImage = dojo.declare("dojox.editor.plugins.UploadImage", _Plugin, {
15 // summary:
16 // Adds an icon to the Editor toolbar that when clicked, opens a system dialog
17 // Although the toolbar icon is a tiny "image" the uploader could be used for
18 // any file type
19
20 tempImageUrl: "",
21 iconClassPrefix: "editorIcon",
22 useDefaultCommand: false,
23 uploadUrl: "",
24 button:null,
25 label:"Upload",
26
27 setToolbar: function(toolbar){
28 this.button.destroy();
29 this.createFileInput();
30 toolbar.addChild(this.button);
31 },
32 _initButton: function(){
33 this.command = "uploadImage";
34 this.editor.commands[this.command] = "Upload Image";
35 this.inherited("_initButton", arguments);
36 delete this.command;
37 },
38
39 updateState: function(){
40 // summary:
41 // Over-ride for button state control for disabled to work.
42 this.button.set("disabled", this.get("disabled"));
43 },
44
45 createFileInput: function(){
46 var node = dojo.create('span', {innerHTML:"."}, document.body)
47 dojo.style(node, {
48 width:"40px",
49 height:"20px",
50 paddingLeft:"8px",
51 paddingRight:"8px"
52 });
53 this.button = new dojox.form.FileUploader({
54 isDebug:true,
55 //force:"html",
56 uploadUrl:this.uploadUrl,
57 uploadOnChange:true,
58 selectMultipleFiles:false,
59 baseClass:"dojoxEditorUploadNorm",
60 hoverClass:"dojoxEditorUploadHover",
61 activeClass:"dojoxEditorUploadActive",
62 disabledClass:"dojoxEditorUploadDisabled"
63 }, node);
64 this.connect(this.button, "onChange", "insertTempImage");
65 this.connect(this.button, "onComplete", "onComplete");
66 },
67
68 onComplete: function(data,ioArgs,widgetRef){
69 data = data[0];
70 // Image is ready to insert
71 var tmpImgNode = dojo.byId(this.currentImageId, this.editor.document);
72 var file;
73 // download path is mainly used so we can access a PHP script
74 // not relative to this file. The server *should* return a qualified path.
75 if(this.downloadPath){
76 file = this.downloadPath+data.name
77 }else{
78 file = data.file;
79 }
80
81 tmpImgNode.src = file;
82 dojo.attr(tmpImgNode,'_djrealurl',file);
83
84 if(data.width){
85 tmpImgNode.width = data.width;
86 tmpImgNode.height = data.height;
87 }
88 },
89
90 insertTempImage: function(){
91 // summary:
92 // inserting a "busy" image to show something is hapening
93 // during upload and download of the image.
94 this.currentImageId = "img_"+(new Date().getTime());
95 var iTxt = '<img id="'+this.currentImageId+'" src="'+this.tempImageUrl+'" width="32" height="32"/>';
96 this.editor.execCommand('inserthtml', iTxt);
97 }
98 });
99
100 dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
101 if(o.plugin){ return; }
102 switch(o.args.name){
103 case "uploadImage":
104 o.plugin = new UploadImage({url: o.args.url});
105 }
106 });
107
108 return UploadImage;
109 });