1
YUI.add('api-list', function (Y) {
6
APIList = Y.namespace('APIList'),
8
classesNode = Y.one('#api-classes'),
9
inputNode = Y.one('#api-filter'),
10
modulesNode = Y.one('#api-modules'),
11
tabviewNode = Y.one('#api-tabview'),
13
tabs = APIList.tabs = {},
15
filter = APIList.filter = new Y.APIFilter({
16
inputNode : inputNode,
20
results: onFilterResults
24
search = APIList.search = new Y.APISearch({
25
inputNode : inputNode,
29
clear : onSearchClear,
30
results: onSearchResults
34
tabview = APIList.tabview = new Y.TabView({
35
srcNode : tabviewNode,
36
panelNode: '#api-tabview-panel',
40
selectionChange: onTabSelectionChange
44
focusManager = APIList.focusManager = tabviewNode.plug(Y.Plugin.NodeFocusManager, {
46
descendants: '#api-filter, .yui3-tab-panel-selected .api-list-item a, .yui3-tab-panel-selected .result a',
47
keys : {next: 'down:40', previous: 'down:38'}
51
'<li class="api-list-item {typeSingular}">' +
52
'<a href="{rootPath}{typePlural}/{name}.html">{displayName}</a>' +
55
// -- Init ---------------------------------------------------------------------
57
// Duckpunch FocusManager's key event handling to prevent it from handling key
58
// events when a modifier is pressed.
59
Y.before(function (e, activeDescendant) {
60
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
61
return new Y.Do.Prevent();
63
}, focusManager, '_focusPrevious', focusManager);
65
Y.before(function (e, activeDescendant) {
66
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
67
return new Y.Do.Prevent();
69
}, focusManager, '_focusNext', focusManager);
71
// Create a mapping of tabs in the tabview so we can refer to them easily later.
72
tabview.each(function (tab, index) {
73
var name = tab.get('label').toLowerCase();
82
// Switch tabs on Ctrl/Cmd-Left/Right arrows.
83
tabviewNode.on('key', onTabSwitchKey, 'down:37,39');
85
// Focus the filter input when the `/` key is pressed.
86
Y.one(Y.config.doc).on('key', onSearchKey, 'down:83');
88
// Keep the Focus Manager up to date.
89
inputNode.on('focus', function () {
90
focusManager.set('activeDescendant', inputNode);
93
// Update all tabview links to resolved URLs.
94
tabview.get('panelNode').all('a').each(function (link) {
95
link.setAttribute('href', link.get('href'));
98
// -- Private Functions --------------------------------------------------------
99
function getFilterResultNode() {
100
return filter.get('queryType') === 'classes' ? classesNode : modulesNode;
103
// -- Event Handlers -----------------------------------------------------------
104
function onFilterResults(e) {
105
var frag = Y.one(Y.config.doc.createDocumentFragment()),
106
resultNode = getFilterResultNode(),
107
typePlural = filter.get('queryType'),
108
typeSingular = typePlural === 'classes' ? 'class' : 'module';
110
if (e.results.length) {
111
YArray.each(e.results, function (result) {
112
frag.append(Lang.sub(LIST_ITEM_TEMPLATE, {
113
rootPath : APIList.rootPath,
114
displayName : filter.getDisplayName(result.highlighted),
116
typePlural : typePlural,
117
typeSingular: typeSingular
122
'<li class="message">' +
123
'No ' + typePlural + ' found.' +
128
resultNode.empty(true);
129
resultNode.append(frag);
131
focusManager.refresh();
134
function onSearchClear(e) {
136
focusManager.refresh();
139
function onSearchKey(e) {
140
var target = e.target;
142
if (target.test('input,select,textarea')
143
|| target.get('isContentEditable')) {
150
focusManager.refresh();
153
function onSearchResults(e) {
154
var frag = Y.one(Y.config.doc.createDocumentFragment());
156
if (e.results.length) {
157
YArray.each(e.results, function (result) {
158
frag.append(result.display);
162
'<li class="message">' +
163
'No results found. Maybe you\'ll have better luck with a ' +
170
focusManager.refresh();
173
function onTabSelectionChange(e) {
175
name = tab.get('label').toLowerCase();
178
index: tab.get('index'),
184
case 'classes': // fallthru
191
search.set('minQueryLength', -1);
193
// Only send a request if this isn't the initially-selected tab.
195
filter.sendRequest(filter.get('value'));
200
filter.set('minQueryLength', -1);
201
search.set('minQueryLength', 1);
203
if (search.get('value')) {
204
search.sendRequest(search.get('value'));
211
// WTF? We shouldn't be here!
212
filter.set('minQueryLength', -1);
213
search.set('minQueryLength', -1);
217
setTimeout(function () {
218
focusManager.refresh();
223
function onTabSwitchKey(e) {
224
var currentTabIndex = tabs.selected.index;
226
if (!(e.ctrlKey || e.metaKey)) {
233
case 37: // left arrow
234
if (currentTabIndex > 0) {
235
tabview.selectChild(currentTabIndex - 1);
240
case 39: // right arrow
241
if (currentTabIndex < (Y.Object.size(tabs) - 2)) {
242
tabview.selectChild(currentTabIndex + 1);
249
}, '3.4.0', {requires: [
250
'api-filter', 'api-search', 'event-key', 'node-focusmanager', 'tabview'