mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
416134 - r=sayrer, a=schrep - properly handle nested microformats
This commit is contained in:
parent
7127d6306d
commit
302888f80f
@ -692,6 +692,38 @@ var Microformats = {
|
||||
} else {
|
||||
propnodes = Microformats.getElementsByClassName(mfnode, propname);
|
||||
}
|
||||
for (let i=propnodes.length-1; i >= 0; i--) {
|
||||
/* The reason getParent is not used here is because this code does */
|
||||
/* not apply to attribute based microformats, plus adr and geo */
|
||||
/* when contained in hCard are a special case */
|
||||
var parentnode;
|
||||
var node = propnodes[i];
|
||||
var xpathExpression = "";
|
||||
for (let j=0; j < Microformats.list.length; j++) {
|
||||
/* Don't treat adr or geo in an hCard as a microformat in this case */
|
||||
if ((mfname == "hCard") && ((Microformats.list[j] == "adr") || (Microformats.list[j] == "geo"))) {
|
||||
continue;
|
||||
}
|
||||
if (Microformats[Microformats.list[j]].className) {
|
||||
if (xpathExpression.length == 0) {
|
||||
xpathExpression = "ancestor::*[";
|
||||
} else {
|
||||
xpathExpression += " or ";
|
||||
}
|
||||
xpathExpression += "contains(concat(' ', @class, ' '), ' " + Microformats[Microformats.list[j]].className + " ')";
|
||||
}
|
||||
}
|
||||
xpathExpression += "][1]";
|
||||
var xpathResult = (node.ownerDocument || node).evaluate(xpathExpression, node, null, Components.interfaces.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE, null);
|
||||
if (xpathResult.singleNodeValue) {
|
||||
xpathResult.singleNodeValue.microformat = mfname;
|
||||
parentnode = xpathResult.singleNodeValue;
|
||||
}
|
||||
/* If the propnode is not a child of the microformat, remove it*/
|
||||
if (parentnode != mfnode) {
|
||||
propnodes.splice(i,1);
|
||||
}
|
||||
}
|
||||
if (propnodes.length > 0) {
|
||||
var resultArray = [];
|
||||
for (let i = 0; i < propnodes.length; i++) {
|
||||
|
@ -66,7 +66,20 @@
|
||||
<span class="value">Doe</span>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
|
||||
<div class="vcard" id="nested_vcard1">
|
||||
<div class="agent vcard" id="nested_vcard2">
|
||||
<div class="agent vcard" id="nested_vcard3">
|
||||
<span class="fn">Bob Smith</span>
|
||||
<span class="title">Office Assistant</span>
|
||||
</div>
|
||||
<span class="fn">Jack Jones</span>
|
||||
<span class="title">Executive Assistant</span>
|
||||
</div>
|
||||
<span class="fn">John Doe</span>
|
||||
<span class="title">CEO</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
@ -117,6 +130,18 @@ function test_Microformats() {
|
||||
var valueCard = new hCard(document.getElementById("value_test"));
|
||||
|
||||
is(valueCard.fn, "JohnDoe", "value_test");
|
||||
|
||||
var nestCard1 = new hCard(document.getElementById("nested_vcard1"));
|
||||
var nestCard2 = new hCard(document.getElementById("nested_vcard2"));
|
||||
var nestCard3 = new hCard(document.getElementById("nested_vcard3"));
|
||||
|
||||
is(nestCard1.fn, "John Doe", "nesting (fn) 1");
|
||||
is(nestCard1.title, "CEO", "nesting (title) 1");
|
||||
is(nestCard2.fn, "Jack Jones", "nesting (fn) 2");
|
||||
is(nestCard2.title, "Executive Assistant", "nesting (title) 2");
|
||||
is(nestCard3.fn, "Bob Smith", "nesting (fn) 3");
|
||||
is(nestCard3.title, "Office Assistant", "nesting (title) 3");
|
||||
is(nestCard1.agent[0].agent[0].fn, "Bob Smith", "nesting all");
|
||||
}
|
||||
|
||||
function test_hCard() {
|
||||
|
Loading…
Reference in New Issue
Block a user