posted by aqshakirzhan on December 31, 2014

/**
 * перестроение списка для итоговой сортировки по алфавиту в колонках
 * @param ul
 */
function ulVerticalAlph(ul) {

    li = ul.getElement('li');
    var style = ul.currentStyle || window.getComputedStyle(ul);
    width = ul.clientWidth - parseInt(style.paddingLeft) - parseInt(style.paddingRight);

    cols_count = Math.floor(width/li.clientWidth);
    
    lis = ul.getElements('li');
    
    lis.sort(function(a,b) {
        if (a.innerText < b.innerText)
            return -1;        
            
        if (a.innerText > b.innerText)
            return 1;
            
        return 0;
    });

    ul.innerHTML = '';
    rows_count = Math.ceil(lis.length/cols_count)
    last_row_count = lis.length % cols_count; //кол-во элементов в неполной строке

    for (var row = 0; row<rows_count; row++) {
        n = row;
        step = rows_count
        for (var i = 0; i<cols_count; i++) {
        
            if (row == rows_count-1 && i >= last_row_count && last_row_count>0)
                break;

            if (i>last_row_count-1 && last_row_count>0)
                step = rows_count - 1;

            if (n>=lis.length)
                break;

            ul.appendChild(lis[n]);
            n = n + step; 
        }
        
    }
    
}

    var timerId_0=false;

    window.onresize = function() {
        clearTimeout(timerId_0);
        timerId_0 = setTimeout("ulVerticalAlph($('select-links').getElement('ul'));",20);

    };

    window.onload = function() {
        ulVerticalAlph($('select-links').getElement('ul'));
    };

Leave a Comment

Fields with * are required.