From a3a5299481a07bcfe5aeae857cc44263d406d627 Mon Sep 17 00:00:00 2001 From: anekos Date: Wed, 12 Nov 2008 06:10:09 +0000 Subject: __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 --- i_love_echo.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'i_love_echo.js') 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]) }); // }}} -- cgit v1.2.3