CollapsibleToolbar.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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.CollapsibleToolbar"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.editor.plugins.CollapsibleToolbar"] = true;
  8. dojo.provide("dojox.editor.plugins.CollapsibleToolbar");
  9. dojo.require("dijit._Widget");
  10. dojo.require("dijit._Templated");
  11. dojo.require("dijit._editor._Plugin");
  12. dojo.require("dijit.form.Button");
  13. dojo.require("dojo.i18n");
  14. dojo.requireLocalization("dojox.editor.plugins", "CollapsibleToolbar", null, "ROOT,ar,bg,ca,cs,da,de,el,es,fi,fr,he,hr,hu,it,ja,kk,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
  15. dojo.declare("dojox.editor.plugins._CollapsibleToolbarButton", [dijit._Widget, dijit._Templated], {
  16. // summary:
  17. // Simple internal widget for representing a clickable button for expand/collapse
  18. // with A11Y support.
  19. // tags:
  20. // private
  21. templateString: "<div tabindex='0' role='button' title='${title}' class='${buttonClass}' " +
  22. "dojoAttachEvent='ondijitclick: onClick'><span class='${textClass}'>${text}</span></div>",
  23. // title [public] String
  24. // The text to read by a screen reader that gets button focus.
  25. title: "",
  26. // buttonClass [public] String
  27. // The classname to apply to the expand/collapse button.
  28. buttonClass: "",
  29. // text [public] String
  30. // The text to use as expand/collapse in A11Y mode.
  31. text: "",
  32. // textClass [public] String
  33. // The classname to apply to the expand/collapse text.
  34. textClass: "",
  35. onClick: function(e){
  36. // summary:
  37. // Simple synthetic event to listen for dijit click events (mouse or keyboard)
  38. }
  39. });
  40. dojo.declare("dojox.editor.plugins.CollapsibleToolbar",dijit._editor._Plugin,{
  41. // summary:
  42. // This plugin provides a weappable toolbar container to allow expand/collapse
  43. // of the editor toolbars. This plugin should be registered first in most cases to
  44. // avoid conflicts in toolbar construction.
  45. // _myWidgets: [private] array
  46. // Container for widgets I allocate that will need to be destroyed.
  47. _myWidgets: null,
  48. setEditor: function(editor){
  49. // summary:
  50. // Over-ride for the setting of the editor.
  51. // editor: Object
  52. // The editor to configure for this plugin to use.
  53. this.editor = editor;
  54. this._constructContainer();
  55. },
  56. _constructContainer: function(){
  57. // summary:
  58. // Internal function to construct a wrapper for the toolbar/header that allows
  59. // it to expand and collapse. It effectively builds a containing table,
  60. // which handles the layout nicely and gets BIDI support by default.
  61. // tags:
  62. // private
  63. var strings = dojo.i18n.getLocalization("dojox.editor.plugins", "CollapsibleToolbar");
  64. this._myWidgets = [];
  65. // Build the containers.
  66. var container = dojo.create("table", {style: { width: "100%" }, tabindex: -1, "class": "dojoxCollapsibleToolbarContainer"});
  67. var tbody = dojo.create("tbody", {tabindex: -1}, container);
  68. var row = dojo.create("tr", {tabindex: -1}, tbody);
  69. var openTd = dojo.create("td", {"class": "dojoxCollapsibleToolbarControl", tabindex: -1}, row);
  70. var closeTd = dojo.create("td", {"class": "dojoxCollapsibleToolbarControl", tabindex: -1}, row);
  71. var menuTd = dojo.create("td", {style: { width: "100%" }, tabindex: -1}, row);
  72. var m = dojo.create("span", {style: { width: "100%" }, tabindex: -1}, menuTd);
  73. var collapseButton = new dojox.editor.plugins._CollapsibleToolbarButton({
  74. buttonClass: "dojoxCollapsibleToolbarCollapse",
  75. title: strings.collapse,
  76. text: "-",
  77. textClass: "dojoxCollapsibleToolbarCollapseText"
  78. });
  79. dojo.place(collapseButton.domNode, openTd);
  80. var expandButton = new dojox.editor.plugins._CollapsibleToolbarButton({
  81. buttonClass: "dojoxCollapsibleToolbarExpand",
  82. title: strings.expand,
  83. text: "+",
  84. textClass: "dojoxCollapsibleToolbarExpandText"
  85. });
  86. dojo.place(expandButton.domNode, closeTd);
  87. this._myWidgets.push(collapseButton);
  88. this._myWidgets.push(expandButton);
  89. // Attach everything in now.
  90. dojo.style(closeTd, "display", "none");
  91. dojo.place(container, this.editor.toolbar.domNode, "after");
  92. dojo.place(this.editor.toolbar.domNode, m);
  93. this.openTd = openTd;
  94. this.closeTd = closeTd;
  95. this.menu = m;
  96. // Establish the events to handle open/close.
  97. this.connect(collapseButton, "onClick", "_onClose");
  98. this.connect(expandButton, "onClick", "_onOpen");
  99. },
  100. _onClose: function(e){
  101. // summary:
  102. // Internal function for handling a click event that will close the toolbar.
  103. // e:
  104. // The click event.
  105. // tags:
  106. // private
  107. if(e){ dojo.stopEvent(e); }
  108. var size = dojo.marginBox(this.editor.domNode);
  109. dojo.style(this.openTd, "display", "none");
  110. dojo.style(this.closeTd, "display", "");
  111. dojo.style(this.menu, "display", "none");
  112. this.editor.resize({h: size.h});
  113. // work around IE rendering glitch in a11y mode.
  114. if(dojo.isIE){
  115. this.editor.header.className = this.editor.header.className;
  116. this.editor.footer.className = this.editor.footer.className;
  117. }
  118. dijit.focus(this.closeTd.firstChild);
  119. },
  120. _onOpen: function(e) {
  121. // summary:
  122. // Internal function for handling a click event that will open the toolbar.
  123. // e:
  124. // The click event.
  125. // tags:
  126. // private
  127. if(e){ dojo.stopEvent(e); }
  128. var size = dojo.marginBox(this.editor.domNode);
  129. dojo.style(this.closeTd, "display", "none");
  130. dojo.style(this.openTd, "display", "");
  131. dojo.style(this.menu, "display", "");
  132. this.editor.resize({h: size.h});
  133. // work around IE rendering glitch in a11y mode.
  134. if(dojo.isIE){
  135. this.editor.header.className = this.editor.header.className;
  136. this.editor.footer.className = this.editor.footer.className;
  137. }
  138. dijit.focus(this.openTd.firstChild);
  139. },
  140. destroy: function(){
  141. // summary:
  142. // Over-ride of destroy method for cleanup.
  143. this.inherited(arguments);
  144. if(this._myWidgets){
  145. while(this._myWidgets.length){
  146. this._myWidgets.pop().destroy();
  147. }
  148. delete this._myWidgets;
  149. }
  150. }
  151. });
  152. // Register this plugin.
  153. dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
  154. if(o.plugin){ return; }
  155. var name = o.args.name.toLowerCase();
  156. if(name === "collapsibletoolbar"){
  157. o.plugin = new dojox.editor.plugins.CollapsibleToolbar({});
  158. }
  159. });
  160. }