From 7539a095f66413cc7359303b8a1ef74ec98332d9 Mon Sep 17 00:00:00 2001 From: Paul Bakaus Date: Sat, 7 Jun 2008 23:38:03 +0000 Subject: [PATCH] draggable,sortable: fixed containment "document", added containment: "window" (fixes #2936,#2171) --- ui/ui.draggable.js | 8 +++++++- ui/ui.sortable.js | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ui/ui.draggable.js b/ui/ui.draggable.js index d58e54100..12a3a6e9b 100644 --- a/ui/ui.draggable.js +++ b/ui/ui.draggable.js @@ -103,7 +103,13 @@ $.widget("ui.draggable", $.extend($.ui.mouse, { if(o.containment) { if(o.containment == 'parent') o.containment = this.helper[0].parentNode; - if(o.containment == 'document') this.containment = [0,0,$(document).width(), ($(document).height() || document.body.parentNode.scrollHeight)]; + if(o.containment == 'document' || o.containment == 'window') this.containment = [ + 0 - this.offset.relative.left - this.offset.parent.left, + 0 - this.offset.relative.top - this.offset.parent.top, + $(o.containment == 'document' ? document : window).width() - this.offset.relative.left - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.element.css("marginRight"),10) || 0), + ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.offset.relative.top - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.element.css("marginBottom"),10) || 0) + ]; + if(!(/^(document|window|parent)$/).test(o.containment)) { var ce = $(o.containment)[0]; var co = $(o.containment).offset(); diff --git a/ui/ui.sortable.js b/ui/ui.sortable.js index cbfdd6623..84eb0df93 100644 --- a/ui/ui.sortable.js +++ b/ui/ui.sortable.js @@ -355,7 +355,13 @@ $.widget("ui.sortable", $.extend($.ui.mouse, { if(o.containment) { if(o.containment == 'parent') o.containment = this.helper[0].parentNode; - if(o.containment == 'document') this.containment = [0,0,$(document).width(), ($(document).height() || document.body.parentNode.scrollHeight)]; + if(o.containment == 'document' || o.containment == 'window') this.containment = [ + 0 - this.offset.parent.left, + 0 - this.offset.parent.top, + $(o.containment == 'document' ? document : window).width() - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.element.css("marginRight"),10) || 0), + ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.element.css("marginBottom"),10) || 0) + ]; + if(!(/^(document|window|parent)$/).test(o.containment)) { var ce = $(o.containment)[0]; var co = $(o.containment).offset(); -- 2.39.5