aboutsummaryrefslogtreecommitdiffstats
path: root/bookmarktoolbar-hint.js
diff options
context:
space:
mode:
authorteramako2008-06-08 01:31:08 +0000
committerteramako2008-06-08 01:31:08 +0000
commit23f52da95525e0b78053d5d44c3d2c47f9bf7e25 (patch)
tree39c507a933620c58d6e2dcfb02b9ba0c7ee6f799 /bookmarktoolbar-hint.js
parent2bc4cc225c6743938746e1536bb81452e0e9e807 (diff)
downloadvimperator-plugins-23f52da95525e0b78053d5d44c3d2c47f9bf7e25.tar.bz2
フォーカス移動の追加
「タブで全て開く」に対応 選択されているアイテムのツールチップにスタイルを適用 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@13457 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'bookmarktoolbar-hint.js')
-rw-r--r--bookmarktoolbar-hint.js142
1 files changed, 98 insertions, 44 deletions
diff --git a/bookmarktoolbar-hint.js b/bookmarktoolbar-hint.js
index 0749a30..77646ee 100644
--- a/bookmarktoolbar-hint.js
+++ b/bookmarktoolbar-hint.js
@@ -2,7 +2,7 @@
// @name BookmarksToolbar-Hint
// @description Feature the BookmarksToolbar-Hint
// @description-ja ブックマークツールバーのヒント機能を提供
-// @version 0.2a
+// @version 0.2b
// ==/VimperatorPlugin==
//
// Usage:
@@ -10,17 +10,20 @@
// <Leader>f -> open current tab
// <Leader>F -> open new tab
//
-// Note: <Leader>はデフォルトでは`\'になっています
+// Note: <Leader> is `\' by default
+//
+// duaing BookmarksToolbar-Hint, numbering tooltip is appear.
+// the item of matched number will open when type the number
+// and <BS> remove pending number or backward to parent (at opening a folder)
+//
liberator.plugins.bookmarkToolbarHints = (function(){
- function $(id){
- return document.getElementById(id);
- }
function createTooltip(){
var tooltip = document.createElement('tooltip');
- tooltip.setAttribute('style','padding:0');
+ tooltip.setAttribute('style','padding:0;margin:0;');
var label = document.createElement('label');
label.setAttribute('value',tooltipbox.childNodes.length+1);
+ label.setAttribute('style','padding:0;margin:0 2px;');
tooltip.appendChild(label);
tooltipbox.appendChild(tooltip);
return tooltip;
@@ -35,26 +38,44 @@ liberator.plugins.bookmarkToolbarHints = (function(){
if (toolbar)
return toolbar;
else
- toolbar = $('bookmarksBarContent');
+ toolbar = document.getElementById('bookmarksBarContent');
return toolbar;
}
function onKeyPress(event){
manager.onEvent(event);
+ event.stopPropagation();
+ event.preventDefault();
+ }
+ function updateSelector(){
+ for (var i=0; i<tooltipbox.childNodes.length; i++){
+ tooltipbox.childNodes[i].style.color = (i+1).toString().indexOf(currentNum+1) == 0 ? "red" : "black";
+ }
+ }
+ function itemOpen(target){
+ if (target.hasAttribute('oncommand')){
+ var fn = new Function("event", target.getAttribute("oncommand"));
+ if (where == liberator.CURRENT_TAB)
+ fn.call(target, {button:0, ctrlKey:false});
+ else
+ fn.call(target, {button:1, ctrlKey:true});
+ } else {
+ liberator.open(target.node.uri, where);
+ }
+ closeMenus(target);
+ liberator.options.guioptions = manager.go;
}
- function allHidePopup(node){
- if (node.hidePopup) node.hidePopup();
- if (node.parentNode) allHidePopup(node.parentNode);
+ function folderOpen(target){
+ target.firstChild.showPopup();
+ manager.quit();
+ manager.show(target.firstChild);
}
function toolbarOpen(target){
if (target.getAttribute('container') == 'true'){
- target.firstChild.showPopup();
- liberator.plugins.bookmarkToolbarHints.hide();
- liberator.plugins.bookmarkToolbarHints.show(target.firstChild);
+ folderOpen(target);
return true;
} else {
- liberator.open(target.node.uri, where);
- liberator.options.guioptions = liberator.plugins.bookmarkToolbarHints.go;
+ itemOpen(target);
}
return false;
}
@@ -62,13 +83,20 @@ liberator.plugins.bookmarkToolbarHints = (function(){
var toolbar;
var current;
var currentNum = 0;
- var focusNum = 0;
+ var useShift = false;
var where = liberator.CURERNT_TAB;
var manager = {
get toolbar(){ return getToolbar(); },
go : null,
get where(){ return where; },
set where(value){ where = value; },
+ startup: function(where){
+ this.go = options.guioptions;
+ options.guioptions += "b";
+ //liberator.modes.setCustomMode('BookmarksToolbar-Hint', this.onEvent, this.quit);
+ liberator.modes.setCustomMode('BookmarksToolbar-Hint', function(){return;}, this.quit);
+ this.show();
+ },
show:function(node){
liberator.modes.set(liberator.modes.CUSTOM, liberator.modes.QUICK_HINT);
hints = [];
@@ -79,32 +107,70 @@ liberator.plugins.bookmarkToolbarHints = (function(){
if (button.localName == "menuseparator") continue;
hints.push(button);
var tooltip = createTooltip();
- tooltip.showPopup(button, -1, -1,"tooltip","topright");
+ tooltip.showPopup(button, -1, -1,"tooltip","topleft","topright");
}
+ updateSelector();
},
onEvent: function(event){
var key = liberator.events.toString(event);
- var num;
switch(key){
case "<Esc>":
case "<C-[>":
- allHidePopup(current);
- liberator.options.guioptions = liberator.plugins.bookmarkToolbarHints.go;
+ closeMenus(current);
+ liberator.options.guioptions = this.go;
break;
case "<Return>":
- if (toolbarOpen(hints[focusNum])) return;
+ if (toolbarOpen(hints[currentNum])) return;
break;
+ case "f":
+ this.where = liberator.CURRENT_TAB;
+ return;
+ case "F":
+ case "t":
+ this.where = liberator.NEW_TAB;
+ return;
case "<Tab>":
+ case "j":
case "<S-Tab>":
- break;
+ case "k":
+ if (key == "j" || key == "<Tab>"){
+ currentNum = hints.length -1 == currentNum ? 0 : currentNum + 1;
+ } else {
+ currentNum = currentNum == 0 ? hints.length -1 : currentNum - 1;
+ }
+ useShift = true;
+ updateSelector();
+ return;
+ case "l":
+ if (hints[currentNum].getAttribute("container") == "true"){
+ folderOpen(hints[currentNum]);
+ }
+ return;
+ case "h":
+ case "<BS>":
+ if (key == "<BS>" && currentNum > 0){
+ currentNum = Math.floor(currentNum / 10);
+ updateSelector();
+ } else {
+ if (current == this.toolbar){
+ closeMenus(current);
+ liberator.options.guioptions = this.go;
+ this.quit();
+ } else {
+ current.hidePopup();
+ clearTooltips();
+ this.show(current.parentNode.parentNode);
+ }
+ }
+ return;
default:
if (/^[0-9]$/.test(key)){
- num = parseInt(key,10);
- if (currentNum) num += currentNum * 10;
+ var num = parseInt(key,10);
+ if (!useShift && currentNum) num += currentNum * 10;
if (hints.length >= num*10){
- currentNum = num;
- forcusNum = num;
+ currentNum = num - 1;
+ updateSelector();
return;
}
if (hints[num-1]){
@@ -112,15 +178,14 @@ liberator.plugins.bookmarkToolbarHints = (function(){
}
}
}
- liberator.plugins.bookmarkToolbarHints.hide();
+ liberator.plugins.bookmarkToolbarHints.quit();
},
- hide: function(){
+ quit: function(){
currentNum = 0;
- focusNum = 0;
+ useShift = false;
window.removeEventListener('keypress',onKeyPress,true);
liberator.modes.reset(true);
- var tooltipbox = document.getElementById('liberator-tooltip-container');
while(tooltipbox.hasChildNodes()){
tooltipbox.firstChild.hidePopup();
tooltipbox.removeChild(tooltipbox.firstChild);
@@ -129,27 +194,16 @@ liberator.plugins.bookmarkToolbarHints = (function(){
};
var tooltipbox = document.createElement('box');
tooltipbox.setAttribute('id','liberator-tooltip-container');
- $('liberator-container').appendChild(tooltipbox);
+ document.getElementById('liberator-container').appendChild(tooltipbox);
return manager;
})();
-liberator.modes.setCustomMode('BookmarksToolbar-Hint', plugins.bookmarkToolbarHints.onEvent, plugins.bookmarkToolbarHints.hide);
liberator.mappings.addUserMap([liberator.modes.NORMAL], ['<Leader>f'],
'Start Toolbar-HINTS (open current tab)',
- function(){
- plugins.bookmarkToolbarHints.go = options.guioptions;
- options.guioptions += "b";
- plugins.bookmarkToolbarHints.where = liberator.CURRENT_TAB;
- plugins.bookmarkToolbarHints.show();
- }
+ function(){ plugins.bookmarkToolbarHints.startup(liberator.CURRENT_TAB); }
);
liberator.mappings.addUserMap([liberator.modes.NORMAL], ['<Leader>F'],
'Start Toolbar-HINTS (open new tab)',
- function(){
- plugins.bookmarkToolbarHints.go = options.guioptions;
- options.guioptions += "b";
- plugins.bookmarkToolbarHints.where = liberator.NEW_TAB;
- plugins.bookmarkToolbarHints.show();
- }
+ function(){ plugins.bookmarkToolbarHints.startup(liberator.NEW_TAB); }
);