diff --git a/index.js b/index.js index 1ccae03..8f07fd6 100644 --- a/index.js +++ b/index.js @@ -305,14 +305,15 @@ function PerformNavResize() { var mensz = 0 var menc = [] var imenc = 0 - for (vmeni = 0; vmeni < vmen.childNodes.length; vmeni++) { + for (vmeni = vmen.childNodes.length - 1; vmeni >= 0; vmeni--) { if (vmen.childNodes[vmeni].nodeType === Node.ELEMENT_NODE) { if (mensz+vmen.childNodes[vmeni].clientWidth > maxbarsz) {menc[imenc] = vmen.childNodes[vmeni]; imenc++;} mensz += vmen.childNodes[vmeni].clientWidth } } if (menc.length > 0) { - for (vmeni = 0; vmeni < menc.length; vmeni++) {men.appendChild(men.removeChild(menc[vmeni]));} + for (vmeni = 0; vmeni < menc.length; vmeni++) {vmen.removeChild(menc[vmeni]);} + for (vmeni = menc.length - 1; vmeni >= 0; vmeni--) {InsertBefore(men, menc[vmeni]);} } else { for (vmeni = 0; vmeni < men.childNodes.length; vmeni++) { if (men.childNodes[vmeni].nodeType === Node.ELEMENT_NODE) { @@ -322,8 +323,7 @@ function PerformNavResize() { mensz += menaw } } - for (vmeni = 0; vmeni < menc.length; vmeni++) {men.removeChild(menc[vmeni]);} - for (vmeni = menc.length - 1; vmeni >= 0; vmeni--) {InsertBefore(vmen, menc[vmeni]);} + for (vmeni = 0; vmeni < menc.length; vmeni++) {vmen.appendChild(men.removeChild(menc[vmeni]));} } } }