[go: nahoru, domu]

Jump to content

User:Ucucha/HarvErrors.js and User:Ucucha/HarvErrors2.js: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
fix
 
more possibilities for what the section is called
 
Line 1: Line 1:
if(window.checkLinksToCitations === undefined)
if(window.checkLinksToCitations === undefined) {
window.checkLinksToCitations = true;
window.checkLinksToCitations = true;
}


jQuery(document).ready(function($) {
jQuery(document).ready(function($) {
// first check: do links in Harvard citations point to a valid citation?
// first check: do links in Harvard citations point to a valid citation?
links = document.links;
var links = document.links;
for (i=0; i < links.length; i++)
for (var i = 0; i < links.length; i++) {
var href = links[i].getAttribute('href');
{
href = links[i].getAttribute('href');
if (href.indexOf('#CITEREF') === 0) {
if (href.indexOf('#CITEREF') == 0)
if (document.getElementById(href.substring(1)) === null) {
if (document.getElementById(href.substring(1)) == null)
links[i].parentNode.innerHTML +=
links[i].parentNode.innerHTML +=
" <strong class=error>Harv error: link to " +
" <strong class=error>Harv error: link to " +
href +
href +
" doesn't point to any citation.</strong>";
" doesn't point to any citation.</strong>";
}
}
}
}


// second check: do CITEREF IDs have Harvard citations pointing to them?
// second check: do CITEREF IDs have Harvard citations pointing to them?
if(window.checkLinksToCitations) {
if(window.checkLinksToCitations) {
// limit ourselves to citations inside reference sections
cites = jQuery('.citation');
for(i=0; i < cites.length; i++) {
var refheaders = [
"References", "Bibliography", "Literature cited", "Works cited",
id = cites[i].getAttribute('id');
"Citations", "Sources", "Notes"
// we only need to check citations with a
];
if(!id || id.indexOf('CITEREF') !== 0)
var query = refheaders
.map(function(val) { return "#" + val; })
.join(", ");
var refsection = jQuery(query).parent().next();
var cites = refsection.find('.citation');
for(var i = 0; i < cites.length; i++) {
var id = cites[i].getAttribute('id');
// we only need to check citations with a CITEREF
if(!id || id.indexOf('CITEREF') !== 0) {
continue;
continue;
}
// don't do cites that are inside a ref
// don't do cites that are inside a ref
parentid = cites[i].parentNode.parentNode.getAttribute('id');
var parentid = cites[i].parentNode.getAttribute('id');
if(parentid && parentid.indexOf('cite_note') === 0)
if(parentid && parentid.indexOf('cite_note') === 0) {
continue;
continue;
}
// check for links to this citation
// check for links to this citation
query = 'a[href|="#' + id + '"]';
var query = 'a[href|="#' + id + '"]';
if(jQuery(query).length == 0) {
if(jQuery(query).length === 0) {
cites[i].innerHTML +=
cites[i].innerHTML +=
" <strong class=error>Harv error: There is no link pointing to this citation.</strong>";
" <strong class=error>Harv error: There is no link pointing to this citation.</strong>";