<commit_before>package com.sksamuel.jqm4gwt;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Widget;
import com.sksamuel.jqm4gwt.JQMPopupEvent.PopupState;

/**
 * @author <NAME> <EMAIL> 16 Sep 2012 00:26:35
 *
 * <br> See <a href="http://demos.jquerymobile.com/1.4.5/popup/">Popup</a>
 */
public class JQMPopup extends JQMContainer {

    private static int counter = 1;

    private String tolerance;

    /**
     * Creates a new {@link JQMPopup} with an automatically assigned id in the form popup-xx where XX is an incrementing number.
     */
    public JQMPopup() {
        this("popup-" + (counter++));
    }

    /**
     * Creates a new {@link JQMPopup} with explicitly defined id.
     */
    public JQMPopup(String popupId) {
        super(popupId, "popup");
    }

    public JQMPopup(Widget... widgets) {
        this();
        add(widgets);
    }

    @Override
    public void setContainerId(String containerId) {
        super.setContainerId(containerId);
        removeAttribute("data-url");
    }

    /**
     * Automatically assigns an id in the form popup-xx where XX is an incrementing number.
     */
    @Override
    public JQMContainer withContainerId() {
        setContainerId("popup-" + (counter++));
        return this;
    }

    private static native void initialize(Element elt) /*-{
        $wnd.$(elt).popup();
    }-*/;

    /**
     * Initialize dynamically added popup with static content (for example added after page is loaded).
     * <br> Also see {@link JQMPopup#waitInitOpen(String)} if you need to wait for images to be loaded.
     */
    public void initDynamic() {
        initialize(getElement());
    }

    private static native void waitInitOpen(String waitForSelector, Element elt) /*-{
        // Wait with opening the popup until the popup image has been loaded in the DOM.
        // This ensures the popup gets the correct size and position
        var pop = $wnd.$(elt);
        var saveDisp = pop.css("display");
        if (saveDisp !== "none") pop.css("display", "none");
        $wnd.$( waitForSelector, elt ).load(function() {
            pop.css("display", saveDisp);
            pop.popup();
            pop.popup( "open" );
            clearTimeout( fallback ); // Clear the fallback
        });
        // Fallback in case the browser doesn't fire a load event
        var fallback = setTimeout(function() {
            pop.css("display", saveDisp);
            pop.popup();
            pop.popup( "open" );
        }, 2000);
    }-*/;

    /**
     * First wait till some elements are loaded, then initialize and open dynamically added popup.
     * <br> See <a href="http://demos.jquerymobile.com/1.4.5/popup-dynamic/#&ui-state=dialog&ui-state=dialog&ui-state=dialog">Dynamic popup with images</a>
     */
    public void waitInitOpen(String waitForSelector) {
        if (waitForSelector == null || waitForSelector.isEmpty()) {
            initDynamic();
            open();
            return;
        }
        waitInitOpen(waitForSelector, getElement());
    }

    private static native void _close(Element elt) /*-{
        $wnd.$(elt).popup("close");
    }-*/;

    private static native void _open(Element elt) /*-{
        $wnd.$(elt).popup("open");
    }-*/;

    public static native void close(String selector) /*-{
        $wnd.$(selector).popup("close");
    }-*/;

    public static native void open(String selector) /*-{
        $wnd.$(selector).popup("open");
    }-*/;

    public JQMPopup close() {
        _close(getElement());
        return this;
    }

    public JQMPopup open() {
        _open(getElement());
        return this;
    }

    @Override
    public String getRelType() {
        return "popup";
    }

    public String getOverlayTheme() {
        return getAttribute("data-overlay-theme");
    }

    public void setOverlayTheme(String theme) {
        setAttribute("data-overlay-theme", theme);
    }

    public JQMPopup withOverlayTheme(String theme) {
        setOverlayTheme(theme);
        return this;
    }

    public boolean isPadding() {
        return JQMCommon.hasStyle(this, "ui-content");
    }

