NavigationButtons¶
-
class
webix.
NavigationButtons
()¶ Navigationbuttons mixin
Referenced by¶
- views
carousel()
.
External references¶
Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | webix.NavigationButtons = {
$init:function(){
this.$ready.push(function(){
this.attachEvent("onKeyPress", this._onKeyPress);
});
},
_moveActive:function(code, e){
if(code === 37 || code === 39){
webix.html.preventEvent(e);
this._showNavItem(code===37?-1:1);
var node = this._navPanel.querySelector("[tabindex='0']");
if(node) node.focus();
}
},
_renderPanel:function(){
webix.html.remove(this._navPanel);
this._navPanel = webix.html.create("DIV",{
"class":"webix_nav_panel "+"webix_nav_panel_"+this._settings.navigation.type,
"role":"tablist"
},"");
this._viewobj.appendChild(this._navPanel);
this._renderNavItems();
this._renderNavButtons();
this._setLinkEventHandler();
},
_setLinkEventHandler: function(){
var h = [];
if(this._navPanel)
h[0] = webix.event(this._navPanel,"click", webix.bind(function(e){
var elem = (e.srcElement || e.target);
var found = false;
while(elem != this._navPanel && !found){
var bindId = elem.getAttribute(this._linkAttr);
if(bindId){
found = true;
this._showPanelBind(bindId);
}
elem = elem.parentNode;
}
},this));
if(this._prevNavButton)
h[1] = webix.event(this._prevNavButton,"click", webix.bind(function(e){
this._showNavItem(-1);
},this));
if(this._nextNavButton)
h[1] = webix.event(this._nextNavButton,"click", webix.bind(function(e){
this._showNavItem(1);
},this));
this.attachEvent("onDestruct", function(){
for(var i=0;i< h.length; i++){
this.detachEvent(h[i]);
}
h = null;
});
},
_showNavItem: function(inc){
if(this._cells){
var index = this._active_cell + inc;
if(index >= this._cells.length || index < 0){
index = (index < 0?this._cells.length-1:0);
}
this.setActiveIndex(index);
}
},
_showPanelBind: function(id){
if(this._cells)
webix.$$(id).show();
},
_renderNavItems:function(){
var item, config;
config = this._settings.navigation;
if(config.items){
this._linkAttr = config.linkAttr || "bind_id";
if(!this._navPanel)
this._renderPanel();
else
this._clearPanel();
var data = (this._cells?this._cells:this.data.order);
if(data.length>1){
for (var i=0; i < data.length; i++){
item = webix.html.create("DIV",{
"class":"webix_nav_item webix_nav_"+(i==this._active_cell?"active":"inactive"),
"role":"tab",
"tabindex":(i==this._active_cell?"0":"-1")
},"<div></div>");
var id = this._cells?this._cells[i]._settings.id:data[i];
if(id)
item.setAttribute(this._linkAttr, id);
this._navPanel.appendChild(item);
}
}
}
},
_clearPanel:function(){
if (this._navPanel){
var coll = this._navPanel.childNodes;
for (var i = coll.length - 1; i >= 0; i--)
webix.html.remove(coll[i]);
}
},
_renderNavButtons: function(){
var item, config;
config = this._settings.navigation;
if(config.buttons){
if(this._prevNavButton)
webix.html.remove(this._prevNavButton);
if(this._prevNavButton)
webix.html.remove(this._nextNavButton);
this._prevNavButton = webix.html.create(
"DIV",
{
"class":"webix_nav_button_"+config.type+" webix_nav_button_prev ",
"role":"button",
"tabindex":"0",
"aria-label":webix.i18n.aria.prevTab
},
"<div class=\"webix_nav_button_inner\"></div>"
);
this._viewobj.appendChild(this._prevNavButton);
this._nextNavButton = webix.html.create(
"DIV",
{
"class":"webix_nav_button_"+config.type+" webix_nav_button_next ",
"role":"button",
"tabindex":"0",
"aria-label":webix.i18n.aria.nextTab
},
"<div class=\"webix_nav_button_inner\"></div>"
);
this._viewobj.appendChild(this._nextNavButton);
}
}
};
|