Created
January 21, 2013 01:01
-
-
Save mrabbitt/4582903 to your computer and use it in GitHub Desktop.
This file contains 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() { | |
function addSectionNumber (elem, sectionNumber, parentSection, level) { | |
var sectionNumberStr = ''; | |
var sectionSpan; | |
if (level > 1) { | |
sectionNumberStr = parentSection + '.' + sectionNumber; | |
} else if (level > 0) { | |
sectionNumberStr = sectionNumber.toString(); | |
} | |
if (level > 0 && jQuery(elem).find('.section-number').length === 0 ) { | |
sectionSpan = jQuery('<span class="section-number">').text(sectionNumberStr + ' '); | |
jQuery(elem).prepend(sectionSpan); | |
} | |
if ( level === 0 ) { | |
jQuery(elem).find('h1').each( function(index, element) { | |
addSectionNumber(element, (index + 1), sectionNumberStr, (level + 1)); | |
}); | |
} else if ( level < 6 ) { | |
jQuery(elem).nextUntil('h' + level, 'h' + level + ',h' + (level + 1)).each( function(index, element) { | |
addSectionNumber(element, (index + 1), sectionNumberStr, (level + 1)); | |
}); | |
} | |
return; | |
} | |
addSectionNumber(jQuery('#main-content').first(), 0, '', 0); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment