<commit_before>// Initialization
$body = $("body");
$(document).on({
    ajaxStart: function() {
        $body.addClass("loading");
    },
    ajaxStop: function() {
        $body.removeClass("loading");
    }
});
$(document).ready(initialize);

var metadata = null;

function processMetadata(meta) {
    var properties = meta.properties;
    var filtered = {};

    for (var key in properties) {
        var property = properties[key];
        if (property.hasOwnProperty('alias')) {
            var aliased = properties[property.alias];
            if (aliased.hasOwnProperty('aliases')) {
                aliased.aliases.push(key)
            } else {
                aliased.aliases = [key];
            }
        } else {
            filtered[key] = property;
        }
    }
    meta.properties = filtered;
    return meta;
}

function makeSelectable(tab, details, populate) {
    tab.selectable({
        selected: function(event, ui) {
            var selected = jQuery(".ui-selected", this);
            var key = selected.data('key');
            details.empty();
            populate(details, key)
        }
    });
}

function populatePropertyList(list, sectionKey) {
    var properties = metadata.properties;
    var section = metadata[sectionKey];
    for (var i = 0; i < section.length; i++) {
        var key = section[i];
        if (!properties.hasOwnProperty(key)) continue;
        var parameter = properties[key];
        var item = $('<li>').text(parameter.name);
        item.addClass('ui-widget-content');
        item.data('key', key);
        list.append(item);
    }
}

function makePropertySelector(selector, section, details) {
     populatePropertyList(selector, section);
     makeSelectable(selector, details, addParameterDetails);
}

function addParameterDetails(container, key) {
    var property = metadata.properties[key];

    var title = $('<div class="titleBanner"/>').text(property.name);
    container.append(title);

    var propertyKey = $('<div class="propertyKeys"/>').text(property.field);
    if (property.hasOwnProperty("aliases")) {
        var aliases = $('<span class="propertyAlias">').text(', ' + property.aliases.join(', '));
        propertyKey.append(aliases);
    }
    container.append(propertyKey);

    var propertyDescription = $('<div class="propertyDescription"/>');
    for (var i = 0; i < property.description.length; i++) {
        propertyDescription.append($('<div class="descriptionLine"/>').html(property.description[i]));
    }
    container.append(propertyDescription);

    var propertyType = metadata.types[property.type];
    var typeDescription = $('<div class="propertyType"/>').text(propertyType.name);
    container.append(typeDescription);

    var propertyTypeDetails = $('<div class="propertyTypeDetails"/>');
    var propertyTypeDescription = $('<div class="propertyTypeDescription"/>');
    for (var i = 0; i < propertyType.description.length; i++) {
        propertyTypeDescription.append($('<div class="descriptionLine"/>').html(propertyType.description[i]));
    }
    propertyTypeDetails.append(propertyTypeDescription);
    var propertyTypeOptions = $('<div class="propertyTypeOptions"/>');
    for (var i = 0; i < propertyType.options.length; i++) {
        propertyTypeOptions.append($('<div class="propertyTypeOption"/>').text(propertyType.options[i]));
    }
    propertyTypeDetails.append(propertyTypeOptions);

    container.append(propertyTypeDetails);

    typeDescription.click(function() {
        propertyTypeDetails.toggle();
    });
}

function populatePropertyHolderList(list, sectionKey) {
    var section = metadata[sectionKey];
    for (var key in section) {
        if (!section.hasOwnProperty(key)) continue;
        var holder = section[key];
        var item = $('<li>').text(holder.name);
        item.addClass('ui-widget-content');
        item.data('key', key);
        list.append(item);
    }
}

function makePropertyHolderSelector(selector, section, details, baseProperties) {
     populatePropertyHolderList(selector, section);
     makeSelectable(selector, details, function(details, key) {
         addPropertyHolderDetails(details, key, section, baseProperties);
     });
}

