| Index: ui/webui/resources/js/cr/ui/node_utils.js
|
| diff --git a/ui/webui/resources/js/cr/ui/node_utils.js b/ui/webui/resources/js/cr/ui/node_utils.js
|
| index a380670e4f31d07968325abddf25797016aa8da7..8f92e9bfe6835bfad0d8cf81ae5f4fde47aac4d0 100644
|
| --- a/ui/webui/resources/js/cr/ui/node_utils.js
|
| +++ b/ui/webui/resources/js/cr/ui/node_utils.js
|
| @@ -31,3 +31,28 @@ cr.ui.reverseButtonStrips = function(opt_root) {
|
| buttonStrip.setAttribute('reversed', '');
|
| }
|
| };
|
| +
|
| +/**
|
| + * Finds a good place to set initial focus. Generally called when UI is shown.
|
| + * @param {!Element} root Where to start looking for focusable controls.
|
| + * @param {string=} opt_extraFocusable A selector for extra focusable items
|
| + * (e.g. '.my-link-class, [tabindex=0]').
|
| + */
|
| +cr.ui.setInitialFocus = function(root, opt_extraFocusable) {
|
| + // Do not change focus if any element in |root| is already focused.
|
| + if (root.contains(document.activeElement))
|
| + return;
|
| +
|
| + var focusableSelector = 'input, list, select, textarea, button';
|
| + if (opt_extraFocusable)
|
| + focusableSelector = opt_extraFocusable + ', ' + focusableSelector;
|
| +
|
| + var elements = root.querySelectorAll(focusableSelector);
|
| + for (var i = 0; i < elements.length; i++) {
|
| + var element = elements[i];
|
| + element.focus();
|
| + // .focus() isn't guaranteed to work. Continue until it does.
|
| + if (document.activeElement == element)
|
| + return;
|
| + }
|
| +};
|
|
|