TabController.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. require({cache:{
  2. 'url:dijit/layout/templates/_TabButton.html':"<div role=\"presentation\" data-dojo-attach-point=\"titleNode\" data-dojo-attach-event='onclick:onClick'>\n <div role=\"presentation\" class='dijitTabInnerDiv' data-dojo-attach-point='innerDiv'>\n <div role=\"presentation\" class='dijitTabContent' data-dojo-attach-point='tabContent'>\n \t<div role=\"presentation\" data-dojo-attach-point='focusNode'>\n\t\t <img src=\"${_blankGif}\" alt=\"\" class=\"dijitIcon dijitTabButtonIcon\" data-dojo-attach-point='iconNode' />\n\t\t <span data-dojo-attach-point='containerNode' class='tabLabel'></span>\n\t\t <span class=\"dijitInline dijitTabCloseButton dijitTabCloseIcon\" data-dojo-attach-point='closeNode'\n\t\t \t\tdata-dojo-attach-event='onclick: onClickCloseButton' role=\"presentation\">\n\t\t <span data-dojo-attach-point='closeText' class='dijitTabCloseText'>[x]</span\n\t\t ></span>\n\t\t\t</div>\n </div>\n </div>\n</div>\n"}});
  3. define("dijit/layout/TabController", [
  4. "dojo/_base/declare", // declare
  5. "dojo/dom", // dom.setSelectable
  6. "dojo/dom-attr", // domAttr.attr
  7. "dojo/dom-class", // domClass.toggle
  8. "dojo/i18n", // i18n.getLocalization
  9. "dojo/_base/lang", // lang.hitch lang.trim
  10. "./StackController",
  11. "../Menu",
  12. "../MenuItem",
  13. "dojo/text!./templates/_TabButton.html",
  14. "dojo/i18n!../nls/common"
  15. ], function(declare, dom, domAttr, domClass, i18n, lang, StackController, Menu, MenuItem, template){
  16. /*=====
  17. var StackController = dijit.layout.StackController;
  18. var Menu = dijit.Menu;
  19. var MenuItem = dijit.MenuItem;
  20. =====*/
  21. // module:
  22. // dijit/layout/TabController
  23. // summary:
  24. // Set of tabs (the things with titles and a close button, that you click to show a tab panel).
  25. // Used internally by `dijit.layout.TabContainer`.
  26. var TabButton = declare("dijit.layout._TabButton", StackController.StackButton, {
  27. // summary:
  28. // A tab (the thing you click to select a pane).
  29. // description:
  30. // Contains the title of the pane, and optionally a close-button to destroy the pane.
  31. // This is an internal widget and should not be instantiated directly.
  32. // tags:
  33. // private
  34. // baseClass: String
  35. // The CSS class applied to the domNode.
  36. baseClass: "dijitTab",
  37. // Apply dijitTabCloseButtonHover when close button is hovered
  38. cssStateNodes: {
  39. closeNode: "dijitTabCloseButton"
  40. },
  41. templateString: template,
  42. // Override _FormWidget.scrollOnFocus.
  43. // Don't scroll the whole tab container into view when the button is focused.
  44. scrollOnFocus: false,
  45. buildRendering: function(){
  46. this.inherited(arguments);
  47. dom.setSelectable(this.containerNode, false);
  48. },
  49. startup: function(){
  50. this.inherited(arguments);
  51. var n = this.domNode;
  52. // Required to give IE6 a kick, as it initially hides the
  53. // tabs until they are focused on.
  54. setTimeout(function(){
  55. n.className = n.className;
  56. }, 1);
  57. },
  58. _setCloseButtonAttr: function(/*Boolean*/ disp){
  59. // summary:
  60. // Hide/show close button
  61. this._set("closeButton", disp);
  62. domClass.toggle(this.innerDiv, "dijitClosable", disp);
  63. this.closeNode.style.display = disp ? "" : "none";
  64. if(disp){
  65. var _nlsResources = i18n.getLocalization("dijit", "common");
  66. if(this.closeNode){
  67. domAttr.set(this.closeNode,"title", _nlsResources.itemClose);
  68. }
  69. // add context menu onto title button
  70. this._closeMenu = new Menu({
  71. id: this.id+"_Menu",
  72. dir: this.dir,
  73. lang: this.lang,
  74. textDir: this.textDir,
  75. targetNodeIds: [this.domNode]
  76. });
  77. this._closeMenu.addChild(new MenuItem({
  78. label: _nlsResources.itemClose,
  79. dir: this.dir,
  80. lang: this.lang,
  81. textDir: this.textDir,
  82. onClick: lang.hitch(this, "onClickCloseButton")
  83. }));
  84. }else{
  85. if(this._closeMenu){
  86. this._closeMenu.destroyRecursive();
  87. delete this._closeMenu;
  88. }
  89. }
  90. },
  91. _setLabelAttr: function(/*String*/ content){
  92. // summary:
  93. // Hook for set('label', ...) to work.
  94. // description:
  95. // takes an HTML string.
  96. // Inherited ToggleButton implementation will Set the label (text) of the button;
  97. // Need to set the alt attribute of icon on tab buttons if no label displayed
  98. this.inherited(arguments);
  99. if(!this.showLabel && !this.params.title){
  100. this.iconNode.alt = lang.trim(this.containerNode.innerText || this.containerNode.textContent || '');
  101. }
  102. },
  103. destroy: function(){
  104. if(this._closeMenu){
  105. this._closeMenu.destroyRecursive();
  106. delete this._closeMenu;
  107. }
  108. this.inherited(arguments);
  109. }
  110. });
  111. var TabController = declare("dijit.layout.TabController", StackController, {
  112. // summary:
  113. // Set of tabs (the things with titles and a close button, that you click to show a tab panel).
  114. // Used internally by `dijit.layout.TabContainer`.
  115. // description:
  116. // Lets the user select the currently shown pane in a TabContainer or StackContainer.
  117. // TabController also monitors the TabContainer, and whenever a pane is
  118. // added or deleted updates itself accordingly.
  119. // tags:
  120. // private
  121. baseClass: "dijitTabController",
  122. templateString: "<div role='tablist' data-dojo-attach-event='onkeypress:onkeypress'></div>",
  123. // tabPosition: String
  124. // Defines where tabs go relative to the content.
  125. // "top", "bottom", "left-h", "right-h"
  126. tabPosition: "top",
  127. // buttonWidget: Constructor
  128. // The tab widget to create to correspond to each page
  129. buttonWidget: TabButton,
  130. _rectifyRtlTabList: function(){
  131. // summary:
  132. // For left/right TabContainer when page is RTL mode, rectify the width of all tabs to be equal, otherwise the tab widths are different in IE
  133. if(0 >= this.tabPosition.indexOf('-h')){ return; }
  134. if(!this.pane2button){ return; }
  135. var maxWidth = 0;
  136. for(var pane in this.pane2button){
  137. var ow = this.pane2button[pane].innerDiv.scrollWidth;
  138. maxWidth = Math.max(maxWidth, ow);
  139. }
  140. //unify the length of all the tabs
  141. for(pane in this.pane2button){
  142. this.pane2button[pane].innerDiv.style.width = maxWidth + 'px';
  143. }
  144. }
  145. });
  146. TabController.TabButton = TabButton; // for monkey patching
  147. return TabController;
  148. });