function addPropertyHolderDetails(container, key, section, baseProperties) {
    var propertyHolder = metadata[section][key];

    var title = $('<div class="titleBanner"/>').text(propertyHolder.name);
    container.append(title);

    var propertyKey = $('<div class="propertyKeys"/>').text(propertyHolder.short_class);
    container.append(propertyKey);

    var description = $('<div class="propertyTypeDescription"/>');
    for (var i = 0; i < propertyHolder.description.length; i++) {
        description.append($('<div class="descriptionLine"/>').html(propertyHolder.description[i]));
    }
    container.append(description);

    if (propertyHolder.examples.length > 0) {
        var exampleDiv = $('<div/>');
        exampleDiv.addClass('exampleContainer');
        exampleDiv.append("Examples: ");
        for (var i = 0; i < propertyHolder.examples.length; i++) {
            var example = propertyHolder.examples[i];
            var exampleLink = $('<a target="_blank">');
            exampleLink.prop('href', 'https://github.com/elBukkit/MagicPlugin/blob/master/Magic/src/main/resources/defaults/spells/' + example + '.yml');
            exampleLink.text(example);
            exampleDiv.append(exampleLink);
        }
        container.append(exampleDiv);
    }

    var parameterContainer = $('<div class="parameterContainer">');
    var parameterListContainer = $('<div class="parameterList">');
    var parameterList = $('<ul>');
    var properties = metadata.properties;
    for (var i = 0; i < propertyHolder.parameters.length; i++) {
        var propertyKey = propertyHolder.parameters[i];
        if (!properties.hasOwnProperty(propertyKey)) continue;
        var property = properties[propertyKey];

        var parameterItem = $('<li>').text(property.name);
        parameterItem.addClass('ui-widget-content');
        parameterItem.data('key', propertyKey);
        parameterList.append(parameterItem);
    }
    baseProperties = metadata[baseProperties];
    for (var i = 0; i < baseProperties.length; i++) {
        var propertyKey = baseProperties[i];
        if (!properties.hasOwnProperty(propertyKey)) continue;
        var property = properties[propertyKey];

        var parameterItem = $('<li class="baseProperty">').text(property.name);
        parameterItem.addClass('ui-widget-content');
        parameterItem.data('key', propertyKey);
        parameterList.append(parameterItem);
    }
    var parameterDetails = jQuery('<div class="details">').text("Select a parameter for details");
    makeSelectable(parameterList, parameterDetails, addParameterDetails);
    parameterListContainer.append(parameterList);
    parameterContainer.append(parameterListContainer);
    parameterContainer.append(parameterDetails);
    container.append(parameterContainer);
}

