<commit_before>/**
 *Source section
 */

//Timer for keyword update
timer = "";

//When the document is ready, prepare and initiate different function to the object of the modal
$(document).ready(function() {
    $("#keywordTable").hide();
    $("#progressBarFiltering").hide();

    //Instanciate the autocomplete for semantic search
    $("#keyword").autocomplete({
        source : [""],
        search : function(event, ui) {
            $("#keyword").autocomplete({
                source : "/complete_entities/" + $("#keyword").val() + ".json"
            });
        },
        select : function(event,ui) {
        	if(ui.item.value.toLowerCase()!=$("#keyword").val().toLowerCase()){
            	askUpdateKeywordTable();
           }
           $("#keyword").attr("filter-uri",ui.item.uri)
           console.log( ui.item ?
          "Selected: " + ui.item.value + " aka " + ui.item.uri :
          "Nothing selected, input was " + this.value );
        },
        minLength : 3
    }).autocomplete("widget").addClass("span1");


    $("#addAllRSS").attr("disable", false);
    $("#addAllTwitter").attr("disable", false);
});

//slide down the source tab for the source selected
function slideDown(id) {
    if ($(id).is(":visible"))
        $(id).slideUp();
    else
        $(".form").not(id).slideUp('swing', function() {
            $(".form").not(id).hide();
            $(id).slideDown();
        });
}

