Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(783)

Unified Diff: node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/browser_functions.js

Issue 800513006: Added vulcanize under third_party/npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/browser_functions.js
diff --git a/node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/browser_functions.js b/node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/browser_functions.js
new file mode 100644
index 0000000000000000000000000000000000000000..024540d01c74ac0af21d3ecc3298b9a08db1bb26
--- /dev/null
+++ b/node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/browser_functions.js
@@ -0,0 +1,67 @@
+function isTag(elem){
+ return elem.nodeType === 1;
+}
+function getChildren(elem){
+ return Array.prototype.slice.call(elem.childNodes, 0);
+}
+function getParent(elem){
+ return elem.parentElement;
+}
+
+module.exports = {
+ isTag: isTag,
+ getSiblings: function(elem){
+ var parent = getParent(elem);
+ return parent && getChildren(parent);
+ },
+ getChildren: getChildren,
+ getParent: getParent,
+ getAttributeValue: function(elem, name){
+ return elem.attributes[name].value;
+ },
+ hasAttrib: function(elem, name){
+ return name in elem.attributes;
+ },
+ getName: function(elem){
+ return elem.tagName.toLowerCase();
+ },
+ findOne: function findOne(test, arr){
+ var elem = null;
+
+ for(var i = 0, l = arr.length; i < l && !elem; i++){
+ if(test(arr[i])){
+ elem = arr[i];
+ } else {
+ var childs = getChildren(arr[i]);
+ if(childs && childs.length > 0){
+ elem = findOne(test, childs);
+ }
+ }
+ }
+
+ return elem;
+ },
+ findAll: function findAll(test, elems){
+ var result = [];
+ for(var i = 0, j = elems.length; i < j; i++){
+ if(!isTag(elems[i])) continue;
+ if(test(elems[i])) result.push(elems[i]);
+ var childs = getChildren(elems[i]);
+ if(childs) result = result.concat(findAll(test, childs));
+ }
+ return result;
+ },
+ //https://github.com/ded/qwery/blob/master/pseudos/qwery-pseudos.js#L47-54
+ getText: function getText(elem) {
+ var str = "",
+ childs = getChildren(elem);
+
+ if(!childs) return str;
+
+ for(var i = 0; i < childs.length; i++){
+ if(isTag(childs[i])) str += elem.textContent || elem.innerText || getText(childs[i]);
+ }
+
+ return str;
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698