forked from ElementUI/lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.js
915 lines (774 loc) · 24 KB
/
menu.js
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "/dist/";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 84);
/******/ })
/************************************************************************/
/******/ ({
/***/ 0:
/***/ (function(module, exports) {
/* globals __VUE_SSR_CONTEXT__ */
// IMPORTANT: Do NOT use ES2015 features in this file.
// This module is a runtime utility for cleaner component module output and will
// be included in the final webpack user bundle.
module.exports = function normalizeComponent (
rawScriptExports,
compiledTemplate,
functionalTemplate,
injectStyles,
scopeId,
moduleIdentifier /* server only */
) {
var esModule
var scriptExports = rawScriptExports = rawScriptExports || {}
// ES6 modules interop
var type = typeof rawScriptExports.default
if (type === 'object' || type === 'function') {
esModule = rawScriptExports
scriptExports = rawScriptExports.default
}
// Vue.extend constructor export interop
var options = typeof scriptExports === 'function'
? scriptExports.options
: scriptExports
// render functions
if (compiledTemplate) {
options.render = compiledTemplate.render
options.staticRenderFns = compiledTemplate.staticRenderFns
options._compiled = true
}
// functional template
if (functionalTemplate) {
options.functional = true
}
// scopedId
if (scopeId) {
options._scopeId = scopeId
}
var hook
if (moduleIdentifier) { // server build
hook = function (context) {
// 2.3 injection
context =
context || // cached call
(this.$vnode && this.$vnode.ssrContext) || // stateful
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__
}
// inject component styles
if (injectStyles) {
injectStyles.call(this, context)
}
// register component module identifier for async chunk inferrence
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier)
}
}
// used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook
} else if (injectStyles) {
hook = injectStyles
}
if (hook) {
var functional = options.functional
var existing = functional
? options.render
: options.beforeCreate
if (!functional) {
// inject component registration as beforeCreate hook
options.beforeCreate = existing
? [].concat(existing, hook)
: [hook]
} else {
// for template-only hot-reload because in that case the render fn doesn't
// go through the normalizer
options._injectStyles = hook
// register for functioal component in vue file
options.render = function renderWithStyleInjection (h, context) {
hook.call(context)
return existing(h, context)
}
}
}
return {
esModule: esModule,
exports: scriptExports,
options: options
}
}
/***/ }),
/***/ 1:
/***/ (function(module, exports) {
module.exports = require("element-ui/lib/mixins/emitter");
/***/ }),
/***/ 3:
/***/ (function(module, exports) {
module.exports = require("element-ui/lib/utils/dom");
/***/ }),
/***/ 47:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var aria = aria || {};
aria.Utils = aria.Utils || {};
/**
* @desc Set focus on descendant nodes until the first focusable element is
* found.
* @param element
* DOM node for which to find the first focusable descendant.
* @returns
* true if a focusable element is found and focus is set.
*/
aria.Utils.focusFirstDescendant = function (element) {
for (var i = 0; i < element.childNodes.length; i++) {
var child = element.childNodes[i];
if (aria.Utils.attemptFocus(child) || aria.Utils.focusFirstDescendant(child)) {
return true;
}
}
return false;
};
/**
* @desc Find the last descendant node that is focusable.
* @param element
* DOM node for which to find the last focusable descendant.
* @returns
* true if a focusable element is found and focus is set.
*/
aria.Utils.focusLastDescendant = function (element) {
for (var i = element.childNodes.length - 1; i >= 0; i--) {
var child = element.childNodes[i];
if (aria.Utils.attemptFocus(child) || aria.Utils.focusLastDescendant(child)) {
return true;
}
}
return false;
};
/**
* @desc Set Attempt to set focus on the current node.
* @param element
* The node to attempt to focus on.
* @returns
* true if element is focused.
*/
aria.Utils.attemptFocus = function (element) {
if (!aria.Utils.isFocusable(element)) {
return false;
}
aria.Utils.IgnoreUtilFocusChanges = true;
try {
element.focus();
} catch (e) {}
aria.Utils.IgnoreUtilFocusChanges = false;
return document.activeElement === element;
};
aria.Utils.isFocusable = function (element) {
if (element.tabIndex > 0 || element.tabIndex === 0 && element.getAttribute('tabIndex') !== null) {
return true;
}
if (element.disabled) {
return false;
}
switch (element.nodeName) {
case 'A':
return !!element.href && element.rel !== 'ignore';
case 'INPUT':
return element.type !== 'hidden' && element.type !== 'file';
case 'BUTTON':
case 'SELECT':
case 'TEXTAREA':
return true;
default:
return false;
}
};
/**
* 触发一个事件
* mouseenter, mouseleave, mouseover, keyup, change, click 等
* @param {Element} elm
* @param {String} name
* @param {*} opts
*/
aria.Utils.triggerEvent = function (elm, name) {
var eventName = void 0;
if (/^mouse|click/.test(name)) {
eventName = 'MouseEvents';
} else if (/^key/.test(name)) {
eventName = 'KeyboardEvent';
} else {
eventName = 'HTMLEvents';
}
var evt = document.createEvent(eventName);
for (var _len = arguments.length, opts = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
opts[_key - 2] = arguments[_key];
}
evt.initEvent.apply(evt, [name].concat(opts));
elm.dispatchEvent ? elm.dispatchEvent(evt) : elm.fireEvent('on' + name, evt);
return elm;
};
aria.Utils.keys = {
tab: 9,
enter: 13,
space: 32,
left: 37,
up: 38,
right: 39,
down: 40
};
exports.default = aria.Utils;
/***/ }),
/***/ 8:
/***/ (function(module, exports) {
module.exports = require("element-ui/lib/mixins/migrating");
/***/ }),
/***/ 84:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _menu = __webpack_require__(85);
var _menu2 = _interopRequireDefault(_menu);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* istanbul ignore next */
_menu2.default.install = function (Vue) {
Vue.component(_menu2.default.name, _menu2.default);
};
exports.default = _menu2.default;
/***/ }),
/***/ 85:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_menu_vue__ = __webpack_require__(86);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_menu_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_menu_vue__);
var normalizeComponent = __webpack_require__(0)
/* script */
/* template */
var __vue_template__ = null
/* template functional */
var __vue_template_functional__ = false
/* styles */
var __vue_styles__ = null
/* scopeId */
var __vue_scopeId__ = null
/* moduleIdentifier (server only) */
var __vue_module_identifier__ = null
var Component = normalizeComponent(
__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_menu_vue___default.a,
__vue_template__,
__vue_template_functional__,
__vue_styles__,
__vue_scopeId__,
__vue_module_identifier__
)
/* harmony default export */ __webpack_exports__["default"] = (Component.exports);
/***/ }),
/***/ 86:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _emitter = __webpack_require__(1);
var _emitter2 = _interopRequireDefault(_emitter);
var _migrating = __webpack_require__(8);
var _migrating2 = _interopRequireDefault(_migrating);
var _ariaMenubar = __webpack_require__(87);
var _ariaMenubar2 = _interopRequireDefault(_ariaMenubar);
var _dom = __webpack_require__(3);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = {
name: 'ElMenu',
render: function render(h) {
var component = h(
'ul',
{
attrs: {
role: 'menubar'
},
key: +this.collapse,
style: { backgroundColor: this.backgroundColor || '' },
'class': {
'el-menu--horizontal': this.mode === 'horizontal',
'el-menu--collapse': this.collapse,
"el-menu": true
}
},
[this.$slots.default]
);
if (this.collapseTransition) {
return h(
'el-menu-collapse-transition',
null,
[component]
);
} else {
return component;
}
},
componentName: 'ElMenu',
mixins: [_emitter2.default, _migrating2.default],
provide: function provide() {
return {
rootMenu: this
};
},
components: {
'el-menu-collapse-transition': {
functional: true,
render: function render(createElement, context) {
var data = {
props: {
mode: 'out-in'
},
on: {
beforeEnter: function beforeEnter(el) {
el.style.opacity = 0.2;
},
enter: function enter(el) {
(0, _dom.addClass)(el, 'el-opacity-transition');
el.style.opacity = 1;
},
afterEnter: function afterEnter(el) {
(0, _dom.removeClass)(el, 'el-opacity-transition');
el.style.opacity = '';
},
beforeLeave: function beforeLeave(el) {
if (!el.dataset) el.dataset = {};
if ((0, _dom.hasClass)(el, 'el-menu--collapse')) {
(0, _dom.removeClass)(el, 'el-menu--collapse');
el.dataset.oldOverflow = el.style.overflow;
el.dataset.scrollWidth = el.clientWidth;
(0, _dom.addClass)(el, 'el-menu--collapse');
} else {
(0, _dom.addClass)(el, 'el-menu--collapse');
el.dataset.oldOverflow = el.style.overflow;
el.dataset.scrollWidth = el.clientWidth;
(0, _dom.removeClass)(el, 'el-menu--collapse');
}
el.style.width = el.scrollWidth + 'px';
el.style.overflow = 'hidden';
},
leave: function leave(el) {
(0, _dom.addClass)(el, 'horizontal-collapse-transition');
el.style.width = el.dataset.scrollWidth + 'px';
}
}
};
return createElement('transition', data, context.children);
}
}
},
props: {
mode: {
type: String,
default: 'vertical'
},
defaultActive: {
type: String,
default: ''
},
defaultOpeneds: Array,
uniqueOpened: Boolean,
router: Boolean,
menuTrigger: {
type: String,
default: 'hover'
},
collapse: Boolean,
backgroundColor: String,
textColor: String,
activeTextColor: String,
collapseTransition: {
type: Boolean,
default: true
}
},
data: function data() {
return {
activeIndex: this.defaultActive,
openedMenus: this.defaultOpeneds && !this.collapse ? this.defaultOpeneds.slice(0) : [],
items: {},
submenus: {}
};
},
computed: {
hoverBackground: function hoverBackground() {
return this.backgroundColor ? this.mixColor(this.backgroundColor, 0.2) : '';
},
isMenuPopup: function isMenuPopup() {
return this.mode === 'horizontal' || this.mode === 'vertical' && this.collapse;
}
},
watch: {
defaultActive: 'updateActiveIndex',
defaultOpeneds: function defaultOpeneds(value) {
if (!this.collapse) {
this.openedMenus = value;
}
},
collapse: function collapse(value) {
if (value) this.openedMenus = [];
this.broadcast('ElSubmenu', 'toggle-collapse', value);
}
},
methods: {
updateActiveIndex: function updateActiveIndex(val) {
var item = this.items[val] || this.items[this.activeIndex] || this.items[this.defaultActive];
if (item) {
this.activeIndex = item.index;
this.initOpenedMenu();
} else {
this.activeIndex = null;
}
},
getMigratingConfig: function getMigratingConfig() {
return {
props: {
'theme': 'theme is removed.'
}
};
},
getColorChannels: function getColorChannels(color) {
color = color.replace('#', '');
if (/^[0-9a-fA-F]{3}$/.test(color)) {
color = color.split('');
for (var i = 2; i >= 0; i--) {
color.splice(i, 0, color[i]);
}
color = color.join('');
}
if (/^[0-9a-fA-F]{6}$/.test(color)) {
return {
red: parseInt(color.slice(0, 2), 16),
green: parseInt(color.slice(2, 4), 16),
blue: parseInt(color.slice(4, 6), 16)
};
} else {
return {
red: 255,
green: 255,
blue: 255
};
}
},
mixColor: function mixColor(color, percent) {
var _getColorChannels = this.getColorChannels(color),
red = _getColorChannels.red,
green = _getColorChannels.green,
blue = _getColorChannels.blue;
if (percent > 0) {
// shade given color
red *= 1 - percent;
green *= 1 - percent;
blue *= 1 - percent;
} else {
// tint given color
red += (255 - red) * percent;
green += (255 - green) * percent;
blue += (255 - blue) * percent;
}
return 'rgb(' + Math.round(red) + ', ' + Math.round(green) + ', ' + Math.round(blue) + ')';
},
addItem: function addItem(item) {
this.$set(this.items, item.index, item);
},
removeItem: function removeItem(item) {
delete this.items[item.index];
},
addSubmenu: function addSubmenu(item) {
this.$set(this.submenus, item.index, item);
},
removeSubmenu: function removeSubmenu(item) {
delete this.submenus[item.index];
},
openMenu: function openMenu(index, indexPath) {
var openedMenus = this.openedMenus;
if (openedMenus.indexOf(index) !== -1) return;
// 将不在该菜单路径下的其余菜单收起
// collapse all menu that are not under current menu item
if (this.uniqueOpened) {
this.openedMenus = openedMenus.filter(function (index) {
return indexPath.indexOf(index) !== -1;
});
}
this.openedMenus.push(index);
},
closeMenu: function closeMenu(index) {
var i = this.openedMenus.indexOf(index);
if (i !== -1) {
this.openedMenus.splice(i, 1);
}
},
handleSubmenuClick: function handleSubmenuClick(submenu) {
var index = submenu.index,
indexPath = submenu.indexPath;
var isOpened = this.openedMenus.indexOf(index) !== -1;
if (isOpened) {
this.closeMenu(index);
this.$emit('close', index, indexPath);
} else {
this.openMenu(index, indexPath);
this.$emit('open', index, indexPath);
}
},
handleItemClick: function handleItemClick(item) {
var _this = this;
var index = item.index,
indexPath = item.indexPath;
var oldActiveIndex = this.activeIndex;
this.activeIndex = item.index;
this.$emit('select', index, indexPath, item);
if (this.mode === 'horizontal' || this.collapse) {
this.openedMenus = [];
}
if (this.router) {
this.routeToItem(item, function (error) {
_this.activeIndex = oldActiveIndex;
if (error) console.error(error);
});
}
},
// 初始化展开菜单
// initialize opened menu
initOpenedMenu: function initOpenedMenu() {
var _this2 = this;
var index = this.activeIndex;
var activeItem = this.items[index];
if (!activeItem || this.mode === 'horizontal' || this.collapse) return;
var indexPath = activeItem.indexPath;
// 展开该菜单项的路径上所有子菜单
// expand all submenus of the menu item
indexPath.forEach(function (index) {
var submenu = _this2.submenus[index];
submenu && _this2.openMenu(index, submenu.indexPath);
});
},
routeToItem: function routeToItem(item, onError) {
var route = item.route || item.index;
try {
this.$router.push(route, function () {}, onError);
} catch (e) {
console.error(e);
}
},
open: function open(index) {
var _this3 = this;
var indexPath = this.submenus[index.toString()].indexPath;
indexPath.forEach(function (i) {
return _this3.openMenu(i, indexPath);
});
},
close: function close(index) {
this.closeMenu(index);
}
},
mounted: function mounted() {
this.initOpenedMenu();
this.$on('item-click', this.handleItemClick);
this.$on('submenu-click', this.handleSubmenuClick);
if (this.mode === 'horizontal') {
new _ariaMenubar2.default(this.$el); // eslint-disable-line
}
this.$watch('items', this.updateActiveIndex);
}
};
/***/ }),
/***/ 87:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _ariaMenuitem = __webpack_require__(88);
var _ariaMenuitem2 = _interopRequireDefault(_ariaMenuitem);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Menu = function Menu(domNode) {
this.domNode = domNode;
this.init();
};
Menu.prototype.init = function () {
var menuChildren = this.domNode.childNodes;
[].filter.call(menuChildren, function (child) {
return child.nodeType === 1;
}).forEach(function (child) {
new _ariaMenuitem2.default(child); // eslint-disable-line
});
};
exports.default = Menu;
/***/ }),
/***/ 88:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _ariaUtils = __webpack_require__(47);
var _ariaUtils2 = _interopRequireDefault(_ariaUtils);
var _ariaSubmenu = __webpack_require__(89);
var _ariaSubmenu2 = _interopRequireDefault(_ariaSubmenu);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var MenuItem = function MenuItem(domNode) {
this.domNode = domNode;
this.submenu = null;
this.init();
};
MenuItem.prototype.init = function () {
this.domNode.setAttribute('tabindex', '0');
var menuChild = this.domNode.querySelector('.el-menu');
if (menuChild) {
this.submenu = new _ariaSubmenu2.default(this, menuChild);
}
this.addListeners();
};
MenuItem.prototype.addListeners = function () {
var _this = this;
var keys = _ariaUtils2.default.keys;
this.domNode.addEventListener('keydown', function (event) {
var prevDef = false;
switch (event.keyCode) {
case keys.down:
_ariaUtils2.default.triggerEvent(event.currentTarget, 'mouseenter');
_this.submenu && _this.submenu.gotoSubIndex(0);
prevDef = true;
break;
case keys.up:
_ariaUtils2.default.triggerEvent(event.currentTarget, 'mouseenter');
_this.submenu && _this.submenu.gotoSubIndex(_this.submenu.subMenuItems.length - 1);
prevDef = true;
break;
case keys.tab:
_ariaUtils2.default.triggerEvent(event.currentTarget, 'mouseleave');
break;
case keys.enter:
case keys.space:
prevDef = true;
event.currentTarget.click();
break;
}
if (prevDef) {
event.preventDefault();
}
});
};
exports.default = MenuItem;
/***/ }),
/***/ 89:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _ariaUtils = __webpack_require__(47);
var _ariaUtils2 = _interopRequireDefault(_ariaUtils);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var SubMenu = function SubMenu(parent, domNode) {
this.domNode = domNode;
this.parent = parent;
this.subMenuItems = [];
this.subIndex = 0;
this.init();
};
SubMenu.prototype.init = function () {
this.subMenuItems = this.domNode.querySelectorAll('li');
this.addListeners();
};
SubMenu.prototype.gotoSubIndex = function (idx) {
if (idx === this.subMenuItems.length) {
idx = 0;
} else if (idx < 0) {
idx = this.subMenuItems.length - 1;
}
this.subMenuItems[idx].focus();
this.subIndex = idx;
};
SubMenu.prototype.addListeners = function () {
var _this = this;
var keys = _ariaUtils2.default.keys;
var parentNode = this.parent.domNode;
Array.prototype.forEach.call(this.subMenuItems, function (el) {
el.addEventListener('keydown', function (event) {
var prevDef = false;
switch (event.keyCode) {
case keys.down:
_this.gotoSubIndex(_this.subIndex + 1);
prevDef = true;
break;
case keys.up:
_this.gotoSubIndex(_this.subIndex - 1);
prevDef = true;
break;
case keys.tab:
_ariaUtils2.default.triggerEvent(parentNode, 'mouseleave');
break;
case keys.enter:
case keys.space:
prevDef = true;
event.currentTarget.click();
break;
}
if (prevDef) {
event.preventDefault();
event.stopPropagation();
}
return false;
});
});
};
exports.default = SubMenu;
/***/ })
/******/ });