    public void setPadding(boolean padding) {
        if (padding) {<commit_msg>JQMPopup.setTheme() changed to allow dynamic usage.<commit_after>package com.sksamuel.jqm4gwt;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Widget;
import com.sksamuel.jqm4gwt.JQMPopupEvent.PopupState;

/**
 * @author <NAME> <EMAIL> 16 Sep 2012 00:26:35
 *
 * <br> See <a href="http://demos.jquerymobile.com/1.4.5/popup/">Popup</a>
 */
public class JQMPopup extends JQMContainer {

    private static int counter = 1;

    private String tolerance;

    /**
     * Creates a new {@link JQMPopup} with an automatically assigned id in the form popup-xx where XX is an incrementing number.
     */
    public JQMPopup() {
        this("popup-" + (counter++));
    }

    /**
     * Creates a new {@link JQMPopup} with explicitly defined id.
     */
    public JQMPopup(String popupId) {
        super(popupId, "popup");
    }

    public JQMPopup(Widget... widgets) {
        this();
        add(widgets);
    }

    @Override
    public void setContainerId(String containerId) {
        super.setContainerId(containerId);
        removeAttribute("data-url");
    }

    /**
     * Automatically assigns an id in the form popup-xx where XX is an incrementing number.
     */
    @Override
    public JQMContainer withContainerId() {
        setContainerId("popup-" + (counter++));
        return this;
    }

    private static native void initialize(Element elt) /*-{
        $wnd.$(elt).popup();
    }-*/;

    /**
     * Initialize dynamically added popup with static content (for example added after page is loaded).
     * <br> Also see {@link JQMPopup#waitInitOpen(String)} if you need to wait for images to be loaded.
     */
    public void initDynamic() {
        initialize(getElement());
    }

    private static native void waitInitOpen(String waitForSelector, Element elt) /*-{
        // Wait with opening the popup until the popup image has been loaded in the DOM.
        // This ensures the popup gets the correct size and position
        var pop = $wnd.$(elt);
        var saveDisp = pop.css("display");
        if (saveDisp !== "none") pop.css("display", "none");
        $wnd.$( waitForSelector, elt ).load(function() {
            pop.css("display", saveDisp);
            pop.popup();
            pop.popup( "open" );
            clearTimeout( fallback ); // Clear the fallback
        });
        // Fallback in case the browser doesn't fire a load event
        var fallback = setTimeout(function() {
            pop.css("display", saveDisp);
            pop.popup();
            pop.popup( "open" );
        }, 2000);
    }-*/;

    /**
     * First wait till some elements are loaded, then initialize and open dynamically added popup.
     * <br> See <a href="http://demos.jquerymobile.com/1.4.5/popup-dynamic/#&ui-state=dialog&ui-state=dialog&ui-state=dialog">Dynamic popup with images</a>
     */
    public void waitInitOpen(String waitForSelector) {
        if (waitForSelector == null || waitForSelector.isEmpty()) {
            initDynamic();
            open();
            return;
        }
        waitInitOpen(waitForSelector, getElement());
    }

    private static native void _close(Element elt) /*-{
        $wnd.$(elt).popup("close");
    }-*/;

    private static native void _open(Element elt) /*-{
        $wnd.$(elt).popup("open");
    }-*/;

    public static native void close(String selector) /*-{
        $wnd.$(selector).popup("close");
    }-*/;

    public static native void open(String selector) /*-{
        $wnd.$(selector).popup("open");
    }-*/;

    public JQMPopup close() {
        _close(getElement());
        return this;
    }

    public JQMPopup open() {
        _open(getElement());
        return this;
    }

    @Override
    public String getRelType() {
        return "popup";
    }

    @Override
    public String getTheme() {
        String rslt = JQMCommon.getThemeEx(this, JQMCommon.STYLE_UI_BODY);
        if (rslt == null || rslt.isEmpty()) rslt = super.getTheme();
        return rslt;
    }

    @Override
    public void setTheme(String theme) {
        JQMCommon.setThemeEx(this, theme, JQMCommon.STYLE_UI_BODY);
    }

    public String getOverlayTheme() {
        return getAttribute("data-overlay-theme");
    }

    public void setOverlayTheme(String theme) {
        setAttribute("data-overlay-theme", theme);
    }

    public JQMPopup withOverlayTheme(String theme) {
        setOverlayTheme(theme);
        return this;
    }

    public boolean isPadding() {
        return JQMCommon.hasStyle(this, "ui-content");
    }

    public void setPadding(boolean padding) {
        if (padding) {
{'fraction_non_alphanumeric': 0.12981140399250027, 'fraction_numerical': 0.005514503143266791, 'mean_word_length': 2.4115876598946575, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '5104113', 'n_tokens_mistral': 2798, 'n_tokens_neox': 2668, 'n_words': 699}