#ubiquity-entry now retrieves focus on accesskeyed clicks. .preview-list now uses onclick rather than onfocus.

This commit is contained in:
satyr 2010-03-15 08:44:29 +09:00
Родитель 92ad8f453a
Коммит f631c81f48
2 изменённых файлов: 24 добавлений и 19 удалений

Просмотреть файл

@ -257,6 +257,9 @@ Ubiquity.prototype = {
this.execute(); this.execute();
} }
else { else {
target.accessKey && setTimeout(function U_refocusTextBox(self) {
if (self.isWindowOpen) self.__textBox.focus();
}, 99, this);
do var {href} = target; while (!href && (target = target.parentNode)); do var {href} = target; while (!href && (target = target.parentNode));
if (!href || if (!href ||
~href.lastIndexOf("javascript:", 0) || ~href.lastIndexOf("javascript:", 0) ||

Просмотреть файл

@ -936,7 +936,7 @@ function CreateAlias(options) {
// }); // });
// //
// CmdUtils.makeSearchCommand({ // CmdUtils.makeSearchCommand({
// names: ["video.baidu", "百度视频"], // names: ["video.baidu", "\u767E\u5EA6\u89C6\u9891"],
// url: "http://video.baidu.com/v?word={QUERY}", // url: "http://video.baidu.com/v?word={QUERY}",
// charset: "gb2312", // charset: "gb2312",
// parser: { // parser: {
@ -1315,45 +1315,47 @@ function previewCallback(pblock, callback, abortCallback) {
// {{{css}}} is an optional CSS string inserted along with the list. // {{{css}}} is an optional CSS string inserted along with the list.
function previewList(block, htmls, callback, css) { function previewList(block, htmls, callback, css) {
var {escapeHtml} = Utils, list = "", num = 0; var {escapeHtml} = Utils, list = "", num = 0, CU = this;
for (let id in htmls) { for (let key in htmls) {
let k = ++num < 36 ? num.toString(36) : "-"; let k = ++num < 36 ? num.toString(36) : "-";
list += ('<li><label for="' + num + '"><button id="' + num + list += ('<li><label for="' + num + '"><input type="button" id="' + num +
'" value="' + escapeHtml(id) + '" accesskey="' + k + '">' + k + '" class="button" value="' + k + '" accesskey="' + k +
'</button>' + htmls[id] + '</label></li>'); '" key="' + escapeHtml(key) + '"/>' + htmls[key] +
'</label></li>');
} }
block.innerHTML = ( block.innerHTML = (
'<ol class="preview-list">' + '<ol class="preview-list">' +
'<style>' + previewList.CSS + (css || "") + '</style>' + '<style>' + previewList.CSS + (css || "") + '</style>' +
'<button id="keyshifter" accesskey="0">0</button>' + '<input type="button" class="button" id="keyshifter"' +
list + '</ol>'); ' value="0" accesskey="0"/>' + list + '</ol>');
var ol = block.firstChild, start = 0; var ol = block.firstChild, start = 0;
callback && ol.addEventListener("focus", function onPreviewListFocus(ev) { callback && ol.addEventListener("click", function onPreviewListClick(ev) {
var {target} = ev; var {target} = ev;
if (/^(?!button$)/i.test(target.nodeName)) return; if (target.type !== "button") return;
target.blur(); ev.preventDefault();
if (target.id === "keyshifter") { if (target.id === "keyshifter") {
if (num < 36) return; if (num < 36) return;
let buttons = Array.slice(this.getElementsByTagName("button"), 1); let buttons = Array.slice(this.getElementsByClassName("button"), 1);
start = (start + 35) % buttons.length; start = (start + 35) % buttons.length;
buttons = buttons.splice(start).concat(buttons); buttons = buttons.splice(start).concat(buttons);
for (let i = 0, b; b = buttons[i];) for (let i = 0, b; b = buttons[i];)
b.textContent = b.accessKey = ++i < 36 ? i.toString(36) : "-"; b.value = b.accessKey = ++i < 36 ? i.toString(36) : "-";
return; return;
} }
target.disabled = true; target.disabled = true;
if (callback(target.value, ev)) if (callback.call(this, target.getAttribute("key"), ev))
Utils.setTimeout(function reenable() { target.disabled = false }); Utils.setTimeout(function reenableButton() { target.disabled = false });
}, true); }, false);
return ol; return ol;
} }
previewList.CSS = "" + <![CDATA[ previewList.CSS = "" + <![CDATA[
.preview-list {margin: 0; padding-left: 1.5em; list-style-type: none} .preview-list {margin: 0; padding-left: 1.5em; list-style-type: none}
.preview-list > li {line-height: 1.4; text-indent: -1.5em} .preview-list > li {position: relative; min-height: 3ex}
.preview-list > li:hover {outline: 1px solid; -moz-outline-radius: 8px} .preview-list > li:hover {outline: 1px solid; -moz-outline-radius: 8px}
.preview-list label {display: block; cursor: pointer} .preview-list label {display: block; cursor: pointer}
.preview-list button { .preview-list .button {
margin-right: 0.3em; padding: 0; border-width: 1px; position: absolute; left: -1.5em; height: 3ex;
padding: 0; border-width: 1px;
font: bold 108% monospace; text-transform: uppercase} font: bold 108% monospace; text-transform: uppercase}
#keyshifter {position:absolute; top:-9999px} #keyshifter {position:absolute; top:-9999px}
]]>; ]]>;