EasyUI Forum

General Category => General Discussion => Topic started by: aswzen on October 29, 2015, 08:24:28 PM



Title: Child window position limit (constrained) as default behavior
Post by: aswzen on October 29, 2015, 08:24:28 PM
i saw this 3 years old question
http://www.jeasyui.com/forum/index.php?topic=603.0
about How to limit draggable/window movement

but i see this problem solution still not implemented as default behavior of easyui window if the properti inline:true
see this fiddle: http://jsfiddle.net/hocu4Lwp/2/

(http://i.imgur.com/e5NZtHt.jpg)

can you make this as default behavior?

thank you in advance


Title: Re: Child window position limit (constrained) as default behavior
Post by: jarry on October 30, 2015, 01:03:59 AM
The extended method 'constrain' method can be used to prevent the window from moving out of its parent container.
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){
var d = e.data;
if (d.left < 0){d.left = 0;}
if (d.top < 0){d.top = 0;}
var parent = state.options.inline ? $(d.parent) : $(window);
if (d.left + $(d.target).outerWidth() > parent.width()){
d.left = parent.width() - $(d.target).outerWidth();
}
if (d.top + $(d.target).outerHeight() > parent.height()){
d.top = parent.height() - $(d.target).outerHeight();
}

state.proxy.css({
display:'block',
left: e.data.left,
top: e.data.top
});

return false;
}
})
})
}
})

Please refer to http://jsfiddle.net/hocu4Lwp/3/


Title: Re: Child window position limit (constrained) as default behavior
Post by: aswzen on October 30, 2015, 01:26:21 AM
absolutely thankyou jarry.. :)
谢谢

please make it to easyui default behaviour if you consider


Title: Re: Child window position limit (constrained) as default behavior
Post by: arma on November 08, 2015, 03:17:49 PM
It's for window only not applied to dialog isn't it ?
I replace the window to dialog and it works good.

Code:
$.extend($.fn.dialog.methods, {
    constrain: function (jq) {
        return jq.each(function () {
            var target = this;
            var state = $(target).data('window');
            $(target).dialog('dialog').draggable({
....