aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dijit/_editor/_Plugin.js
diff options
context:
space:
mode:
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
commite44a7e37b6c7b5961adaffc62b9042b8d442938e (patch)
tree95b67c356e93163467db2451f2b8cce84ed5d582 /includes/js/dijit/_editor/_Plugin.js
parenta62b9742ee5e28bcec6872d88f50f25b820914f6 (diff)
downloadsemanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.gz
semanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.bz2
New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'includes/js/dijit/_editor/_Plugin.js')
-rw-r--r--includes/js/dijit/_editor/_Plugin.js101
1 files changed, 101 insertions, 0 deletions
diff --git a/includes/js/dijit/_editor/_Plugin.js b/includes/js/dijit/_editor/_Plugin.js
new file mode 100644
index 0000000..32fde3b
--- /dev/null
+++ b/includes/js/dijit/_editor/_Plugin.js
@@ -0,0 +1,101 @@
+if(!dojo._hasResource["dijit._editor._Plugin"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dijit._editor._Plugin"] = true;
+dojo.provide("dijit._editor._Plugin");
+dojo.require("dijit._Widget");
+dojo.require("dijit.Editor");
+dojo.require("dijit.form.Button");
+
+dojo.declare("dijit._editor._Plugin", null, {
+ // summary
+ // This represents a "plugin" to the editor, which is basically
+ // a single button on the Toolbar and some associated code
+ constructor: function(/*Object?*/args, /*DomNode?*/node){
+ if(args){
+ dojo.mixin(this, args);
+ }
+ this._connects=[];
+ },
+
+ editor: null,
+ iconClassPrefix: "dijitEditorIcon",
+ button: null,
+ queryCommand: null,
+ command: "",
+ commandArg: null,
+ useDefaultCommand: true,
+ buttonClass: dijit.form.Button,
+ getLabel: function(key){
+ return this.editor.commands[key];
+ },
+ _initButton: function(props){
+ if(this.command.length){
+ var label = this.getLabel(this.command);
+ var className = this.iconClassPrefix+" "+this.iconClassPrefix + this.command.charAt(0).toUpperCase() + this.command.substr(1);
+ if(!this.button){
+ props = dojo.mixin({
+ label: label,
+ showLabel: false,
+ iconClass: className,
+ dropDown: this.dropDown,
+ tabIndex: "-1"
+ }, props || {});
+ this.button = new this.buttonClass(props);
+ }
+ }
+ },
+ destroy: function(f){
+ dojo.forEach(this._connects, dojo.disconnect);
+ },
+ connect: function(o, f, tf){
+ this._connects.push(dojo.connect(o, f, this, tf));
+ },
+ updateState: function(){
+ var _e = this.editor;
+ var _c = this.command;
+ if(!_e){ return; }
+ if(!_e.isLoaded){ return; }
+ if(!_c.length){ return; }
+ if(this.button){
+ try{
+ var enabled = _e.queryCommandEnabled(_c);
+ this.button.setAttribute('disabled', !enabled);
+ if(typeof this.button.checked == 'boolean'){
+ this.button.setAttribute('checked', _e.queryCommandState(_c));
+ }
+ }catch(e){
+ console.debug(e);
+ }
+ }
+ },
+ setEditor: function(/*Widget*/editor){
+ // FIXME: detatch from previous editor!!
+ this.editor = editor;
+
+ // FIXME: prevent creating this if we don't need to (i.e., editor can't handle our command)
+ this._initButton();
+
+ // FIXME: wire up editor to button here!
+ if(this.command.length &&
+ !this.editor.queryCommandAvailable(this.command)
+ ){
+ // console.debug("hiding:", this.command);
+ if(this.button){
+ this.button.domNode.style.display = "none";
+ }
+ }
+ if(this.button && this.useDefaultCommand){
+ this.connect(this.button, "onClick",
+ dojo.hitch(this.editor, "execCommand", this.command, this.commandArg)
+ );
+ }
+ this.connect(this.editor, "onNormalizedDisplayChanged", "updateState");
+ },
+ setToolbar: function(/*Widget*/toolbar){
+ if(this.button){
+ toolbar.addChild(this.button);
+ }
+ // console.debug("adding", this.button, "to:", toolbar);
+ }
+});
+
+}