Fix COinS and unAPI on pages served as application/xhtml+xml
This requires testing, since it could easily break COinS/unAPI on some pages.
This commit is contained in:
parent
917910d1d0
commit
60e5ff103c
2 changed files with 26 additions and 6 deletions
|
@ -8,7 +8,7 @@
|
||||||
"maxVersion":"",
|
"maxVersion":"",
|
||||||
"priority":300,
|
"priority":300,
|
||||||
"inRepository":true,
|
"inRepository":true,
|
||||||
"lastUpdated":"2010-06-16 18:15:00"
|
"lastUpdated":"2010-09-15 18:42:44"
|
||||||
}
|
}
|
||||||
|
|
||||||
function detectWeb(doc, url) {
|
function detectWeb(doc, url) {
|
||||||
|
@ -16,7 +16,15 @@ function detectWeb(doc, url) {
|
||||||
|
|
||||||
var encounteredType = false;
|
var encounteredType = false;
|
||||||
|
|
||||||
var spans = doc.evaluate('//span[contains(@class, " Z3988") or contains(@class, "Z3988 ") or @class="Z3988"][@title]', doc, null, XPathResult.ANY_TYPE, null);
|
// This and the x: prefix in the XPath are to work around an issue with pages
|
||||||
|
// served as application/xhtml+xml
|
||||||
|
//
|
||||||
|
// https://developer.mozilla.org/en/Introduction_to_using_XPath_in_JavaScript#Implementing_a_default_namespace_for_XML_documents
|
||||||
|
function nsResolver() {
|
||||||
|
return 'http://www.w3.org/1999/xhtml';
|
||||||
|
}
|
||||||
|
|
||||||
|
var spans = doc.evaluate('//x:span[contains(@class, " Z3988") or contains(@class, "Z3988 ") or @class="Z3988"][@title]', doc, nsResolver, XPathResult.ANY_TYPE, null);
|
||||||
var span;
|
var span;
|
||||||
while(span = spans.iterateNext()) {
|
while(span = spans.iterateNext()) {
|
||||||
// determine if it's a valid type
|
// determine if it's a valid type
|
||||||
|
@ -141,7 +149,13 @@ function doWeb(doc, url) {
|
||||||
var needFullItems = new Array();
|
var needFullItems = new Array();
|
||||||
var couldUseFullItems = new Array();
|
var couldUseFullItems = new Array();
|
||||||
|
|
||||||
var spans = doc.evaluate('//span[contains(@class, " Z3988") or contains(@class, "Z3988 ") or @class="Z3988"][@title]', doc, null, XPathResult.ANY_TYPE, null);
|
|
||||||
|
// See note in detectWeb()
|
||||||
|
function nsResolver() {
|
||||||
|
return 'http://www.w3.org/1999/xhtml';
|
||||||
|
}
|
||||||
|
|
||||||
|
var spans = doc.evaluate('//x:span[contains(@class, " Z3988") or contains(@class, "Z3988 ") or @class="Z3988"][@title]', doc, nsResolver, XPathResult.ANY_TYPE, null);
|
||||||
var span;
|
var span;
|
||||||
while(span = spans.iterateNext()) {
|
while(span = spans.iterateNext()) {
|
||||||
var spanTitle = span.title;
|
var spanTitle = span.title;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
"maxVersion":"",
|
"maxVersion":"",
|
||||||
"priority":200,
|
"priority":200,
|
||||||
"inRepository":true,
|
"inRepository":true,
|
||||||
"lastUpdated":"2010-09-04 20:28:04"
|
"lastUpdated":"2010-09-15 18:42:44"
|
||||||
}
|
}
|
||||||
|
|
||||||
var RECOGNIZABLE_FORMATS = ["mods", "marc", "endnote", "ris", "bibtex", "rdf"];
|
var RECOGNIZABLE_FORMATS = ["mods", "marc", "endnote", "ris", "bibtex", "rdf"];
|
||||||
|
@ -34,10 +34,16 @@ function detectWeb(doc, url) {
|
||||||
// Set the domain we're scraping
|
// Set the domain we're scraping
|
||||||
domain = doc.location.href.match(/https?:\/\/([^/]+)/);
|
domain = doc.location.href.match(/https?:\/\/([^/]+)/);
|
||||||
|
|
||||||
var nsResolver = doc.createNSResolver(doc.documentElement);
|
// This and the x: prefix in the XPath are to work around an issue with pages
|
||||||
|
// served as application/xhtml+xml
|
||||||
|
//
|
||||||
|
// https://developer.mozilla.org/en/Introduction_to_using_XPath_in_JavaScript#Implementing_a_default_namespace_for_XML_documents
|
||||||
|
function nsResolver() {
|
||||||
|
return 'http://www.w3.org/1999/xhtml';
|
||||||
|
}
|
||||||
|
|
||||||
// look for a resolver
|
// look for a resolver
|
||||||
unAPIResolver = doc.evaluate('//link[@rel="unapi-server"]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
unAPIResolver = doc.evaluate('//x:link[@rel="unapi-server"]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
||||||
if(!unAPIResolver) return false;
|
if(!unAPIResolver) return false;
|
||||||
unAPIResolver = unAPIResolver.getAttribute("href");
|
unAPIResolver = unAPIResolver.getAttribute("href");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue