]> source.dussan.org Git - jquery-ui.git/commitdiff
draggable,sortable: fixed containment "document", added containment: "window" (fixes...
authorPaul Bakaus <paul.bakaus@googlemail.com>
Sat, 7 Jun 2008 23:38:03 +0000 (23:38 +0000)
committerPaul Bakaus <paul.bakaus@googlemail.com>
Sat, 7 Jun 2008 23:38:03 +0000 (23:38 +0000)
ui/ui.draggable.js
ui/ui.sortable.js

index d58e5410074b8873af8ffe423dca6d1c228fc429..12a3a6e9bd5c45cbe0fdcfd4a669584d0fc5ae97 100644 (file)
@@ -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();
index cbfdd66236ecc635adb21fe45af10edc782e5f48..84eb0df93efe807b3fe0eabc6a52a99002e82119 100644 (file)
@@ -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();