root / trunk / web / dojo / dijit / _editor / _Plugin.js
History | View | Annotate | Download (2.15 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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["dijit._editor._Plugin"]){ |
||
9 | dojo._hasResource["dijit._editor._Plugin"]=true; |
||
10 | dojo.provide("dijit._editor._Plugin");
|
||
11 | dojo.require("dijit._Widget");
|
||
12 | dojo.require("dijit.form.Button");
|
||
13 | dojo.declare("dijit._editor._Plugin",null,{constructor:function(_1,_2){ |
||
14 | this.params=_1||{};
|
||
15 | dojo.mixin(this,this.params); |
||
16 | this._connects=[];
|
||
17 | },editor:null,iconClassPrefix:"dijitEditorIcon",button:null,command:"",useDefaultCommand:true,buttonClass:dijit.form.Button,getLabel:function(_3){ |
||
18 | return this.editor.commands[_3]; |
||
19 | },_initButton:function(){ |
||
20 | if(this.command.length){ |
||
21 | var _4=this.getLabel(this.command),_5=this.editor,_6=this.iconClassPrefix+" "+this.iconClassPrefix+this.command.charAt(0).toUpperCase()+this.command.substr(1); |
||
22 | if(!this.button){ |
||
23 | var _7=dojo.mixin({label:_4,dir:_5.dir,lang:_5.lang,showLabel:false,iconClass:_6,dropDown:this.dropDown,tabIndex:"-1"},this.params||{}); |
||
24 | this.button=new this.buttonClass(_7); |
||
25 | } |
||
26 | } |
||
27 | },destroy:function(){ |
||
28 | dojo.forEach(this._connects,dojo.disconnect);
|
||
29 | if(this.dropDown){ |
||
30 | this.dropDown.destroyRecursive();
|
||
31 | } |
||
32 | },connect:function(o,f,tf){ |
||
33 | this._connects.push(dojo.connect(o,f,this,tf)); |
||
34 | },updateState:function(){ |
||
35 | var e=this.editor,c=this.command,_8,_9; |
||
36 | if(!e||!e.isLoaded||!c.length){
|
||
37 | return;
|
||
38 | } |
||
39 | if(this.button){ |
||
40 | try{
|
||
41 | _9=e.queryCommandEnabled(c); |
||
42 | if(this.enabled!==_9){ |
||
43 | this.enabled=_9;
|
||
44 | this.button.set("disabled",!_9); |
||
45 | } |
||
46 | if(typeof this.button.checked=="boolean"){ |
||
47 | _8=e.queryCommandState(c); |
||
48 | if(this.checked!==_8){ |
||
49 | this.checked=_8;
|
||
50 | this.button.set("checked",e.queryCommandState(c)); |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | catch(e){
|
||
55 | } |
||
56 | } |
||
57 | },setEditor:function(_a){ |
||
58 | this.editor=_a;
|
||
59 | this._initButton();
|
||
60 | if(this.button&&this.useDefaultCommand){ |
||
61 | if(this.editor.queryCommandAvailable(this.command)){ |
||
62 | this.connect(this.button,"onClick",dojo.hitch(this.editor,"execCommand",this.command,this.commandArg)); |
||
63 | }else{
|
||
64 | this.button.domNode.style.display="none"; |
||
65 | } |
||
66 | } |
||
67 | this.connect(this.editor,"onNormalizedDisplayChanged","updateState"); |
||
68 | },setToolbar:function(_b){ |
||
69 | if(this.button){ |
||
70 | _b.addChild(this.button);
|
||
71 | } |
||
72 | }}); |
||
73 | } |