Bug #430691 - r=sayre - microformats - When parsing tel or email, ignore type when inferring value

This commit is contained in:
Michael Kaply 2008-09-21 18:48:15 -05:00
Родитель 80aa3b19a4
Коммит 2728a8a9a2
2 изменённых файлов: 58 добавлений и 16 удалений

Просмотреть файл

@ -439,6 +439,15 @@ var Microformats = {
if (Microformats.matchClass(propnode, "value")) {
return Microformats.parser.textGetter(parentnode, parentnode);
} else {
/* Virtual case */
if (!parentnode && (Microformats.getElementsByClassName(propnode, "type").length > 0)) {
var tempNode = propnode.cloneNode(true);
var typeNodes = Microformats.getElementsByClassName(tempNode, "type");
for (let i=0; i < typeNodes.length; i++) {
typeNodes[i].parentNode.removeChild(typeNodes[i]);
}
return Microformats.parser.textGetter(tempNode);
}
return Microformats.parser.textGetter(propnode, parentnode);
}
},
@ -469,6 +478,15 @@ var Microformats = {
if (Microformats.matchClass(propnode, "value")) {
return Microformats.parser.textGetter(parentnode, parentnode);
} else {
/* Virtual case */
if (!parentnode && (Microformats.getElementsByClassName(propnode, "type").length > 0)) {
var tempNode = propnode.cloneNode(true);
var typeNodes = Microformats.getElementsByClassName(tempNode, "type");
for (let i=0; i < typeNodes.length; i++) {
typeNodes[i].parentNode.removeChild(typeNodes[i]);
}
return Microformats.parser.textGetter(tempNode);
}
return Microformats.parser.textGetter(propnode, parentnode);
}
}
@ -524,9 +542,6 @@ var Microformats = {
datatypeHelper: function(prop, node, parentnode) {
var result;
var datatype = prop.datatype;
if (prop.implied) {
datatype = prop.subproperties[prop.implied].datatype;
}
switch (datatype) {
case "dateTime":
result = Microformats.parser.dateTimeGetter(node, parentnode);
@ -571,15 +586,11 @@ var Microformats = {
}
/* This handles the case where one property implies another property */
/* For instance, org by itself is actually org.organization-name */
if (prop.implied && (result != undefined)) {
var temp = result;
result = {};
result[prop.implied] = temp;
}
if (prop.values && (result != undefined)) {
var validType = false;
for (let value in prop.values) {
if (result.toLowerCase() == prop.values[value]) {
result = result.toLowerCase();
validType = true;
break;
}
@ -683,8 +694,6 @@ var Microformats = {
} else {
result = Microformats.parser.datatypeHelper(propobj, propnode);
}
} else if (propobj.implied) {
result = Microformats.parser.datatypeHelper(propobj, propnode);
}
} else if (!result) {
result = Microformats.parser.datatypeHelper(propobj, propnode, parentnode);
@ -1357,13 +1366,13 @@ var hCard_definition = {
"org" : {
subproperties: {
"organization-name" : {
virtual: true
},
"organization-unit" : {
plural: true
}
},
plural: true,
implied: "organization-name"
plural: true
},
"photo" : {
plural: true,
@ -1392,11 +1401,11 @@ var hCard_definition = {
values: ["msg", "home", "work", "pref", "voice", "fax", "cell", "video", "pager", "bbs", "car", "isdn", "pcs"]
},
"value" : {
datatype: "tel"
datatype: "tel",
virtual: true
}
},
plural: true,
implied: "value"
plural: true
},
"tz" : {
},

Просмотреть файл

@ -191,6 +191,16 @@
<area class="tel" href="modem:+1.415.555.1243">call me</area>
</div>
<div class="vcard" id="21-tel.2">
<span class="fn">John Doe</span>
<span class="tel"><span class="type">Home</span> +1.415.555.1212</span>
</div>
<div class="vcard" id="21-tel.3">
<span class="fn">John Doe</span>
<span class="tel"><span class="type">Home</span><span class="type"> Pref</span> +1.415.555.1212</span>
</div>
<!-- TODO: add test for 'extended' -->
<div class="vcard" id="22-adr">
<p class="fn">John Doe</p>
@ -540,6 +550,15 @@
<span class="note"><b>Note</b></span>
</div>
<div class="vcard" id="email-type">
<span class="fn">John Doe</span>
<span class="email">
<span class="type">internet</span>
<a href="mailto:notthis@example.com">john@example.com</a>
</span>
</div>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
@ -791,6 +810,17 @@ function test_hCard() {
is(hcard.tel[8].value, "+1.415.555.1241", "21-tel - tel");
is(hcard.tel[9].value, "+1.415.555.1242", "21-tel - tel");
hcard = new hCard(document.getElementById("21-tel.2"));
is(hcard.tel[0].type[0], "home", "21-tel.2 - type");
is(hcard.tel[0].value, "+1.415.555.1212", "21-tel.2 - tel");
hcard = new hCard(document.getElementById("21-tel.3"));
is(hcard.tel[0].type[0], "home", "21-tel.3 - type (home)");
is(hcard.tel[0].type[1], "pref", "21-tel.3 - type (pref)");
is(hcard.tel[0].value, "+1.415.555.1212", "21-tel.3 - tel");
hcard = new hCard(document.getElementById("22-adr"));
is(hcard.fn, "John Doe", "22-adr - fn");
@ -1143,6 +1173,9 @@ function test_hCard() {
is(hcard.note[0].toHTML(), "<b>Note</b>", "39-noteHTML - note as HTML");
is(hcard.note[0].match("Note"), "Note", "39-noteHTML - match in note");
hcard = new hCard(document.getElementById("email-type"));
is(hcard.email[0].type, "internet", "email - type no value (type)");
is(hcard.email[0].value, "john@example.com", "email - type no value (value)");
}
</script>