<commit_before>/* In the Margins Side Panel Functions */
/* Based on https://github.com/AndreaLombardo/BootSideMenu */
function getSide(listClasses){
    var side;
    for (var i = 0; i<listClasses.length; i++) {
        if (listClasses[i]=='sidebar-left') {
            side = "left";
            break;
        } else if (listClasses[i]=='sidebar-right') {
            side = "right";
            break;
        } else {
            side = null;
        }
    }
    return side;
}

function doAnimation(container, containerWidth, sidebarSide, sidebarStatus) {
    var toggler = container.children()[1];
    if (sidebarStatus == "opened") {
        if (sidebarSide == "left") {
            container.animate({
                left: -(containerWidth+32)
            });
            toggleArrow("left");
        } else if (sidebarSide == "right") {
            container.animate({
                right: -(containerWidth +2)
            });
            toggleArrow("right");
        }
        container.attr('data-status', 'closed');
    } else {
        if (sidebarSide == "left") {
            container.animate({
                left:0
            });
            toggleArrow("right");
        } else if (sidebarSide == "right") {
            container.animate({
                right:0
            });
            toggleArrow("left");
        }
        container.attr('data-status', 'opened');
    }
}

function toggleArrow(side){
    if (side=="left") {
        $("#toggler").children(".glyphicon-chevron-right").css('display', 'block');
        $("#toggler").children(".glyphicon-chevron-left").css('display', 'none');
    } else if (side=="right") {
        $("#toggler").children(".glyphicon-chevron-left").css('display', 'block');
        $("#toggler").children(".glyphicon-chevron-right").css('display', 'none');
    }
}

/* In the Margins API Functions */
function callAPI(slug, type) {

    // No reason not to hard code this here since we only need the slug
    var url = "http://scalar.usc.edu/works/lexos/rdf/node/"+slug+"?rec=0&format=json";

    // Ajax call
    $.ajax({
        type:"GET",
        url:url,
        dataType:'jsonp',
        success: function(data){
            processData(data, type, url);
        }, 
        error: handleError
    });
}

function handleError(XMLHttpRequest, textStatus, errorThrown) {
    var error_msg = "Lexos cannot load <em>In the Margins</em> content from Scalar. ";
    error_msg += "There may be a problem with your internet connection. If you think ";
    error_msg += "your internet connection is working, try accessing <em>In the ";
    error_msg += "Margins</em> content directly from the <a href='https://scalar.usc.edu/works/lexos/' target='_blank'>";
    error_msg += "Scalar website</a>.";
    $('#error-modal-message').html(error_msg);
    $('#error-modal').modal(); 
}

function processData(data, type, url) {
    for (var nodeProp in data) {
        node = data[nodeProp]
        content_path = node['http://rdfs.org/sioc/ns#content'];
        if (node['http://purl.org/dc/terms/title'] != null) {
            var title = node['http://purl.org/dc/terms/title'][0].value;
            var url = node['http://purl.org/dc/terms/isVersionOf'][0].value;
        }
        if (node['http://simile.mit.edu/2003/10/ontologies/artstor#url'] != null) {
            var video_url = node['http://simile.mit.edu/2003/10/ontologies/artstor#url'][0].value;
            //var url = node['http://purl.org/dc/terms/isVersionOf'][0].value;
        }
        if (node['http://simile.mit.edu/2003/10/ontologies/artstor#url'] != null) {
            var url = node['http://purl.org/dc/terms/isVersionOf'][0].value;
        }
        if (content_path != null) {
            var content = content_path[0].value;
            content = content.replace(new RegExp('\r?\n\r?\n','g'), '<br><br>'); // Replace line breaks
        }
    }
    displayITMcontent(content, title, url, type, video_url);
}

