TabController.js 5.7 KB

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