EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: samuelzhu001 on April 16, 2020, 11:30:55 AM



Title: show window or dialog or messager center to browser window,not to document windo
Post by: samuelzhu001 on April 16, 2020, 11:30:55 AM
I use layout in my project and almost all pages are shown in center region with iframe,  when window,dialog or messager are shown in pages, they are centered to the page window , but not the browser window.  I don't want to realize it by setting top/left or moving every time the window or dialog are open.  Allthough parent.$.messager can  be a good method for messagers, but I don't want its modal property applying to whole window.
How can I easily realize it?


Title: Re: show window or dialog or messager center to browser window,not to document windo
Post by: samuelzhu001 on April 17, 2020, 03:31:56 AM
I found a solution:

    function centerOverall(target, offset) {
        let jq = $(target);
        let opts = jq.data('window').options;
        let offsetTop = opts.top - (window.parent.innerHeight -  window.innerHeight) / 2 + ((offset && offset.y) ? offset.y : 0);
        let offsetLeft = opts.left - (window.parent.innerWidth -  window.innerWidth) / 2 + ((offset && offset.x) ? offset.x : 0);
        if (offsetTop < 0) offsetTop = 0;
        if (offsetLeft < 0) offsetLeft = 0;
        jq.window("move", { top: offsetTop, left: offsetLeft });
    }
    //extend easyui window
    $.extend($.fn.window.methods, {
        centerOverall: function (jq, offset) {
            return jq.each(function () {
                centerOverall(this, offset);
            });
        },
    });