diff options
author | anekos | 2011-08-26 22:52:17 +0900 |
---|---|---|
committer | anekos | 2011-08-26 22:52:17 +0900 |
commit | 2962193f17e7f07556e5a38d2615c50fefd291e3 (patch) | |
tree | cd7f847c62a69910cc1704e4406b87296da61690 /_libly.js | |
parent | bb829261fa05684ed36b016a12e09707dd205354 (diff) | |
download | vimperator-plugins-2962193f17e7f07556e5a38d2615c50fefd291e3.tar.bz2 |
命名が標準的でないので修正
onSuccess -> success など
Diffstat (limited to '_libly.js')
-rw-r--r-- | _libly.js | 30 |
1 files changed, 19 insertions, 11 deletions
@@ -14,7 +14,7 @@ var PLUGIN_INFO = <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.35</version> + <version>0.1.36</version> <minVersion>2.3pre</minVersion> <updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/_libly.js</updateURL> <detail><![CDATA[ @@ -150,11 +150,11 @@ Request(url, headers, options): addEventListener(name, func): イベントリスナを登録する。 name: - 'onSuccess': + 'success': 成功時 - 'onFailure': + 'failure': 失敗を表すステータスコードが返ってきた時 - 'onException': + 'exception': 例外発生時 func: イベント発火時の処理 @@ -196,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) { @@ -517,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) { @@ -567,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() { @@ -592,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; } } }, @@ -642,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; @@ -710,7 +718,7 @@ 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) { + req.addEventListener('success', libly.$U.bind(this, function(res) { var text = res.responseText; if (!text) { errDispatcher('response is null.', cache); @@ -729,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(); } }; |