function initialize() {
    $.ajax( {
        type: "GET",
        url: "../meta.json",
        dataType: 'json'
    }).done(function(meta) {<commit_msg>Sort lists by display name in reference manual<commit_after>// Initialization
$body = $("body");
$(document).on({
    ajaxStart: function() {
        $body.addClass("loading");
    },
    ajaxStop: function() {
        $body.removeClass("loading");
    }
});
$(document).ready(initialize);

var metadata = null;

function processMetadata(meta) {
    var properties = meta.properties;
    var filtered = {};

    for (var key in properties) {
        var property = properties[key];
        if (property.hasOwnProperty('alias')) {
            var aliased = properties[property.alias];
            if (aliased.hasOwnProperty('aliases')) {
                aliased.aliases.push(key)
            } else {
                aliased.aliases = [key];
            }
        } else {
            filtered[key] = property;
        }
    }
    meta.properties = filtered;
    return meta;
}

function makeSelectable(tab, details, populate) {
    tab.selectable({
        selected: function(event, ui) {
            var selected = jQuery(".ui-selected", this);
            var key = selected.data('key');
            details.empty();
            populate(details, key)
        }
    });
}

function populatePropertyList(list, sectionKey) {
    var properties = metadata.properties;
    var section = metadata[sectionKey];
    for (var i = 0; i < section.length; i++) {
        var key = section[i];
        if (!properties.hasOwnProperty(key)) continue;
        var parameter = properties[key];
        var item = $('<li>').text(parameter.name);
        item.addClass('ui-widget-content');
        item.data('key', key);
        list.append(item);
    }
    sortList(list);
}

function makePropertySelector(selector, section, details) {
     populatePropertyList(selector, section);
     makeSelectable(selector, details, addParameterDetails);
}

function addParameterDetails(container, key) {
    var property = metadata.properties[key];

    var title = $('<div class="titleBanner"/>').text(property.name);
    container.append(title);

    var propertyKey = $('<div class="propertyKeys"/>').text(property.field);
    if (property.hasOwnProperty("aliases")) {
        var aliases = $('<span class="propertyAlias">').text(', ' + property.aliases.join(', '));
        propertyKey.append(aliases);
    }
    container.append(propertyKey);

    var propertyDescription = $('<div class="propertyDescription"/>');
    for (var i = 0; i < property.description.length; i++) {
        propertyDescription.append($('<div class="descriptionLine"/>').html(property.description[i]));
    }
    container.append(propertyDescription);

    var propertyType = metadata.types[property.type];
    var typeDescription = $('<div class="propertyType"/>').text(propertyType.name);
    container.append(typeDescription);

    var propertyTypeDetails = $('<div class="propertyTypeDetails"/>');
    var propertyTypeDescription = $('<div class="propertyTypeDescription"/>');
    for (var i = 0; i < propertyType.description.length; i++) {
        propertyTypeDescription.append($('<div class="descriptionLine"/>').html(propertyType.description[i]));
    }
    propertyTypeDetails.append(propertyTypeDescription);
    var propertyTypeOptions = $('<div class="propertyTypeOptions"/>');
    for (var i = 0; i < propertyType.options.length; i++) {
        propertyTypeOptions.append($('<div class="propertyTypeOption"/>').text(propertyType.options[i]));
    }
    propertyTypeDetails.append(propertyTypeOptions);

    container.append(propertyTypeDetails);

    typeDescription.click(function() {
        propertyTypeDetails.toggle();
    });
}

function populatePropertyHolderList(list, sectionKey) {
    var section = metadata[sectionKey];
    for (var key in section) {
        if (!section.hasOwnProperty(key)) continue;
        var holder = section[key];
        var item = $('<li>').text(holder.name);
        item.addClass('ui-widget-content');
        item.data('key', key);
        list.append(item);
    }
    sortList(list);
}

function makePropertyHolderSelector(selector, section, details, baseProperties) {
     populatePropertyHolderList(selector, section);
     makeSelectable(selector, details, function(details, key) {
         addPropertyHolderDetails(details, key, section, baseProperties);
     });
}

function sortProperties(list) {
    list.sort(function(a, b) {
        var aName = metadata.properties.hasOwnProperty(a) ? metadata.properties[a].name : a;
        var bName = metadata.properties.hasOwnProperty(b) ? metadata.properties[b].name : b;
        return a.localeCompare(b);
    });
}

function sortList(ul) {
    var listitems = ul.children('li').get();
    listitems.sort(function(a, b) {
       return $(a).text().toUpperCase().localeCompare($(b).text().toUpperCase());
    });
    $.each(listitems, function(idx, itm) { ul.append(itm); });
}

function addPropertyHolderDetails(container, key, section, baseProperties) {
    var propertyHolder = metadata[section][key];

    var title = $('<div class="titleBanner"/>').text(propertyHolder.name);
    container.append(title);

    var propertyKey = $('<div class="propertyKeys"/>').text('class: ' + propertyHolder.short_class);
    container.append(propertyKey);

    var description = $('<div class="propertyTypeDescription"/>');
    for (var i = 0; i < propertyHolder.description.length; i++) {
        description.append($('<div class="descriptionLine"/>').html(propertyHolder.description[i]));
    }
    container.append(description);

    if (propertyHolder.examples.length > 0) {
        var exampleDiv = $('<div/>');
        exampleDiv.addClass('exampleContainer');
        exampleDiv.append("Examples: ");
        for (var i = 0; i < propertyHolder.examples.length; i++) {
            var example = propertyHolder.examples[i];
            var exampleLink = $('<a target="_blank">');
            exampleLink.prop('href', 'https://github.com/elBukkit/MagicPlugin/blob/master/Magic/src/main/resources/defaults/spells/' + example + '.yml');
            exampleLink.text(example);
            exampleDiv.append(exampleLink);
        }
        container.append(exampleDiv);
    }

    var parameterContainer = $('<div class="parameterContainer">');
    var parameterListContainer = $('<div class="parameterList">');
    var parameterList = $('<ul>');
    var properties = metadata.properties;
    sortProperties(propertyHolder.parameters);
    for (var i = 0; i < propertyHolder.parameters.length; i++) {
        var propertyKey = propertyHolder.parameters[i];
        if (!properties.hasOwnProperty(propertyKey)) continue;
        var property = properties[propertyKey];

        var parameterItem = $('<li>').text(property.name);
        parameterItem.addClass('ui-widget-content');
        parameterItem.data('key', propertyKey);
        parameterList.append(parameterItem);
    }
    baseProperties = metadata[baseProperties];
    sortProperties(baseProperties);
    for (var i = 0; i < baseProperties.length; i++) {
        var propertyKey = baseProperties[i];
        if (!properties.hasOwnProperty(propertyKey)) continue;
        var property = properties[propertyKey];

        var parameterItem = $('<li class="baseProperty">').text(property.name);
        parameterItem.addClass('ui-widget-content');
        parameterItem.data('key', propertyKey);
        parameterList.append(parameterItem);
    }
    var parameterDetails = jQuery('<div class="details">').text("Select a parameter for details");
    makeSelectable(parameterList, parameterDetails, addParameterDetails);
    parameterListContainer.append(parameterList);
    parameterContainer.append(parameterListContainer);
    parameterContainer.append(parameterDetails);
    container.append(parameterContainer);
}

function initialize() {
    $.ajax( {
        type: "GET",
        url: "../meta.json",
        dataType: 'json'
    }).done(function(meta) {
{'fraction_non_alphanumeric': 0.14872068230277186, 'fraction_numerical': 0.001199360341151386, 'mean_word_length': 3.3975974216232054, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 55, 'https://': 2, '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': '4526985', 'n_tokens_mistral': 4031, 'n_tokens_neox': 3972, 'n_words': 793}