| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/dom-class", |
| 5 |
"dojo/dom-geometry", |
| 6 |
"dojo/dom-style", |
| 7 |
"dojo/_base/fx", |
| 8 |
"dojo/_base/lang", |
| 9 |
"dojo/on", |
| 10 |
"dojo/query", |
| 11 |
"dojo/sniff", |
| 12 |
"../registry", |
| 13 |
"dojo/text!./templates/ScrollingTabController.html", |
| 14 |
"dojo/text!./templates/_ScrollingTabControllerButton.html", |
| 15 |
"./TabController", |
| 16 |
"./utils", |
| 17 |
"../_WidgetsInTemplateMixin", |
| 18 |
"../Menu", |
| 19 |
"../MenuItem", |
| 20 |
"../form/Button", |
| 21 |
"../_HasDropDown", |
| 22 |
"dojo/NodeList-dom", |
| 23 |
"../a11yclick" |
| 24 |
], function(array, declare, domClass, domGeometry, domStyle, fx, lang, on, query, has, |
| 25 |
registry, tabControllerTemplate, buttonTemplate, TabController, layoutUtils, _WidgetsInTemplateMixin, |
| 26 |
Menu, MenuItem, Button, _HasDropDown){ |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
var ScrollingTabController = declare("dijit.layout.ScrollingTabController", [TabController, _WidgetsInTemplateMixin], { |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
baseClass: "dijitTabController dijitScrollingTabController", |
| 41 |
|
| 42 |
templateString: tabControllerTemplate, |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
useMenu: true, |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
useSlider: true, |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
tabStripClass: "", |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
_minScroll: 5, |
| 63 |
|
| 64 |
|
| 65 |
_setClassAttr: { node: "containerNode", type: "class" }, |
| 66 |
|
| 67 |
buildRendering: function(){ |
| 68 |
this.inherited(arguments); |
| 69 |
var n = this.domNode; |
| 70 |
|
| 71 |
this.scrollNode = this.tablistWrapper; |
| 72 |
this._initButtons(); |
| 73 |
|
| 74 |
if(!this.tabStripClass){ |
| 75 |
this.tabStripClass = "dijitTabContainer" + |
| 76 |
this.tabPosition.charAt(0).toUpperCase() + |
| 77 |
this.tabPosition.substr(1).replace(/-.*/, "") + |
| 78 |
"None"; |
| 79 |
domClass.add(n, "tabStrip-disabled") |
| 80 |
} |
| 81 |
|
| 82 |
domClass.add(this.tablistWrapper, this.tabStripClass); |
| 83 |
}, |
| 84 |
|
| 85 |
onStartup: function(){ |
| 86 |
this.inherited(arguments); |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
domStyle.set(this.domNode, "visibility", ""); |
| 92 |
this._postStartup = true; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
this.own(on(this.containerNode, "attrmodified-label, attrmodified-iconclass", lang.hitch(this, function(evt){ |
| 97 |
if(this._dim){ |
| 98 |
this.resize(this._dim); |
| 99 |
} |
| 100 |
}))); |
| 101 |
}, |
| 102 |
|
| 103 |
onAddChild: function(page, insertIndex){ |
| 104 |
this.inherited(arguments); |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
domStyle.set(this.containerNode, "width", |
| 111 |
(domStyle.get(this.containerNode, "width") + 200) + "px"); |
| 112 |
}, |
| 113 |
|
| 114 |
onRemoveChild: function(page, insertIndex){ |
| 115 |
|
| 116 |
var button = this.pane2button(page.id); |
| 117 |
if(this._selectedTab === button.domNode){ |
| 118 |
this._selectedTab = null; |
| 119 |
} |
| 120 |
|
| 121 |
this.inherited(arguments); |
| 122 |
}, |
| 123 |
|
| 124 |
_initButtons: function(){ |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
this._btnWidth = 0; |
| 133 |
this._buttons = query("> .tabStripButton", this.domNode).filter(function(btn){ |
| 134 |
if((this.useMenu && btn == this._menuBtn.domNode) || |
| 135 |
(this.useSlider && (btn == this._rightBtn.domNode || btn == this._leftBtn.domNode))){ |
| 136 |
this._btnWidth += domGeometry.getMarginSize(btn).w; |
| 137 |
return true; |
| 138 |
}else{ |
| 139 |
domStyle.set(btn, "display", "none"); |
| 140 |
return false; |
| 141 |
} |
| 142 |
}, this); |
| 143 |
}, |
| 144 |
|
| 145 |
_getTabsWidth: function(){ |
| 146 |
var children = this.getChildren(); |
| 147 |
if(children.length){ |
| 148 |
var leftTab = children[this.isLeftToRight() ? 0 : children.length - 1].domNode, |
| 149 |
rightTab = children[this.isLeftToRight() ? children.length - 1 : 0].domNode; |
| 150 |
return rightTab.offsetLeft + rightTab.offsetWidth - leftTab.offsetLeft; |
| 151 |
}else{ |
| 152 |
return 0; |
| 153 |
} |
| 154 |
}, |
| 155 |
|
| 156 |
_enableBtn: function(width){ |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
var tabsWidth = this._getTabsWidth(); |
| 161 |
width = width || domStyle.get(this.scrollNode, "width"); |
| 162 |
return tabsWidth > 0 && width < tabsWidth; |
| 163 |
}, |
| 164 |
|
| 165 |
resize: function(dim){ |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
this._dim = dim; |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
this.scrollNode.style.height = "auto"; |
| 178 |
var cb = this._contentBox = layoutUtils.marginBox2contentBox(this.domNode, {h: 0, w: dim.w}); |
| 179 |
cb.h = this.scrollNode.offsetHeight; |
| 180 |
domGeometry.setContentSize(this.domNode, cb); |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
var enable = this._enableBtn(this._contentBox.w); |
| 185 |
this._buttons.style("display", enable ? "" : "none"); |
| 186 |
|
| 187 |
|
| 188 |
this._leftBtn.region = "left"; |
| 189 |
this._rightBtn.region = "right"; |
| 190 |
this._menuBtn.region = this.isLeftToRight() ? "right" : "left"; |
| 191 |
layoutUtils.layoutChildren(this.domNode, this._contentBox, |
| 192 |
[this._menuBtn, this._leftBtn, this._rightBtn, {domNode: this.scrollNode, region: "center"}]); |
| 193 |
|
| 194 |
|
| 195 |
if(this._selectedTab){ |
| 196 |
if(this._anim && this._anim.status() == "playing"){ |
| 197 |
this._anim.stop(); |
| 198 |
} |
| 199 |
this.scrollNode.scrollLeft = this._convertToScrollLeft(this._getScrollForSelectedTab()); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
this._setButtonClass(this._getScroll()); |
| 204 |
|
| 205 |
this._postResize = true; |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
return {h: this._contentBox.h, w: dim.w}; |
| 210 |
}, |
| 211 |
|
| 212 |
_getScroll: function(){ |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
return (this.isLeftToRight() || has("ie") < 8 || (has("trident") && has("quirks")) || has("webkit")) ? |
| 218 |
this.scrollNode.scrollLeft : |
| 219 |
domStyle.get(this.containerNode, "width") - domStyle.get(this.scrollNode, "width") |
| 220 |
+ (has("trident") || has("edge") ? -1 : 1) * this.scrollNode.scrollLeft; |
| 221 |
}, |
| 222 |
|
| 223 |
_convertToScrollLeft: function(val){ |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
if(this.isLeftToRight() || has("ie") < 8 || (has("trident") && has("quirks")) || has("webkit")){ |
| 232 |
return val; |
| 233 |
}else{ |
| 234 |
var maxScroll = domStyle.get(this.containerNode, "width") - domStyle.get(this.scrollNode, "width"); |
| 235 |
return (has("trident") || has("edge") ? -1 : 1) * (val - maxScroll); |
| 236 |
} |
| 237 |
}, |
| 238 |
|
| 239 |
onSelectChild: function( page, tabContainerFocused){ |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
var tab = this.pane2button(page.id); |
| 244 |
if(!tab){ |
| 245 |
return; |
| 246 |
} |
| 247 |
|
| 248 |
var node = tab.domNode; |
| 249 |
|
| 250 |
|
| 251 |
if(node != this._selectedTab){ |
| 252 |
this._selectedTab = node; |
| 253 |
|
| 254 |
|
| 255 |
if(this._postResize){ |
| 256 |
var sl = this._getScroll(); |
| 257 |
|
| 258 |
if(sl > node.offsetLeft || |
| 259 |
sl + domStyle.get(this.scrollNode, "width") < |
| 260 |
node.offsetLeft + domStyle.get(node, "width")){ |
| 261 |
var anim = this.createSmoothScroll(); |
| 262 |
if(tabContainerFocused){ |
| 263 |
anim.onEnd = function(){ |
| 264 |
|
| 265 |
tab.focus(); |
| 266 |
}; |
| 267 |
} |
| 268 |
anim.play(); |
| 269 |
}else if(tabContainerFocused){ |
| 270 |
|
| 271 |
tab.focus(); |
| 272 |
} |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
this.inherited(arguments); |
| 277 |
}, |
| 278 |
|
| 279 |
_getScrollBounds: function(){ |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
var children = this.getChildren(), |
| 284 |
scrollNodeWidth = domStyle.get(this.scrollNode, "width"), |
| 285 |
containerWidth = domStyle.get(this.containerNode, "width"), |
| 286 |
maxPossibleScroll = containerWidth - scrollNodeWidth, |
| 287 |
tabsWidth = this._getTabsWidth(); |
| 288 |
|
| 289 |
if(children.length && tabsWidth > scrollNodeWidth){ |
| 290 |
|
| 291 |
return { |
| 292 |
min: this.isLeftToRight() ? 0 : children[children.length - 1].domNode.offsetLeft, |
| 293 |
max: this.isLeftToRight() ? |
| 294 |
(children[children.length - 1].domNode.offsetLeft + children[children.length - 1].domNode.offsetWidth) - scrollNodeWidth : |
| 295 |
maxPossibleScroll |
| 296 |
}; |
| 297 |
}else{ |
| 298 |
|
| 299 |
var onlyScrollPosition = this.isLeftToRight() ? 0 : maxPossibleScroll; |
| 300 |
return { |
| 301 |
min: onlyScrollPosition, |
| 302 |
max: onlyScrollPosition |
| 303 |
}; |
| 304 |
} |
| 305 |
}, |
| 306 |
|
| 307 |
_getScrollForSelectedTab: function(){ |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
var w = this.scrollNode, |
| 312 |
n = this._selectedTab, |
| 313 |
scrollNodeWidth = domStyle.get(this.scrollNode, "width"), |
| 314 |
scrollBounds = this._getScrollBounds(); |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
var pos = (n.offsetLeft + domStyle.get(n, "width") / 2) - scrollNodeWidth / 2; |
| 319 |
pos = Math.min(Math.max(pos, scrollBounds.min), scrollBounds.max); |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
return pos; |
| 326 |
}, |
| 327 |
|
| 328 |
createSmoothScroll: function(x){ |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
if(arguments.length > 0){ |
| 341 |
|
| 342 |
var scrollBounds = this._getScrollBounds(); |
| 343 |
x = Math.min(Math.max(x, scrollBounds.min), scrollBounds.max); |
| 344 |
}else{ |
| 345 |
|
| 346 |
x = this._getScrollForSelectedTab(); |
| 347 |
} |
| 348 |
|
| 349 |
if(this._anim && this._anim.status() == "playing"){ |
| 350 |
this._anim.stop(); |
| 351 |
} |
| 352 |
|
| 353 |
var self = this, |
| 354 |
w = this.scrollNode, |
| 355 |
anim = new fx.Animation({ |
| 356 |
beforeBegin: function(){ |
| 357 |
if(this.curve){ |
| 358 |
delete this.curve; |
| 359 |
} |
| 360 |
var oldS = w.scrollLeft, |
| 361 |
newS = self._convertToScrollLeft(x); |
| 362 |
anim.curve = new fx._Line(oldS, newS); |
| 363 |
}, |
| 364 |
onAnimate: function(val){ |
| 365 |
w.scrollLeft = val; |
| 366 |
} |
| 367 |
}); |
| 368 |
this._anim = anim; |
| 369 |
|
| 370 |
|
| 371 |
this._setButtonClass(x); |
| 372 |
|
| 373 |
return anim; |
| 374 |
}, |
| 375 |
|
| 376 |
_getBtnNode: function( e){ |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
var n = e.target; |
| 382 |
while(n && !domClass.contains(n, "tabStripButton")){ |
| 383 |
n = n.parentNode; |
| 384 |
} |
| 385 |
return n; |
| 386 |
}, |
| 387 |
|
| 388 |
doSlideRight: function( e){ |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
this.doSlide(1, this._getBtnNode(e)); |
| 394 |
}, |
| 395 |
|
| 396 |
doSlideLeft: function( e){ |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
this.doSlide(-1, this._getBtnNode(e)); |
| 402 |
}, |
| 403 |
|
| 404 |
doSlide: function( direction, node){ |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
if(node && domClass.contains(node, "dijitTabDisabled")){ |
| 412 |
return; |
| 413 |
} |
| 414 |
|
| 415 |
var sWidth = domStyle.get(this.scrollNode, "width"); |
| 416 |
var d = (sWidth * 0.75) * direction; |
| 417 |
|
| 418 |
var to = this._getScroll() + d; |
| 419 |
|
| 420 |
this._setButtonClass(to); |
| 421 |
|
| 422 |
this.createSmoothScroll(to).play(); |
| 423 |
}, |
| 424 |
|
| 425 |
_setButtonClass: function( scroll){ |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
var scrollBounds = this._getScrollBounds(); |
| 433 |
this._leftBtn.set("disabled", scroll <= scrollBounds.min); |
| 434 |
this._rightBtn.set("disabled", scroll >= scrollBounds.max); |
| 435 |
} |
| 436 |
}); |
| 437 |
|
| 438 |
|
| 439 |
var ScrollingTabControllerButtonMixin = declare("dijit.layout._ScrollingTabControllerButtonMixin", null, { |
| 440 |
baseClass: "dijitTab tabStripButton", |
| 441 |
|
| 442 |
templateString: buttonTemplate, |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
tabIndex: "", |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
isFocusable: function(){ |
| 451 |
return false; |
| 452 |
} |
| 453 |
}); |
| 454 |
|
| 455 |
|
| 456 |
declare("dijit.layout._ScrollingTabControllerButton", [Button, ScrollingTabControllerButtonMixin]); |
| 457 |
|
| 458 |
|
| 459 |
declare("dijit.layout._ScrollingTabControllerMenuButton", [Button, _HasDropDown, ScrollingTabControllerButtonMixin], { |
| 460 |
|
| 461 |
containerId: "", |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
tabIndex: "-1", |
| 466 |
|
| 467 |
isLoaded: function(){ |
| 468 |
|
| 469 |
return false; |
| 470 |
}, |
| 471 |
|
| 472 |
loadDropDown: function(callback){ |
| 473 |
this.dropDown = new Menu({ |
| 474 |
id: this.containerId + "_menu", |
| 475 |
ownerDocument: this.ownerDocument, |
| 476 |
dir: this.dir, |
| 477 |
lang: this.lang, |
| 478 |
textDir: this.textDir |
| 479 |
}); |
| 480 |
var container = registry.byId(this.containerId); |
| 481 |
array.forEach(container.getChildren(), function(page){ |
| 482 |
var menuItem = new MenuItem({ |
| 483 |
id: page.id + "_stcMi", |
| 484 |
label: page.title, |
| 485 |
iconClass: page.iconClass, |
| 486 |
disabled: page.disabled, |
| 487 |
ownerDocument: this.ownerDocument, |
| 488 |
dir: page.dir, |
| 489 |
lang: page.lang, |
| 490 |
textDir: page.textDir || container.textDir, |
| 491 |
onClick: function(){ |
| 492 |
container.selectChild(page); |
| 493 |
} |
| 494 |
}); |
| 495 |
this.dropDown.addChild(menuItem); |
| 496 |
}, this); |
| 497 |
callback(); |
| 498 |
}, |
| 499 |
|
| 500 |
closeDropDown: function( focus){ |
| 501 |
this.inherited(arguments); |
| 502 |
if(this.dropDown){ |
| 503 |
this._popupStateNode.removeAttribute("aria-owns"); |
| 504 |
this.dropDown.destroyRecursive(); |
| 505 |
delete this.dropDown; |
| 506 |
} |
| 507 |
} |
| 508 |
}); |
| 509 |
|
| 510 |
return ScrollingTabController; |
| 511 |
}); |