398676, r=sayrer, a=schrep - add support for tel/modem/fax protocols in the hCard microformat

This commit is contained in:
mkaply@us.ibm.com 2008-01-18 11:53:31 -08:00
Родитель 392c0584c5
Коммит ff5b51978d
2 изменённых файлов: 39 добавлений и 15 удалений

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

@ -372,7 +372,27 @@ var Microformats = {
* @return A string with the telephone number
*/
telGetter: function(propnode, parentnode) {
/* Special case - if this node is a value, use the parent node to get all the values */
var pairs = {"a":"href", "object":"data", "area":"href"};
var name = propnode.nodeName.toLowerCase();
if (pairs.hasOwnProperty(name)) {
var protocol;
if (propnode[pairs[name]].indexOf("tel:") == 0) {
protocol = "tel:";
}
if (propnode[pairs[name]].indexOf("fax:") == 0) {
protocol = "fax:";
}
if (propnode[pairs[name]].indexOf("modem:") == 0) {
protocol = "modem:";
}
if (protocol) {
if (propnode[pairs[name]].indexOf('?') > 0) {
return unescape(propnode[pairs[name]].substring(protocol.length, propnode[pairs[name]].indexOf('?')));
} else {
return unescape(propnode[pairs[name]].substring(protocol.length));
}
}
}
if (Microformats.matchClass(propnode, "value")) {
return Microformats.parser.textGetter(parentnode, parentnode);
} else {
@ -464,7 +484,11 @@ var Microformats = {
*/
datatypeHelper: function(prop, node, parentnode) {
var result;
switch (prop.datatype) {
var datatype = prop.datatype;
if (prop.implied) {
datatype = prop.subproperties[prop.implied].datatype;
}
switch (datatype) {
case "dateTime":
result = Microformats.parser.dateTimeGetter(node, parentnode);
break;
@ -501,13 +525,15 @@ var Microformats = {
}
default:
result = Microformats.parser.textGetter(node, parentnode);
if ((prop.implied) && (result)) {
var temp = result;
result = {};
result[prop.implied] = temp;
}
break;
}
/* This handles the case where one property implies another property */
/* For instance, org by itself is actually org.organization-name */
if ((prop.implied) && (result)) {
var temp = result;
result = {};
result[prop.implied] = temp;
}
if (result && prop.values) {
var validType = false;
for (let value in prop.values) {

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

@ -775,14 +775,12 @@ function test_hCard() {
isnot(hcard.tel[2].type[13], "invalid", "21-tel - type");
is(hcard.tel[3].value, "+1 415 555 1234", "21-tel - tel");
is(hcard.tel[3].type[0], "home", "21-tel - type");
// is(hcard.tel[4].value, "+1.415.555.1235", "21-tel - tel");
// is(hcard.tel[5].value, "+1.415.555.1236", "21-tel - tel");
// is(hcard.tel[6].value, "+1.415.555.1237", "21-tel - tel");
// is(hcard.tel[7].value, "+1.415.555.1238", "21-tel - tel");
// is(hcard.tel[8].value, "+1.415.555.1239", "21-tel - tel");
// is(hcard.tel[9].value, "+1.415.555.1240", "21-tel - tel");
// is(hcard.tel[9].value, "+1.415.555.1241", "21-tel - tel");
// is(hcard.tel[9].value, "+1.415.555.1242", "21-tel - tel");
is(hcard.tel[4].value, "+1.415.555.1235", "21-tel - tel");
is(hcard.tel[5].value, "+1.415.555.1236", "21-tel - tel");
is(hcard.tel[6].value, "+1.415.555.1238", "21-tel - tel");
is(hcard.tel[7].value, "+1.415.555.1239", "21-tel - tel");
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("22-adr"));