author | Julien Cristau <julien.cristau@logilab.fr> |
Thu, 23 Oct 2014 11:42:20 +0200 | |
changeset 10100 | 6718c03f8938 |
permissions | -rw-r--r-- |
10100
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
1 |
/* |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
2 |
* jQuery UI Sortable |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
3 |
* |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
4 |
* Copyright (c) 2008 Paul Bakaus |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
5 |
* Dual licensed under the MIT (MIT-LICENSE.txt) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
6 |
* and GPL (GPL-LICENSE.txt) licenses. |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
7 |
* |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
8 |
* http://docs.jquery.com/UI/Sortables |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
9 |
* |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
10 |
* Depends: |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
11 |
* ui.base.js |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
12 |
* |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
13 |
* Revision: $Id: ui.sortable.js 5262 2008-04-17 13:13:51Z paul.bakaus $ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
14 |
*/ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
15 |
;(function($) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
16 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
17 |
if (window.Node && Node.prototype && !Node.prototype.contains) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
18 |
Node.prototype.contains = function (arg) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
19 |
return !!(this.compareDocumentPosition(arg) & 16); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
20 |
}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
21 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
22 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
23 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
24 |
$.widget("ui.sortableTree", $.extend($.ui.mouse, { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
25 |
init: function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
26 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
27 |
//Initialize needed constants |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
28 |
var self = this, o = this.options; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
29 |
this.containerCache = {}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
30 |
this.element.addClass("ui-sortableTree"); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
31 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
32 |
//Get the items |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
33 |
this.refresh(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
34 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
35 |
//Let's determine the parent's offset |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
36 |
if(!(/(relative|absolute|fixed)/).test(this.element.css('position'))) this.element.css('position', 'relative'); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
37 |
this.offset = this.element.offset(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
38 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
39 |
//Initialize mouse events for interaction |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
40 |
this.mouseInit(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
41 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
42 |
//Prepare cursorAt |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
43 |
if(o.cursorAt && o.cursorAt.constructor == Array) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
44 |
o.cursorAt = { left: o.cursorAt[0], top: o.cursorAt[1] }; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
45 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
46 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
47 |
plugins: {}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
48 |
ui: function(inst) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
49 |
return { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
50 |
helper: (inst || this)["helper"], |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
51 |
position: (inst || this)["position"].current, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
52 |
absolutePosition: (inst || this)["position"].absolute, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
53 |
instance: this, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
54 |
options: this.options, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
55 |
element: this.element, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
56 |
item: (inst || this)["currentItem"], |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
57 |
sender: inst ? inst.element : null |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
58 |
}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
59 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
60 |
propagate: function(n,e,inst) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
61 |
$.ui.plugin.call(this, n, [e, this.ui(inst)]); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
62 |
this.element.triggerHandler(n == "sort" ? n : "sort"+n, [e, this.ui(inst)], this.options[n]); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
63 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
64 |
serialize: function(o) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
65 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
66 |
var items = $(this.options.items, this.element).not('.ui-sortableTree-helper'); //Only the items of the sortable itself |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
67 |
var str = []; o = o || {}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
68 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
69 |
items.each(function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
70 |
var res = ($(this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/)); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
71 |
if(res) str.push((o.key || res[1])+'[]='+(o.key ? res[1] : res[2])); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
72 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
73 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
74 |
return str.join('&'); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
75 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
76 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
77 |
toArray: function(attr) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
78 |
var items = $(this.options.items, this.element).not('.ui-sortableTree-helper'); //Only the items of the sortable itself |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
79 |
var ret = []; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
80 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
81 |
items.each(function() { ret.push($(this).attr(attr || 'id')); }); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
82 |
return ret; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
83 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
84 |
enable: function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
85 |
this.element.removeClass("ui-sortableTree-disabled"); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
86 |
this.options.disabled = false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
87 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
88 |
disable: function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
89 |
this.element.addClass("ui-sortableTree-disabled"); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
90 |
this.options.disabled = true; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
91 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
92 |
/* Be careful with the following core functions */ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
93 |
intersectsWith: function(item) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
94 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
95 |
var x1 = this.position.absolute.left - 10, x2 = x1 + 10, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
96 |
y1 = this.position.absolute.top - 10, y2 = y1 + 10; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
97 |
var l = item.left, r = l + item.width, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
98 |
t = item.top, b = t + item.height; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
99 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
100 |
return ( l < x1 + (this.helperProportions.width / 2) // Right Half |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
101 |
&& x2 - (this.helperProportions.width / 2) < r // Left Half |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
102 |
&& t < y1 + (this.helperProportions.height / 2) // Bottom Half |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
103 |
&& y2 - (this.helperProportions.height / 2) < b ); // Top Half |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
104 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
105 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
106 |
intersectsWithEdge: function(item) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
107 |
var y1 = this.position.absolute.top - 10, y2 = y1 + 10; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
108 |
var t = item.top, b = t + item.height; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
109 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
110 |
if(!this.intersectsWith(item.item.parents(".ui-sortableTree").data("sortableTree").containerCache)) return false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
111 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
112 |
if (!( t < y1 + (this.helperProportions.height / 2) // Bottom Half |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
113 |
&& y2 - (this.helperProportions.height / 2) < b )) return false; // Top Half |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
114 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
115 |
if(y2 > t && y1 < t) return 1; //Crosses top edge |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
116 |
if(y1 < b && y2 > b) return 2; //Crosses bottom edge |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
117 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
118 |
return false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
119 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
120 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
121 |
refresh: function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
122 |
this.refreshItems(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
123 |
this.refreshPositions(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
124 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
125 |
refreshItems: function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
126 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
127 |
this.items = []; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
128 |
this.containers = [this]; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
129 |
var items = this.items; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
130 |
var queries = [$(this.options.items, this.element)]; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
131 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
132 |
if(this.options.connectWith) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
133 |
for (var i = this.options.connectWith.length - 1; i >= 0; i--){ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
134 |
var cur = $(this.options.connectWith[i]); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
135 |
for (var j = cur.length - 1; j >= 0; j--){ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
136 |
var inst = $.data(cur[j], 'sortableTree'); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
137 |
if(inst && !inst.options.disabled) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
138 |
queries.push($(inst.options.items, inst.element)); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
139 |
this.containers.push(inst); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
140 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
141 |
}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
142 |
}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
143 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
144 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
145 |
for (var i = queries.length - 1; i >= 0; i--){ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
146 |
queries[i].each(function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
147 |
$.data(this, 'sortableTree-item', true); // Data for target checking (mouse manager) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
148 |
items.push({ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
149 |
item: $(this), |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
150 |
width: 0, height: 0, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
151 |
left: 0, top: 0 |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
152 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
153 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
154 |
}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
155 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
156 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
157 |
refreshPositions: function(fast) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
158 |
for (var i = this.items.length - 1; i >= 0; i--){ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
159 |
if(!fast) this.items[i].height = this.items[i].item.outerHeight(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
160 |
this.items[i].top = this.items[i].item.offset().top; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
161 |
}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
162 |
for (var i = this.containers.length - 1; i >= 0; i--){ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
163 |
var p =this.containers[i].element.offset(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
164 |
this.containers[i].containerCache.left = p.left; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
165 |
this.containers[i].containerCache.top = p.top; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
166 |
this.containers[i].containerCache.width = this.containers[i].element.outerWidth(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
167 |
this.containers[i].containerCache.height= this.containers[i].element.outerHeight(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
168 |
}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
169 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
170 |
destroy: function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
171 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
172 |
this.element |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
173 |
.removeClass("ui-sortableTree ui-sortableTree-disabled") |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
174 |
.removeData("sortableTree") |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
175 |
.unbind(".sortableTree"); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
176 |
this.mouseDestroy(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
177 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
178 |
for ( var i = this.items.length - 1; i >= 0; i-- ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
179 |
this.items[i].item.removeData("sortableTree-item"); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
180 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
181 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
182 |
contactContainers: function(e) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
183 |
for (var i = this.containers.length - 1; i >= 0; i--){ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
184 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
185 |
if(this.intersectsWith(this.containers[i].containerCache)) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
186 |
if(!this.containers[i].containerCache.over) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
187 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
188 |
if(this.currentContainer != this.containers[i]) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
189 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
190 |
//When entering a new container, we will find the item with the least distance and append our item near it |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
191 |
var dist = 10000; var itemWithLeastDistance = null; var base = this.position.absolute.top; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
192 |
for (var j = this.items.length - 1; j >= 0; j--) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
193 |
if(!this.containers[i].element[0].contains(this.items[j].item[0])) continue; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
194 |
var cur = this.items[j].top; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
195 |
if(Math.abs(cur - base) < dist) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
196 |
dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j]; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
197 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
198 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
199 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
200 |
itemWithLeastDistance ? this.rearrange(e, itemWithLeastDistance) : this.rearrange(e, null, this.containers[i].element); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
201 |
this.propagate("change", e); //Call plugins and callbacks |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
202 |
this.containers[i].propagate("change", e, this); //Call plugins and callbacks |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
203 |
this.currentContainer = this.containers[i]; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
204 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
205 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
206 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
207 |
this.containers[i].propagate("over", e, this); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
208 |
this.containers[i].containerCache.over = 1; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
209 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
210 |
} else { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
211 |
if(this.containers[i].containerCache.over) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
212 |
this.containers[i].propagate("out", e, this); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
213 |
this.containers[i].containerCache.over = 0; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
214 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
215 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
216 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
217 |
}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
218 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
219 |
mouseStart: function(e,el) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
220 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
221 |
if(this.options.disabled || this.options.type == 'static') return false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
222 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
223 |
//Find out if the clicked node (or one of its parents) is a actual item in this.items |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
224 |
var currentItem = null, nodes = $(e.target).parents().each(function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
225 |
if($.data(this, 'sortableTree-item')) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
226 |
currentItem = $(this); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
227 |
return false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
228 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
229 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
230 |
if($.data(e.target, 'sortableTree-item')) currentItem = $(e.target); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
231 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
232 |
if(!currentItem) return false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
233 |
if(this.options.handle) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
234 |
var validHandle = false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
235 |
$(this.options.handle, currentItem).each(function() { if(this == e.target) validHandle = true; }); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
236 |
if(!validHandle) return false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
237 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
238 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
239 |
this.currentItem = currentItem; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
240 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
241 |
var o = this.options; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
242 |
this.currentContainer = this; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
243 |
this.refresh(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
244 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
245 |
//Create and append the visible helper |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
246 |
this.helper = typeof o.helper == 'function' ? $(o.helper.apply(this.element[0], [e, this.currentItem])) : this.currentItem.clone(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
247 |
if(!this.helper.parents('body').length) this.helper.appendTo("body"); //Add the helper to the DOM if that didn't happen already |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
248 |
this.helper.css({ position: 'absolute', clear: 'both' }).addClass('ui-sortableTree-helper'); //Position it absolutely and add a helper class |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
249 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
250 |
//Prepare variables for position generation |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
251 |
$.extend(this, { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
252 |
offsetParent: this.helper.offsetParent(), |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
253 |
offsets: { absolute: this.currentItem.offset() } |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
254 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
255 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
256 |
//Save the first time position |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
257 |
$.extend(this, { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
258 |
position: { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
259 |
current: { left: e.pageX, top: e.pageY }, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
260 |
absolute: { left: e.pageX, top: e.pageY }, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
261 |
dom: this.currentItem.prev()[0] |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
262 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
263 |
clickOffset: { left: -5, top: -5 } |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
264 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
265 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
266 |
this.propagate("start", e); //Call plugins and callbacks |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
267 |
this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() }; //Save and store the helper proportions |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
268 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
269 |
for (var i = this.containers.length - 1; i >= 0; i--) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
270 |
this.containers[i].propagate("activate", e, this); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
271 |
} //Post 'activate' events to possible containers |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
272 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
273 |
//Prepare possible droppables |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
274 |
if($.ui.ddmanager) $.ui.ddmanager.current = this; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
275 |
if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
276 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
277 |
this.dragging = true; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
278 |
return true; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
279 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
280 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
281 |
mouseStop: function(e) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
282 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
283 |
if(this.newPositionAt) this.options.sortIndication.remove.call(this.currentItem, this.newPositionAt); //remove sort indicator |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
284 |
this.propagate("stop", e); //Call plugins and trigger callbacks |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
285 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
286 |
//If we are using droppables, inform the manager about the drop |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
287 |
var dropped = ($.ui.ddmanager && !this.options.dropBehaviour) ? $.ui.ddmanager.drop(this, e) : false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
288 |
if(!dropped && this.newPositionAt) this.newPositionAt[this.direction == 'down' ? 'before' : 'after'](this.currentItem); //Append to element to its new position |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
289 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
290 |
if(this.position.dom != this.currentItem.prev()[0]) this.propagate("update", e); //Trigger update callback if the DOM position has changed |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
291 |
if(!this.element[0].contains(this.currentItem[0])) { //Node was moved out of the current element |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
292 |
this.propagate("remove", e); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
293 |
for (var i = this.containers.length - 1; i >= 0; i--){ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
294 |
if(this.containers[i].element[0].contains(this.currentItem[0])) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
295 |
this.containers[i].propagate("update", e, this); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
296 |
this.containers[i].propagate("receive", e, this); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
297 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
298 |
}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
299 |
}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
300 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
301 |
//Post events to containers |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
302 |
for (var i = this.containers.length - 1; i >= 0; i--){ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
303 |
this.containers[i].propagate("deactivate", e, this); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
304 |
if(this.containers[i].containerCache.over) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
305 |
this.containers[i].propagate("out", e, this); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
306 |
this.containers[i].containerCache.over = 0; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
307 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
308 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
309 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
310 |
this.dragging = false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
311 |
if(this.cancelHelperRemoval) return false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
312 |
this.helper.remove(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
313 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
314 |
return false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
315 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
316 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
317 |
mouseDrag: function(e) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
318 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
319 |
//Compute the helpers position |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
320 |
this.position.current = { top: e.pageY + 5, left: e.pageX + 5 }; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
321 |
this.position.absolute = { left: e.pageX + 5, top: e.pageY + 5 }; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
322 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
323 |
//Interconnect with droppables |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
324 |
if($.ui.ddmanager) $.ui.ddmanager.drag(this, e); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
325 |
var intersectsWithDroppable = false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
326 |
$.each($.ui.ddmanager.droppables, function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
327 |
if(this.isover) intersectsWithDroppable = true; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
328 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
329 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
330 |
//Rearrange |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
331 |
if(intersectsWithDroppable) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
332 |
if(this.newPositionAt) this.options.sortIndication.remove.call(this.currentItem, this.newPositionAt); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
333 |
} else { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
334 |
for (var i = this.items.length - 1; i >= 0; i--) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
335 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
336 |
if(this.currentItem[0].contains(this.items[i].item[0])) continue; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
337 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
338 |
var intersection = this.intersectsWithEdge(this.items[i]); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
339 |
if(!intersection) continue; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
340 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
341 |
this.direction = intersection == 1 ? "down" : "up"; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
342 |
this.rearrange(e, this.items[i]); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
343 |
this.propagate("change", e); //Call plugins and callbacks |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
344 |
break; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
345 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
346 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
347 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
348 |
//Post events to containers |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
349 |
this.contactContainers(e); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
350 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
351 |
this.propagate("sort", e); //Call plugins and callbacks |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
352 |
this.helper.css({ left: this.position.current.left+'px', top: this.position.current.top+'px' }); // Stick the helper to the cursor |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
353 |
return false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
354 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
355 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
356 |
rearrange: function(e, i, a) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
357 |
if(i) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
358 |
if(this.newPositionAt) this.options.sortIndication.remove.call(this.currentItem, this.newPositionAt); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
359 |
this.newPositionAt = i.item; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
360 |
this.options.sortIndication[this.direction].call(this.currentItem, this.newPositionAt); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
361 |
} else { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
362 |
//Append |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
363 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
364 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
365 |
})); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
366 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
367 |
$.extend($.ui.sortableTree, { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
368 |
defaults: { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
369 |
items: '> *', |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
370 |
zIndex: 1000, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
371 |
distance: 1 |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
372 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
373 |
getter: "serialize toArray" |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
374 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
375 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
376 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
377 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
378 |
})(jQuery); |