⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 microformats.js

📁 this is Microformats.js for linux
💻 JS
📖 第 1 页 / 共 5 页
字号:
      for (let i = 0; i < attributeList.length; i++) {        if (i != 0) {          xpathExpression += " or ";        }        xpathExpression += "contains(concat(' ', @" + attributeName + ", ' '), ' " + attributeList[i] + " ')";      }      xpathExpression += "]";       var xpathResult = (rootNode.ownerDocument || rootNode).evaluate(xpathExpression, rootNode, null, 0, null);      var node;      while (node = xpathResult.iterateNext()) {        returnElements.push(node);      }    } else {    /* Need Slow fallback for testing */    }    return returnElements;  },  matchClass: function matchClass(node, className) {    var classValue = node.getAttribute("class");    return (classValue && classValue.match("(^|\\s)" + className + "(\\s|$)"));  }};/* MICROFORMAT DEFINITIONS BEGIN HERE */function adr(node, validate) {  if (node) {    Microformats.parser.newMicroformat(this, node, "adr", validate);  }}adr.prototype.toString = function() {  var address_text = "";  var start_parens = false;  if (this["street-address"]) {    address_text += this["street-address"][0];  } else if (this["extended-address"]) {    address_text += this["extended-address"];  }  if (this["locality"]) {    if (this["street-address"] || this["extended-address"]) {      address_text += " (";      start_parens = true;    }    address_text += this["locality"];  }  if (this["region"]) {    if ((this["street-address"] || this["extended-address"]) && (!start_parens)) {      address_text += " (";      start_parens = true;    } else if (this["locality"]) {      address_text += ", ";    }    address_text += this["region"];  }  if (this["country-name"]) {    if ((this["street-address"] || this["extended-address"]) && (!start_parens)) {      address_text += " (";      start_parens = true;      address_text += this["country-name"];    } else if ((!this["locality"]) && (!this["region"])) {      address_text += this["country-name"];    } else if (((!this["locality"]) && (this["region"])) || ((this["locality"]) && (!this["region"]))) {      address_text += ", ";      address_text += this["country-name"];    }  }  if (start_parens) {    address_text += ")";  }  return address_text;}var adr_definition = {  mfObject: adr,  className: "adr",  properties: {    "type" : {      plural: true,      values: ["work", "home", "pref", "postal", "dom", "intl", "parcel"]    },    "post-office-box" : {    },    "street-address" : {      plural: true    },    "extended-address" : {    },    "locality" : {    },    "region" : {    },    "postal-code" : {    },    "country-name" : {    }  },  validate: function(node) {    var xpathExpression = "count(descendant::*[" +                                              "contains(concat(' ', @class, ' '), ' post-office-box ')" +                                              " or contains(concat(' ', @class, ' '), ' street-address ')" +                                              " or contains(concat(' ', @class, ' '), ' extended-address ')" +                                              " or contains(concat(' ', @class, ' '), ' locality ')" +                                              " or contains(concat(' ', @class, ' '), ' region ')" +                                              " or contains(concat(' ', @class, ' '), ' postal-code ')" +                                              " or contains(concat(' ', @class, ' '), ' country-name')" +                                              "])";    var xpathResult = (node.ownerDocument || node).evaluate(xpathExpression, node, null,  Components.interfaces.nsIDOMXPathResult.ANY_TYPE, null).numberValue;    if (xpathResult == 0) {      throw("Unable to create microformat");    }    return true;  }};Microformats.add("adr", adr_definition);function hCard(node, validate) {  if (node) {    Microformats.parser.newMicroformat(this, node, "hCard", validate);  }}hCard.prototype.toString = function() {  if (this.resolvedNode) {    /* If this microformat has an include pattern, put the */    /* organization-name in parenthesis after the fn to differentiate */    /* them. */    var fns = Microformats.getElementsByClassName(this.node, "fn");    if (fns.length === 0) {      if (this.fn) {        if (this.org && this.org[0]["organization-name"] && (this.fn != this.org[0]["organization-name"])) {          return this.fn + " (" + this.org[0]["organization-name"] + ")";        }      }    }  }  return this.fn;}var hCard_definition = {  mfObject: hCard,  className: "vcard",  required: ["fn"],  properties: {    "adr" : {      plural: true,      datatype: "microformat",      microformat: "adr"    },    "agent" : {      plural: true,      datatype: "microformat",      microformat: "hCard"    },    "bday" : {      datatype: "dateTime"    },    "class" : {    },    "category" : {      plural: true,      datatype: "microformat",      microformat: "tag",      microformat_property: "tag"    },    "email" : {      subproperties: {        "type" : {          plural: true,          values: ["internet", "x400", "pref"]        },        "value" : {          datatype: "email",          virtual: true        }      },      plural: true       },    "fn" : {      required: true    },    "geo" : {      datatype: "microformat",      microformat: "geo"    },    "key" : {      plural: true    },    "label" : {      plural: true    },    "logo" : {      plural: true,      datatype: "anyURI"    },    "mailer" : {      plural: true    },    "n" : {      subproperties: {        "honorific-prefix" : {          plural: true        },        "given-name" : {          plural: true        },        "additional-name" : {          plural: true        },        "family-name" : {          plural: true        },        "honorific-suffix" : {          plural: true        }      },      virtual: true,      /*  Implied "n" Optimization */      /* http://microformats.org/wiki/hcard#Implied_.22n.22_Optimization */      virtualGetter: function(mfnode) {        var fn = Microformats.parser.getMicroformatProperty(mfnode, "hCard", "fn");        var orgs = Microformats.parser.getMicroformatProperty(mfnode, "hCard", "org");        var given_name = [];        var family_name = [];        if (fn && (!orgs || (orgs.length > 1) || (fn != orgs[0]["organization-name"]))) {          var fns = fn.split(" ");          if (fns.length === 2) {            if (fns[0].charAt(fns[0].length-1) == ',') {              given_name[0] = fns[1];              family_name[0] = fns[0].substr(0, fns[0].length-1);            } else if (fns[1].length == 1) {              given_name[0] = fns[1];              family_name[0] = fns[0];            } else if ((fns[1].length == 2) && (fns[1].charAt(fns[1].length-1) == '.')) {              given_name[0] = fns[1];              family_name[0] = fns[0];            } else {              given_name[0] = fns[0];              family_name[0] = fns[1];            }            return {"given-name" : given_name, "family-name" : family_name};          }        }      }    },    "nickname" : {      plural: true,      virtual: true,      /* Implied "nickname" Optimization */      /* http://microformats.org/wiki/hcard#Implied_.22nickname.22_Optimization */      virtualGetter: function(mfnode) {        var fn = Microformats.parser.getMicroformatProperty(mfnode, "hCard", "fn");        var orgs = Microformats.parser.getMicroformatProperty(mfnode, "hCard", "org");        var given_name;        var family_name;        if (fn && (!orgs || (orgs.length) > 1 || (fn != orgs[0]["organization-name"]))) {          var fns = fn.split(" ");          if (fns.length === 1) {            return [fns[0]];          }        }        return;      }    },    "note" : {      plural: true,      datatype: "HTML"    },    "org" : {      subproperties: {        "organization-name" : {        },        "organization-unit" : {          plural: true        }      },      plural: true,      implied: "organization-name"    },    "photo" : {      plural: true,      datatype: "anyURI"    },    "rev" : {      datatype: "dateTime"    },    "role" : {      plural: true    },    "sequence" : {    },    "sort-string" : {    },    "sound" : {      plural: true    },    "title" : {      plural: true    },    "tel" : {      subproperties: {        "type" : {          plural: true,          values: ["msg", "home", "work", "pref", "voice", "fax", "cell", "video", "pager", "bbs", "car", "isdn", "pcs"]        },        "value" : {          datatype: "tel"        }      },      plural: true,      implied: "value"    },    "tz" : {    },    "uid" : {      datatype: "anyURI"    },    "url" : {      plural: true,      datatype: "anyURI"    }  }};Microformats.add("hCard", hCard_definition);function hCalendar(node, validate) {  if (node) {    Microformats.parser.newMicroformat(this, node, "hCalendar", validate);  }}hCalendar.prototype.toString = function() {  if (this.resolvedNode) {    /* If this microformat has an include pattern, put the */    /* dtstart in parenthesis after the summary to differentiate */    /* them. */    var summaries = Microformats.getElementsByClassName(this.node, "summary");    if (summaries.length === 0) {      if (this.summary) {        if (this.dtstart) {          return this.summary + " (" + Microformats.dateFromISO8601(this.dtstart).toLocaleString() + ")";        }      }    }  }  if (this.dtstart) {    return this.summary;  }  return;}var hCalendar_definition = {  mfObject: hCalendar,  className: "vevent",  required: ["summary", "dtstart"],  properties: {    "category" : {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -