Created
October 29, 2010 12:48
-
-
Save think49/653491 to your computer and use it in GitHub Desktop.
この gist は更新しても反映されない不具合があるため、http://gist.github.com/658057 に移行しました。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ExtXPathEvaluator.js | |
function ExtXPathEvaluator () { | |
if (!(this instanceof ExtXPathEvaluator)) { | |
throw new Error(this + ' is not a object created by constructor'); | |
} | |
return this; | |
} | |
(function () { | |
this.evaluate = function (domObject, expression /*, contextNode*/) { | |
var contextNode; | |
contextNode = arguments[2]; | |
if (!contextNode) { | |
contextNode = domObject; | |
} | |
this.xPathResult = domObject.evaluate(expression, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
return this; | |
}; | |
this.replace = function (property, searchValue, replaceValue) { | |
var xPathResult, node, i; | |
xPathResult = this.xPathResult; | |
for (i = xPathResult.snapshotLength - 1; i > -1; i--) { | |
node = xPathResult.snapshotItem(i); | |
node[property] = node[property].replace(searchValue, replaceValue); | |
} | |
return this; | |
}; | |
this.forEach = function (callbackfn /*, thisArg*/) { | |
var xPathResult, thisArg, k, len, foo; | |
if (typeof callbackfn !== 'function') { | |
throw new TypeError(callbackfn + ' is not a function'); | |
} | |
xPathResult = this.xPathResult; | |
if (arguments.length < 2) { | |
for (k = 0, len = xPathResult.snapshotLength; k < len; k++){ | |
callbackfn(xPathResult.snapshotItem(k)); | |
} | |
} else { | |
thisArg = arguments[1]; | |
for (k = 0, len = xPathResult.snapshotLength; k < len; k++){ | |
callbackfn.call(thisArg, xPathResult.snapshotItem(k)); | |
} | |
} | |
return this; | |
}; | |
}).call(ExtXPathEvaluator.prototype); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
この gist は更新しても反映されない不具合があります。
サポートに連絡したところ、「同不具合は修正されましたが、新しく gist を作り直すことでしか解決することはできない」との返答を得ました。
そのため、http://gist.github.com/658057 に移動しました。