StatusBar.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. define("dojox/editor/plugins/StatusBar", [
  2. "dojo",
  3. "dijit",
  4. "dojox",
  5. "dijit/_Widget",
  6. "dijit/_TemplatedMixin",
  7. "dijit/_editor/_Plugin",
  8. "dojo/_base/connect",
  9. "dojo/_base/declare",
  10. "dojox/layout/ResizeHandle"
  11. ], function(dojo, dijit, dojox) {
  12. dojo.experimental("dojox.editor.plugins.StatusBar");
  13. dojo.declare("dojox.editor.plugins._StatusBar", [dijit._Widget, dijit._TemplatedMixin],{
  14. // templateString: String
  15. // Template for the widget. Currently using table to get the alignment behavior and
  16. // bordering I wanted. Would prefer not to use table, though.
  17. templateString: '<div class="dojoxEditorStatusBar">' +
  18. '<table><tbody><tr>'+
  19. '<td class="dojoxEditorStatusBarText" tabindex="-1" aria-role="presentation" aria-live="aggressive"><span dojoAttachPoint="barContent">&nbsp;</span></td>' +
  20. '<td><span dojoAttachPoint="handle"></span></td>' +
  21. '</tr></tbody><table>'+
  22. '</div>',
  23. _getValueAttr: function(){
  24. // summary:
  25. // Over-ride to get the value of the status bar from the widget.
  26. // tags:
  27. // Protected
  28. return this.barContent.innerHTML;
  29. },
  30. _setValueAttr: function(str){
  31. // summary:
  32. // Over-ride to set the value of the status bar from the widget.
  33. // If no value is set, it is replaced with a non-blocking space.
  34. // str: String
  35. // The string to set as the status bar content.
  36. // tags:
  37. // protected
  38. if(str){
  39. str = dojo.trim(str);
  40. if(!str){
  41. str = "&nbsp;";
  42. }
  43. }else{
  44. str = "&nbsp;";
  45. }
  46. this.barContent.innerHTML = str;
  47. }
  48. });
  49. dojo.declare("dojox.editor.plugins.StatusBar",dijit._editor._Plugin,{
  50. // summary:
  51. // This plugin provides StatusBar cabability to the editor.
  52. // Basically a footer bar where status can be published. It also
  53. // puts a resize handle on the status bar, allowing you to resize the
  54. // editor via mouse.
  55. // statusBar: [protected]
  56. // The status bar and resizer.
  57. statusBar: null,
  58. // resizer: [public] Boolean
  59. // Flag indicating that a resizer should be shown or not. Default is true.
  60. // There are cases (such as using center pane border container to autoresize the editor
  61. // That a resizer is not valued.
  62. resizer: true,
  63. setEditor: function(editor){
  64. // summary:
  65. // Over-ride for the setting of the editor.
  66. // editor: Object
  67. // The editor to configure for this plugin to use.
  68. this.editor = editor;
  69. this.statusBar = new dojox.editor.plugins._StatusBar();
  70. if(this.resizer){
  71. this.resizeHandle = new dojox.layout.ResizeHandle({targetId: this.editor, activeResize: true}, this.statusBar.handle);
  72. this.resizeHandle.startup();
  73. }else{
  74. dojo.style(this.statusBar.handle.parentNode, "display", "none");
  75. }
  76. var pos = null;
  77. if(editor.footer.lastChild){
  78. pos = "after";
  79. }
  80. dojo.place(this.statusBar.domNode, editor.footer.lastChild || editor.footer, pos);
  81. this.statusBar.startup();
  82. this.editor.statusBar = this;
  83. // Register a pub-sub event to listen for status bar messages, in addition to being available off
  84. // the editor as a property 'statusBar'
  85. this._msgListener = dojo.subscribe(this.editor.id + "_statusBar", dojo.hitch(this, this._setValueAttr));
  86. },
  87. _getValueAttr: function(){
  88. // summary:
  89. // Over-ride to get the value of the status bar from the widget.
  90. // tags:
  91. // protected
  92. return this.statusBar.get("value");
  93. },
  94. _setValueAttr: function(str){
  95. // summary:
  96. // Over-ride to set the value of the status bar from the widget.
  97. // If no value is set, it is replaced with a non-blocking space.
  98. // str: String
  99. // The String value to set in the bar.
  100. // tags:
  101. // protected
  102. this.statusBar.set("value", str);
  103. },
  104. set: function(attr, val){
  105. // summary:
  106. // Quick and dirty implementation of 'set' pattern
  107. // attr:
  108. // The attribute to set.
  109. // val:
  110. // The value to set it to.
  111. if(attr){
  112. var fName = "_set" + attr.charAt(0).toUpperCase() + attr.substring(1, attr.length) + "Attr";
  113. if(dojo.isFunction(this[fName])){
  114. this[fName](val);
  115. }else{
  116. this[attr] = val;
  117. }
  118. }
  119. },
  120. get: function(attr){
  121. // summary:
  122. // Quick and dirty implementation of 'get' pattern
  123. // attr:
  124. // The attribute to get.
  125. if(attr){
  126. var fName = "_get" + attr.charAt(0).toUpperCase() + attr.substring(1, attr.length) + "Attr";
  127. var f = this[fName];
  128. if(dojo.isFunction(f)){
  129. return this[fName]();
  130. }else{
  131. return this[attr];
  132. }
  133. }
  134. return null;
  135. },
  136. destroy: function(){
  137. // summary:
  138. // Over-ride to clean up the breadcrumb toolbar.
  139. if(this.statusBar){
  140. this.statusBar.destroy();
  141. delete this.statusBar;
  142. }
  143. if(this.resizeHandle){
  144. this.resizeHandle.destroy();
  145. delete this.resizeHandle;
  146. }
  147. if(this._msgListener){
  148. dojo.unsubscribe(this._msgListener);
  149. delete this._msgListener;
  150. }
  151. delete this.editor.statusBar;
  152. }
  153. });
  154. // Register this plugin.
  155. dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
  156. if(o.plugin){ return; }
  157. var name = o.args.name.toLowerCase();
  158. if(name === "statusbar"){
  159. var resizer = ("resizer" in o.args)?o.args.resizer:true;
  160. o.plugin = new dojox.editor.plugins.StatusBar({resizer: resizer});
  161. }
  162. });
  163. return dojox.editor.plugins.StatusBar;
  164. });