<commit_before>import Widget               from "../../jsutils/Widget";
import parseHTML            from "../../jsutils/parseHTML";
import objectExtend         from "../../jsutils/objectExtend";
import dataStore            from "../../jsutils/dataStore";
import domPosition          from "../../domutils/domPosition";
import domAddEventListener  from "../../domutils/domAddEventListener";
import popupTemplate        from "./popup.html";
import "./popup.less";

var
PRIVATE = dataStore.create(),
BODY = document.body,

/**
 * Displays a popup relative to a given element (attached to).
 *
 * @class Popup
 * @extends Widget
 *
 * @param {Object} [options]
 * @param {Widget|HTMLElement} [options.content]
 * @param {HTMLElement} [options.attachTo]
 * @param {Object} [options.position]
 *  Object with any param accepted by `domPosition` utility.
 *  Example:
 *
 *      {
 *          my: "top right",
 *          at: "bottom right"
 *      }
 *
 */
Popup = {
    init: function(options){
        var inst = {
            opt:            objectExtend({}, Popup.defaults, options),
            $ele:           null,
            domListeners:   []
        };

        PRIVATE.set(this, inst);

        this.$ui = parseHTML(popupTemplate).firstChild;

        if (inst.opt.content) {
            this.setContent(inst.opt.content);
        }

        if (inst.opt.attachTo) {
            this.attachTo(inst.opt.attachTo);
        }

        this.onDestroy(removeAllDomListeners.bind(this));
    },

    /**
     * Sets the content of the popup
     *
     * @param {Widget|HTMLElement} [content]
     */
    setContent: function(content){
        var $ui = this.getEle();

        $ui.innerHTML = "";

        if (!content){
            return;
        }

        if (content.appendTo) {
            content.appendTo($ui);

        } else if ("childNodes" in content) {
            $ui.addChild(content);
        }
    },

    /**
     * Attaches the popup to a given element
     *
     * @param {HTMLElement} ele
     */
    attachTo: function(ele){
        var inst = PRIVATE.get(this);
        inst.$ele = ele;

        if (this.isVisible()) {
            this.show();
        }
    },

    show: function(){
        var inst    = PRIVATE.get(this),
            $ui     = this.getEle();

        if (!inst.$ele) {
            return;
        }
<commit_msg>Bug fix to Popup<commit_after>import Widget               from "../../jsutils/Widget";
import parseHTML            from "../../jsutils/parseHTML";
import objectExtend         from "../../jsutils/objectExtend";
import dataStore            from "../../jsutils/dataStore";
import domPosition          from "../../domutils/domPosition";
import domAddEventListener  from "../../domutils/domAddEventListener";
import popupTemplate        from "./popup.html";
import "./popup.less";

var
PRIVATE = dataStore.create(),
BODY = document.body,

/**
 * Displays a popup relative to a given element (attached to).
 *
 * @class Popup
 * @extends Widget
 *
 * @param {Object} [options]
 * @param {Widget|HTMLElement} [options.content]
 * @param {HTMLElement} [options.attachTo]
 * @param {Object} [options.position]
 *  Object with any param accepted by `domPosition` utility.
 *  Example:
 *
 *      {
 *          my: "top right",
 *          at: "bottom right"
 *      }
 *
 */
Popup = {
    init: function(options){
        var inst = {
            opt:            objectExtend({}, Popup.defaults, options),
            $ele:           null,
            domListeners:   []
        };

        PRIVATE.set(this, inst);

        this.$ui = parseHTML(popupTemplate).firstChild;

        if (inst.opt.content) {
            this.setContent(inst.opt.content);
        }

        if (inst.opt.attachTo) {
            this.attachTo(inst.opt.attachTo);
        }

        this.onDestroy(removeAllDomListeners.bind(this));
    },

    /**
     * Sets the content of the popup
     *
     * @param {Widget|HTMLElement} [content]
     */
    setContent: function(content){
        var $ui = this.getEle();

        $ui.innerHTML = "";

        if (!content){
            return;
        }

        if (content.appendTo) {
            content.appendTo($ui);

        } else if ("childNodes" in content) {
            $ui.appendChild(content);
        }
    },

    /**
     * Attaches the popup to a given element
     *
     * @param {HTMLElement} ele
     */
    attachTo: function(ele){
        var inst = PRIVATE.get(this);
        inst.$ele = ele;

        if (this.isVisible()) {
            this.show();
        }
    },

    show: function(){
        var inst    = PRIVATE.get(this),
            $ui     = this.getEle();

        if (!inst.$ele) {
            return;
        }

{'fraction_non_alphanumeric': 0.142433234421365, 'fraction_numerical': 0.0, 'mean_word_length': 1.7532088681446907, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4793267', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1373, 'n_words': 315}