diff options
-rw-r--r-- | tests/visual/tree.html | 92 | ||||
-rw-r--r-- | ui/ui.draggable.js | 3 | ||||
-rw-r--r-- | ui/ui.droppable.js | 29 | ||||
-rw-r--r-- | ui/ui.sortable.js | 23 |
4 files changed, 71 insertions, 76 deletions
diff --git a/tests/visual/tree.html b/tests/visual/tree.html index a2c2e14d0..e50f280a2 100644 --- a/tests/visual/tree.html +++ b/tests/visual/tree.html @@ -10,69 +10,16 @@ <script type="text/javascript" src="../../ui/ui.droppable.js"></script>
<script type="text/javascript" src="../../ui/ui.resizable.js"></script>
<script type="text/javascript" src="../../ui/ui.sortable.js"></script>
+<script type="text/javascript" src="../../../branches/1.8/ui.tree.js"></script>
<script>
$(document).ready(function(){
-
-$.widget("ui.tree", {
- init: function() {
-
- var self = this;
-
- this.element.sortable({
- items: this.options.sortOn,
- placeholder: "ui-tree-placeholder",
- start: function() {
- $(this).data("sortable").placeholder.hide();
- $(this).data("sortable").refreshPositions(true);
- },
- stop: function() {
- var self = $(this).data("sortable");
- $(self.options.items, self.element).css("border-top", "0").css("border-bottom", "0");
- },
- sortIndicator: function(e, item, append, hardRefresh) {
-
- append ? append[0].appendChild(this.placeholder[0]) : item.item[0].parentNode.insertBefore(this.placeholder[0], (this.direction == 'down' ? item.item[0] : item.item[0].nextSibling));
-
- $(this.options.items, this.element).css("border-top", "0").css("border-bottom", "0");
- item.item.css("border-"+(this.direction == "down" ? "top" : "bottom"), "2px solid black");
-
- }
- });
-
-
-
- //Make certain nodes droppable
- $(this.options.dropOn, this.element).droppable({
- accept: this.options.sortOn,
- hoverClass: this.options.hoverClass,
- //tolerance: "pointer",
- over: function() {
- $(self.options.sortOn, self.element).css("border-top", "0").css("border-bottom", "0");
- },
- drop: function(e, ui) {
- $(this).parent().find("ul").append(ui.draggable);
- self.element.data("sortable")._noFinalSort = true;
- }
- });
-
- }
-});
-
-$.extend($.ui.tree, {
- defaults: {
- sortOn: "*",
- dropOn: "div",
- hoverClass: "ui-tree-hover"
- }
-});
-
$("ul.sortable").tree({
sortOn: "li",
- dropOn: "div",
- hoverClass: "hover"
+ dropOn: ".folder",
+ dropHoverClass: "hover"
});
@@ -96,14 +43,31 @@ font-family:"lucida grande", tahoma, verdana, arial, sans-serif; .placeholder {
display: none;
}
+
+.hover-up {
+ border-bottom: 2px solid black;
+}
+
+.hover-down {
+ border-top: 2px solid black;
+}
+
+.folder {
+ border: 1px solid black;
+}
+
+li {
+ padding: 3px;
+}
+
</style>
</head>
<body>
<ul class="sortable">
- <li>Item 1</li>
- <li><div>Item 2</div>
+ <li><div class="folder">Item 1</div></li>
+ <li><div class="folder">Item 2</div>
<ul>
<li>Sub Item 1</li>
<li>Sub Item 3</li>
@@ -111,9 +75,15 @@ font-family:"lucida grande", tahoma, verdana, arial, sans-serif; <li>Sub Item 5</li>
</ul>
</li>
- <li>Item 3</li>
- <li>Item 4</li>
- <li><div>Item 2</div>
+ <li><div class="folder">Item 3</div></li>
+ <li><div class="folder">Item 4</div></li>
+ <li><div class="folder">Item 4</div></li>
+ <li><div class="folder">Item 4</div></li>
+ <li><div class="folder">Item 4</div></li>
+ <li><div class="folder">Item 4</div></li>
+ <li><div class="folder">Item 4</div></li>
+ <li><div class="folder">Item 4</div></li>
+ <li><div class="folder">Item 2</div>
<ul>
<li>Sub Item 1</li>
<li>Sub Item 3</li>
diff --git a/ui/ui.draggable.js b/ui/ui.draggable.js index 80024a4d6..d72e24685 100644 --- a/ui/ui.draggable.js +++ b/ui/ui.draggable.js @@ -267,7 +267,8 @@ $.extend($.ui.draggable, { cancel: ":input", delay: 0, distance: 1, - helper: "original" + helper: "original", + scope: "default" } }); diff --git a/ui/ui.droppable.js b/ui/ui.droppable.js index 6833c4dfd..3e5d2999e 100644 --- a/ui/ui.droppable.js +++ b/ui/ui.droppable.js @@ -27,7 +27,8 @@ $.widget("ui.droppable", { this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight }; // Add the reference and positions to the manager - $.ui.ddmanager.droppables.push(this); + $.ui.ddmanager.droppables[this.options.scope] = $.ui.ddmanager.droppables[this.options.scope] || []; + $.ui.ddmanager.droppables[this.options.scope].push(this); }, plugins: {}, @@ -42,7 +43,7 @@ $.widget("ui.droppable", { }; }, destroy: function() { - var drop = $.ui.ddmanager.droppables; + var drop = $.ui.ddmanager.droppables[this.options.scope]; for ( var i = 0; i < drop.length; i++ ) if ( drop[i] == this ) drop.splice(i, 1); @@ -116,7 +117,8 @@ $.widget("ui.droppable", { $.extend($.ui.droppable, { defaults: { disabled: false, - tolerance: 'intersect' + tolerance: 'intersect', + scope: 'default' } }); @@ -167,26 +169,31 @@ $.ui.intersect = function(draggable, droppable, toleranceMode) { */ $.ui.ddmanager = { current: null, - droppables: [], + droppables: { scope: [] }, prepareOffsets: function(t, e) { - var m = $.ui.ddmanager.droppables; + var m = $.ui.ddmanager.droppables[t.options.scope]; var type = e ? e.type : null; // workaround for #2317 + var list = (t.currentItem || t.element).find(":data(droppable)").andSelf(); - for (var i = 0; i < m.length; i++) { - if(m[i].options.disabled || (t && !m[i].options.accept.call(m[i].element,(t.currentItem || t.element)))) continue; - m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue + droppablesLoop: for (var i = 0; i < m.length; i++) { + + if(m[i].options.disabled || (t && !m[i].options.accept.call(m[i].element,(t.currentItem || t.element)))) continue; //No disabled and non-accepted + for (var j=0; j < list.length; j++) { if(list[j] == m[i].element[0]) { m[i].proportions.height = 0; continue droppablesLoop; } }; //Filter out elements in the current dragged item + m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue + m[i].offset = m[i].element.offset(); m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight }; - if(type == "dragstart" || type == "sortactivate") m[i].activate.call(m[i], e); //Activate the droppable if used directly from draggables + if(type == "dragstart" || type == "sortactivate") m[i].activate.call(m[i], e); //Activate the droppable if used directly from draggables + } }, drop: function(draggable, e) { var dropped = false; - $.each($.ui.ddmanager.droppables, function() { + $.each($.ui.ddmanager.droppables[draggable.options.scope], function() { if(!this.options) return; if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance)) @@ -208,7 +215,7 @@ $.ui.ddmanager = { //Run through all droppables and check their positions based on specific tolerance options - $.each($.ui.ddmanager.droppables, function() { + $.each($.ui.ddmanager.droppables[draggable.options.scope], function() { if(this.options.disabled || this.greedyChild || !this.visible) return; var intersects = $.ui.intersect(draggable, this, this.options.tolerance); diff --git a/ui/ui.sortable.js b/ui/ui.sortable.js index 803531f43..24c934852 100644 --- a/ui/ui.sortable.js +++ b/ui/ui.sortable.js @@ -127,7 +127,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { if ((x1 + dxClick) > l && (x1 + dxClick) < l + item.width/2) return 2; if ((x1 + dxClick) > l + item.width/2 && (x1 + dxClick) < r) return 1; } else { - var height = item.height, helperHeight = this.helperProportions.height; + var height = item.height; var direction = y1 - this.updateOriginalPosition.top < 0 ? 2 : 1; // 2 = up if (direction == 1 && (y1 + dyClick) < t + height/2) { return 2; } // up @@ -188,6 +188,21 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { }, + removeCurrentsFromItems: function() { + + var list = this.currentItem.find(":data(sortable-item)"); + + for (var i=0; i < this.items.length; i++) { + + for (var j=0; j < list.length; j++) { + if(list[j] == this.items[i].item[0]) + this.items.splice(i,1); + }; + + }; + + }, + refreshItems: function() { this.items = []; @@ -371,6 +386,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { } this.currentItem = currentItem; + this.removeCurrentsFromItems(); return true; }, @@ -437,7 +453,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { //Call plugins and callbacks this.propagate("start", e); - this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Recache the helper size + if(!this._preserveHelperProportions) this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Recache the helper size if(o.cursorAt) { if(o.cursorAt.left != undefined) this.offset.click.left = o.cursorAt.left; @@ -705,7 +721,8 @@ $.extend($.ui.sortable, { zIndex: 1000, dropOnEmpty: true, appendTo: "parent", - sortIndicator: $.ui.sortable.prototype.rearrange + sortIndicator: $.ui.sortable.prototype.rearrange, + scope: "default" } }); |