<commit_before>/**
 * Created by Aseem on 5/22/14.
 */

var cur_location = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
var static_url = '/static/BookMarker';
var static_img_url = cur_location + static_url + '/img';

var category_input = $("#category_inp");

$(function () {
    category_input.autocomplete({
        source: "auto/"
    });
});

//Add Bindings for keys
category_input.keyup(function (e) {
    if (e.keyCode == 13) {
        $(this).trigger("enterKey");
    }
});

category_input.bind("enterKey", function (e) {
    var already_present = false;
    $(".category").each(function (index) {
            if (category_input.val() == $.trim($(this).text())) {
                alert("Category already added");
                already_present = true;
                return false;
            }
        }
    )
    if (already_present == false) {
        $("#category_list").append(
            '<span class="category ' + category_input.val() + '">' +
                category_input.val() +
                ' <img src="' + static_img_url + '/delete.png" class="delete-cat ' + category_input.val() + '" ' +
                ' title="Remove category ' + category_input.val() + '"/>' +
                '</span>'
        );
    }
});

$(document).on('click', ".delete-cat", function (e) {
    var classList = $(this).attr('class').split(/\s+/);
    $.each(classList, function (index, item) {
        if (item != 'delete-cat') {
            $('.category.' + item).remove();
        }
    });
})<commit_msg>Added check for adding category on page only if category is present<commit_after>/**
 * Created by Aseem on 5/22/14.
 */

var cur_location = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
var static_url = '/static/BookMarker';
var static_img_url = cur_location + static_url + '/img';

var category_input = $("#category_inp");

$(function () {
    category_input.autocomplete({
        source: "auto/"
    });
});

//Add Bindings for keys
category_input.keyup(function (e) {
    if (e.keyCode == 13) {
        $(this).trigger("enterKey");
    }
});

category_input.bind("enterKey", function (e) {

    var is_category = false;

    $(".ui-menu-item").each(function (index) {
            if (category_input.val() == $.trim($(this).text())) {
                is_category = true;
                return false;
            }
        }
    )
    
    if (is_category == false) {
        alert("Not a category");
        return false;
    }

    var already_present = false;

    $(".category").each(function (index) {
            if (category_input.val() == $.trim($(this).text())) {
                alert("Category already added");
                already_present = true;
                return false;
            }
        }
    )

    if (already_present == false) {
        $("#category_list").append(
            '<li class="category ' + category_input.val() + '">' +
                ' <img src="' + static_img_url + '/delete.png" class="delete-cat ' + category_input.val() + '" ' +
                ' title="Remove category ' + category_input.val() + '"/>' +
                category_input.val() +
                '</li>'
        );
    }
    category_input.val("");
});

$(document).on('click', ".delete-cat", function (e) {
    var classList = $(this).attr('class').split(/\s+/);
    $.each(classList, function (index, item) {
        if (item != 'delete-cat') {
            $('.category.' + item).remove();
        }
    });
})
{'fraction_non_alphanumeric': 0.18571023532747377, 'fraction_numerical': 0.00396937907570173, 'mean_word_length': 2.133214920071048, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2738356', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1061, 'n_words': 210}