Created
January 22, 2019 23:28
-
-
Save kgaughan/4c744b794a23e2f022b08c82a29ca84d to your computer and use it in GitHub Desktop.
Some old JS code from an older version of my site. The timestamp is April 2006, but it probably dates from earlier. Looks to be a way to make smart blockquotes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addEvent(obj, type, fn) { | |
// Mozilla/W3C listeners? | |
if (obj.addEventListener) { | |
obj.addEventListener(type, fn, false); | |
return true; | |
} | |
// IE-style listeners? | |
if (obj.attachEvent) { | |
return obj.attachEvent('on' + type, fn); | |
} | |
return false; | |
} | |
addEvent(window, 'load', function() { | |
if (!document.createElement) { | |
return; | |
} | |
// For each block quote... | |
var quotes = document.getElementsByTagName('blockquote'); | |
for (var i = 0; i < quotes.length; ++i) { | |
// ...that includes a citation... | |
var cite = quotes[i].getAttribute('cite'); | |
if (cite != '' && cite != null) { | |
// Create a link to the cited resource... | |
var a = document.createElement('a'); | |
a.setAttribute('href', cite); | |
var titleNode; | |
var title = quotes[i].getAttribute('title'); | |
if (title == '' || title == null) { | |
a.setAttribute('title', cite); | |
titleNode = document.createTextNode('Source'); | |
} else { | |
a.setAttribute('title', title); | |
titleNode = document.createTextNode(title); | |
} | |
a.appendChild(titleNode); | |
// ...wrap it in a paragraph with class 'source',... | |
var p = document.createElement('p'); | |
p.className = 'source'; | |
p.appendChild(a); | |
// ...and put it at the end of the blockquote. | |
quotes[i].appendChild(p); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment