diff --git a/js/core/include-config.js b/js/core/include-config.js
index c09979eaf3..2e0ce802ad 100644
--- a/js/core/include-config.js
+++ b/js/core/include-config.js
@@ -40,6 +40,7 @@ define(
script.innerHTML = JSON.stringify(initialUserConfig, confFilter, 2);
script.type = 'application/json';
doc.head.appendChild(script);
+ conf.initialUserConfig = initialUserConfig;
});
msg.pub('end', 'core/include-config');
cb();
diff --git a/js/core/override-configuration.js b/js/core/override-configuration.js
index 85eb4daa59..6332b983ac 100644
--- a/js/core/override-configuration.js
+++ b/js/core/override-configuration.js
@@ -26,9 +26,13 @@ define(
else if (v === "null") v = null;
else if (/\[\]$/.test(k)) {
k = k.replace(/\[\]/, "");
- v = $.parseJSON(v);
+ v = JSON.parse(v);
+ }
+ try {
+ conf[k] = JSON.parse(v);
+ } catch (err) {
+ conf[k] = v;
}
- conf[k] = v;
}
}
msg.pub("end", "core/override-configuration");
diff --git a/js/w3c/headers.js b/js/w3c/headers.js
index b50c08dcce..b5b2a50220 100644
--- a/js/w3c/headers.js
+++ b/js/w3c/headers.js
@@ -123,6 +123,7 @@ define(
rm = " property='foaf:mbox'";
rwu = " property='foaf:workplaceHomepage'";
rpu = " property='foaf:homepage'";
+ propSeeAlso = " property='rdfs:seeAlso'";
}
var ret = "";
for (var i = 0, n = items.length; i < n; i++) {
@@ -158,6 +159,34 @@ define(
ret += ", " + p.mailto + "";
}
if (p.note) ret += " (" + p.note + ")";
+ if (p.extras) {
+ var resultHTML = p.extras
+ // Remove empty names
+ .filter(function (extra) {
+ return extra.name && extra.name.trim();
+ })
+ // Convert to HTML
+ .map(function (extra) {
+ var span = document.createElement('span');
+ var textContainer = span;
+ if (extra.class) {
+ span.className = extra.class;
+ }
+ if (extra.href) {
+ var a = document.createElement('a');
+ span.appendChild(a);
+ a.href = extra.href;
+ textContainer = a;
+ if (this.doRDFa) {
+ a.setAttribute('property', 'rdfs:seeAlso');
+ }
+ }
+ textContainer.innerHTML = extra.name;
+ return span.outerHTML;
+ }.bind(this))
+ .join(', ');
+ ret += resultHTML;
+ }
if (this.doRDFa) {
ret += "\n";
if (name === "Editor") ret += "\n";
@@ -358,7 +387,9 @@ define(
var peopCheck = function (i, it) {
if (!it.name) msg.pub("error", "All authors and editors must have a name.");
};
- $.each(conf.editors, peopCheck);
+ if(conf.editors) {
+ conf.editors.forEach(peopCheck);
+ }
$.each(conf.authors || [], peopCheck);
conf.multipleEditors = conf.editors.length > 1;
conf.multipleAuthors = conf.authors && conf.authors.length > 1;
diff --git a/tests/spec/w3c/headers-spec.js b/tests/spec/w3c/headers-spec.js
index 5bec6551db..2feea883fd 100644
--- a/tests/spec/w3c/headers-spec.js
+++ b/tests/spec/w3c/headers-spec.js
@@ -1,3 +1,6 @@
+/*globals expect, it, $, runs, waitsFor, describe*/
+(function(){ // prevent this loadWithConfig being trashed by other files
+"use strict";
function loadWithConfig (conf, check) {
var config = [];
for (var k in conf) {
@@ -24,6 +27,10 @@ function loadWithConfig (conf, check) {
});
}
+function isPhantom () {
+ return window.callPhantom || window._phantom
+}
+
// the matrix of features here is such that we're not testing everything
// however the intent is that as bugs are found, we add tests for them
// we're definitely not testing SotD much
@@ -79,6 +86,87 @@ describe("W3C — Headers", function () {
});
});
+ it("should not add RDFa stuff to editors extras when doRDFa is false", function() {
+ var config = {
+ specStatus: "REC",
+ doRDFa: false,
+ editors: [{
+ name: "Mr foo",
+ extras: [{
+ "name": "0000-0003-0782-2704",
+ "href": "http://orcid.org/0000-0003-0782-2704",
+ "class": "orcid"
+ }]
+ }]
+ };
+ loadWithConfig(config, function($ifr) {
+ var doc = $ifr[0].contentDocument;
+ var oricdHref = config.editors[0].extras[0].href;
+ var orcidAnchor = doc.querySelector("a[href='" + oricdHref + "']");
+ if (!isPhantom()) {
+ // Check that RDFa is applied
+ expect(orcidAnchor.getAttribute("property")).toEqual(null);
+ expect(orcidAnchor.parentNode.className).toEqual("orcid");
+ }
+ });
+ });
+
+ it("should take editors extras into account", function() {
+ var config = {
+ specStatus: "REC",
+ doRDFa: true,
+ editors: [{
+ name: "Mr foo",
+ extras: [{
+ "name": "0000-0003-0782-2704",
+ "href": "http://orcid.org/0000-0003-0782-2704",
+ "class": "orcid"
+ }, {
+ "name": "@ivan_herman",
+ "href": "http://twitter.com/ivan_herman",
+ "class": "twitter"
+ },
+ //this should not exist in the doc, as it doesn't have a name
+ {
+ "href": "http://not-valid-missing-name",
+ "class": "invalid"
+ },
+ //this should not exist in the doc, as the name is empty
+ {
+ "name": "\n\t \n",
+ "href": "http://empty-name",
+ "class": "invalid"
+ }
+ ]
+ }]
+ };
+ loadWithConfig(config, function($ifr) {
+ var doc = $ifr[0].contentDocument;
+ var oricdHref = config.editors[0].extras[0].href;
+ var twitterHref = config.editors[0].extras[1].href;
+ var orcidAnchor = doc.querySelector("a[href='" + oricdHref + "']");
+ var twitterAnchor = doc.querySelector("a[href='" + twitterHref + "']");
+ // general checks
+ var header = doc.querySelector("#respecHeader");
+ if (!isPhantom()) {
+ [orcidAnchor, twitterAnchor].forEach(function(elem) {
+ // Check parent is correct.
+ expect(elem.parentNode.localName).toEqual("span");
+ // Check that RDFa is applied
+ expect(elem.hasAttribute("property")).toEqual(true);
+ // Check that it's in the header of the document
+ expect(header.contains(elem)).toEqual(true);
+ });
+ // Check CSS is correctly applied
+ expect(orcidAnchor.parentNode.className).toEqual("orcid");
+ expect(twitterAnchor.parentNode.className).toEqual("twitter");
+ }
+ // check that extra items with no name are ignored
+ expect(document.querySelector("a[href='http://not-valid']")).toEqual(null);
+ expect(document.querySelector("a[href='http://empty-name']")).toEqual(null);
+ });
+ });
+
// authors
it("should take authors into account", function () {
loadWithConfig({ specStatus: "REC", doRDFa: false, "authors[]": [{ name: "NAME1" }] }, function ($ifr) {
@@ -137,7 +225,7 @@ describe("W3C — Headers", function () {
var licenses = document.querySelectorAll("#respecHeader a[rel=license]");
expect(licenses.length).toEqual(1);
expect(licenses.item(0).tagName).toEqual("A");
- expect(licenses.item().href).toEqual("http://www.w3.org/Consortium/Legal/2015/copyright-software-and-document");
+ expect(licenses.item(0).href).toEqual("http://www.w3.org/Consortium/Legal/2015/copyright-software-and-document");
});
});
@@ -349,3 +437,4 @@ describe("W3C — Headers", function () {
});
});
});
+}());