From 243742acd09e39a4f7a51c6be1d108b26c553d90 Mon Sep 17 00:00:00 2001
From: secondlife
Date: Sun, 5 Jul 2009 13:00:05 +0000
Subject: Scala API 検索プラグイン
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@34303 d0d07461-0603-4401-acd4-de1884942a52
---
scalapi.js | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 93 insertions(+)
create mode 100644 scalapi.js
(limited to 'scalapi.js')
diff --git a/scalapi.js b/scalapi.js
new file mode 100644
index 0000000..55a3434
--- /dev/null
+++ b/scalapi.js
@@ -0,0 +1,93 @@
+var PLUGIN_INFO =
+
+{NAME}
+Scala API document
+Scala API を検索し、補完します。
+2.0pre
+2.0pre
+http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/scalapi.js
+Yuichi Tateno
+MPL 1.1/GPL 2.0/LGPL 2.1
+0.1
+
+;
+
+(function() {
+var p = function(arg) {
+ Application.console.log(arg);
+ // liberator.log(arg);
+};
+
+var scalaApiURL = liberator.globalVariables.scalaApiURL || 'http://www.scala-lang.org/docu/files/api/';
+if (!liberator.globalVariables.scalaApiCache) {
+ let xhr = new XMLHttpRequest();
+ let regex = new RegExp('([^.]+)', 'g');
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4) {
+ if (xhr.status == 200) {
+ let text = xhr.responseText;
+ let res = [];
+ res.hashMap = {};
+ text.replace(regex, function(m) {
+ let path = RegExp.$1;
+ let name = path.replace('$object', '');
+ name = name.replace(/\//g, '.');
+ res.push([name, path]);
+ res.hashMap[name] = path;
+ });
+ liberator.globalVariables.scalaApiCache = res;
+ } else {
+ liberator.echoerr('Scala API : XHR Error: ' + xhr.statusText);
+ // throw new Error(xhr.statusText);
+ }
+ }
+ };
+ xhr.open('GET', scalaApiURL + 'all-classes.html', true);
+ xhr.send(null);
+}
+
+commands.addUserCommand(
+ liberator.globalVariables.scalaApiCommands || ['scalapi', 'sc'],
+ 'Scala API Search',
+ function(args) {
+ var name = (args.string || '');
+ var url = (name && liberator.globalVariables.scalaApiCache.hashMap[name]) ? scalaApiURL + 'scala/' + liberator.globalVariables.scalaApiCache.hashMap[name] + '.html' : scalaApiURL + 'index.html';
+ liberator.open(url, args.bang ? liberator.NEW_TAB : null);
+ }, {
+ completer: function(context) {
+ context.title = ['API Name', 'API'];
+ var word = context.filter;// .toUpperCase();
+ /*
+ if (word.indexOf('.') >= 0) {
+ let regex = word.split(/\.+/).map(function(i) i + '[^.]*').join('.');
+ p(regex);
+ regex = new RegExp('^' + regex.replace(/\[\^\.\]\*$/, ''));
+ p(regex);
+ context.filters = [function(item) regex.test(item.item[0])];
+ } else {
+ context.filters = [function(item) item.item[0].toUpperCase().indexOf(word) != -1];
+ }
+ */
+ try {
+ var regex = new RegExp(word, 'i');
+ context.filters = [function(item) regex.test(item.item[0])];
+ } catch(e) {
+ var word = context.filter.toUpperCase();
+ context.filters = [function(item) item.item[0].toUpperCase().indexOf(word) != -1];
+ }
+ context.completions = liberator.globalVariables.scalaApiCache || [];
+ },
+ argCount: '*',
+ bang: true
+ },
+ true
+);
+
+})();
+
--
cgit v1.2.3