<commit_before>/**
 * @license
 * Patterns @VERSION@ tooltip - tooltips
 *
 * Copyright 2008-2012 Simplon B.V.
 * Copyright 2011 <NAME>
 * Copyright 2011 SYSLAB.COM GmbH
 */
(function($) {
    mapal = mapal || {passivePatterns: {}};
    // Register as active pattern to prevent errors on clicks.
    $.extend(mapal.patterns, {
    "tooltip": {
        execute: function() {}
    }});

    $.extend(mapal.passivePatterns, {
    "tooltip": {
        init: function() {
        },

        initContent: function(root) {
            var tooltip = mapal.passivePatterns.tooltip;
            $("*[data-tooltip]", root).each(function() {
                var $trigger = $(this);

                tooltip.parseOptions($trigger);
                tooltip.createContainer($trigger);
                tooltip.setupShowEvents($trigger);
            });
        },

        parseOptions: function($trigger) {
            var input = $trigger.data("tooltip") || "",
                params = input.split("!"),
                options = {}, name, value, index;

            for (var i=0; i<params.length; i++) {
                index = params[i].indexOf("=");
                if (index === -1) {
                    name = params[i];
                    value = true;
                } else {
                    name = params[i].slice(0, index);
                    value = params[i].slice(index+1);
                }
                options[name] = value;
            }
            $trigger.data("mapal.tooltip", options);
        },

        setupShowEvents: function($trigger) {
            var tooltip = mapal.passivePatterns.tooltip,
                parameters = $trigger.data("mapal.tooltip");
            if (parameters.click) {
                $trigger.on("click.tooltip", $trigger, tooltip.show);
            } else {
                $trigger.on("mouseover.tooltip", $trigger, tooltip.show);
            }
        },

        removeShowEvents: function($trigger) {
            $trigger.off(".tooltip");
        },

        setupHideEvents: function($trigger) {
            var tooltip = mapal.passivePatterns.tooltip,
                parameters = $trigger.data("mapal.tooltip");
            if (parameters.sticky) {
                $trigger.data("mapal.tooltip.container").find(".closePanel")
                    .on("click.tooltip", $trigger, tooltip.hide);
            } else if (parameters.click) {
                $trigger.on("click.tooltip", $trigger, tooltip.hide);
            } else {
                $trigger.on("mouseleave.tooltip", $trigger, tooltip.hide);
            }
        },

        removeHideEvents: function($trigger) {
            $trigger.find(".closePanel").off(".tooltip");
            $trigger.off(".tooltip");
        },

        show: function(event) {
            var tooltip = mapal.passivePatterns.tooltip,
                $trigger = event.data,
                $container = $trigger.data("mapal.tooltip.container");

            tooltip.removeShowEvents($trigger);
            tooltip.positionContainer($trigger, $container);
            $container.css("visibility", "visible");
            tooltip.setupHideEvents($trigger);
        },

        hide: function(event) {
            var tooltip = mapal.passivePatterns.tooltip,
                $trigger = event.data,
                $container = $trigger.data("mapal.tooltip.container");
            tooltip.removeHideEvents($trigger);
            $container.css("visibility", "hidden");
            tooltip.setupShowEvents($trigger);
        },

        createContainer: function($trigger) {
            var content = $trigger.attr("title"),
                options = $trigger.data("mapal.tooltip");
            $trigger.removeAttr("title");

            $container = $("<div/>", {"class": "tooltip-container"});
            $container.css("visibility", "hidden");
            $container.append(
                $("<div/>").css("display", "block")
                    .append($("<p/>").text(content)))
                .append($("<span></span>", {"class": "pointer"}));
            if (options.sticky) {
                $("<button/>", {"class": "closePanel"})
                    .text("Close")
                    .insertBefore($container.find("p"));
            }
            $("body").append($container);
            $trigger.data("mapal.tooltip.container", $container);
        },

        boundingBox: function($el) {
            var box = $el.offset();
            box.height = $el.height();
            box.width = $el.width();
            box.bottom = box.top + box.height;
            box.right = box.left + box.width;
            return box;
        },

        positionContainer: function($trigger, $container) {
            var tooltip = mapal.passivePatterns.tooltip,
                trigger_box = tooltip.boundingBox($trigger),
                tooltip_box = tooltip.boundingBox($container),
                $window = $(window),
                window_width = $window.width(),
                window_height = $window.height(),
                trigger_center,
                space_top, space_right, space_bottom, space_left,
                container_offset = {},
                tip_offset = {}
                cls = "";

            trigger_center = {top: trigger_box.top + (trigger_box.height/2),
                              left: trigger_box.left + (trigger_box.width/2)};
            space_top = trigger_box.top - $window.scrollTop();
            space_bottom = window_height - space_top - trigger_box.height;
            space_left = trigger_box.left - $window.scrollLeft();
            space_right = window_width - space_left - trigger_box.width;

            if (space_top > Math.max(space_right, space_bottom, space_left)) {
                container_offset.top = trigger_box.top - tooltip_box.height + 10;
                tip_offset.top = tooltip_box.height - 23;
                cls = "t";
            } else if (space_right > Math.max(space_bottom, space_left, space_top)) {
                container_offset.left = trigger_box.right + 20;
                tip_offset.left = 0;
                cls = "r";
            } else if (space_bottom > Math.max(space_left, space_top, space_right)) {
                container_offset.top = trigger_box.bottom + 20;
                tip_offset.top = 0;
                cls = "b";
            } else {
                container_offset.right = trigger_box.left - tooltip_box.width;
                tip_offset.left = tooltip_box.width;
                cls = "l";
            }

            if (container_offset.left===undefined) {
                if (Math.abs(space_left-space_right) < 20) {
                    cls += "m";
                    container_offset.left = trigger_center.left - (tooltip_box.width/2);
                    tip_offset.left = tooltip_box.width/2;
                } else if (space_left > space_right) {
                    cls += "r";
                    container_offset.left = trigger_center.left + 20 - tooltip_box.width;
                    tip_offset.left = tooltip_box.width - 20;
                } else {
                    cls += "l";<commit_msg>Fix left-positioned tooltips positioning.<commit_after>/**
 * @license
 * Patterns @VERSION@ tooltip - tooltips
 *
 * Copyright 2008-2012 Simplon B.V.
 * Copyright 2011 <NAME>
 * Copyright 2011 SYSLAB.COM GmbH
 */
(function($) {
    mapal = mapal || {passivePatterns: {}};
    // Register as active pattern to prevent errors on clicks.
    $.extend(mapal.patterns, {
    "tooltip": {
        execute: function() {}
    }});

    $.extend(mapal.passivePatterns, {
    "tooltip": {
        init: function() {
        },

        initContent: function(root) {
            var tooltip = mapal.passivePatterns.tooltip;
            $("*[data-tooltip]", root).each(function() {
                var $trigger = $(this);

                tooltip.parseOptions($trigger);
                tooltip.createContainer($trigger);
                tooltip.setupShowEvents($trigger);
            });
        },

        parseOptions: function($trigger) {
            var input = $trigger.data("tooltip") || "",
                params = input.split("!"),
                options = {}, name, value, index;

            for (var i=0; i<params.length; i++) {
                index = params[i].indexOf("=");
                if (index === -1) {
                    name = params[i];
                    value = true;
                } else {
                    name = params[i].slice(0, index);
                    value = params[i].slice(index+1);
                }
                options[name] = value;
            }
            $trigger.data("mapal.tooltip", options);
        },

        setupShowEvents: function($trigger) {
            var tooltip = mapal.passivePatterns.tooltip,
                parameters = $trigger.data("mapal.tooltip");
            if (parameters.click) {
                $trigger.on("click.tooltip", $trigger, tooltip.show);
            } else {
                $trigger.on("mouseover.tooltip", $trigger, tooltip.show);
            }
        },

        removeShowEvents: function($trigger) {
            $trigger.off(".tooltip");
        },

        setupHideEvents: function($trigger) {
            var tooltip = mapal.passivePatterns.tooltip,
                parameters = $trigger.data("mapal.tooltip");
            if (parameters.sticky) {
                $trigger.data("mapal.tooltip.container").find(".closePanel")
                    .on("click.tooltip", $trigger, tooltip.hide);
            } else if (parameters.click) {
                $trigger.on("click.tooltip", $trigger, tooltip.hide);
            } else {
                $trigger.on("mouseleave.tooltip", $trigger, tooltip.hide);
            }
        },

        removeHideEvents: function($trigger) {
            $trigger.find(".closePanel").off(".tooltip");
            $trigger.off(".tooltip");
        },

        show: function(event) {
            var tooltip = mapal.passivePatterns.tooltip,
                $trigger = event.data,
                $container = $trigger.data("mapal.tooltip.container");

            tooltip.removeShowEvents($trigger);
            tooltip.positionContainer($trigger, $container);
            $container.css("visibility", "visible");
            tooltip.setupHideEvents($trigger);
        },

        hide: function(event) {
            var tooltip = mapal.passivePatterns.tooltip,
                $trigger = event.data,
                $container = $trigger.data("mapal.tooltip.container");
            tooltip.removeHideEvents($trigger);
            $container.css("visibility", "hidden");
            tooltip.setupShowEvents($trigger);
        },

        createContainer: function($trigger) {
            var content = $trigger.attr("title"),
                options = $trigger.data("mapal.tooltip");
            $trigger.removeAttr("title");

            $container = $("<div/>", {"class": "tooltip-container"});
            $container.css("visibility", "hidden");
            $container.append(
                $("<div/>").css("display", "block")
                    .append($("<p/>").text(content)))
                .append($("<span></span>", {"class": "pointer"}));
            if (options.sticky) {
                $("<button/>", {"class": "closePanel"})
                    .text("Close")
                    .insertBefore($container.find("p"));
            }
            $("body").append($container);
            $trigger.data("mapal.tooltip.container", $container);
        },

        boundingBox: function($el) {
            var box = $el.offset();
            box.height = $el.height();
            box.width = $el.width();
            box.bottom = box.top + box.height;
            box.right = box.left + box.width;
            return box;
        },

        positionContainer: function($trigger, $container) {
            var tooltip = mapal.passivePatterns.tooltip,
                trigger_box = tooltip.boundingBox($trigger),
                tooltip_box = tooltip.boundingBox($container),
                $window = $(window),
                window_width = $window.width(),
                window_height = $window.height(),
                trigger_center,
                space_top, space_right, space_bottom, space_left,
                container_offset = {},
                tip_offset = {}
                cls = "";

            trigger_center = {top: trigger_box.top + (trigger_box.height/2),
                              left: trigger_box.left + (trigger_box.width/2)};
            space_top = trigger_box.top - $window.scrollTop();
            space_bottom = window_height - space_top - trigger_box.height;
            space_left = trigger_box.left - $window.scrollLeft();
            space_right = window_width - space_left - trigger_box.width;

            if (space_top > Math.max(space_right, space_bottom, space_left)) {
                container_offset.top = trigger_box.top - tooltip_box.height + 10;
                tip_offset.top = tooltip_box.height - 23;
                cls = "t";
            } else if (space_right > Math.max(space_bottom, space_left, space_top)) {
                container_offset.left = trigger_box.right + 20;
                tip_offset.left = 0;
                cls = "r";
            } else if (space_bottom > Math.max(space_left, space_top, space_right)) {
                container_offset.top = trigger_box.bottom + 20;
                tip_offset.top = 0;
                cls = "b";
            } else {
                container_offset.left = trigger_box.left - tooltip_box.width - 20;
                tip_offset.left = tooltip_box.width - 23;
                cls = "l";
            }

            if (container_offset.left===undefined) {
                if (Math.abs(space_left-space_right) < 20) {
                    cls += "m";
                    container_offset.left = trigger_center.left - (tooltip_box.width/2);
                    tip_offset.left = tooltip_box.width/2;
                } else if (space_left > space_right) {
                    cls += "r";
                    container_offset.left = trigger_center.left + 20 - tooltip_box.width;
                    tip_offset.left = tooltip_box.width - 20;
                } else {
                    cls += "l";
{'fraction_non_alphanumeric': 0.13535311031629146, 'fraction_numerical': 0.005891016200294551, 'mean_word_length': 1.5993437841779075, 'pattern_counts': {'":': 10, '<': 21, '<?xml version=': 0, '>': 25, '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': '1272511', 'n_tokens_mistral': 3942, 'n_tokens_neox': 3670, 'n_words': 662}