aboutsummaryrefslogtreecommitdiffstats
path: root/command_menu.js
diff options
context:
space:
mode:
authordrry2008-10-29 22:01:16 +0000
committerdrry2008-10-29 22:01:16 +0000
commit234105267fdd5d2af0dddaddfccfeb3c9a31d686 (patch)
tree4cbd6da31bbb8b54896386be4d6a12b955a42d22 /command_menu.js
parent92cf3fa2041d42e7139e52af46f03010ff41a91c (diff)
downloadvimperator-plugins-234105267fdd5d2af0dddaddfccfeb3c9a31d686.tar.bz2
* カナダ英語を除去しました。
* 正規表現を修正しました。 * Array オブジェクトに対する `for...in` および `for each` 文を回避しました。 * ほか。 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@22343 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'command_menu.js')
-rw-r--r--command_menu.js94
1 files changed, 41 insertions, 53 deletions
diff --git a/command_menu.js b/command_menu.js
index 4c95088..4cabb55 100644
--- a/command_menu.js
+++ b/command_menu.js
@@ -19,38 +19,37 @@
//
// License:
// http://creativecommons.org/licenses/by-sa/2.1/jp/
-// http://creativecommons.org/licenses/by-sa/2.1/jp/deed.en_CA
+// http://creativecommons.org/licenses/by-sa/2.1/jp/deed
-(function(){
+(function () {
const migemo = Components
.classes['@piro.sakura.ne.jp/xmigemo/factory;1']
.getService(Components.interfaces.pIXMigemoFactory)
.getService("ja");
- function id (v) v;
-
function equal (x) function (y) x == y;
- function cloneArray (src) src.map(id);
+ function cloneArray (src) src.map(function (id) id);
function matchPath (elem, path, getName) {
- for (let i = 0; i < path.length; i++) {
+ var i = 0;
+ for (let l = path.length; i < l; i++) {
if (!path[i](getName(elem)))
break;
}
if (i) {
let res = [];
- for (let j = i; j < path.length; j++)
+ for (let j = i, l = path.length; j < l; j++)
res.push(path[j]);
return res;
}
}
function getElementsByPath (elem, path, getName, isTarget, isEnabled) {
- try{
+ try {
function get (point, elem, path) {
- let m = path[0](getName(elem, true));
+ var m = path[0](getName(elem, true));
if (isTarget(elem)) {
if (!isEnabled(elem))
@@ -65,11 +64,11 @@
}
//elem.containerOpen = true;
- let res, cs = elem.childNodes, result = [];
+ var res, cs = elem.childNodes, result = [];
if (cs && cs.length) {
- for (let i = 0; i < cs.length; i++) {
+ for (let i = 0, l = cs.length; i < l; i++) {
if (res = get(m + point, cs[i], path))
- res.map(function(it) it && result.push(it));
+ res.map(function (it) it && result.push(it));
}
}
//elem.containerOpen = false;
@@ -78,26 +77,21 @@
}
return get(0, elem, path).sort().map(function (it) it[1]);
- }catch(e){ liberator.log(e); }
+ } catch (e) { liberator.log(e); }
}
- function getPathMatchers (args) {
- return args.split('-').map(function(it){
- let n = it.toLowerCase();
- let s = migemo.getRegExp(it.replace(/^\s+|\s+$/, ''));
- let re = new RegExp(s, 'i');
- return function (l) {
- if (!l) return 0;
- if (l == it) return 1;
- if (l.toLowerCase().indexOf(n) >= 0) return 2;
- if (re.test(l)) return 3;
- return 0;
- }
- });
- }
+ function getPathMatchers (args)
+ args.split('-').map(function (it)
+ function (l)
+ !l ? 0 :
+ l == it ? 1 :
+ l.toLowerCase().indexOf(it.toLowerCase()) >= 0 ? 2 :
+ new RegExp(migemo.getRegExp(it.replace(/^\s+|\s+$/, '')),
+ 'i').test(l) ? 3 :
+ 0);
function getPathString (elem, isRoot, getName, isTarget) {
- let res = [];
+ var res = [];
while (!isRoot(elem)) {
isTarget(elem) && res.unshift(getName(elem));
elem = elem.parentNode;
@@ -116,32 +110,27 @@
const toolbox = document.getElementById('navigator-toolbox');
const contextmenu = document.getElementById('contentAreaContextMenu');
- function fixName (name) {
- return name ? name.replace(/^\s+|\s+$/, '').replace(/[\-\s]+/g, '_') : '';
- }
+ function fixName (name)
+ name ? name.replace(/^\s+|\s+$/, '').replace(/[-\s]+/g, '_') : '';
- function getElementName (elem, multi) {
- const f = function (it) { return fixName(it) || ''; }
- return multi ? [elem.label, elem.tooltipText].map(f).join('-')
- : fixName(elem.label || elem.tooltipText || '') ;
- }
+ function getElementName (elem, multi)
+ multi ? [elem.label, elem.tooltipText].map(function (it) fixName(it) || '')
+ .join('-')
+ : fixName(elem.label || elem.tooltipText || '');
- function isNotHidden (elem) {
- return !elem.hidden;
- }
+ function isNotHidden (elem)
+ !elem.hidden ? true : false;
- function isClickable (elem) {
- const re = /^(menu(item)?|toolbarbutton)$/i;
- return elem.nodeName.match(re);
- }
+ function isClickable (elem)
+ /^(?:menu(?:item)?|toolbarbutton)$/.test(elem.nodeName.toLowerCase());
- function addCommand(cmds, name, root, action) {
+ function addCommand (cmds, name, root, action) {
function _find (args, single) {
- let result = getElementsByPath(root,
- getPathMatchers(args),
- getElementName,
- isClickable,
- isNotHidden);
+ var result = getElementsByPath(root,
+ getPathMatchers(args),
+ getElementName,
+ isClickable,
+ isNotHidden);
return single ? result[0] : result;
}
@@ -161,7 +150,7 @@
// for HEAD (2)
if (args.string != undefined)
args = args.string;
- let res = _find(args.replace(/-\s*$/,''), true);
+ var res = _find(args.replace(/-\s*$/,''), true);
if (!(res && action(res)))
liberator.echoerr('menu not found');
},
@@ -178,8 +167,8 @@
addCommand(['me[nu]'], 'Command MainMenu', mainMenubar);
addCommand(['toolbar', 'tb'], 'Command Toolbar', toolbox);
addCommand(['conme', 'contextmenu'],
- 'Context Menu',
- contextmenu,
+ 'Context Menu',
+ contextmenu,
function (elem) {
//contextmenu.openPopup(null, null, 0, 0, true);
//contextmenu.hidePopup();
@@ -190,4 +179,3 @@
);
})();
-