_Plugin.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //>>built
  2. define("dijit/_editor/_Plugin",["dojo/_base/connect","dojo/_base/declare","dojo/_base/lang","../Destroyable","../form/Button"],function(_1,_2,_3,_4,_5){
  3. var _6=_2("dijit._editor._Plugin",_4,{constructor:function(_7){
  4. this.params=_7||{};
  5. _3.mixin(this,this.params);
  6. this._attrPairNames={};
  7. },editor:null,iconClassPrefix:"dijitEditorIcon",button:null,command:"",useDefaultCommand:true,buttonClass:_5,disabled:false,getLabel:function(_8){
  8. return this.editor.commands[_8];
  9. },_initButton:function(){
  10. if(this.command.length){
  11. var _9=this.getLabel(this.command),_a=this.editor,_b=this.iconClassPrefix+" "+this.iconClassPrefix+this.command.charAt(0).toUpperCase()+this.command.substr(1);
  12. if(!this.button){
  13. var _c=_3.mixin({label:_9,ownerDocument:_a.ownerDocument,dir:_a.dir,lang:_a.lang,showLabel:false,iconClass:_b,dropDown:this.dropDown,tabIndex:"-1"},this.params||{});
  14. this.button=new this.buttonClass(_c);
  15. }
  16. }
  17. if(this.get("disabled")&&this.button){
  18. this.button.set("disabled",this.get("disabled"));
  19. }
  20. },destroy:function(){
  21. if(this.dropDown){
  22. this.dropDown.destroyRecursive();
  23. }
  24. this.inherited(arguments);
  25. },connect:function(o,f,tf){
  26. this.own(_1.connect(o,f,this,tf));
  27. },updateState:function(){
  28. var e=this.editor,c=this.command,_d,_e;
  29. if(!e||!e.isLoaded||!c.length){
  30. return;
  31. }
  32. var _f=this.get("disabled");
  33. if(this.button){
  34. try{
  35. _e=!_f&&e.queryCommandEnabled(c);
  36. if(this.enabled!==_e){
  37. this.enabled=_e;
  38. this.button.set("disabled",!_e);
  39. }
  40. if(_e){
  41. if(typeof this.button.checked=="boolean"){
  42. _d=e.queryCommandState(c);
  43. if(this.checked!==_d){
  44. this.checked=_d;
  45. this.button.set("checked",e.queryCommandState(c));
  46. }
  47. }
  48. }
  49. }
  50. catch(e){
  51. }
  52. }
  53. },setEditor:function(_10){
  54. this.editor=_10;
  55. this._initButton();
  56. if(this.button&&this.useDefaultCommand){
  57. if(this.editor.queryCommandAvailable(this.command)){
  58. this.own(this.button.on("click",_3.hitch(this.editor,"execCommand",this.command,this.commandArg)));
  59. }else{
  60. this.button.domNode.style.display="none";
  61. }
  62. }
  63. this.own(this.editor.on("NormalizedDisplayChanged",_3.hitch(this,"updateState")));
  64. },setToolbar:function(_11){
  65. if(this.button){
  66. _11.addChild(this.button);
  67. }
  68. },set:function(_12,_13){
  69. if(typeof _12==="object"){
  70. for(var x in _12){
  71. this.set(x,_12[x]);
  72. }
  73. return this;
  74. }
  75. var _14=this._getAttrNames(_12);
  76. if(this[_14.s]){
  77. var _15=this[_14.s].apply(this,Array.prototype.slice.call(arguments,1));
  78. }else{
  79. this._set(_12,_13);
  80. }
  81. return _15||this;
  82. },get:function(_16){
  83. var _17=this._getAttrNames(_16);
  84. return this[_17.g]?this[_17.g]():this[_16];
  85. },_setDisabledAttr:function(_18){
  86. this._set("disabled",_18);
  87. this.updateState();
  88. },_getAttrNames:function(_19){
  89. var apn=this._attrPairNames;
  90. if(apn[_19]){
  91. return apn[_19];
  92. }
  93. var uc=_19.charAt(0).toUpperCase()+_19.substr(1);
  94. return (apn[_19]={s:"_set"+uc+"Attr",g:"_get"+uc+"Attr"});
  95. },_set:function(_1a,_1b){
  96. this[_1a]=_1b;
  97. }});
  98. _6.registry={};
  99. return _6;
  100. });