linenumber.js 675 B

1234567891011121314151617181920212223242526
  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. })();