]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dijit/_editor/_Plugin.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dijit / _editor / _Plugin.js
1 if(!dojo._hasResource["dijit._editor._Plugin"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit._editor._Plugin"] = true;
3 dojo.provide("dijit._editor._Plugin");
4 dojo.require("dijit._Widget");
5 dojo.require("dijit.Editor");
6 dojo.require("dijit.form.Button");
7
8 dojo.declare("dijit._editor._Plugin", null, {
9         // summary
10         //              This represents a "plugin" to the editor, which is basically
11         //              a single button on the Toolbar and some associated code
12         constructor: function(/*Object?*/args, /*DomNode?*/node){
13                 if(args){
14                         dojo.mixin(this, args);
15                 }
16                 this._connects=[];
17         },
18
19         editor: null,
20         iconClassPrefix: "dijitEditorIcon",
21         button: null,
22         queryCommand: null,
23         command: "",
24         commandArg: null,
25         useDefaultCommand: true,
26         buttonClass: dijit.form.Button,
27         getLabel: function(key){
28                 return this.editor.commands[key];
29         },
30         _initButton: function(props){
31                 if(this.command.length){
32                         var label = this.getLabel(this.command);
33                         var className = this.iconClassPrefix+" "+this.iconClassPrefix + this.command.charAt(0).toUpperCase() + this.command.substr(1);
34                         if(!this.button){
35                                 props = dojo.mixin({
36                                         label: label,
37                                         showLabel: false,
38                                         iconClass: className,
39                                         dropDown: this.dropDown,
40                                         tabIndex: "-1"
41                                 }, props || {});
42                                 this.button = new this.buttonClass(props);
43                         }
44                 }
45         },
46         destroy: function(f){
47                 dojo.forEach(this._connects, dojo.disconnect);
48         },
49         connect: function(o, f, tf){
50                 this._connects.push(dojo.connect(o, f, this, tf));
51         },
52         updateState: function(){
53                 var _e = this.editor;
54                 var _c = this.command;
55                 if(!_e){ return; }
56                 if(!_e.isLoaded){ return; }
57                 if(!_c.length){ return; }
58                 if(this.button){
59                         try{
60                                 var enabled = _e.queryCommandEnabled(_c);
61                                 this.button.setAttribute('disabled', !enabled);
62                                 if(typeof this.button.checked == 'boolean'){
63                                         this.button.setAttribute('checked', _e.queryCommandState(_c));
64                                 }
65                         }catch(e){
66                                 console.debug(e);
67                         }
68                 }
69         },
70         setEditor: function(/*Widget*/editor){
71                 // FIXME: detatch from previous editor!!
72                 this.editor = editor;
73
74                 // FIXME: prevent creating this if we don't need to (i.e., editor can't handle our command)
75                 this._initButton();
76
77                 // FIXME: wire up editor to button here!
78                 if(this.command.length &&
79                         !this.editor.queryCommandAvailable(this.command)
80                 ){
81                         // console.debug("hiding:", this.command);
82                         if(this.button){
83                                 this.button.domNode.style.display = "none";
84                         }
85                 }
86                 if(this.button && this.useDefaultCommand){
87                         this.connect(this.button, "onClick",
88                                 dojo.hitch(this.editor, "execCommand", this.command, this.commandArg)
89                         );
90                 }
91                 this.connect(this.editor, "onNormalizedDisplayChanged", "updateState");
92         },
93         setToolbar: function(/*Widget*/toolbar){
94                 if(this.button){
95                         toolbar.addChild(this.button);
96                 }
97                 // console.debug("adding", this.button, "to:", toolbar);
98         }
99 });
100
101 }