<commit_before>/*
 * This file is part of wger Workout Manager.
 *
 * wger Workout Manager is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * wger Workout Manager is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 */

/*jslint browser: true*/
/*global $, jQuery, alert*/


/*
 * Own functions
 *
 */

"use strict";


/*
 * AJAX related functions
 *
 * See https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax for
 * more information
 */
function getCookie(name) {
    var cookieValue = null;
    if (document.cookie && document.cookie != '') {
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; i++) {
            var cookie = jQuery.trim(cookies[i]);
            // Does this cookie string begin with the name we want?
            if (cookie.substring(0, name.length + 1) == (name + '=')) {
                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                break;
            }
        }
    }
    return cookieValue;
}


function csrfSafeMethod(method) {
    // these HTTP methods do not require CSRF protection
    return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}

$.ajaxSetup({
    crossDomain: false, // obviates need for sameOrigin test
    beforeSend: function(xhr, settings) {
        if (!csrfSafeMethod(settings.type)) {
            xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
        }
    }
});


/*
 * Others
 */
function get_current_language() {
    /* Returns a short name, like 'en' or 'de' */
    return $('#current-language').data('currentLanguage');
}

/*
 * Define an own widget, which is basically an autocompleter that groups
 * results by category
 */
$.widget("custom.catcomplete", $.ui.autocomplete, {
    _renderMenu: function (ul, items) {
        var that = this,
            currentCategory = "";
        $.each(items, function (index, item) {
            if (item.category !== currentCategory) {

                ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
                currentCategory = item.category;
            }
            that._renderItemData(ul, item);
        });
    },
    _renderItem: function (ul, item) {
        var li_style = '';
        if (item.image) {
            li_style = "style='background-image:url(" + item.image_thumbnail + ");background-size:30px 30px;background-repeat:no-repeat;'";
        }

        return $("<li " + li_style + ">")
            .append("<a style='margin-left:30px;'>" + item.name + "</a>")
            .appendTo(ul);
    }
});


/*
 * Setup JQuery sortables to make the sets sortable
 */
function setup_sortable() {
    $(".workout-table tbody").sortable({
        handle: '.dragndrop-handle',
        revert: true,
        update : function (event, ui) {
            // Monkey around the HTML, till we find the IDs of the set and the day
            var day_element = ui.item.parent().parent().find('tr').first().attr('id'); //day-xy
            var day_id = day_element.match(/\d+/)[0];

            // returns something in the form "set-1,set-2,set-3,"
            var order = $(this).sortable('toArray');<commit_msg>Only allow vertically sorting of exercises in workout page<commit_after>/*
 * This file is part of wger Workout Manager.
 *
 * wger Workout Manager is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * wger Workout Manager is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 */

/*jslint browser: true*/
/*global $, jQuery, alert*/


/*
 * Own functions
 *
 */

"use strict";


/*
 * AJAX related functions
 *
 * See https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax for
 * more information
 */
function getCookie(name) {
    var cookieValue = null;
    if (document.cookie && document.cookie != '') {
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; i++) {
            var cookie = jQuery.trim(cookies[i]);
            // Does this cookie string begin with the name we want?
            if (cookie.substring(0, name.length + 1) == (name + '=')) {
                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                break;
            }
        }
    }
    return cookieValue;
}


function csrfSafeMethod(method) {
    // these HTTP methods do not require CSRF protection
    return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}

$.ajaxSetup({
    crossDomain: false, // obviates need for sameOrigin test
    beforeSend: function(xhr, settings) {
        if (!csrfSafeMethod(settings.type)) {
            xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
        }
    }
});


/*
 * Others
 */
function get_current_language() {
    /* Returns a short name, like 'en' or 'de' */
    return $('#current-language').data('currentLanguage');
}

/*
 * Define an own widget, which is basically an autocompleter that groups
 * results by category
 */
$.widget("custom.catcomplete", $.ui.autocomplete, {
    _renderMenu: function (ul, items) {
        var that = this,
            currentCategory = "";
        $.each(items, function (index, item) {
            if (item.category !== currentCategory) {

                ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
                currentCategory = item.category;
            }
            that._renderItemData(ul, item);
        });
    },
    _renderItem: function (ul, item) {
        var li_style = '';
        if (item.image) {
            li_style = "style='background-image:url(" + item.image_thumbnail + ");background-size:30px 30px;background-repeat:no-repeat;'";
        }

        return $("<li " + li_style + ">")
            .append("<a style='margin-left:30px;'>" + item.name + "</a>")
            .appendTo(ul);
    }
});


/*
 * Setup JQuery sortables to make the sets sortable
 */
function setup_sortable() {
    $(".workout-table tbody").sortable({
        handle: '.dragndrop-handle',
        revert: true,
        axis: 'y',
        update : function (event, ui) {
            // Monkey around the HTML, till we find the IDs of the set and the day
            var day_element = ui.item.parent().parent().find('tr').first().attr('id'); //day-xy
            var day_id = day_element.match(/\d+/)[0];

            // returns something in the form "set-1,set-2,set-3,"
            var order = $(this).sortable('toArray');
{'fraction_non_alphanumeric': 0.1345624656026417, 'fraction_numerical': 0.004127682993946065, 'mean_word_length': 2.4930321960595867, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '3817567', 'n_tokens_mistral': 2116, 'n_tokens_neox': 2063, 'n_words': 639}