Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 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
	},
17
 
18
	editor: null,
19
	iconClassPrefix: "dijitEditorIcon",
20
	button: null,
21
	queryCommand: null,
22
	command: "",
23
	commandArg: null,
24
	useDefaultCommand: true,
25
	buttonClass: dijit.form.Button,
26
	updateInterval: 200, // only allow updates every two tenths of a second
27
	_initButton: function(){
28
		if(this.command.length){
29
			var label = this.editor.commands[this.command];
30
			var className = "dijitEditorIcon "+this.iconClassPrefix + this.command.charAt(0).toUpperCase() + this.command.substr(1);
31
			if(!this.button){
32
				var props = {
33
					label: label,
34
					showLabel: false,
35
					iconClass: className,
36
					dropDown: this.dropDown
37
				};
38
				this.button = new this.buttonClass(props);
39
			}
40
		}
41
	},
42
	updateState: function(){
43
		var _e = this.editor;
44
		var _c = this.command;
45
		if(!_e){ return; }
46
		if(!_e.isLoaded){ return; }
47
		if(!_c.length){ return; }
48
		if(this.button){
49
			try{
50
				var enabled = _e.queryCommandEnabled(_c);
51
				this.button.setDisabled(!enabled);
52
				if(this.button.setChecked){
53
					this.button.setChecked(_e.queryCommandState(_c));
54
				}
55
			}catch(e){
56
				console.debug(e);
57
			}
58
		}
59
	},
60
	setEditor: function(/*Widget*/editor){
61
		// FIXME: detatch from previous editor!!
62
		this.editor = editor;
63
 
64
		// FIXME: prevent creating this if we don't need to (i.e., editor can't handle our command)
65
		this._initButton();
66
 
67
		// FIXME: wire up editor to button here!
68
		if(	(this.command.length) &&
69
			(!this.editor.queryCommandAvailable(this.command))
70
		){
71
			// console.debug("hiding:", this.command);
72
			if(this.button){
73
				this.button.domNode.style.display = "none";
74
			}
75
		}
76
		if(this.button && this.useDefaultCommand){
77
			dojo.connect(this.button, "onClick",
78
				dojo.hitch(this.editor, "execCommand", this.command, this.commandArg)
79
			);
80
		}
81
		dojo.connect(this.editor, "onNormalizedDisplayChanged", this, "updateState");
82
	},
83
	setToolbar: function(/*Widget*/toolbar){
84
		if(this.button){
85
			toolbar.addChild(this.button);
86
		}
87
		// console.debug("adding", this.button, "to:", toolbar);
88
	}
89
});
90
 
91
}