I am writing a simple breadcrumb inspired by https://stackoverflow.com/a/3834694/721084. How I am trying to achieve this is by classifying each item by the page it would be on. The code below is meant to do that but it always ends up in an infinite loop. What am I doing wrong?
EDIT: Pastebin link to entire JS code http://pastebin.com/nxUhQmqF
Sample DOM:
<ul id="progress_bar" class="nostyle clearfix">
<li class="first"><a href="">Blah</a></li>
<li class=""><a href="">Blah</a></li>
<li class="selected"><a href="">Blah</a></li>
<li class="last"><a href="">Blah</a></li>
</ul>
JS Code:
function classifyPages(bcParent, totalItems) {
var pages = 1,
wd = 0,
parentWd = findWidthOfParent(bcParent),
crumbs = bcParent.find('li'),
i = 0;
for( i = 0; i < totalItems; i++) {
wd = 0;
while(wd < parentWd) {
crumb = crumbs.eq(i);
wd += crumb.outerWidth();
if( wd < parentWd) {
i += 1;
crumb.addClass( 'bcPage-' + pages);
}
}
pages += 1;
}
return pages;
}