Skip to content

Instantly share code, notes, and snippets.

@termi
Last active December 20, 2015 04:18
Show Gist options
  • Save termi/6069645 to your computer and use it in GitHub Desktop.
Save termi/6069645 to your computer and use it in GitHub Desktop.
Find Microdata properties Note: Without itemref support
function findMicrodataProperties(itemScopeNode, itemPropName) {
if( !itemScopeNode.hasAttribute("itemscope") ) {
return[];
}
var pending = []
, tmp
, currentNode
, k = -1
, el
, result = []
;
itemPropName = " " + itemPropName + " ";
while( currentNode = itemScopeNode.childNodes[++k] ) {
if( currentNode.nodeType === 1 ) {
pending.push(currentNode);
}
}
while( currentNode = pending.pop() ) {
if( tmp = currentNode.getAttribute("itemprop") ) {
if( (" " + tmp + " ").indexOf(itemPropName) !== -1 ) {
result.push(currentNode);
}
}
if( !currentNode.hasAttribute("itemscope") ) {
// Push all the child elements of current onto pending, in tree order
// (so the first child of current will be the next element to be
// popped from pending).
k = currentNode.childNodes.length;
while( el = currentNode.childNodes[--k] ) {
if( el.nodeType === 1 ) {
pending.push(el);
}
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment