<commit_before>
/**
 * @author Anakeen
 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
 */

include_js('WHAT/Layout/AnchorPosition.js');
include_js('FDL/Layout/common.js');
include_js('WHAT/Layout/DHTMLapi.js');
include_js('WHAT/Layout/AnchorPosition.js');
include_js('WHAT/Layout/geometry.js');
include_js('FDL/Layout/iframe.js');

function displayWindow(height, width, ref, title, x, y, id, backgroundcolor) {
    var dialogFrame = $("#"+id+"_s");
    var oldFrame = $("#oldFrame_"+id);
    if (dialogFrame.length <= 0) {
        dialogFrame = $('<iframe id="'+id+'_s" style="padding: 0;" frameborder="0"  allowtransparency="yes"></iframe>').appendTo('body');
    } else {
         if (dialogFrame.dialog("isOpen") == true) {
             var position = dialogFrame.dialog("option", "position");
             x = position[0];
             y = position[1];
             height = dialogFrame.dialog("option", "height");
             width = dialogFrame.dialog("option", "width");
         } else {
             x = parseFloat(oldFrame.attr("data-posX"));
             y = parseFloat(oldFrame.attr("data-posY"));
             height = oldFrame.height();
             width = oldFrame.width();
         }
        dialogFrame.attr("src", ref);
    }

   dialogFrame.dialog({
        autoOpen:true,
        modal:false,
        draggable:true,
        resizable:true,
        height:height,
        width:width,
        title: title,
        open:function (event, ui) {
            if (isIE) {
                $('body').css('overflow', 'hidden');
            }
        },
        position:[x, y],
        beforeClose:function () {
            $(this).attr("src", "Images/1x1.gif");
            return false;
        },
        dragStop: function(event, ui) {
            if (id == "POPDOC") {
                var newParam = parseInt(ui.position.left) +"+"+parseInt(ui.position.top)+"+"+parseInt($(this).width())+"x"+parseInt($(this).height());
                setparamu("FDL", "MVIEW_GEO", newParam);
            }
        },
        resizeStop: function(event, ui) {
            if (id == "POPDOC") {
                var newParam =parseInt(ui.position.left)+"+"+parseInt(ui.position.top)+"+"+parseInt(ui.size.width)+"x"+parseInt(ui.size.height);
                setparamu("FDL", "MVIEW_GEO", newParam);
            }
        }
    });
    dialogFrame.width(width).height(height);
    dialogFrame.attr("src", ref);
    if (backgroundcolor) {
        dialogFrame.css("background-color", backgroundcolor);
        dialogFrame.parent().find(".ui-dialog-titlebar").removeClass("ui-widget-header").css("background-color", backgroundcolor);
    }

    dialogFrame.on("load", function () {
            var $this = $(this), doc, oldFrame, position;
            doc = this.contentDocument || this.contentWindow.document;
            if (doc) {
                if (title !== false) {
                    dialogFrame.dialog("option", "title", $("<div/>").text((doc.title || title)).html());
                }
                if (backgroundcolor &&  doc.getElementById("documentBody")) {
                    doc.getElementById("documentBody").style.backgroundColor =  backgroundcolor;
                }
            }
            if (doc && doc.location && doc.location.href &&
                doc.location.href.toLowerCase().indexOf("images/1x1.gif") > -1) {
                oldFrame = $("#oldFrame_"+id);
                if (oldFrame.length === 0) {
                    oldFrame = $('<div id="oldFrame_'+id+'" style="display : none;"></div>');
                    $("body").append(oldFrame);
                }
                oldFrame.empty();
                if (dialogFrame.dialog("isOpen") == true) {
                    position = dialogFrame.dialog("option", "position");
                    oldFrame.height(dialogFrame.dialog("option", "height"));
                    oldFrame.width(dialogFrame.dialog("option", "width"));
                    oldFrame.attr({
                        "data-posX": position[0],
                        "data-posY": position[1]
                    });
                    if (isIE) $this.dialog("close");
                }
                if (isIE) {
                    $('body').css('overflow', 'auto');

                }
                oldFrame.append($this);
            }
        });
}
function popdoc(event,url,title) {
  if (event) event.cancelBubble=true;
    if (ctrlPushed(event)) {
        window.open(
            url,
            '_blank',
            'resizable=yes,scrollbars=yes,width='+[FDL_VD2SIZE]+',height='+[FDL_HD2SIZE]);
    } else {
        var scrolly=window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
        if (! title) title='';
        var mviewgeo = $("meta[name=document-mviewgeo]").attr("content");
        var x = [mgeox],
            y = [mgeoy],
            h = [mgeoh],
            w = [mgeow];
        if (mviewgeo != undefined) {
            var match = mviewgeo.match(/([0-9]+)\+([0-9]+)\+([0-9]+)x([0-9]+)/);
            x = parseInt(match[1]);
            y = parseInt(match[2]);
            w = parseInt(match[3]);
            h = parseInt(match[4]);
        }
        displayWindow(h, w, url, title, x, y +scrolly, 'POPDOC');
    }
}<commit_msg>correct popdoc geometry when it is not initialized yet (refs #3888)<commit_after>
/**
 * @author Anakeen
 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
 */

include_js('WHAT/Layout/AnchorPosition.js');
include_js('FDL/Layout/common.js');
include_js('WHAT/Layout/DHTMLapi.js');
include_js('WHAT/Layout/AnchorPosition.js');
include_js('WHAT/Layout/geometry.js');
include_js('FDL/Layout/iframe.js');

function displayWindow(height, width, ref, title, x, y, id, backgroundcolor) {
    var dialogFrame = $("#"+id+"_s");
    var oldFrame = $("#oldFrame_"+id);
    if (dialogFrame.length <= 0) {
        dialogFrame = $('<iframe id="'+id+'_s" style="padding: 0;" frameborder="0"  allowtransparency="yes"></iframe>').appendTo('body');
    } else {
         if (dialogFrame.dialog("isOpen") == true) {
             var position = dialogFrame.dialog("option", "position");
             x = position[0];
             y = position[1];
             height = dialogFrame.dialog("option", "height");
             width = dialogFrame.dialog("option", "width");
         } else {
             x = parseFloat(oldFrame.attr("data-posX"));
             y = parseFloat(oldFrame.attr("data-posY"));
             height = oldFrame.height();
             width = oldFrame.width();
         }
        dialogFrame.attr("src", ref);
    }

   dialogFrame.dialog({
        autoOpen:true,
        modal:false,
        draggable:true,
        resizable:true,
        height:height,
        width:width,
        title: title,
        open:function (event, ui) {
            if (isIE) {
                $('body').css('overflow', 'hidden');
            }
        },
        position:[x, y],
        beforeClose:function () {
            $(this).attr("src", "Images/1x1.gif");
            return false;
        },
        dragStop: function(event, ui) {
            if (id == "POPDOC") {
                var newParam = parseInt(ui.position.left) +"+"+parseInt(ui.position.top)+"+"+parseInt($(this).width())+"x"+parseInt($(this).height());
                setparamu("FDL", "MVIEW_GEO", newParam);
            }
        },
        resizeStop: function(event, ui) {
            if (id == "POPDOC") {
                var newParam =parseInt(ui.position.left)+"+"+parseInt(ui.position.top)+"+"+parseInt(ui.size.width)+"x"+parseInt(ui.size.height);
                setparamu("FDL", "MVIEW_GEO", newParam);
            }
        }
    });
    dialogFrame.width(width).height(height);
    dialogFrame.attr("src", ref);
    if (backgroundcolor) {
        dialogFrame.css("background-color", backgroundcolor);
        dialogFrame.parent().find(".ui-dialog-titlebar").removeClass("ui-widget-header").css("background-color", backgroundcolor);
    }

    dialogFrame.on("load", function () {
            var $this = $(this), doc, oldFrame, position;
            doc = this.contentDocument || this.contentWindow.document;
            if (doc) {
                if (title !== false) {
                    dialogFrame.dialog("option", "title", $("<div/>").text((doc.title || title)).html());
                }
                if (backgroundcolor &&  doc.getElementById("documentBody")) {
                    doc.getElementById("documentBody").style.backgroundColor =  backgroundcolor;
                }
            }
            if (doc && doc.location && doc.location.href &&
                doc.location.href.toLowerCase().indexOf("images/1x1.gif") > -1) {
                oldFrame = $("#oldFrame_"+id);
                if (oldFrame.length === 0) {
                    oldFrame = $('<div id="oldFrame_'+id+'" style="display : none;"></div>');
                    $("body").append(oldFrame);
                }
                oldFrame.empty();
                if (dialogFrame.dialog("isOpen") == true) {
                    position = dialogFrame.dialog("option", "position");
                    oldFrame.height(dialogFrame.dialog("option", "height"));
                    oldFrame.width(dialogFrame.dialog("option", "width"));
                    oldFrame.attr({
                        "data-posX": position[0],
                        "data-posY": position[1]
                    });
                    if (isIE) $this.dialog("close");
                }
                if (isIE) {
                    $('body').css('overflow', 'auto');

                }
                oldFrame.append($this);
            }
        });
}
function popdoc(event,url,title) {
  if (event) event.cancelBubble=true;
    if (ctrlPushed(event)) {
        window.open(
            url,
            '_blank',
            'resizable=yes,scrollbars=yes,width='+[FDL_VD2SIZE]+',height='+[FDL_HD2SIZE]);
    } else {
        var scrolly=window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
        if (! title) title='';
        var mviewgeo = $("meta[name=document-mviewgeo]").attr("content");
        var x = [mgeox],
            y = [mgeoy],
            h = [mgeoh],
            w = [mgeow];
        if (mviewgeo != undefined) {
            var match = mviewgeo.match(/([0-9]+)\+([0-9]+)\+([0-9]+)x([0-9]+)/);
            if (match && match.length >4) {
                x = parseInt(match[1]);
                y = parseInt(match[2]);
                w = parseInt(match[3]);
                h = parseInt(match[4]);
            }
        }
        displayWindow(h, w, url, title, x, y +scrolly, 'POPDOC');
    }
}
{'fraction_non_alphanumeric': 0.17132997575079276, 'fraction_numerical': 0.0058757694459988805, 'mean_word_length': 1.9210024516480524, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5281865', 'n_tokens_mistral': 3173, 'n_tokens_neox': 3095, 'n_words': 506}