<commit_before>/**
 * Patterns calendar - Calendar with different views for patterns.
 *
 * Copyright 2013-2014 <NAME>
 * Copyright 2014 <NAME>
 * Copyright 2014 Syslab.com GmbH
 */
define([
    "jquery",
    "pat-logger",
    "pat-parser",
    "pat-store",
    "pat-utils",
    "pat-registry",
    "pat-calendar-moment-timezone-data",
    "jquery.fullcalendar.dnd",
    "jquery.fullcalendar"
], function($, logger, Parser, store, utils, registry) {
    "use strict";
    var log = logger.getLogger("calendar"),
        parser = new Parser("calendar");

    parser.add_argument("height", "auto");
    parser.add_argument("start-date");
    parser.add_argument("time-format", "h(:mm)t");
    parser.add_argument("title-month", "MMMM YYYY");
    parser.add_argument("title-week", "MMM D YYYY");
    parser.add_argument("title-day", "dddd, MMM d, YYYY");
    parser.add_argument("column-month", "ddd");
    parser.add_argument("column-week", "ddd M/d");
    parser.add_argument("column-day", "dddd M/d");
    parser.add_argument("first-day", "0");
    parser.add_argument("first-hour", "6");
    parser.add_argument("calendar-controls", "");
    parser.add_argument("category-controls", "");
    parser.add_argument("default-view", "month",
                        ["month", "basicWeek", "basicDay",
                         "agendaWeek", "agendaDay"]);
    parser.add_argument("store", "none", ["none", "session", "local"]);
    parser.add_argument("ignore-url", false);

    var _ = {
        name: "calendar",
        trigger: ".pat-calendar",

        _parseSearchString: function() {
            var context = {};
            window.location.search.substr(1).split("&").forEach(function(str) {
                if (str) {
                    var keyValue = str.split("="),
                        key = keyValue[0],
                        value = decodeURIComponent(keyValue[1]);
                    if (value && (value.match(/^\[.*\]$/) ||
                                  value.match(/^\{.*\}$/))) {
                        context[key] = JSON.parse(value);
                    } else {
                        context[key] = value;
                    }
                }
            });
            return context;
        },

        init: function($el, opts) {
            opts = opts || {};
            var cfg = store.updateOptions($el[0], parser.parse($el)),
                storage = cfg.store === "none" ? null : store[cfg.store](_.name + $el[0].id);

            cfg.defaultDate = storage.get("date") || cfg.defaultDate;
            cfg.defaultView = storage.get("view") || cfg.defaultView;
            cfg.tooltip = $el.data('patCalendarTooltip');

            if (!opts.ignoreUrl) {
                var search = _._parseSearchString();
                if (search["default-date"]) {
                    cfg.defaultDate = search["default-date"];
                }
                if (search["default-view"]) {
                    cfg.defaultView = search["default-view"];
                }
            }

            var calOpts = {
                    axisFormat: cfg.timeFormat,
                    columnFormat: cfg.column,
                    defaultDate: cfg.defaultDate,
                    defaultView: cfg.defaultView,
                    droppable: true,
                    editable: true,
                    firstHour: cfg.first.hour,
                    header: false,
                    timeFormat: cfg.timeFormat,
                    titleFormat: cfg.title,
                    viewRender: _.highlightButtons,

                    // Callback functions
                    // ------------------
                    eventDrop: function(event) {
                        $.getJSON(
                            event.url,
                            { 'start': event.start.toISOString(),
                              'end': event.end.toISOString(),
                              'pat-calendar-event-drop': true
                            }
                        );
                    },
                    events: function(start, end, timezone, callback) {
                        var events = _.parseEvents($el, timezone);
                        callback(events);
                    },
                    dayClick: function () {
                        /* Allows for a tooltip (via pat-tooltip) to be shown
                         * when a user clicks on a day.
                         *
                         * The configuration is the same as pat-tooltip but
                         * appears under "data-pat-calendar-tooltip".
                         */
                        if (!cfg.tooltip) {
                            return;
                        }
                        var $tooltip = $(this).find('a.pat-tooltip');
                        if ($tooltip.length === 0) {
                            /* Retrieve the injection URL from the tooltip
                             * config data and add the day's date to its query
                             * string.
                             * Then take this data and use it to create and
                             * configure a tooltip trigger element, which is
                             * then triggered.
                             */
                            var match = cfg.tooltip.match(/url:[ ](.*?)(;|$)/),
                                data = cfg.tooltip.replace(match[0], ''),
                                url = utils.addURLQueryParameter(match[1], 'date', $(this).data('date'));
                            $tooltip = $(this).append(
                                    $('<a/>').attr({'href': url}).attr({'data-pat-tooltip': data}).addClass('pat-tooltip')
                                ).find('a.pat-tooltip');
                            registry.scan($tooltip);
                        }
                        $tooltip.trigger('click.tooltip');
                    }
                };

            $el.__cfg = cfg;
            $el.__storage = storage;

            if (cfg.height !== "auto") {
                calOpts.height = cfg.height;
            }

            var dayNames = [ "su", "mo", "tu", "we", "th", "fr", "sa" ];
            if (dayNames.indexOf(cfg.first.day) >= 0) {
                calOpts.firstDay = dayNames.indexOf(cfg.first.day);
            }<commit_msg>Don't add another <a/> element, reuse existing <td/>...<commit_after>/**
 * Patterns calendar - Calendar with different views for patterns.
 *
 * Copyright 2013-2014 <NAME>
 * Copyright 2014 <NAME>
 * Copyright 2014 Syslab.com GmbH
 */
define([
    "jquery",
    "pat-logger",
    "pat-parser",
    "pat-store",
    "pat-utils",
    "pat-registry",
    "pat-calendar-moment-timezone-data",
    "jquery.fullcalendar.dnd",
    "jquery.fullcalendar"
], function($, logger, Parser, store, utils, registry) {
    "use strict";
    var log = logger.getLogger("calendar"),
        parser = new Parser("calendar");

    parser.add_argument("height", "auto");
    parser.add_argument("start-date");
    parser.add_argument("time-format", "h(:mm)t");
    parser.add_argument("title-month", "MMMM YYYY");
    parser.add_argument("title-week", "MMM D YYYY");
    parser.add_argument("title-day", "dddd, MMM d, YYYY");
    parser.add_argument("column-month", "ddd");
    parser.add_argument("column-week", "ddd M/d");
    parser.add_argument("column-day", "dddd M/d");
    parser.add_argument("first-day", "0");
    parser.add_argument("first-hour", "6");
    parser.add_argument("calendar-controls", "");
    parser.add_argument("category-controls", "");
    parser.add_argument("default-view", "month",
                        ["month", "basicWeek", "basicDay",
                         "agendaWeek", "agendaDay"]);
    parser.add_argument("store", "none", ["none", "session", "local"]);
    parser.add_argument("ignore-url", false);

    var _ = {
        name: "calendar",
        trigger: ".pat-calendar",

        _parseSearchString: function() {
            var context = {};
            window.location.search.substr(1).split("&").forEach(function(str) {
                if (str) {
                    var keyValue = str.split("="),
                        key = keyValue[0],
                        value = decodeURIComponent(keyValue[1]);
                    if (value && (value.match(/^\[.*\]$/) ||
                                  value.match(/^\{.*\}$/))) {
                        context[key] = JSON.parse(value);
                    } else {
                        context[key] = value;
                    }
                }
            });
            return context;
        },

        init: function($el, opts) {
            opts = opts || {};
            var cfg = store.updateOptions($el[0], parser.parse($el)),
                storage = cfg.store === "none" ? null : store[cfg.store](_.name + $el[0].id);

            cfg.defaultDate = storage.get("date") || cfg.defaultDate;
            cfg.defaultView = storage.get("view") || cfg.defaultView;
            cfg.tooltip = $el.data('patCalendarTooltip');

            if (!opts.ignoreUrl) {
                var search = _._parseSearchString();
                if (search["default-date"]) {
                    cfg.defaultDate = search["default-date"];
                }
                if (search["default-view"]) {
                    cfg.defaultView = search["default-view"];
                }
            }

            var calOpts = {
                    axisFormat: cfg.timeFormat,
                    columnFormat: cfg.column,
                    defaultDate: cfg.defaultDate,
                    defaultView: cfg.defaultView,
                    droppable: true,
                    editable: true,
                    firstHour: cfg.first.hour,
                    header: false,
                    timeFormat: cfg.timeFormat,
                    titleFormat: cfg.title,
                    viewRender: _.highlightButtons,

                    // Callback functions
                    // ------------------
                    eventDrop: function(event) {
                        $.getJSON(
                            event.url,
                            { 'start': event.start.toISOString(),
                              'end': event.end.toISOString(),
                              'pat-calendar-event-drop': true
                            }
                        );
                    },
                    events: function(start, end, timezone, callback) {
                        var events = _.parseEvents($el, timezone);
                        callback(events);
                    },
                    dayClick: function () {
                        /* Allows for a tooltip (via pat-tooltip) to be shown
                         * when a user clicks on a day.
                         *
                         * The configuration is the same as pat-tooltip but
                         * appears under "data-pat-calendar-tooltip".
                         */
                        if (!cfg.tooltip) {
                            return;
                        }
                        var $el = $(this);
                        if (!$el.hasClass('pat-tooltip')) {
                            /* Retrieve the injection URL from the tooltip
                             * config data and add the day's date to its query
                             * string.
                             * Then take this data and use it to create and
                             * configure a tooltip trigger element, which is
                             * then triggered.
                             */
                            var match = cfg.tooltip.match(/url:[ ](.*?)(;|$)/),
                                data = cfg.tooltip.replace(match[0], ''),
                                url = utils.addURLQueryParameter(match[1], 'date', $(this).data('date'));
                            registry.scan($el.addClass('pat-tooltip').attr({'data-pat-tooltip': data}).attr({'href': url}));
                            $el.trigger('click.tooltip');
                        }
                    }
                };

            $el.__cfg = cfg;
            $el.__storage = storage;

            if (cfg.height !== "auto") {
                calOpts.height = cfg.height;
            }

            var dayNames = [ "su", "mo", "tu", "we", "th", "fr", "sa" ];
            if (dayNames.indexOf(cfg.first.day) >= 0) {
                calOpts.firstDay = dayNames.indexOf(cfg.first.day);
            }
{'fraction_non_alphanumeric': 0.13738198111697872, 'fraction_numerical': 0.0042406785085613696, 'mean_word_length': 1.2252091863984333, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5082158', 'n_tokens_mistral': 3229, 'n_tokens_neox': 3052, 'n_words': 632}