//Add a source in the table
function addSource(table, value) {
    if (table == "Twitter") {
    	var reg = new RegExp('[, ]+');
        text = $(value).val().split(reg);
        if (value == "#searchTwitter"){
        	$.each(text,function(){
        		content = "#" + this;
           		$("#wellSources").append("<span class='label label-info twitterSource'>" + content + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();checkWell()'></i></span> ");
        	})
        }else{
			$.each(text,function(){
        		content = "@" + this;
           		$("#wellSources").append("<span class='label label-info twitterSource'>" + content + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();checkWell()'></i></span> ");
       		})
        }
        $("#addAllTwitter").attr("disabled", true);
    } else if (table == "RSS") {
        $("#wellSources").append("<span class='label-wrap label label-warning rssSource' >" + $(value).val() + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").next(\"br\").remove();$(this).closest(\"span\").remove();checkWell()'></i></span> ");
        $("#addAllRSS").attr("disabled", true);
    }
    $(value).val("");
    $(value).html("");
}

//add "all" sources in the table
function addAllSource(table, value) {
    if (table == "Twitter") {
        $("#wellSources").append("<span class='label label-info twitterSource'>" + value + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();$(\"#loginTwitter\").attr(\"disabled\",false);$(\"#searchTwitter\").attr(\"disabled\",false);checkWell(\"Twitter\")'></i></span> ");
        $("#searchTwitter").attr("disabled", true);
        $("#loginTwitter").attr("disabled", true);
        $("#searchTwitter").val("").html("");
        $("#loginTwitter").val("").html("");
        $("#addAllTwitter").attr("disabled", true);
    } else if (table == "RSS") {
        $("#wellSources").append("<span class='label label-warning label-wrap rssSource'>" + value + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").next(\"br\").remove();$(this).closest(\"span\").remove();$(\"#searchRSS\").attr(\"disabled\",false);checkWell(\"RSS\")'></i></span> ");
        $("#searchRSS").attr("disabled", true);
        $("#searchRSS").val("").html("");
        $("#addAllRSS").attr("disabled", true);
    }
}

//Check the well to see if it has children. If not, addAllSources button are activated.
function checkWell(table) {
    if (table == "Twitter")
        $("#addAllTwitter").attr("disabled", false);
    else if (table == "RSS")
        $("#addAllRSS").attr("disabled", false);
    if ($("#wellSources").children(".twitterSource").length == 0)
        $("#addAllTwitter").attr("disabled", false);
    if ($("#wellSources").children(".rssSource").length == 0)
        $("#addAllRSS").attr("disabled", false);
}

/*
 * End of source section
 */

/**
 * Filtering section
 */

//Add a filter to the list of filter
function addFilter(type) {
    $("#progressBarFiltering").hide();
    $("#keywordTable").hide();
    clearTimeout(timer);
    if ($('#keyword').val() == "") {
        return false
    }
    var id = 1;
    var classtr = "";
    //Choose the class of the line of the table ( red for WITHOUT, blue for OR, green for AND)
    if (type == 'and') {
        id = 1;
        classtr == 'success';
    } else if (type == 'or') {
        id = 0;
        classtr = 'info';
    } else if (type == 'without') {
        id = 2;
        classtr = 'error';
    } else {
        return false;
    }

    //Add the related word to the keyword
    var motcle = $('#keyword').val();

	var id = getId();
    //Add the line to the table
    if (type == 'and')
        $('#wellAnd').append("<span id='"+id+"' class='label label-success' draggable='true' ondragstart='drag(event)' filter-uri='"+$("#keyword").attr('filter-uri')+"'>" + motcle + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();'></i></span>");
    else if (type == 'or')
        $('#wellOr').append("<span id='"+id+"' class='label label-info' draggable='true' ondragstart='drag(event)' filter-uri='"+$("#keyword").attr('filter-uri')+"'>" + motcle + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();'></i></span>");
    else if (type == 'without')
        $('#wellWithout').append("<span id='"+id+"' class='label label-danger' draggable='true' ondragstart='drag(event)' filter-uri='"+$("#keyword").attr('filter-uri')+"'>" + motcle + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();'></i></span>");

    $('#keywordTable tbody > tr > td > label > input').each(function() {
        if ($(this).is(':checked')) {
        	id = getId();
            if (type == 'and')
                $('#wellAnd').append("<span id='"+id+"' class='label label-success' filter-uri='"+$(this).attr('filter-uri')+"'>" + $(this).val() + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();'></i></span>");
            else if (type == 'or')
                $('#wellOr').append("<span id='"+id+"' class='label label-info' filter-uri='"+$(this).attr('filter-uri')+"'>" + $(this).val() + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();'></i></span>");
            else if (type == 'without')
                $('#wellWithout').append("<span id='"+id+"' class='label label-danger' filter-uri='"+$(this).attr('filter-uri')+"'>" + $(this).val() + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();'></i></span>");
        }
    });
    $('#keyword').val('');
    $('#keyword').attr('filter-uri','undefined');
	
    //Reset the filtering
    rebootFiltering();
}

//Reset the dropdown selector and the table of related word
function rebootFiltering() {
    $('#keywordTable tbody > tr').each(function() {
        $(this).remove();
    });

}

//Fill the related keyword table with the right keyword
function updateKeywordTable() {
    rebootFiltering();
    if ($('#keyword').val() != "" && $('#keyword').val() != null)
        $.getJSON('/linked_words/' + $('#keyword').val() + '.json', function(data) {
            rebootFiltering();
            $.each(data, function(key, val) {
                if ($('#keyword').val() != "" && $('#keyword').val().length>2) {
                    $('#keywordTable').append('<tr><td><label class="checkbox"><input type="checkbox" value="' + val.value + '" filter-uri="'+ val.uri+'">' + val.value + '</label></td></tr>');
                }
            });
            $("#keywordTable").show();
            $("#progressBarFiltering").hide();
        });
}

//ask the timer if the related keyword table can be show. It will wait 1 second before doing it. If the function is call again, it will stop the current timer and start a new
function askUpdateKeywordTable() {
    $("#keywordTable").hide();
    if ($('#keyword').val() != "" && $('#keyword').val() != null && $('#keyword').val().length>2) {
        $("#progressBarFiltering").show();
        clearTimeout(timer);
        timer = setTimeout(function() {
            updateKeywordTable()
        }, 1000);
    } else {
        $("#progressBarFiltering").hide();
    }
}

//Define the action on ENTER key press for the filtering
function keywordComplete() {
    if (event.keyCode == 13) {
        addFilter();
        $('#keyword').autocomplete('close');
        return false;
    }
}

//Allow to switch tab in the new semantic search
function switchTab() {
    if ($('#filtering').hasClass('active'))
        return;
    $('#sources').removeClass('active');
    $('#breadcrumbSources').removeClass('active');

    $('#filtering').addClass('active');
    $('#breadcrumbFiltering').addClass('active');
    $('#breadcrumbFiltering').show();

    $('#filtering').hide();
    $('#sources').fadeOut('swing', function() {
        $('#filtering').fadeIn();
    });

    $(".form").hide();
}

//Allow to reverse switch tab in the new semantic search
function reverseSwitchTab() {
    if ($('#sources').hasClass('active'))
        return;
    $('#filtering').removeClass('active');
    $('#breadcrumbFiltering').removeClass('active');

    $('#sources').addClass('active');
    $('#breadcrumbSources').addClass('active');
    $('#breadcrumbSources').show();

    $('#sources').hide();
    $('#filtering').fadeOut('swing', function() {
        $('#sources').fadeIn();
    });
}

//show or hide the import rss panel
function showImportRss(){
	if ( $(".importRss").is(":visible")){
		$(".importRss").slideUp();
	} else{
		$(".importRss").slideDown();
	}
}

function addPersonnalRss(url){
	$("#wellSources").append("<span class='label-wrap label label-warning rssSource' >" + url + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").next(\"br\").remove();$(this).closest(\"span\").remove();checkWell()'></i></span> ");
    $("#addAllRSS").attr("disabled", true);
}
<commit_msg>Block the backspace action and reverse switch tab<commit_after>/**
 *Source section
 */

//Timer for keyword update
timer = "";

//When the document is ready, prepare and initiate different function to the object of the modal
$(document).ready(function() {
    $("#keywordTable").hide();
    $("#progressBarFiltering").hide();

    //Instanciate the autocomplete for semantic search
    $("#keyword").autocomplete({
        source : [""],
        search : function(event, ui) {
            $("#keyword").autocomplete({
                source : "/complete_entities/" + $("#keyword").val() + ".json"
            });
        },
        select : function(event,ui) {
        	if(ui.item.value.toLowerCase()!=$("#keyword").val().toLowerCase()){
            	askUpdateKeywordTable();
           }
           $("#keyword").attr("filter-uri",ui.item.uri)
           console.log( ui.item ?
          "Selected: " + ui.item.value + " aka " + ui.item.uri :
          "Nothing selected, input was " + this.value );
        },
        minLength : 3
    }).autocomplete("widget").addClass("span1");


    $("#addAllRSS").attr("disable", false);
    $("#addAllTwitter").attr("disable", false);
    
    //Block the original backspace action, and reverse switch the tab of the search
    $(document).keydown(function(e){
    	if(e.keyCode == 8){
    		reverseSwitchTab();
    		e.preventDefault();
    	}
   })  
});

//slide down the source tab for the source selected
function slideDown(id) {
    if ($(id).is(":visible"))
        $(id).slideUp();
    else
        $(".form").not(id).slideUp('swing', function() {
            $(".form").not(id).hide();
            $(id).slideDown();
        });
}

//Add a source in the table
function addSource(table, value) {
    if (table == "Twitter") {
    	var reg = new RegExp('[, ]+');
        text = $(value).val().split(reg);
        if (value == "#searchTwitter"){
        	$.each(text,function(){
        		content = "#" + this;
           		$("#wellSources").append("<span class='label label-info twitterSource'>" + content + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();checkWell()'></i></span> ");
        	})
        }else{
			$.each(text,function(){
        		content = "@" + this;
           		$("#wellSources").append("<span class='label label-info twitterSource'>" + content + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();checkWell()'></i></span> ");
       		})
        }
        $("#addAllTwitter").attr("disabled", true);
    } else if (table == "RSS") {
        $("#wellSources").append("<span class='label-wrap label label-warning rssSource' >" + $(value).val() + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").next(\"br\").remove();$(this).closest(\"span\").remove();checkWell()'></i></span> ");
        $("#addAllRSS").attr("disabled", true);
    }
    $(value).val("");
    $(value).html("");
}

//add "all" sources in the table
function addAllSource(table, value) {
    if (table == "Twitter") {
        $("#wellSources").append("<span class='label label-info twitterSource'>" + value + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();$(\"#loginTwitter\").attr(\"disabled\",false);$(\"#searchTwitter\").attr(\"disabled\",false);checkWell(\"Twitter\")'></i></span> ");
        $("#searchTwitter").attr("disabled", true);
        $("#loginTwitter").attr("disabled", true);
        $("#searchTwitter").val("").html("");
        $("#loginTwitter").val("").html("");
        $("#addAllTwitter").attr("disabled", true);
    } else if (table == "RSS") {
        $("#wellSources").append("<span class='label label-warning label-wrap rssSource'>" + value + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").next(\"br\").remove();$(this).closest(\"span\").remove();$(\"#searchRSS\").attr(\"disabled\",false);checkWell(\"RSS\")'></i></span> ");
        $("#searchRSS").attr("disabled", true);
        $("#searchRSS").val("").html("");
        $("#addAllRSS").attr("disabled", true);
    }
}

//Check the well to see if it has children. If not, addAllSources button are activated.
function checkWell(table) {
    if (table == "Twitter")
        $("#addAllTwitter").attr("disabled", false);
    else if (table == "RSS")
        $("#addAllRSS").attr("disabled", false);
    if ($("#wellSources").children(".twitterSource").length == 0)
        $("#addAllTwitter").attr("disabled", false);
    if ($("#wellSources").children(".rssSource").length == 0)
        $("#addAllRSS").attr("disabled", false);
}

/*
 * End of source section
 */

/**
 * Filtering section
 */

//Add a filter to the list of filter
function addFilter(type) {
    $("#progressBarFiltering").hide();
    $("#keywordTable").hide();
    clearTimeout(timer);
    if ($('#keyword').val() == "") {
        return false
    }
    var id = 1;
    var classtr = "";
    //Choose the class of the line of the table ( red for WITHOUT, blue for OR, green for AND)
    if (type == 'and') {
        id = 1;
        classtr == 'success';
    } else if (type == 'or') {
        id = 0;
        classtr = 'info';
    } else if (type == 'without') {
        id = 2;
        classtr = 'error';
    } else {
        return false;
    }

    //Add the related word to the keyword
    var motcle = $('#keyword').val();

	var id = getId();
    //Add the line to the table
    if (type == 'and')
        $('#wellAnd').append("<span id='"+id+"' class='label label-success' draggable='true' ondragstart='drag(event)' filter-uri='"+$("#keyword").attr('filter-uri')+"'>" + motcle + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();'></i></span>");
    else if (type == 'or')
        $('#wellOr').append("<span id='"+id+"' class='label label-info' draggable='true' ondragstart='drag(event)' filter-uri='"+$("#keyword").attr('filter-uri')+"'>" + motcle + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();'></i></span>");
    else if (type == 'without')
        $('#wellWithout').append("<span id='"+id+"' class='label label-danger' draggable='true' ondragstart='drag(event)' filter-uri='"+$("#keyword").attr('filter-uri')+"'>" + motcle + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();'></i></span>");

    $('#keywordTable tbody > tr > td > label > input').each(function() {
        if ($(this).is(':checked')) {
        	id = getId();
            if (type == 'and')
                $('#wellAnd').append("<span id='"+id+"' class='label label-success' filter-uri='"+$(this).attr('filter-uri')+"'>" + $(this).val() + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();'></i></span>");
            else if (type == 'or')
                $('#wellOr').append("<span id='"+id+"' class='label label-info' filter-uri='"+$(this).attr('filter-uri')+"'>" + $(this).val() + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();'></i></span>");
            else if (type == 'without')
                $('#wellWithout').append("<span id='"+id+"' class='label label-danger' filter-uri='"+$(this).attr('filter-uri')+"'>" + $(this).val() + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").remove();'></i></span>");
        }
    });
    $('#keyword').val('');
    $('#keyword').attr('filter-uri','undefined');
	
    //Reset the filtering
    rebootFiltering();
}

//Reset the dropdown selector and the table of related word
function rebootFiltering() {
    $('#keywordTable tbody > tr').each(function() {
        $(this).remove();
    });

}

//Fill the related keyword table with the right keyword
function updateKeywordTable() {
    rebootFiltering();
    if ($('#keyword').val() != "" && $('#keyword').val() != null)
        $.getJSON('/linked_words/' + $('#keyword').val() + '.json', function(data) {
            rebootFiltering();
            $.each(data, function(key, val) {
                if ($('#keyword').val() != "" && $('#keyword').val().length>2) {
                    $('#keywordTable').append('<tr><td><label class="checkbox"><input type="checkbox" value="' + val.value + '" filter-uri="'+ val.uri+'">' + val.value + '</label></td></tr>');
                }
            });
            $("#keywordTable").show();
            $("#progressBarFiltering").hide();
        });
}

//ask the timer if the related keyword table can be show. It will wait 1 second before doing it. If the function is call again, it will stop the current timer and start a new
function askUpdateKeywordTable() {
    $("#keywordTable").hide();
    if ($('#keyword').val() != "" && $('#keyword').val() != null && $('#keyword').val().length>2) {
        $("#progressBarFiltering").show();
        clearTimeout(timer);
        timer = setTimeout(function() {
            updateKeywordTable()
        }, 1000);
    } else {
        $("#progressBarFiltering").hide();
    }
}

//Define the action on ENTER key press for the filtering
function keywordComplete() {
    if (event.keyCode == 13) {
        addFilter();
        $('#keyword').autocomplete('close');
        return false;
    }
}

//Allow to switch tab in the new semantic search
function switchTab() {
    if ($('#filtering').hasClass('active'))
        return;
    $('#sources').removeClass('active');
    $('#breadcrumbSources').removeClass('active');

    $('#filtering').addClass('active');
    $('#breadcrumbFiltering').addClass('active');
    $('#breadcrumbFiltering').show();

    $('#filtering').hide();
    $('#sources').fadeOut('swing', function() {
        $('#filtering').fadeIn();
    });

    $(".form").hide();
}

//Allow to reverse switch tab in the new semantic search
function reverseSwitchTab() {
    if ($('#sources').hasClass('active'))
        return;
    $('#filtering').removeClass('active');
    $('#breadcrumbFiltering').removeClass('active');

    $('#sources').addClass('active');
    $('#breadcrumbSources').addClass('active');
    $('#breadcrumbSources').show();

    $('#sources').hide();
    $('#filtering').fadeOut('swing', function() {
        $('#sources').fadeIn();
    });
}

//show or hide the import rss panel
function showImportRss(){
	if ( $(".importRss").is(":visible")){
		$(".importRss").slideUp();
	} else{
		$(".importRss").slideDown();
	}
}

function addPersonnalRss(url){
	$("#wellSources").append("<span class='label-wrap label label-warning rssSource' >" + url + " <i class='icon-remove pointerMouse' onclick='$(this).closest(\"span\").next(\"br\").remove();$(this).closest(\"span\").remove();checkWell()'></i></span> ");
    $("#addAllRSS").attr("disabled", true);
}

{'fraction_non_alphanumeric': 0.23732915717539863, 'fraction_numerical': 0.001660971905846621, 'mean_word_length': 3.217974379503603, 'pattern_counts': {'":': 4, '<': 113, '<?xml version=': 0, '>': 127, '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': '6880488', 'n_tokens_mistral': 6292, 'n_tokens_neox': 6301, 'n_words': 1289}