User:Ucucha/HarvErrors.js and User:Ucucha/HarvErrors2.js: Difference between pages
Appearance
(Difference between pages)
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++) { |
||
⚫ | |||
⚫ | |||
if (href.indexOf('#CITEREF') === 0) { |
|||
if (href. |
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 |
|||
⚫ | |||
var refheaders = [ |
|||
"References", "Bibliography", "Literature cited", "Works cited", |
|||
⚫ | |||
"Citations", "Sources", "Notes" |
|||
⚫ | |||
]; |
|||
⚫ | |||
var query = refheaders |
|||
.map(function(val) { return "#" + val; }) |
|||
.join(", "); |
|||
var refsection = jQuery(query).parent().next(); |
|||
⚫ | |||
for(var i = 0; i < cites.length; i++) { |
|||
var id = cites[i].getAttribute('id'); |
|||
⚫ | |||
⚫ | |||
continue; |
continue; |
||
} |
|||
// don't do cites that are inside a ref |
// don't do cites that are inside a ref |
||
parentid = cites[i] |
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>"; |