| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/dom", |
| 4 |
"dojo/dom-attr", |
| 5 |
"dojo/dom-class", |
| 6 |
"dojo/has", |
| 7 |
"dojo/i18n", |
| 8 |
"dojo/_base/lang", |
| 9 |
"./StackController", |
| 10 |
"../registry", |
| 11 |
"../Menu", |
| 12 |
"../MenuItem", |
| 13 |
"dojo/text!./templates/_TabButton.html", |
| 14 |
"dojo/i18n!../nls/common" |
| 15 |
], function(declare, dom, domAttr, domClass, has, i18n, lang, StackController, registry, Menu, MenuItem, template){ |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
var TabButton = declare("dijit.layout._TabButton" + (has("dojo-bidi") ? "_NoBidi" : ""), StackController.StackButton, { |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
baseClass: "dijitTab", |
| 32 |
|
| 33 |
|
| 34 |
cssStateNodes: { |
| 35 |
closeNode: "dijitTabCloseButton" |
| 36 |
}, |
| 37 |
|
| 38 |
templateString: template, |
| 39 |
|
| 40 |
|
| 41 |
_setNameAttr: "focusNode", |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
scrollOnFocus: false, |
| 46 |
|
| 47 |
buildRendering: function(){ |
| 48 |
this.inherited(arguments); |
| 49 |
|
| 50 |
dom.setSelectable(this.containerNode, false); |
| 51 |
}, |
| 52 |
|
| 53 |
startup: function(){ |
| 54 |
this.inherited(arguments); |
| 55 |
var n = this.domNode; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
this.defer(function(){ |
| 60 |
n.className = n.className; |
| 61 |
}, 1); |
| 62 |
}, |
| 63 |
|
| 64 |
_setCloseButtonAttr: function( disp){ |
| 65 |
|
| 66 |
|
| 67 |
this._set("closeButton", disp); |
| 68 |
domClass.toggle(this.domNode, "dijitClosable", disp); |
| 69 |
this.closeNode.style.display = disp ? "" : "none"; |
| 70 |
if(disp){ |
| 71 |
var _nlsResources = i18n.getLocalization("dijit", "common"); |
| 72 |
if(this.closeNode){ |
| 73 |
domAttr.set(this.closeNode, "title", _nlsResources.itemClose); |
| 74 |
} |
| 75 |
} |
| 76 |
}, |
| 77 |
|
| 78 |
_setDisabledAttr: function( disabled){ |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
this.inherited(arguments); |
| 83 |
|
| 84 |
|
| 85 |
if(this.closeNode){ |
| 86 |
if(disabled){ |
| 87 |
domAttr.remove(this.closeNode, "title"); |
| 88 |
}else{ |
| 89 |
var _nlsResources = i18n.getLocalization("dijit", "common"); |
| 90 |
domAttr.set(this.closeNode, "title", _nlsResources.itemClose); |
| 91 |
} |
| 92 |
} |
| 93 |
}, |
| 94 |
|
| 95 |
_setLabelAttr: function( content){ |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
this.inherited(arguments); |
| 103 |
if(!this.showLabel && !this.params.title){ |
| 104 |
this.iconNode.alt = lang.trim(this.containerNode.innerText || this.containerNode.textContent || ''); |
| 105 |
} |
| 106 |
} |
| 107 |
}); |
| 108 |
|
| 109 |
if(has("dojo-bidi")){ |
| 110 |
TabButton = declare("dijit.layout._TabButton", TabButton, { |
| 111 |
_setLabelAttr: function( content){ |
| 112 |
this.inherited(arguments); |
| 113 |
this.applyTextDir(this.iconNode, this.iconNode.alt); |
| 114 |
} |
| 115 |
}); |
| 116 |
} |
| 117 |
|
| 118 |
var TabController = declare("dijit.layout.TabController", StackController, { |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
baseClass: "dijitTabController", |
| 130 |
|
| 131 |
templateString: "<div role='tablist' data-dojo-attach-event='onkeydown:onkeydown'></div>", |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
tabPosition: "top", |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
buttonWidget: TabButton, |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
buttonWidgetCloseClass: "dijitTabCloseButton", |
| 145 |
|
| 146 |
postCreate: function(){ |
| 147 |
this.inherited(arguments); |
| 148 |
|
| 149 |
|
| 150 |
var closeMenu = new Menu({ |
| 151 |
id: this.id + "_Menu", |
| 152 |
ownerDocument: this.ownerDocument, |
| 153 |
dir: this.dir, |
| 154 |
lang: this.lang, |
| 155 |
textDir: this.textDir, |
| 156 |
targetNodeIds: [this.domNode], |
| 157 |
selector: function(node){ |
| 158 |
return domClass.contains(node, "dijitClosable") && !domClass.contains(node, "dijitTabDisabled"); |
| 159 |
} |
| 160 |
}); |
| 161 |
this.own(closeMenu); |
| 162 |
|
| 163 |
var _nlsResources = i18n.getLocalization("dijit", "common"), |
| 164 |
controller = this; |
| 165 |
closeMenu.addChild(new MenuItem({ |
| 166 |
label: _nlsResources.itemClose, |
| 167 |
ownerDocument: this.ownerDocument, |
| 168 |
dir: this.dir, |
| 169 |
lang: this.lang, |
| 170 |
textDir: this.textDir, |
| 171 |
onClick: function(evt){ |
| 172 |
var button = registry.byNode(this.getParent().currentTarget); |
| 173 |
controller.onCloseButtonClick(button.page); |
| 174 |
} |
| 175 |
})); |
| 176 |
} |
| 177 |
}); |
| 178 |
|
| 179 |
TabController.TabButton = TabButton; |
| 180 |
|
| 181 |
return TabController; |
| 182 |
}); |