123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- define("dijit/layout/StackController", [
- "dojo/_base/array",
- "dojo/_base/declare",
- "dojo/_base/event",
- "dojo/keys",
- "dojo/_base/lang",
- "dojo/_base/sniff",
- "../focus",
- "../registry",
- "../_Widget",
- "../_TemplatedMixin",
- "../_Container",
- "../form/ToggleButton",
- "dojo/i18n!../nls/common"
- ], function(array, declare, event, keys, lang, has,
- focus, registry, _Widget, _TemplatedMixin, _Container, ToggleButton){
-
-
-
-
- var StackButton = declare("dijit.layout._StackButton", ToggleButton, {
-
-
-
-
-
-
-
-
-
- tabIndex: "-1",
-
-
- closeButton: false,
-
- _setCheckedAttr: function(/*Boolean*/ value, /*Boolean?*/ priorityChange){
- this.inherited(arguments);
- this.focusNode.removeAttribute("aria-pressed");
- },
- buildRendering: function(/*Event*/ evt){
- this.inherited(arguments);
- (this.focusNode || this.domNode).setAttribute("role", "tab");
- },
- onClick: function(/*Event*/ /*===== evt =====*/){
-
-
-
-
- focus.focus(this.focusNode);
-
- },
- onClickCloseButton: function(/*Event*/ evt){
-
-
-
-
- evt.stopPropagation();
- }
- });
- var StackController = declare("dijit.layout.StackController", [_Widget, _TemplatedMixin, _Container], {
-
-
-
-
-
- baseClass: "dijitStackController",
- templateString: "<span role='tablist' data-dojo-attach-event='onkeypress'></span>",
-
-
- containerId: "",
-
-
- buttonWidget: StackButton,
- constructor: function(){
- this.pane2button = {};
- this.pane2connects = {};
- this.pane2watches = {};
- },
- postCreate: function(){
- this.inherited(arguments);
-
- this.subscribe(this.containerId+"-startup", "onStartup");
- this.subscribe(this.containerId+"-addChild", "onAddChild");
- this.subscribe(this.containerId+"-removeChild", "onRemoveChild");
- this.subscribe(this.containerId+"-selectChild", "onSelectChild");
- this.subscribe(this.containerId+"-containerKeyPress", "onContainerKeyPress");
- },
- onStartup: function(/*Object*/ info){
-
-
-
-
- array.forEach(info.children, this.onAddChild, this);
- if(info.selected){
-
-
- this.onSelectChild(info.selected);
- }
- },
- destroy: function(){
- for(var pane in this.pane2button){
- this.onRemoveChild(registry.byId(pane));
- }
- this.inherited(arguments);
- },
- onAddChild: function(/*dijit._Widget*/ page, /*Integer?*/ insertIndex){
-
-
-
-
-
-
-
- var cls = lang.isString(this.buttonWidget) ? lang.getObject(this.buttonWidget) : this.buttonWidget;
- var button = new cls({
- id: this.id + "_" + page.id,
- label: page.title,
- dir: page.dir,
- lang: page.lang,
- textDir: page.textDir,
- showLabel: page.showTitle,
- iconClass: page.iconClass,
- closeButton: page.closable,
- title: page.tooltip
- });
- button.focusNode.setAttribute("aria-selected", "false");
-
- var pageAttrList = ["title", "showTitle", "iconClass", "closable", "tooltip"],
- buttonAttrList = ["label", "showLabel", "iconClass", "closeButton", "title"];
-
- this.pane2watches[page.id] = array.map(pageAttrList, function(pageAttr, idx){
- return page.watch(pageAttr, function(name, oldVal, newVal){
- button.set(buttonAttrList[idx], newVal);
- });
- });
-
- this.pane2connects[page.id] = [
- this.connect(button, 'onClick', lang.hitch(this,"onButtonClick", page)),
- this.connect(button, 'onClickCloseButton', lang.hitch(this,"onCloseButtonClick", page))
- ];
- this.addChild(button, insertIndex);
- this.pane2button[page.id] = button;
- page.controlButton = button;
- if(!this._currentChild){
- button.focusNode.setAttribute("tabIndex", "0");
- button.focusNode.setAttribute("aria-selected", "true");
- this._currentChild = page;
- }
-
- if(!this.isLeftToRight() && has("ie") && this._rectifyRtlTabList){
- this._rectifyRtlTabList();
- }
- },
- onRemoveChild: function(/*dijit._Widget*/ page){
-
-
-
-
-
- if(this._currentChild === page){ this._currentChild = null; }
-
- array.forEach(this.pane2connects[page.id], lang.hitch(this, "disconnect"));
- delete this.pane2connects[page.id];
- array.forEach(this.pane2watches[page.id], function(w){ w.unwatch(); });
- delete this.pane2watches[page.id];
- var button = this.pane2button[page.id];
- if(button){
- this.removeChild(button);
- delete this.pane2button[page.id];
- button.destroy();
- }
- delete page.controlButton;
- },
- onSelectChild: function(/*dijit._Widget*/ page){
-
-
-
-
- if(!page){ return; }
- if(this._currentChild){
- var oldButton=this.pane2button[this._currentChild.id];
- oldButton.set('checked', false);
- oldButton.focusNode.setAttribute("aria-selected", "false");
- oldButton.focusNode.setAttribute("tabIndex", "-1");
- }
- var newButton=this.pane2button[page.id];
- newButton.set('checked', true);
- newButton.focusNode.setAttribute("aria-selected", "true");
- this._currentChild = page;
- newButton.focusNode.setAttribute("tabIndex", "0");
- var container = registry.byId(this.containerId);
- container.containerNode.setAttribute("aria-labelledby", newButton.id);
- },
- onButtonClick: function(/*dijit._Widget*/ page){
-
-
-
-
- if(this._currentChild.id === page.id) {
-
- var button=this.pane2button[page.id];
- button.set('checked', true);
- }
- var container = registry.byId(this.containerId);
- container.selectChild(page);
- },
- onCloseButtonClick: function(/*dijit._Widget*/ page){
-
-
-
-
- var container = registry.byId(this.containerId);
- container.closeChild(page);
- if(this._currentChild){
- var b = this.pane2button[this._currentChild.id];
- if(b){
- focus.focus(b.focusNode || b.domNode);
- }
- }
- },
-
- adjacent: function(/*Boolean*/ forward){
-
-
-
-
- if(!this.isLeftToRight() && (!this.tabPosition || /top|bottom/.test(this.tabPosition))){ forward = !forward; }
-
- var children = this.getChildren();
- var current = array.indexOf(children, this.pane2button[this._currentChild.id]);
-
- var offset = forward ? 1 : children.length - 1;
- return children[ (current + offset) % children.length ];
- },
- onkeypress: function(/*Event*/ e){
-
-
-
-
-
- if(this.disabled || e.altKey ){ return; }
- var forward = null;
- if(e.ctrlKey || !e._djpage){
- switch(e.charOrCode){
- case keys.LEFT_ARROW:
- case keys.UP_ARROW:
- if(!e._djpage){ forward = false; }
- break;
- case keys.PAGE_UP:
- if(e.ctrlKey){ forward = false; }
- break;
- case keys.RIGHT_ARROW:
- case keys.DOWN_ARROW:
- if(!e._djpage){ forward = true; }
- break;
- case keys.PAGE_DOWN:
- if(e.ctrlKey){ forward = true; }
- break;
- case keys.HOME:
- case keys.END:
- var children = this.getChildren();
- if(children && children.length){
- children[e.charOrCode == keys.HOME ? 0 : children.length-1].onClick();
- }
- event.stop(e);
- break;
- case keys.DELETE:
- if(this._currentChild.closable){
- this.onCloseButtonClick(this._currentChild);
- }
- event.stop(e);
- break;
- default:
- if(e.ctrlKey){
- if(e.charOrCode === keys.TAB){
- this.adjacent(!e.shiftKey).onClick();
- event.stop(e);
- }else if(e.charOrCode == "w"){
- if(this._currentChild.closable){
- this.onCloseButtonClick(this._currentChild);
- }
- event.stop(e);
- }
- }
- }
-
- if(forward !== null){
- this.adjacent(forward).onClick();
- event.stop(e);
- }
- }
- },
- onContainerKeyPress: function(/*Object*/ info){
-
-
-
-
- info.e._djpage = info.page;
- this.onkeypress(info.e);
- }
- });
- StackController.StackButton = StackButton;
- return StackController;
- });
|