diff options
author | anekos | 2008-11-12 06:10:09 +0000 |
---|---|---|
committer | anekos | 2008-11-12 06:10:09 +0000 |
commit | a3a5299481a07bcfe5aeae857cc44263d406d627 (patch) | |
tree | 82e0f8723bc7334594a448976440a7e8fc297b1b /i_love_echo.js | |
parent | fbe655104805ef1254b165401f780443e42f49b9 (diff) | |
download | vimperator-plugins-a3a5299481a07bcfe5aeae857cc44263d406d627.tar.bz2 |
__noSuchMethod__ の返値を $() でくるむように修正
$s に evaluate メソッド追加
$a に first/last メソッド追加
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@23331 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'i_love_echo.js')
-rw-r--r-- | i_love_echo.js | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/i_love_echo.js b/i_love_echo.js index 3d15d9b..7380fc6 100644 --- a/i_love_echo.js +++ b/i_love_echo.js @@ -131,7 +131,7 @@ $c.prototype = { return this.value.toString(); }, __noSuchMethod__: function(name, args){ - return this.value[name].apply(this.value, args); + return $(this.value[name].apply(this.value, args)); } }; // }}} @@ -148,7 +148,7 @@ createPrototype($s, { get base64() $(window.btoa(this.value)), get encodeURICompoenent() $(encodeURIComponent(this.value)), get MD5Hash(){ - var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter); +context converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter); converter.charset = "UTF-8"; var result = {}; var data = converter.convertToByteArray(this.value, result); @@ -172,6 +172,17 @@ createPrototype($s, { } catch (e){ return null; } + }, + evaluate: function(doc,context){ + if (!doc) doc = content.document; + if (!context) context = doc; + var result = []; + var nodes = doc.evaluate(this.value, context, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); + var node; + while (node = nodes.iterateNext()) { + result.push(node); + } + return $(result); } }); // }}} @@ -198,7 +209,9 @@ createPrototype($a, { unshift: function(arg){ this.value.unshift(arg); return this; - } + }, + get first() $(this.value[0]), + get last() $(this.value[this.length - 1]) }); // }}} |