Permalink
Browse files

Update Vimperator plugins

  • Loading branch information...
1 parent 0b52130 commit 80e7a04ff0e1fc796917b1c36ad52819bc059034 Nikolai Weibull committed Apr 28, 2012
Showing with 155 additions and 107 deletions.
  1. +40 −22 vimperator/plugin/_libly.js
  2. +115 −85 vimperator/plugin/feed-some-keys.js
@@ -1,5 +1,6 @@
/*** BEGIN LICENSE BLOCK {{{
Copyright (c) 2008 suVene<suvene@zeromemory.info>
+ Copyright (c) 2008-2011 anekos<anekos@snca.net>
distributable under the terms of an MIT-style license.
http://www.opensource.jp/licenses/mit-license.html
@@ -11,11 +12,11 @@ var PLUGIN_INFO =
<description>Vimperator plugins library?</description>
<description lang="ja">適当なライブラリっぽいものたち。</description>
<author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author>
+ <author mail="anekos@snca.net" homepage="http://snca.net/">anekos</author>
<license>MIT</license>
- <version>0.1.33</version>
+ <version>0.1.38</version>
<minVersion>2.3pre</minVersion>
- <maxVersion>2.3</maxVersion>
- <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/_libly.js</updateURL>
+ <updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/_libly.js</updateURL>
<detail><![CDATA[
== Objects ==
- liberator.plugins.libly.$U
@@ -137,7 +138,7 @@ Request(url, headers, options):
options:
オプションとして以下のようなオブジェクトを指定できる(省略可)
asynchronous:
- true: 同期モード/false: 非同期モード(デフォルト:true
+ true: 非同期モード/false: 同期モード(デフォルト:true
encoding:
エンコーディング(デフォルト: 'UTF-8'
username:
@@ -149,11 +150,11 @@ Request(url, headers, options):
addEventListener(name, func):
イベントリスナを登録する。
name:
- 'onSuccess':
+ 'success':
成功時
- 'onFailure':
+ 'failure':
失敗を表すステータスコードが返ってきた時
- 'onException':
+ 'exception':
例外発生時
func:
イベント発火時の処理
@@ -195,6 +196,11 @@ clearCache:
liberator.plugins.libly = {};
var libly = liberator.plugins.libly;
+// XXX for backward compatibillity
+function fixEventName(name) {
+ return name.replace(/^on/, '').toLowerCase();
+}
+
libly.$U = {//{{{
// Logger {{{
getLogger: function(prefix) {
@@ -239,8 +245,8 @@ libly.$U = {//{{{
let pluginPath;
Error('hoge').stack.split(/\n/).some(
function (s)
- let (m = s.match(/^\(\)@chrome:\/\/liberator\/content\/liberator\.js -> (.+):\d+$/))
- (m && (pluginPath = m[1]))
+ let (m = s.match(/^(?:\(\))?@chrome:\/\/liberator\/content\/liberator\.js -> (.+):\d+$/))
+ (m && (pluginPath = m[1].replace(/\?.*$/, '')))
);
return pluginPath;
}
@@ -275,7 +281,7 @@ libly.$U = {//{{{
let self = this, args = arguments;
return func.call(self, function (_args) original.apply(self, _args || args), args);
};
- libly.$U.extend(current, {original: original.original || original, restore: restore});
+ libly.$U.extend(current, {original: original && original.original || original, restore: restore});
return libly.$U.extend({
original: original,
current: current,
@@ -516,14 +522,16 @@ libly.Request.prototype = {
this.observers = {};
},
addEventListener: function(name, func) {
+ name = fixEventName(name);
try {
if (typeof this.observers[name] == 'undefined') this.observers[name] = [];
this.observers[name].push(func);
} catch (e) {
- if (!this.fireEvent('onException', new libly.Response(this), e)) throw e;
+ if (!this.fireEvent('exception', new libly.Response(this), e)) throw e;
}
},
fireEvent: function(name, args, asynchronous) {
+ name = fixEventName(name);
if (!(this.observers[name] instanceof Array)) return false;
this.observers[name].forEach(function(event) {
if (asynchronous) {
@@ -544,20 +552,29 @@ libly.Request.prototype = {
this.transport = new XMLHttpRequest();
this.transport.open(method, this.url, this.options.asynchronous, this.options.username, this.options.password);
- this.transport.onreadystatechange = libly.$U.bind(this, this._onStateChange);
+ var stateChangeException;
+ this.transport.onreadystatechange = libly.$U.bind(this, function () {
+ try {
+ this._onStateChange();
+ } catch (e) {
+ stateChangeException = e;
+ }
+ });
this.setRequestHeaders();
- this.transport.overrideMimeType('text/html; charset=' + this.options.encoding);
+ this.transport.overrideMimeType(this.options.mimetype || 'text/html; charset=' + this.options.encoding);
this.body = this.method == 'POST' ? this.options.postBody : null;
this.transport.send(this.body);
+ if (!this.options.asynchronous && stateChangeException) throw stateChangeException;
+
// Force Firefox to handle ready state 4 for synchronous requests
if (!this.options.asynchronous && this.transport.overrideMimeType)
this._onStateChange();
} catch (e) {
- if (!this.fireEvent('onException', new libly.Response(this), e)) throw e;
+ if (!this.fireEvent('exception', new libly.Response(this), e)) throw e;
}
},
_onStateChange: function() {
@@ -582,9 +599,9 @@ libly.Request.prototype = {
libly.Request.requestCount--;
try {
this._complete = true;
- this.fireEvent('on' + (this.isSuccess() ? 'Success' : 'Failure'), res, this.options.asynchronous);
+ this.fireEvent(this.isSuccess() ? 'success' : 'failure', res, this.options.asynchronous);
} catch (e) {
- if (!this.fireEvent('onException', res, e)) throw e;
+ if (!this.fireEvent('exception', res, e)) throw e;
}
}
},
@@ -632,6 +649,7 @@ libly.Response.prototype = {
this.status = this.getStatus();
this.statusText = this.getStatusText();
this.responseText = (this.transport.responseText == null) ? '' : this.transport.responseText;
+ this.responseXML = this.transport.responseXML;
}
this.doc = null;
@@ -672,8 +690,8 @@ libly.Wedata.prototype = {
getItems: function(expire, itemCallback, finalCallback) {
var logger = this.logger;
- var STORE_KEY = 'plugins-libly-wedata-' + this.dbname + '-items';
- var store = storage.newMap(STORE_KEY, true);
+ var STORE_KEY = 'plugins-libly-wedata-' + encodeURIComponent(this.dbname) + '-items';
+ var store = storage.newMap(STORE_KEY, {store: true});
var cache = store && store.get('data');
if (store && cache && new Date(store.get('expire')) > new Date()) {
@@ -699,8 +717,8 @@ libly.Wedata.prototype = {
}
}
- var req = new libly.Request(this.HOST_NAME + 'databases/' + this.dbname + '/items.json');
- req.addEventListener('onSuccess', libly.$U.bind(this, function(res) {
+ var req = new libly.Request(this.HOST_NAME + 'databases/' + encodeURIComponent(this.dbname) + '/items.json');
+ req.addEventListener('success', libly.$U.bind(this, function(res) {
var text = res.responseText;
if (!text) {
errDispatcher('response is null.', cache);
@@ -719,8 +737,8 @@ libly.Wedata.prototype = {
if (typeof finalCallback == 'function')
finalCallback(true, json);
}));
- req.addEventListener('onFailure', function() errDispatcher('onFailure', cache));
- req.addEventListener('onException', function() errDispatcher('onException', cache));
+ req.addEventListener('failure', function() errDispatcher('onFailure', cache));
+ req.addEventListener('exception', function() errDispatcher('onException', cache));
req.get();
}
};
Oops, something went wrong.

0 comments on commit 80e7a04

Please sign in to comment.