StatusBar.js 5.4 KB

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