diff options
Diffstat (limited to '_libly.js')
-rw-r--r-- | _libly.js | 45 |
1 files changed, 27 insertions, 18 deletions
@@ -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,10 +12,10 @@ 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.34</version> + <version>0.1.37</version> <minVersion>2.3pre</minVersion> - <maxVersion>3.0</maxVersion> <updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/_libly.js</updateURL> <detail><![CDATA[ == Objects == @@ -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) { @@ -566,7 +574,7 @@ libly.Request.prototype = { 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() { @@ -591,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; } } }, @@ -641,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; @@ -681,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()) { @@ -708,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); @@ -728,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(); } }; |