EasyUI Forum
October 18, 2025, 07:58:56 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Manage window resizing  (Read 13928 times)
korenanzo
Guest
« on: May 25, 2016, 02:17:40 AM »

this post i is partially related to
http://www.jeasyui.com/forum/index.php?topic=5361.0


I've managed to have a popup window that is contained ito the boundaries of it container.

I need to do the same thing when resizing.

I'd like to stop the resizing when the cursor (mouse) reaches the edge of the container.

the simplest thing should be: to stop the resize action when reached the border. BUT how can I do it? OR there is another way?
Code:
w.window('window').resizable({

onResize: function(e){
 
var d = e.data;
if (d.left < 0){d.left = 0;}
if (d.top < 0){d.top = 0;}
var parent = $(window);
var stop=false;
if (d.left + $(d.target).outerWidth() > parent.width()){
stop =true;
}
if (d.top + $(d.target).outerHeight() > parent.height()){
stop =true;
}
if (stop)
// what to do here??
},
 
})


thanks, rik
Logged
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #1 on: May 25, 2016, 05:46:25 PM »

Please call this extended method 'constrain' to limit the window position when resizing it.

Code:
$.extend($.fn.window.methods, {
    constrain: function(jq){
        return jq.each(function(){
            var target = this;
            var state = $(target).data('window');
            $(target).window('window').draggable({
                onDrag: function(e){
                    setPosition(e);
                    return false;
                }
            }).resizable({
                onResize: function(e){
                    setSize(e);
                    return false;
                },
                onStopResize: function(e){
                    setSize(e);
                    $(target).window('resize', e.data);
                    state.pmask.remove();
                    state.pmask = null;
                    state.proxy.remove();
                    state.proxy = null;
                }
            });
            
            function setPosition(e){
                var d = e.data;
                var parent = state.options.inline ? $(d.target).parent() : $(window);
                if (d.left < 0){d.left = 0;}
                if (d.top < parent.scrollTop()){
                    d.top = parent.scrollTop();
                }

                if (d.left + $(d.target).outerWidth() > parent.width()){
                    d.left = parent.width() - $(d.target).outerWidth();
                }
                if (d.top - parent.scrollTop() + $(d.target).outerHeight() > parent.height()){
                    d.top = parent.height() - $(d.target).outerHeight() + parent.scrollTop();
                }

                state.proxy.css({
                    display:'block',
                    left: e.data.left,
                    top: e.data.top
                });
            }
            function setSize(e){
                var d = e.data;
                var parent = state.options.inline ? $(d.target).parent() : $(window);
                if (d.left < 0){d.left = 0;}
                if (d.top < parent.scrollTop()){
                    d.top = parent.scrollTop();
                }
                if (d.left + d.width > parent.width()){
                    d.width = parent.width() - d.left;
                }
                if (d.top + d.height - parent.scrollTop() > parent.height()){
                    d.height = parent.height() - d.top + parent.scrollTop();
                }
                state.proxy.css({
                    left: e.data.left,
                    top: e.data.top
                });
                state.proxy._outerWidth(e.data.width);
                state.proxy._outerHeight(e.data.height);
            }
        });
    }
})
« Last Edit: May 26, 2016, 08:34:51 AM by jarry » Logged
korenanzo
Guest
« Reply #2 on: May 26, 2016, 03:01:36 AM »

I have problems

when moving or resizing I get an error

 Uncaught TypeError: Cannot read property 'css' of undefined
 
 state.proxy.css({...

I use it in this way:

first I create the window, then call the method

var o = $("<div  id="w" ></div>");

o.window({params})

o.window('constrain')
Logged
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #3 on: May 26, 2016, 08:35:10 AM »

Please look at this example http://code.reloado.com/uzunec3/edit#javascript,html. It works fine.
Logged
korenanzo
Guest
« Reply #4 on: May 31, 2016, 11:55:17 PM »


If you load the patch file

jquery.easyui.patch.js

you will get the error

http://code.reloado.com/ecibef3/2/edit
Logged
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #5 on: June 01, 2016, 12:48:51 AM »

Please try to download the updated patch from http://www.jeasyui.com/download/downloads/jquery-easyui-1.4.5-patch.zip. If you are using the online 'http://www.jeasyui.com/easyui/jquery.easyui.min.js' file, no patches are needed.
Logged
korenanzo
Guest
« Reply #6 on: June 01, 2016, 12:58:15 AM »

It works, thanks
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!