<commit_before>"use strict";

var $ = require('jquery'),
    Bacon = require('baconjs'),
    _ = require('lodash'),

    dom = {
        // popovers live in a detached portion of the DOM
        // that is not wrapped in any specific div. Here
        // we abstract over that implementation detail so
        // that it does not appear that events are carelessly
        // scoped to body due to programmer error.
        popupContainer: 'body',
        popupTriggers: '[data-toggle="popover"]',
        popup: {
            outermostElement: 'div.popover',
            cancelButton: '.popover-cancel',
            acceptButton: '.popover-accept',
            innerData: '.popover-data'
        }
    },

    actions = { show: 'show',
                hide: 'hide'};


// Placed onto the jquery object
require('bootstrap');

function hideAssociatedPopup(event) {
    // When this event happens, there is no link back to
    // the element who owns this popover, so we can't do
    // a simple thing like:
    // $(event.currentTarget).owner().popover(actions.hide);
    // we have to manually hide the popup.
    $(event.currentTarget).closest(dom.popup.outermostElement).hide();
}

function showPopup (event) {
    $(dom.popupTriggers).not(event.currentTarget).popover(actions.hide);
    $(event.currentTarget).popover(actions.show);
}

exports.init = function ($container) {
    $container.on('click', dom.popupTriggers, showPopup);
    $(dom.popupContainer).on('click', dom.popup.cancelButton, hideAssociatedPopup);

    var acceptStream = $(dom.popupContainer)
            .asEventStream('click', dom.popup.acceptButton);
    acceptStream.onValue(hideAssociatedPopup);
    return acceptStream;
};

exports.activateAll = function () {
    $('.popover').remove();
    _.each($(dom.popupTriggers), function (cell) {
        var $cell = $(cell),
            $data = $cell.find(dom.popup.innerData),
            data = _.isEmpty($data) ? {} : {content: $data.html(), html: true };
        $cell.popover(data);
    });
};

<commit_msg>Anchor popovers inside the managing element<commit_after>"use strict";

var $ = require('jquery'),
    R = require('ramda'),
    Bacon = require('baconjs'),
    _ = require('lodash'),

    dom = {
        popupTriggers: '[data-toggle="popover"]',
        popup: {
            outermostElement: 'div.popover',
            cancelButton: '.popover-cancel',
            acceptButton: '.popover-accept',
            innerData: '.popover-data'
        }
    },

    actions = { show: 'show',
                hide: 'hide'};


// Placed onto the jquery object
require('bootstrap');

function hideAssociatedPopup(event) {
    $(event.currentTarget).closest(dom.popupTriggers).popover(actions.hide);
}

function showPopup (event) {
    $(dom.popupTriggers).not(event.currentTarget).popover(actions.hide);
    $(event.currentTarget).popover(actions.show);
}

exports.init = function ($container) {
    // any click inside a popup must stop propagating because it will clash
    // with the click behavior on its container
    $container.on('click', dom.popup.outermostElement, R.func('stopPropagation'));
    $container.on('click', dom.popup.cancelButton, hideAssociatedPopup);
    $container.on('click', dom.popupTriggers, showPopup);

    var acceptStream = $container.asEventStream('click', dom.popup.acceptButton);
    acceptStream.onValue(hideAssociatedPopup);
    return acceptStream;
};

exports.activateAll = function () {
    $('.popover').remove();
    _.each($(dom.popupTriggers), function (cell) {
        var $cell = $(cell),
            $data = $cell.find(dom.popup.innerData),
            data = _.isEmpty($data) ? {} : {content: $data.html(),
                                            container: cell,
                                            html: true };
        $cell.popover(data);
    });
};


{'fraction_non_alphanumeric': 0.1444936214527467, 'fraction_numerical': 0.0, 'mean_word_length': 2.6660305343511452, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3815801', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1092, 'n_words': 251}