<commit_before>/**
 * div_sortable.js
 *
 * Table sorting for div-tables
 *
 * See the supplied README file for more details
 *
 **/

/*
 * make sure we can compare strings
 *
 */
String.prototype.cmp = function(b) {
    var a = this+'';
    return (a===b) ? 0 : (a>b) ? 1 : -1;
}

// keep track of the availble sortable tables
var tables = new Array();

// set the symbols (or images if you like) for selected and unselected up and
// down links
var sortLinkSymbols = $H({
    unselected: $H({ up: "&#x25b3;", down: "&#x25bd;" }),
    selected:   $H({ up: "&#x25b2;", down: "&#x25bc;" })
});

/*
 * find all the sortable tables and place sort links on the header row and
 * figure out if there are datatypes defined
 *
 */
function initSortable() {
    // keep track of the tables by index
    var tableCount = 0;

    $$('div.table.sortable').each(function(table) {
        // keep track of the columns by index
        var colCount  = 0;
        var dataTypes = new Array();

        table.select('div.header.row').each(function(header_row) {
            header_row.select('div.cell').each(function(cell) {
                if ( cell.readAttribute('data-unsortable') != "true" ) {
                  cell.insert("&nbsp;");
                  cell.insert(sortLink(tableCount, colCount, "down"));
                  cell.insert(sortLink(tableCount, colCount, "up"));
                  cell.insert("&nbsp;&nbsp;");

                  dataTypes[colCount] = getType(cell);
                }
                
                colCount++;
            });
        });

        tables[tableCount++] = $H( { element: table, dataTypes: dataTypes } );
    });
}

/*
 * generate a sort link for the table/column in the right direction
 *
 */
function sortLink(tableCount, colCount, direction) {
    var id     = "su";
    var func   = "sortUp";
    var symbol = sortLinkSymbols.get('unselected').get('up');

    // when sorting in a different direction, make different links
    if ( direction == "down" ) {
        id     = "sd";
        func   = "sortDown";
        symbol = sortLinkSymbols.get('unselected').get('down');
    }

    var fullId = id + "_" + tableCount + "_" + colCount;

    // TODO : create element by prototype
    return "<a data-noblock='true' " +
        "id='" + fullId + "' href='#' class='sortlink'" +
        "onclick='"+
          func + "(" + tableCount + "," + colCount + ");" +
          "setSelectedSortLink(\"" + fullId + "\"); return false;" +
        "'>" + symbol + "</a>";
}

/*
 * return the given link to the normal state
 *
 */
function unselectSortLink(element) {
    var symbol = sortLinkSymbols.get('unselected').get('up');
    if ( element.readAttribute('id').match(/sd_/) ) {
        symbol = sortLinkSymbols.get('unselected').get('down');
    }

    element.update(symbol);
}

/*
 * set the given link-id to a selected state<commit_msg>Insert sort links using new Element()<commit_after>/**
 * div_sortable.js
 *
 * Table sorting for div-tables
 *
 * See the supplied README file for more details
 *
 **/

/*
 * make sure we can compare strings
 *
 */
String.prototype.cmp = function(b) {
    var a = this+'';
    return (a===b) ? 0 : (a>b) ? 1 : -1;
}

// keep track of the availble sortable tables
var tables = new Array();

// set the symbols (or images if you like) for selected and unselected up and
// down links
var sortLinkSymbols = $H({
    unselected: $H({ up: "&#x25b3;", down: "&#x25bd;" }),
    selected:   $H({ up: "&#x25b2;", down: "&#x25bc;" })
});

/*
 * find all the sortable tables and place sort links on the header row and
 * figure out if there are datatypes defined
 *
 */
function initSortable() {
    // keep track of the tables by index
    var tableCount = 0;

    $$('div.table.sortable').each(function(table) {
        // keep track of the columns by index
        var colCount  = 0;
        var dataTypes = new Array();

        table.select('div.header.row').each(function(header_row) {
            header_row.select('div.cell').each(function(cell) {
                if ( cell.readAttribute('data-unsortable') != "true" ) {
                  cell.insert("&nbsp;");
                  cell.insert(sortLink(tableCount, colCount, "down"));
                  cell.insert(sortLink(tableCount, colCount, "up"));
                  cell.insert("&nbsp;&nbsp;");

                  dataTypes[colCount] = getType(cell);
                }
                
                colCount++;
            });
        });

        tables[tableCount++] = $H( { element: table, dataTypes: dataTypes } );
    });
}

/*
 * generate a sort link for the table/column in the right direction
 *
 */
function sortLink(tableCount, colCount, direction) {
    var id     = "su";
    var func   = "sortUp";
    var symbol = sortLinkSymbols.get('unselected').get('up');

    // when sorting in a different direction, make different links
    if ( direction == "down" ) {
        id     = "sd";
        func   = "sortDown";
        symbol = sortLinkSymbols.get('unselected').get('down');
    }

    var fullId = id + "_" + tableCount + "_" + colCount;

    var a = new Element('a', {
      'class': 'sortlink',
      onclick: func + "(" + tableCount + "," + colCount + ");" + 
               "setSelectedSortLink(\"" + fullId + "\"); return false;",
      href:    '#',
      id:      fullId
    }).update(symbol);

    return a;
}

/*
 * return the given link to the normal state
 *
 */
function unselectSortLink(element) {
    var symbol = sortLinkSymbols.get('unselected').get('up');
    if ( element.readAttribute('id').match(/sd_/) ) {
        symbol = sortLinkSymbols.get('unselected').get('down');
    }

    element.update(symbol);
}

/*
 * set the given link-id to a selected state
{'fraction_non_alphanumeric': 0.15663283164158207, 'fraction_numerical': 0.005250262513125656, 'mean_word_length': 2.328479906814211, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1625401', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1725, 'n_words': 478}