menu¶

class webix.ui.menu(data)¶
Arguments:
  • data (object) – A configuration object

Menu view.

References¶

views
list().
helpers
assert(), bind(), extend(), protoUI(), template(), ui().

Referenced by¶

views
submenu().

External references¶

Official documentation page.

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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
webix.protoUI({
    name:"menu",
    _listClassName:"webix_menu",
    $init:function(config){
        if (config.autowidth){
            this._autowidth_submenu = true;
            delete config.autowidth;
        }

        this.data.attachEvent('onStoreUpdated', webix.bind(function(){
            this._hide_sub_menu();
        },this));
        this.attachEvent('onMouseMove', this._mouse_move_menu);
        this.attachEvent('onMouseOut',function(){
            if (this._menu_was_activated() && this._settings.openAction == "click") return;
            if (!this._child_menu_active)
                this._hide_sub_menu();
        });
        this.attachEvent('onItemClick', function(id, e, trg){
            var item = this.getItem(id);
            if (item){
                if (item.$template) return;

                var parent = this.getTopMenu();

                //ignore disabled items
                if (!this.data.getMark(id, "webix_disabled")){
                    if (!parent.callEvent("onMenuItemClick", [id, e, trg])){
                        e.showpopup = true;
                        return;
                    }

                    if (this != parent)
                        parent._call_onclick(id,e,trg);

                    //click on group - do not close submenus
                    if (!item.submenu){
                        parent._hide_sub_menu(true);
                        if (parent._hide_on_item_click)
                            parent.hide();
                    } else {
                        if ((this === parent || webix.env.touch ) && parent._settings.openAction == "click"){
                            this._mouse_move_activation(id, trg);
                        }

                        //do not close popups when clicking on menu folder
                        e.showpopup = true;
                    }
                }
            }
        });

        this.attachEvent("onKeyPress", function(code, e){
            if(code === 9) this.getTopMenu()._hide_sub_menu();
            else if(code === 13 || code === 32){
                var sel = this.getSelectedId(), node;
                if(sel)
                    node = this.getItemNode(sel);
                if(node)
                    webix.html.triggerEvent(node, "MouseEvents", "click");
            }

        });

        this.data.attachEvent("onClearAll", function(){
            this._hidden_items = [];
        });
        this.data._hidden_items = [];

        this._viewobj.setAttribute("role", "menubar");
    },
    sizeToContent:function(){
        if (this._settings.layout == "y"){
            var texts = [];
            var isSubmenu = false;
            this.data.each(function(obj){
                texts.push(this._toHTML(obj));
                if(obj.submenu)
                    isSubmenu = true;
            }, this);
            // text width + padding + borders+ arrow
            this.config.width = webix.html.getTextSize(texts, this.$view.className).width+8*2+2+(isSubmenu?15:0);
            this.resize();
        } else webix.assert(false, "sizeToContent will work for vertical menu only");
    },
    getTopMenu:function(){
        var parent = this;
        while (parent._parent_menu)
            parent = webix.$$(parent._parent_menu);
        return parent;
    },
    _auto_height_calc:function(count){
        if (this._settings.autoheight) count = this.count();

        var height = 0;
        for (var i=0; i<count; i++){
            var item = this.data.pull[this.data.order[i]];
            if (item && item.$template == "Separator")
                height+=4;
            else
                height+=this.type.height;
        }
        return height;
    },
    on_mouse_move:{},
    type:{
        css:"menu",
        width:"auto",
        aria:function(obj, common, marks){
            return 'role="menuitem"'+(marks && marks.webix_selected?' aria-selected="true" tabindex="0"':'tabindex="-1"')+(obj.submenu?'aria-haspopup="true"':'')+(marks && marks.webix_disabled?' aria-disabled="true"':'');
        },
        templateStart:function(obj, common, mark){
            if (obj.$template === "Separator" || obj.$template === "Spacer"){
                return '<div webix_l_id="#id#" role="separator" tabindex="-1" class="webix_context_'+obj.$template.toLowerCase()+'">';
            }
            var link = (obj.href?" href='"+obj.href+"' ":"")+(obj.target?" target='"+obj.target+"' ":"");
            return webix.ui.list.prototype.type.templateStart(obj,common,mark).replace(/^<div/,"<a "+link)+((obj.submenu && common.subsign)?"<div class='webix_submenu_icon'></div>":"");
        },
        templateEnd: function(obj, common, mark){
            return (obj.$template === "Separator" || obj.$template === "Spacer")?"</div>":"</a>";
        },
        templateSeparator:webix.template("<div class='sep_line'></div>"),
        templateSpacer:webix.template("<div></div>")
    },
    getMenu: function(id){
        if (!this.data.pull[id]){
            for (var subid in this.data.pull){
                var obj = this.getItem(subid);
                if (obj.submenu){
                    var search = this._get_submenu(obj).getMenu(id);
                    if (search) return search;
                }
            }
        } else return this;
    },
    getSubMenu:function(id){
        var menu = this.getMenu(id);
        var obj = menu.getItem(id);
        return (obj.submenu?menu._get_submenu(obj):null);
    },
    getMenuItem:function(id){
        return this.getMenu(id).getItem(id);
    },
    _get_submenu:function(data){
        var sub  = webix.$$(data.submenu);
        if (!sub){
            data.submenu = this._create_sub_menu(data);
            sub = webix.$$(data.submenu);
        }
        return sub;
    },
    _mouse_move_menu:function(id, e, target){
        if (!this._menu_was_activated())
            return;

        this._mouse_move_activation(id, target);
    },
    _menu_was_activated:function(){
        var top = this.getTopMenu();
        if (top._settings.openAction == "click"){
            if (webix.env.touch) return false;
            var sub = top._open_sub_menu;
            if (sub && webix.$$(sub).isVisible())
                return true;
            return false;
        }
        return true;
    },
    _mouse_move_activation:function(id, target){
        var data = this.getItem(id);
        if (!data) return;

        //clear flag of submenu usage
        this._child_menu_active = null;

        //hide previously opened sub-menu
        if (this._open_sub_menu && data.submenu != this._open_sub_menu)
            this._hide_sub_menu(true);

        //show submenu
        if (data.submenu&&!this.config.hidden){

            var sub  = this._get_submenu(data);
            if(this.data.getMark(id,"webix_disabled"))
                return;
            sub.show(target,{ pos:this._settings.subMenuPos });

            sub._parent_menu = this._settings.id;

            this._open_sub_menu = data.submenu;
        }
    },
    disableItem:function(id){
        this.getMenu(id).addCss(id, "webix_disabled");
    },
    enableItem:function(id){
        this.getMenu(id).removeCss(id, "webix_disabled");
    },
    _set_item_hidden:function(id, state){
        var menu = this.data;
        if (menu._hidden_items[id] != state){
            menu._hidden_items[id] = state;
            menu.filter(function(obj){
                return !menu._hidden_items[obj.id];
            });
            this.resize();
        }
    },
    hideItem:function(id){
        var menu = this.getMenu(id);
        if (menu) menu._set_item_hidden(id, true);
    },
    showItem:function(id){
        var menu = this.getMenu(id);
        if (menu){
            menu._set_item_hidden(id, false);
            return webix.ui.list.prototype.showItem.call(menu, id);
        }
    },
    _hide_sub_menu : function(mode){
        if (this._open_sub_menu){
            //recursive sub-closing
            var sub = webix.$$(this._open_sub_menu);
            if (sub._hide_sub_menu)    //custom context may not have submenu
                sub._hide_sub_menu(mode);
            if (mode || !sub._show_on_mouse_out){
                sub.hide();
                this._open_sub_menu = null;
            }
        }
    },
    _create_sub_menu : function(data){
        var listConfig = {
            view:"submenu",
            data:data.submenu
        };

        var settings = this.getTopMenu()._settings.submenuConfig;
        if (settings)
            webix.extend(listConfig, settings, true);

        var parentData = this.getMenuItem(data.id);
        if(parentData && parentData.config)
            webix.extend(listConfig, parentData.config, true);

        var menu = webix.ui(listConfig);
        menu._parent_menu = this;
        return menu._settings.id;
    },
    _skip_item:function(id, prev, mode){
        var item = this.getItem(id);
        if(item.$template == "Separator" || item.$template == "Spacer" || this.data.getMark(id, "webix_disabled")){
            var index = this.getIndexById(id)+(mode == "up"?-1:1);
            id = (index>=0)?this.getIdByIndex(index):null;
            return id? this._skip_item(id, prev, mode) : prev;
        }
        else
            return id;
    },
    $skin:function(){
        webix.ui.list.prototype.$skin.call(this);
        this.type.height = webix.skin.$active.menuHeight;
    },
    defaults:{
        scroll:"",
        layout:"x",
        mouseEventDelay:100,
        subMenuPos:"bottom"
    }
}, webix.ui.list);

Related Topics

  • Documentation overview
    • Views
      • Previous: list
      • Next: multiview

Table Of Contents

  • Proxy object
  • Components
  • Views
    • accordion
    • accordionitem
    • align
    • baselayout
    • baseview
    • button
    • calendar
    • carousel
    • chart
    • checkbox
    • colorboard
    • colorpicker
    • combo
    • context
    • contextmenu
    • counter
    • datatable
    • dataview
    • datepicker
    • fieldset
    • form
    • grouplist
    • headerlayout
    • htmlform
    • icon
    • iframe
    • label
    • layout
    • list
    • menu
    • multiview
    • NonGPL
    • popup
    • property
    • proto
    • radio
    • resizearea
    • resizer
    • richselect
    • scrollview
    • search
    • segmented
    • select
    • sidemenu
    • slider
    • spacer
    • submenu
    • suggest
    • tabbar
    • tabview
    • template
    • text
    • textarea
    • toggle
    • toolbar
    • tooltip
    • tree
    • treetable
    • unitlist
    • uploader
    • video
    • view
    • vscroll
    • window
  • Helpers
  • Mixins

This Page

  • Show Source

Quick search

©2016, Arstecnica. | Powered by Sphinx 1.5.2 & Alabaster 0.7.9 | Page source