linenumber.js 674 B

12345678910111213141516171819202122232425
  1. /*global document */
  2. (function() {
  3. var source = document.getElementsByClassName('prettyprint source linenums');
  4. var i = 0;
  5. var lineNumber = 0;
  6. var lineId;
  7. var lines;
  8. var totalLines;
  9. var anchorHash;
  10. if (source && source[0]) {
  11. anchorHash = document.location.hash.substring(1);
  12. lines = source[0].getElementsByTagName('li');
  13. totalLines = lines.length;
  14. for (; i < totalLines; i++) {
  15. lineNumber++;
  16. lineId = 'line' + lineNumber;
  17. lines[i].id = lineId;
  18. if (lineId === anchorHash) {
  19. lines[i].className += ' selected';
  20. }
  21. }
  22. }
  23. })();