Guest User

Untitled

a guest
Jan 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. function addEvent(obj, type, fn) {
  2. // Mozilla/W3C listeners?
  3. if (obj.addEventListener) {
  4. obj.addEventListener(type, fn, false);
  5. return true;
  6. }
  7.  
  8. // IE-style listeners?
  9. if (obj.attachEvent) {
  10. return obj.attachEvent('on' + type, fn);
  11. }
  12.  
  13. return false;
  14. }
  15.  
  16. addEvent(window, 'load', function() {
  17. if (!document.createElement) {
  18. return;
  19. }
  20.  
  21. // For each block quote...
  22. var quotes = document.getElementsByTagName('blockquote');
  23. for (var i = 0; i < quotes.length; ++i) {
  24. // ...that includes a citation...
  25. var cite = quotes[i].getAttribute('cite');
  26. if (cite != '' && cite != null) {
  27. // Create a link to the cited resource...
  28. var a = document.createElement('a');
  29. a.setAttribute('href', cite);
  30.  
  31. var titleNode;
  32. var title = quotes[i].getAttribute('title');
  33. if (title == '' || title == null) {
  34. a.setAttribute('title', cite);
  35. titleNode = document.createTextNode('Source');
  36. } else {
  37. a.setAttribute('title', title);
  38. titleNode = document.createTextNode(title);
  39. }
  40. a.appendChild(titleNode);
  41.  
  42. // ...wrap it in a paragraph with class 'source',...
  43. var p = document.createElement('p');
  44. p.className = 'source';
  45. p.appendChild(a);
  46.  
  47. // ...and put it at the end of the blockquote.
  48. quotes[i].appendChild(p);
  49. }
  50. }
  51. });
Add Comment
Please, Sign In to add comment