-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelectOptgroup.js
127 lines (117 loc) · 5.37 KB
/
SelectOptgroup.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
/*! dijit-select-optgroup | The MIT License (MIT) | Copyright (c) 2017 GibboK */
define([
'dojo/_base/declare',
'dojo/_base/lang',
'dijit/form/Select',
'dijit/MenuSeparator',
'MenuItemOptgroup.js',
'dojo/domReady!'
], function (
declare,
lang,
Select,
MenuSeparator,
MenuItem
) {
return declare(Select, {
class: 'SelectOptgroup',
postCreate: function () {
this.inherited(arguments);
this._getMenuItemForOption = function (option) {
// summary:
// For the given option, return the menu item that should be used to display it.
if (!option.value && !option.label) {
return new MenuSeparator({ ownerDocument: this.ownerDocument });
} else {
var click = lang.hitch(this, '_setValueAttr', option),
item = new MenuItem({
option: option,
label: (this.labelType === 'text' ? (option.label || '').toString()
.replace(/&/g, '&').replace(/</g, '<') :
option.label) || this.emptyLabel,
onClick: click,
ownerDocument: this.ownerDocument,
dir: this.dir,
textDir: this.textDir,
disabled: (option.disabled || option.optgroup) || false
});
item.focusNode.setAttribute('role', 'option');
return item;
}
};
this.dropDown._onUpArrow = function () {
// summary:
// Called on up arrow key. Should go to previous child in vertical container widgets like Menu.
this.focusPrev();
}.bind(this.dropDown);
this.dropDown._onDownArrow = function () {
// summary:
// Called on down arrow key. Should go to next child in vertical container widgets like Menu.
this.focusNext();
}.bind(this.dropDown);
this.dropDown.focusNext = function () {
// summary:
// Focus the next child menu item and skip `optgroup` if found.
var focusNext = function () {
var next = this._getNextFocusableChild(this.focusedChild, 1);
this.focusChild(next);
if (next.option.optgroup) {
focusNext();
}
}.bind(this);
focusNext();
}.bind(this.dropDown);
this.dropDown.focusPrev = function () {
// summary:
// Focus the previous child menu item and skip `optgroup` if found.
var focusPrev = function () {
var prev = this._getNextFocusableChild(this.focusedChild, -1);
this.focusChild(prev);
if (prev.option.optgroup) {
focusPrev();
}
}.bind(this);
focusPrev();
}.bind(this.dropDown);
this.dropDown.onItemHover = function (item) {
// summary:
// Called when cursor is over a menu item, skip `optgroup` if found.
if (item.option.optgroup) {
item._set('hovering', false);
return;
}
if (this.activated) {
this.set('selected', item);
if (item.popup && !item.disabled && !this.hover_timer) {
this.hover_timer = this.defer(function () {
this._openItemPopup(item);
}, this.popupDelay);
}
} else if (this.passivePopupDelay < Infinity) {
if (this.passive_hover_timer) {
this.passive_hover_timer.remove();
}
this.passive_hover_timer = this.defer(function () {
this.onItemClick(item, {
type: 'click'
});
}, this.passivePopupDelay);
}
this._hoveredChild = item;
item._set('hovering', true);
}.bind(this.dropDown);
this.dropDown._onItemFocus = function (item) {
// summary:
// Called when child of this Menu gets focus from:
// clicking, tabbing, being opened by a parent menu.
if (item.option.optgroup) {
return;
}
if (this._hoveredChild && this._hoveredChild !== item) {
this.onItemUnhover(this._hoveredChild);
}
this.set('selected', item);
}.bind(this.dropDown);
}
});
});