function displayITMcontent(content, title, url, type, video_url) {
    // In case there is no internet connection or user is in local mode

    var error_msg = "Lexos cannot load <em>In the Margins</em> content from Scalar. ";
    error_msg += "There may be a problem with your internet connection. If you think ";
    error_msg += "your internet connection is working, try accessing <em>In the ";
    error_msg += "Margins</em> content directly from the <a href='https://scalar.usc.edu/works/lexos/' target='_blank'>";
    error_msg += "Scalar website</a>.";<commit_msg>Scalar internal links changed to urls in embedded content<commit_after>/* In the Margins Side Panel Functions */
/* Based on https://github.com/AndreaLombardo/BootSideMenu */
function getSide(listClasses){
    var side;
    for (var i = 0; i<listClasses.length; i++) {
        if (listClasses[i]=='sidebar-left') {
            side = "left";
            break;
        } else if (listClasses[i]=='sidebar-right') {
            side = "right";
            break;
        } else {
            side = null;
        }
    }
    return side;
}

function doAnimation(container, containerWidth, sidebarSide, sidebarStatus) {
    var toggler = container.children()[1];
    if (sidebarStatus == "opened") {
        if (sidebarSide == "left") {
            container.animate({
                left: -(containerWidth+32)
            });
            toggleArrow("left");
        } else if (sidebarSide == "right") {
            container.animate({
                right: -(containerWidth +2)
            });
            toggleArrow("right");
        }
        container.attr('data-status', 'closed');
    } else {
        if (sidebarSide == "left") {
            container.animate({
                left:0
            });
            toggleArrow("right");
        } else if (sidebarSide == "right") {
            container.animate({
                right:0
            });
            toggleArrow("left");
        }
        container.attr('data-status', 'opened');
    }
}

function toggleArrow(side){
    if (side=="left") {
        $("#toggler").children(".glyphicon-chevron-right").css('display', 'block');
        $("#toggler").children(".glyphicon-chevron-left").css('display', 'none');
    } else if (side=="right") {
        $("#toggler").children(".glyphicon-chevron-left").css('display', 'block');
        $("#toggler").children(".glyphicon-chevron-right").css('display', 'none');
    }
}

/* In the Margins API Functions */
function callAPI(slug, type) {

    // No reason not to hard code this here since we only need the slug
    var url = "http://scalar.usc.edu/works/lexos/rdf/node/"+slug+"?rec=0&format=json";

    // Ajax call
    $.ajax({
        type:"GET",
        url:url,
        dataType:'jsonp',
        success: function(data){
            processData(data, type, url);
        }, 
        error: handleError
    });
}

function handleError(XMLHttpRequest, textStatus, errorThrown) {
    var error_msg = "Lexos cannot load <em>In the Margins</em> content from Scalar. ";
    error_msg += "There may be a problem with your internet connection. If you think ";
    error_msg += "your internet connection is working, try accessing <em>In the ";
    error_msg += "Margins</em> content directly from the <a href='https://scalar.usc.edu/works/lexos/' target='_blank'>";
    error_msg += "Scalar website</a>.";
    $('#error-modal-message').html(error_msg);
    $('#error-modal').modal(); 
}

function processData(data, type, url) {
    for (var nodeProp in data) {
        node = data[nodeProp]
        content_path = node['http://rdfs.org/sioc/ns#content'];
        if (node['http://purl.org/dc/terms/title'] != null) {
            var title = node['http://purl.org/dc/terms/title'][0].value;
            var url = node['http://purl.org/dc/terms/isVersionOf'][0].value;
        }
        if (node['http://simile.mit.edu/2003/10/ontologies/artstor#url'] != null) {
            var video_url = node['http://simile.mit.edu/2003/10/ontologies/artstor#url'][0].value;
            //var url = node['http://purl.org/dc/terms/isVersionOf'][0].value;
        }
        if (node['http://simile.mit.edu/2003/10/ontologies/artstor#url'] != null) {
            var url = node['http://purl.org/dc/terms/isVersionOf'][0].value;
        }
        if (content_path != null) {
            var content = content_path[0].value;
            content = content.replace(new RegExp('\r?\n\r?\n','g'), '<br><br>'); // Replace line breaks
        }
    }
    displayITMcontent(content, title, url, type, video_url);
}

function displayITMcontent(content, title, url, type, video_url) {
    // Replace Scalar internal links with urls to Scalar
    content = content.replace(/<a href=\"/g, '<a href="http://scalar.usc.edu/works/lexos/');
    content = content.replace(/http:\/\/http:\/\/scalar.usc.edu\/works\/lexos\//g, 'http://');
    content = content.replace(/<a href=\"http:\/\/scalar/g, '<a target="_blank" href="http://scalar');

    // In case there is no internet connection or user is in local mode
    var error_msg = "Lexos cannot load <em>In the Margins</em> content from Scalar. ";
    error_msg += "There may be a problem with your internet connection. If you think ";
    error_msg += "your internet connection is working, try accessing <em>In the ";
    error_msg += "Margins</em> content directly from the <a href='https://scalar.usc.edu/works/lexos/' target='_blank'>";
    error_msg += "Scalar website</a>.";
{'fraction_non_alphanumeric': 0.16687898089171974, 'fraction_numerical': 0.006794055201698514, 'mean_word_length': 2.419600725952813, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 31, 'https://': 6, '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': '4520165', 'n_tokens_mistral': 2918, 'n_tokens_neox': 2840, 'n_words': 645}