rails_admin_nested_set 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/rails_admin/jquery.mjs.nestedSortable.js +549 -523
- data/app/assets/javascripts/rails_admin/rails_admin_nested_set.js.coffee +0 -1
- data/app/assets/stylesheets/rails_admin/rails_admin_nested_set.css.scss +4 -0
- data/lib/rails_admin_nested_set/helper.rb +1 -1
- data/lib/rails_admin_nested_set/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a4a55e99dae219aafadeda6117da3f3770825ad
|
4
|
+
data.tar.gz: fc9288e602c3e15cb01ba5f45726d154e64da934
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b856a13acbd8d25fbd92dc20ddaacd8a59f8be40cc559a8ee650499df16b6b122ab571f7a91834da8a5c1bb5d868e0c197d2462f39083da48bffc63f71d1b1e
|
7
|
+
data.tar.gz: c55759046b21fe3f835923f4b39f65e12f038f0cf37b639a23b3b23acbe24169edf5e2ce6995fe7ea1269b110acc40c76cb4737ccc848bf810ff10f402e613fd
|
@@ -13,601 +13,627 @@
|
|
13
13
|
|
14
14
|
(function($) {
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
$.widget("mjs.nestedSortable", $.extend({}, $.ui.sortable.prototype, {
|
21
|
-
|
22
|
-
options: {
|
23
|
-
doNotClear: false,
|
24
|
-
expandOnHover: 700,
|
25
|
-
isAllowed: function(placeholder, placeholderParent, originalItem) { return true; },
|
26
|
-
isTree: false,
|
27
|
-
listType: 'ol',
|
28
|
-
maxLevels: 0,
|
29
|
-
protectRoot: false,
|
30
|
-
rootID: null,
|
31
|
-
rtl: false,
|
32
|
-
startCollapsed: false,
|
33
|
-
tabSize: 20,
|
34
|
-
|
35
|
-
branchClass: 'mjs-nestedSortable-branch',
|
36
|
-
collapsedClass: 'mjs-nestedSortable-collapsed',
|
37
|
-
disableNestingClass: 'mjs-nestedSortable-no-nesting',
|
38
|
-
errorClass: 'mjs-nestedSortable-error',
|
39
|
-
expandedClass: 'mjs-nestedSortable-expanded',
|
40
|
-
hoveringClass: 'mjs-nestedSortable-hovering',
|
41
|
-
leafClass: 'mjs-nestedSortable-leaf'
|
42
|
-
},
|
43
|
-
|
44
|
-
_create: function() {
|
45
|
-
this.element.data('ui-sortable', this.element.data('mjs-nestedSortable'));
|
46
|
-
|
47
|
-
// mjs - prevent browser from freezing if the HTML is not correct
|
48
|
-
if (!this.element.is(this.options.listType))
|
49
|
-
throw new Error('nestedSortable: Please check that the listType option is set to your actual list type');
|
50
|
-
|
51
|
-
// mjs - force 'intersect' tolerance method if we have a tree with expanding/collapsing functionality
|
52
|
-
if (this.options.isTree && this.options.expandOnHover) {
|
53
|
-
this.options.tolerance = 'intersect';
|
54
|
-
}
|
55
|
-
|
56
|
-
$.ui.sortable.prototype._create.apply(this, arguments);
|
57
|
-
|
58
|
-
// mjs - prepare the tree by applying the right classes (the CSS is responsible for actual hide/show functionality)
|
59
|
-
if (this.options.isTree) {
|
60
|
-
var self = this;
|
61
|
-
$(this.items).each(function() {
|
62
|
-
var $li = this.item;
|
63
|
-
if ($li.children(self.options.listType).length) {
|
64
|
-
$li.addClass(self.options.branchClass);
|
65
|
-
// expand/collapse class only if they have children
|
66
|
-
if (self.options.startCollapsed) $li.addClass(self.options.collapsedClass);
|
67
|
-
else $li.addClass(self.options.expandedClass);
|
68
|
-
} else {
|
69
|
-
$li.addClass(self.options.leafClass);
|
70
|
-
}
|
71
|
-
})
|
72
|
-
}
|
73
|
-
},
|
74
|
-
|
75
|
-
_destroy: function() {
|
76
|
-
this.element
|
77
|
-
.removeData("mjs-nestedSortable")
|
78
|
-
.removeData("ui-sortable");
|
79
|
-
return $.ui.sortable.prototype._destroy.apply(this, arguments);
|
80
|
-
},
|
81
|
-
|
82
|
-
_mouseDrag: function(event) {
|
83
|
-
var i, item, itemElement, intersection,
|
84
|
-
o = this.options,
|
85
|
-
scrolled = false;
|
86
|
-
|
87
|
-
//Compute the helpers position
|
88
|
-
this.position = this._generatePosition(event);
|
89
|
-
this.positionAbs = this._convertPositionTo("absolute");
|
90
|
-
|
91
|
-
if (!this.lastPositionAbs) {
|
92
|
-
this.lastPositionAbs = this.positionAbs;
|
93
|
-
}
|
94
|
-
|
95
|
-
//Do scrolling
|
96
|
-
if(this.options.scroll) {
|
97
|
-
if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') {
|
98
|
-
|
99
|
-
if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) {
|
100
|
-
this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
|
101
|
-
} else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity) {
|
102
|
-
this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
|
103
|
-
}
|
104
|
-
|
105
|
-
if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) {
|
106
|
-
this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
|
107
|
-
} else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity) {
|
108
|
-
this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
|
109
|
-
}
|
110
|
-
|
111
|
-
} else {
|
112
|
-
|
113
|
-
if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) {
|
114
|
-
scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
|
115
|
-
} else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) {
|
116
|
-
scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
|
117
|
-
}
|
118
|
-
|
119
|
-
if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) {
|
120
|
-
scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
|
121
|
-
} else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
|
122
|
-
scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
|
123
|
-
}
|
16
|
+
function isOverAxis( x, reference, size ) {
|
17
|
+
return ( x > reference ) && ( x < ( reference + size ) );
|
18
|
+
}
|
124
19
|
|
125
|
-
|
20
|
+
$.widget("mjs.nestedSortable", $.extend({}, $.ui.sortable.prototype, {
|
21
|
+
|
22
|
+
options: {
|
23
|
+
doNotClear: false,
|
24
|
+
expandOnHover: 700,
|
25
|
+
isAllowed: function(placeholder, placeholderParent, originalItem) { return true; },
|
26
|
+
isTree: false,
|
27
|
+
listType: 'ol',
|
28
|
+
maxLevels: 0,
|
29
|
+
protectRoot: false,
|
30
|
+
rootID: null,
|
31
|
+
rtl: false,
|
32
|
+
startCollapsed: false,
|
33
|
+
tabSize: 20,
|
34
|
+
scrollX: true, //if true, the page scrolls when a list item is dragged past the width of the container
|
35
|
+
scrollY: true, //if true, the page scrolls when a list item is dragged past the height of the container
|
36
|
+
branchClass: 'mjs-nestedSortable-branch',
|
37
|
+
collapsedClass: 'mjs-nestedSortable-collapsed',
|
38
|
+
disableNestingClass: 'mjs-nestedSortable-no-nesting',
|
39
|
+
errorClass: 'mjs-nestedSortable-error',
|
40
|
+
expandedClass: 'mjs-nestedSortable-expanded',
|
41
|
+
hoveringClass: 'mjs-nestedSortable-hovering',
|
42
|
+
leafClass: 'mjs-nestedSortable-leaf',
|
43
|
+
disabledClass: 'mjs-nestedSortable-disabled'
|
44
|
+
},
|
45
|
+
|
46
|
+
_create: function() {
|
47
|
+
this.element.data('ui-sortable', this.element.data('mjs-nestedSortable'));
|
48
|
+
|
49
|
+
// mjs - prevent browser from freezing if the HTML is not correct
|
50
|
+
if (!this.element.is(this.options.listType))
|
51
|
+
throw new Error('nestedSortable: Please check that the listType option is set to your actual list type');
|
52
|
+
|
53
|
+
// mjs - force 'intersect' tolerance method if we have a tree with expanding/collapsing functionality
|
54
|
+
if (this.options.isTree && this.options.expandOnHover) {
|
55
|
+
this.options.tolerance = 'intersect';
|
56
|
+
}
|
126
57
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
intersection = this._intersectsWithPointer(item);
|
166
|
-
if (!intersection) {
|
167
|
-
continue;
|
168
|
-
}
|
58
|
+
$.ui.sortable.prototype._create.apply(this, arguments);
|
59
|
+
|
60
|
+
// mjs - prepare the tree by applying the right classes (the CSS is responsible for actual hide/show functionality)
|
61
|
+
if (this.options.isTree) {
|
62
|
+
var self = this;
|
63
|
+
$(this.items).each(function() {
|
64
|
+
var $li = this.item;
|
65
|
+
if ($li.children(self.options.listType).length) {
|
66
|
+
$li.addClass(self.options.branchClass);
|
67
|
+
// expand/collapse class only if they have children
|
68
|
+
if (self.options.startCollapsed) $li.addClass(self.options.collapsedClass);
|
69
|
+
else $li.addClass(self.options.expandedClass);
|
70
|
+
} else {
|
71
|
+
$li.addClass(self.options.leafClass);
|
72
|
+
}
|
73
|
+
})
|
74
|
+
}
|
75
|
+
},
|
76
|
+
|
77
|
+
_destroy: function() {
|
78
|
+
this.element
|
79
|
+
.removeData("mjs-nestedSortable")
|
80
|
+
.removeData("ui-sortable");
|
81
|
+
return $.ui.sortable.prototype._destroy.apply(this, arguments);
|
82
|
+
},
|
83
|
+
|
84
|
+
_mouseDrag: function(event) {
|
85
|
+
var i, item, itemElement, intersection,
|
86
|
+
o = this.options,
|
87
|
+
scrolled = false;
|
88
|
+
|
89
|
+
//Compute the helpers position
|
90
|
+
this.position = this._generatePosition(event);
|
91
|
+
this.positionAbs = this._convertPositionTo("absolute");
|
92
|
+
|
93
|
+
if (!this.lastPositionAbs) {
|
94
|
+
this.lastPositionAbs = this.positionAbs;
|
95
|
+
}
|
169
96
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
97
|
+
//Do scrolling
|
98
|
+
if(this.options.scroll) {
|
99
|
+
if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') {
|
100
|
+
|
101
|
+
if( o.scrollY ) {
|
102
|
+
if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) {
|
103
|
+
this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
|
104
|
+
} else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity) {
|
105
|
+
this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
if( o.scrollX ) {
|
109
|
+
if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) {
|
110
|
+
this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
|
111
|
+
} else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity) {
|
112
|
+
this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
} else {
|
116
|
+
if( o.scrollY ) {
|
117
|
+
if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) {
|
118
|
+
scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
|
119
|
+
} else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) {
|
120
|
+
scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
if( o.scrollX ) {
|
124
|
+
if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) {
|
125
|
+
scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
|
126
|
+
} else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
|
127
|
+
scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
180
131
|
|
181
|
-
|
182
|
-
|
183
|
-
// no action if the item moved is the parent of the item checked
|
184
|
-
if (itemElement !== this.currentItem[0] &&
|
185
|
-
this.placeholder[intersection === 1 ? "next" : "prev"]()[0] !== itemElement &&
|
186
|
-
!$.contains(this.placeholder[0], itemElement) &&
|
187
|
-
(this.options.type === "semi-dynamic" ? !$.contains(this.element[0], itemElement) : true)
|
188
|
-
) {
|
189
|
-
|
190
|
-
// mjs - we are intersecting an element: trigger the mouseenter event and store this state
|
191
|
-
if (!this.mouseentered) {
|
192
|
-
$(itemElement).mouseenter();
|
193
|
-
this.mouseentered = true;
|
194
|
-
}
|
195
|
-
|
196
|
-
// mjs - if the element has children and they are hidden, show them after a delay (CSS responsible)
|
197
|
-
if (o.isTree && $(itemElement).hasClass(o.collapsedClass) && o.expandOnHover) {
|
198
|
-
if (!this.hovering) {
|
199
|
-
$(itemElement).addClass(o.hoveringClass);
|
200
|
-
var self = this;
|
201
|
-
this.hovering = window.setTimeout(function() {
|
202
|
-
$(itemElement).removeClass(o.collapsedClass).addClass(o.expandedClass);
|
203
|
-
self.refreshPositions();
|
204
|
-
self._trigger("expand", event, self._uiHash());
|
205
|
-
}, o.expandOnHover);
|
132
|
+
if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
|
133
|
+
$.ui.ddmanager.prepareOffsets(this, event);
|
206
134
|
}
|
207
|
-
}
|
208
135
|
|
209
|
-
|
136
|
+
//Regenerate the absolute position used for position checks
|
137
|
+
this.positionAbs = this._convertPositionTo("absolute");
|
210
138
|
|
211
|
-
|
212
|
-
|
213
|
-
$(itemElement).mouseleave();
|
214
|
-
this.mouseentered = false;
|
215
|
-
$(itemElement).removeClass(o.hoveringClass);
|
216
|
-
this.hovering && window.clearTimeout(this.hovering);
|
217
|
-
this.hovering = null;
|
139
|
+
// mjs - find the top offset before rearrangement,
|
140
|
+
var previousTopOffset = this.placeholder.offset().top;
|
218
141
|
|
219
|
-
//
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
142
|
+
//Set the helper position
|
143
|
+
if(!this.options.axis || this.options.axis !== "y") {
|
144
|
+
this.helper[0].style.left = this.position.left+"px";
|
145
|
+
}
|
146
|
+
if(!this.options.axis || this.options.axis !== "x") {
|
147
|
+
this.helper[0].style.top = this.position.top+"px";
|
148
|
+
}
|
149
|
+
|
150
|
+
// mjs - check and reset hovering state at each cycle
|
151
|
+
this.hovering = this.hovering ? this.hovering : null;
|
152
|
+
this.mouseentered = this.mouseentered ? this.mouseentered : false;
|
153
|
+
|
154
|
+
// mjs - let's start caching some variables
|
155
|
+
var parentItem = (this.placeholder[0].parentNode.parentNode &&
|
156
|
+
$(this.placeholder[0].parentNode.parentNode).closest('.ui-sortable').length)
|
157
|
+
? $(this.placeholder[0].parentNode.parentNode)
|
158
|
+
: null,
|
159
|
+
level = this._getLevel(this.placeholder),
|
160
|
+
childLevels = this._getChildLevels(this.helper);
|
161
|
+
|
162
|
+
var newList = document.createElement(o.listType);
|
163
|
+
|
164
|
+
//Rearrange
|
165
|
+
for (i = this.items.length - 1; i >= 0; i--) {
|
166
|
+
|
167
|
+
//Cache variables and intersection, continue if no intersection
|
168
|
+
item = this.items[i];
|
169
|
+
itemElement = item.item[0];
|
170
|
+
intersection = this._intersectsWithPointer(item);
|
171
|
+
if (!intersection) {
|
172
|
+
continue;
|
173
|
+
}
|
228
174
|
|
229
|
-
|
230
|
-
|
231
|
-
|
175
|
+
// Only put the placeholder inside the current Container, skip all
|
176
|
+
// items form other containers. This works because when moving
|
177
|
+
// an item from one container to another the
|
178
|
+
// currentContainer is switched before the placeholder is moved.
|
179
|
+
//
|
180
|
+
// Without this moving items in "sub-sortables" can cause the placeholder to jitter
|
181
|
+
// beetween the outer and inner container.
|
182
|
+
if (item.instance !== this.currentContainer) {
|
183
|
+
continue;
|
232
184
|
}
|
233
185
|
|
234
|
-
|
235
|
-
|
236
|
-
|
186
|
+
// No action if intersected item is disabled
|
187
|
+
// and the element above or below in the direction we're going is also disabled
|
188
|
+
if (itemElement.className.indexOf(o.disabledClass) !== -1) {
|
189
|
+
// Note: intersection hardcoded direction values from jquery.ui.sortable.js:_intersectsWithPointer
|
190
|
+
if (intersection === 2) {
|
191
|
+
// Going down
|
192
|
+
var itemAfter = this.items[i + 1];
|
193
|
+
if (itemAfter && itemAfter.item[0].className.indexOf(o.disabledClass) !== -1){
|
194
|
+
continue;
|
195
|
+
}
|
196
|
+
|
197
|
+
}
|
198
|
+
else if (intersection === 1) {
|
199
|
+
// Going up
|
200
|
+
var itemBefore = this.items[i - 1];
|
201
|
+
if (itemBefore && itemBefore.item[0].className.indexOf(o.disabledClass) !== -1){
|
202
|
+
continue;
|
203
|
+
}
|
204
|
+
}
|
237
205
|
}
|
238
206
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
207
|
+
// cannot intersect with itself
|
208
|
+
// no useless actions that have been done before
|
209
|
+
// no action if the item moved is the parent of the item checked
|
210
|
+
if (itemElement !== this.currentItem[0] &&
|
211
|
+
this.placeholder[intersection === 1 ? "next" : "prev"]()[0] !== itemElement &&
|
212
|
+
!$.contains(this.placeholder[0], itemElement) &&
|
213
|
+
(this.options.type === "semi-dynamic" ? !$.contains(this.element[0], itemElement) : true)
|
214
|
+
) {
|
215
|
+
|
216
|
+
// mjs - we are intersecting an element: trigger the mouseenter event and store this state
|
217
|
+
if (!this.mouseentered) {
|
218
|
+
$(itemElement).mouseenter();
|
219
|
+
this.mouseentered = true;
|
220
|
+
}
|
221
|
+
|
222
|
+
// mjs - if the element has children and they are hidden, show them after a delay (CSS responsible)
|
223
|
+
if (o.isTree && $(itemElement).hasClass(o.collapsedClass) && o.expandOnHover) {
|
224
|
+
if (!this.hovering) {
|
225
|
+
$(itemElement).addClass(o.hoveringClass);
|
226
|
+
var self = this;
|
227
|
+
this.hovering = window.setTimeout(function() {
|
228
|
+
$(itemElement).removeClass(o.collapsedClass).addClass(o.expandedClass);
|
229
|
+
self.refreshPositions();
|
230
|
+
self._trigger("expand", event, self._uiHash());
|
231
|
+
}, o.expandOnHover);
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
this.direction = intersection == 1 ? "down" : "up";
|
236
|
+
|
237
|
+
// mjs - rearrange the elements and reset timeouts and hovering state
|
238
|
+
if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) {
|
239
|
+
$(itemElement).mouseleave();
|
240
|
+
this.mouseentered = false;
|
241
|
+
$(itemElement).removeClass(o.hoveringClass);
|
242
|
+
this.hovering && window.clearTimeout(this.hovering);
|
243
|
+
this.hovering = null;
|
244
|
+
|
245
|
+
// mjs - do not switch container if it's a root item and 'protectRoot' is true
|
246
|
+
// or if it's not a root item but we are trying to make it root
|
247
|
+
if (o.protectRoot
|
248
|
+
&& ! (this.currentItem[0].parentNode == this.element[0] // it's a root item
|
249
|
+
&& itemElement.parentNode != this.element[0]) // it's intersecting a non-root item
|
250
|
+
) {
|
251
|
+
if (this.currentItem[0].parentNode != this.element[0]
|
252
|
+
&& itemElement.parentNode == this.element[0]
|
253
|
+
) {
|
254
|
+
|
255
|
+
if ( ! $(itemElement).children(o.listType).length) {
|
256
|
+
itemElement.appendChild(newList);
|
257
|
+
o.isTree && $(itemElement).removeClass(o.leafClass).addClass(o.branchClass + ' ' + o.expandedClass);
|
258
|
+
}
|
259
|
+
|
260
|
+
var a = this.direction === "down" ? $(itemElement).prev().children(o.listType) : $(itemElement).children(o.listType);
|
261
|
+
if (a[0] !== undefined) {
|
262
|
+
this._rearrange(event, null, a);
|
263
|
+
}
|
264
|
+
|
265
|
+
} else {
|
266
|
+
this._rearrange(event, item);
|
267
|
+
}
|
268
|
+
} else if ( ! o.protectRoot) {
|
269
|
+
this._rearrange(event, item);
|
270
|
+
}
|
271
|
+
} else {
|
272
|
+
break;
|
273
|
+
}
|
274
|
+
|
275
|
+
// Clear emtpy ul's/ol's
|
276
|
+
this._clearEmpty(itemElement);
|
277
|
+
|
278
|
+
this._trigger("change", event, this._uiHash());
|
279
|
+
break;
|
280
|
+
}
|
244
281
|
}
|
245
|
-
} else {
|
246
|
-
break;
|
247
|
-
}
|
248
282
|
|
249
|
-
|
250
|
-
|
283
|
+
// mjs - to find the previous sibling in the list, keep backtracking until we hit a valid list item.
|
284
|
+
var previousItem = this.placeholder[0].previousSibling ? $(this.placeholder[0].previousSibling) : null;
|
285
|
+
if (previousItem != null) {
|
286
|
+
while (previousItem[0].nodeName.toLowerCase() != 'li' || previousItem[0].className.indexOf(o.disabledClass) !== -1 || previousItem[0] == this.currentItem[0] || previousItem[0] == this.helper[0]) {
|
287
|
+
if (previousItem[0].previousSibling) {
|
288
|
+
previousItem = $(previousItem[0].previousSibling);
|
289
|
+
} else {
|
290
|
+
previousItem = null;
|
291
|
+
break;
|
292
|
+
}
|
293
|
+
}
|
294
|
+
}
|
251
295
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
}
|
267
|
-
}
|
268
|
-
}
|
269
|
-
|
270
|
-
// mjs - to find the next sibling in the list, keep stepping forward until we hit a valid list item.
|
271
|
-
var nextItem = this.placeholder[0].nextSibling ? $(this.placeholder[0].nextSibling) : null;
|
272
|
-
if (nextItem != null) {
|
273
|
-
while (nextItem[0].nodeName.toLowerCase() != $(o.listType)[0].nodeName.toLowerCase() || nextItem[0] == this.currentItem[0] || nextItem[0] == this.helper[0]) {
|
274
|
-
if (nextItem[0].nextSibling) {
|
275
|
-
nextItem = $(nextItem[0].nextSibling);
|
276
|
-
} else {
|
277
|
-
nextItem = null;
|
278
|
-
break;
|
279
|
-
}
|
280
|
-
}
|
281
|
-
}
|
282
|
-
|
283
|
-
this.beyondMaxLevels = 0;
|
284
|
-
|
285
|
-
// mjs - if the item is moved to the left, send it one level up but only if it's at the bottom of the list
|
286
|
-
if (parentItem != null
|
287
|
-
&& nextItem == null
|
288
|
-
&& ! (o.protectRoot && parentItem[0].parentNode == this.element[0])
|
289
|
-
&&
|
290
|
-
(o.rtl && (this.positionAbs.left + this.helper.outerWidth() > parentItem.offset().left + parentItem.outerWidth())
|
291
|
-
|| ! o.rtl && (this.positionAbs.left < parentItem.offset().left))
|
292
|
-
) {
|
293
|
-
|
294
|
-
parentItem.after(this.placeholder[0]);
|
295
|
-
if (o.isTree && parentItem.children(o.listItem).children(o.listItem + ':visible:not(.ui-sortable-helper)').length < 1) {
|
296
|
-
parentItem.removeClass(this.options.branchClass + ' ' + this.options.expandedClass)
|
297
|
-
.addClass(this.options.leafClass);
|
298
|
-
}
|
299
|
-
this._clearEmpty(parentItem[0]);
|
300
|
-
this._trigger("change", event, this._uiHash());
|
301
|
-
}
|
302
|
-
// mjs - if the item is below a sibling and is moved to the right, make it a child of that sibling
|
303
|
-
else if (previousItem != null
|
304
|
-
&& ! previousItem.hasClass(o.disableNestingClass)
|
305
|
-
&&
|
306
|
-
(previousItem.children(o.listType).length && previousItem.children(o.listType).is(':visible')
|
307
|
-
|| ! previousItem.children(o.listType).length)
|
308
|
-
&& ! (o.protectRoot && this.currentItem[0].parentNode == this.element[0])
|
309
|
-
&&
|
310
|
-
(o.rtl && (this.positionAbs.left + this.helper.outerWidth() < previousItem.offset().left + previousItem.outerWidth() - o.tabSize)
|
311
|
-
|| ! o.rtl && (this.positionAbs.left > previousItem.offset().left + o.tabSize))
|
312
|
-
) {
|
313
|
-
|
314
|
-
this._isAllowed(previousItem, level, level+childLevels+1);
|
315
|
-
|
316
|
-
if (!previousItem.children(o.listType).length) {
|
317
|
-
previousItem[0].appendChild(newList);
|
318
|
-
o.isTree && previousItem.removeClass(o.leafClass).addClass(o.branchClass + ' ' + o.expandedClass);
|
319
|
-
}
|
296
|
+
// mjs - to find the next sibling in the list, keep stepping forward until we hit a valid list item.
|
297
|
+
var nextItem = this.placeholder[0].nextSibling ? $(this.placeholder[0].nextSibling) : null;
|
298
|
+
if (nextItem != null) {
|
299
|
+
while (nextItem[0].nodeName.toLowerCase() != 'li' || nextItem[0].className.indexOf(o.disabledClass) !== -1 || nextItem[0] == this.currentItem[0] || nextItem[0] == this.helper[0]) {
|
300
|
+
if (nextItem[0].nextSibling) {
|
301
|
+
nextItem = $(nextItem[0].nextSibling);
|
302
|
+
} else {
|
303
|
+
nextItem = null;
|
304
|
+
break;
|
305
|
+
}
|
306
|
+
}
|
307
|
+
}
|
308
|
+
|
309
|
+
this.beyondMaxLevels = 0;
|
320
310
|
|
321
|
-
// mjs - if
|
322
|
-
if (
|
323
|
-
|
311
|
+
// mjs - if the item is moved to the left, send it one level up but only if it's at the bottom of the list
|
312
|
+
if (parentItem != null
|
313
|
+
&& nextItem == null
|
314
|
+
&& ! (o.protectRoot && parentItem[0].parentNode == this.element[0])
|
315
|
+
&&
|
316
|
+
(o.rtl && (this.positionAbs.left + this.helper.outerWidth() > parentItem.offset().left + parentItem.outerWidth())
|
317
|
+
|| ! o.rtl && (this.positionAbs.left < parentItem.offset().left))
|
318
|
+
) {
|
319
|
+
|
320
|
+
parentItem.after(this.placeholder[0]);
|
321
|
+
if (o.isTree && parentItem.children(o.listItem).children('li:visible:not(.ui-sortable-helper)').length < 1) {
|
322
|
+
parentItem.removeClass(this.options.branchClass + ' ' + this.options.expandedClass)
|
323
|
+
.addClass(this.options.leafClass);
|
324
|
+
}
|
325
|
+
this._clearEmpty(parentItem[0]);
|
326
|
+
this._trigger("change", event, this._uiHash());
|
324
327
|
}
|
325
|
-
// mjs -
|
326
|
-
else if(previousItem
|
327
|
-
|
328
|
-
|
328
|
+
// mjs - if the item is below a sibling and is moved to the right, make it a child of that sibling
|
329
|
+
else if (previousItem != null
|
330
|
+
&& ! previousItem.hasClass(o.disableNestingClass)
|
331
|
+
&&
|
332
|
+
(previousItem.children(o.listType).length && previousItem.children(o.listType).is(':visible')
|
333
|
+
|| ! previousItem.children(o.listType).length)
|
334
|
+
&& ! (o.protectRoot && this.currentItem[0].parentNode == this.element[0])
|
335
|
+
&&
|
336
|
+
(o.rtl && (this.positionAbs.left + this.helper.outerWidth() < previousItem.offset().left + previousItem.outerWidth() - o.tabSize)
|
337
|
+
|| ! o.rtl && (this.positionAbs.left > previousItem.offset().left + o.tabSize))
|
338
|
+
) {
|
329
339
|
|
330
|
-
|
331
|
-
}
|
332
|
-
else {
|
333
|
-
this._isAllowed(parentItem, level, level+childLevels);
|
334
|
-
}
|
340
|
+
this._isAllowed(previousItem, level, level+childLevels+1);
|
335
341
|
|
336
|
-
|
337
|
-
|
342
|
+
if (!previousItem.children(o.listType).length) {
|
343
|
+
previousItem[0].appendChild(newList);
|
344
|
+
o.isTree && previousItem.removeClass(o.leafClass).addClass(o.branchClass + ' ' + o.expandedClass);
|
345
|
+
}
|
338
346
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
347
|
+
// mjs - if this item is being moved from the top, add it to the top of the list.
|
348
|
+
if (previousTopOffset && (previousTopOffset <= previousItem.offset().top)) {
|
349
|
+
previousItem.children(o.listType).prepend(this.placeholder);
|
350
|
+
}
|
351
|
+
// mjs - otherwise, add it to the bottom of the list.
|
352
|
+
else {
|
353
|
+
previousItem.children(o.listType)[0].appendChild(this.placeholder[0]);
|
354
|
+
}
|
343
355
|
|
344
|
-
|
345
|
-
|
356
|
+
this._trigger("change", event, this._uiHash());
|
357
|
+
}
|
358
|
+
else {
|
359
|
+
this._isAllowed(parentItem, level, level+childLevels);
|
360
|
+
}
|
346
361
|
|
347
|
-
|
348
|
-
|
362
|
+
//Post events to containers
|
363
|
+
this._contactContainers(event);
|
349
364
|
|
350
|
-
|
365
|
+
//Interconnect with droppables
|
366
|
+
if($.ui.ddmanager) {
|
367
|
+
$.ui.ddmanager.drag(this, event);
|
368
|
+
}
|
351
369
|
|
352
|
-
|
370
|
+
//Call callbacks
|
371
|
+
this._trigger('sort', event, this._uiHash());
|
353
372
|
|
354
|
-
|
355
|
-
|
373
|
+
this.lastPositionAbs = this.positionAbs;
|
374
|
+
return false;
|
356
375
|
|
357
|
-
|
376
|
+
},
|
358
377
|
|
359
|
-
|
360
|
-
$(this.domPosition.prev).after(this.placeholder);
|
361
|
-
} else {
|
362
|
-
$(this.domPosition.parent).prepend(this.placeholder);
|
363
|
-
}
|
378
|
+
_mouseStop: function(event, noPropagation) {
|
364
379
|
|
365
|
-
|
380
|
+
// mjs - if the item is in a position not allowed, send it back
|
381
|
+
if (this.beyondMaxLevels) {
|
366
382
|
|
367
|
-
|
383
|
+
this.placeholder.removeClass(this.options.errorClass);
|
368
384
|
|
385
|
+
if (this.domPosition.prev) {
|
386
|
+
$(this.domPosition.prev).after(this.placeholder);
|
387
|
+
} else {
|
388
|
+
$(this.domPosition.parent).prepend(this.placeholder);
|
389
|
+
}
|
369
390
|
|
370
|
-
|
371
|
-
$('.'+this.options.hoveringClass).mouseleave().removeClass(this.options.hoveringClass);
|
372
|
-
this.mouseentered = false;
|
373
|
-
this.hovering && window.clearTimeout(this.hovering);
|
374
|
-
this.hovering = null;
|
391
|
+
this._trigger("revert", event, this._uiHash());
|
375
392
|
|
376
|
-
|
393
|
+
}
|
377
394
|
|
378
|
-
},
|
379
395
|
|
380
|
-
|
381
|
-
|
396
|
+
// mjs - clear the hovering timeout, just to be sure
|
397
|
+
$('.'+this.options.hoveringClass).mouseleave().removeClass(this.options.hoveringClass);
|
398
|
+
this.mouseentered = false;
|
399
|
+
this.hovering && window.clearTimeout(this.hovering);
|
400
|
+
this.hovering = null;
|
382
401
|
|
383
|
-
|
402
|
+
$.ui.sortable.prototype._mouseStop.apply(this, arguments);
|
384
403
|
|
385
|
-
|
386
|
-
isOverTopHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top - (item.height*half), item.height),
|
387
|
-
isOverRightHalf = isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
|
388
|
-
verticalDirection = this._getDragVerticalDirection(),
|
389
|
-
horizontalDirection = this._getDragHorizontalDirection();
|
404
|
+
},
|
390
405
|
|
391
|
-
|
392
|
-
|
393
|
-
} else {
|
394
|
-
return verticalDirection && ((verticalDirection == "down" && isOverBottomHalf) || (verticalDirection == "up" && isOverTopHalf));
|
395
|
-
}
|
406
|
+
// mjs - this function is slightly modified to make it easier to hover over a collapsed element and have it expand
|
407
|
+
_intersectsWithSides: function(item) {
|
396
408
|
|
397
|
-
|
409
|
+
var half = this.options.isTree ? .8 : .5;
|
398
410
|
|
399
|
-
|
411
|
+
var isOverBottomHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height*half), item.height),
|
412
|
+
isOverTopHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top - (item.height*half), item.height),
|
413
|
+
isOverRightHalf = isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
|
414
|
+
verticalDirection = this._getDragVerticalDirection(),
|
415
|
+
horizontalDirection = this._getDragHorizontalDirection();
|
400
416
|
|
401
|
-
|
402
|
-
|
403
|
-
|
417
|
+
if (this.floating && horizontalDirection) {
|
418
|
+
return ((horizontalDirection == "right" && isOverRightHalf) || (horizontalDirection == "left" && !isOverRightHalf));
|
419
|
+
} else {
|
420
|
+
return verticalDirection && ((verticalDirection == "down" && isOverBottomHalf) || (verticalDirection == "up" && isOverTopHalf));
|
421
|
+
}
|
404
422
|
|
405
|
-
|
423
|
+
},
|
406
424
|
|
407
|
-
|
425
|
+
_contactContainers: function(event) {
|
408
426
|
|
409
|
-
|
427
|
+
if (this.options.protectRoot && this.currentItem[0].parentNode == this.element[0] ) {
|
428
|
+
return;
|
429
|
+
}
|
410
430
|
|
411
|
-
|
431
|
+
$.ui.sortable.prototype._contactContainers.apply(this, arguments);
|
412
432
|
|
413
|
-
|
414
|
-
for (var i = this.items.length - 1; i >= 0; i--) {
|
415
|
-
var item = this.items[i].item[0];
|
416
|
-
this._clearEmpty(item);
|
417
|
-
}
|
433
|
+
},
|
418
434
|
|
419
|
-
|
435
|
+
_clear: function(event, noPropagation) {
|
420
436
|
|
421
|
-
|
437
|
+
$.ui.sortable.prototype._clear.apply(this, arguments);
|
422
438
|
|
423
|
-
|
424
|
-
|
425
|
-
|
439
|
+
// mjs - clean last empty ul/ol
|
440
|
+
for (var i = this.items.length - 1; i >= 0; i--) {
|
441
|
+
var item = this.items[i].item[0];
|
442
|
+
this._clearEmpty(item);
|
443
|
+
}
|
426
444
|
|
427
|
-
|
428
|
-
var res = ($(o.item || this).attr(o.attribute || 'id') || '')
|
429
|
-
.match(o.expression || (/(.+)[-=_](.+)/)),
|
430
|
-
pid = ($(o.item || this).parent(o.listType)
|
431
|
-
.parent(o.items)
|
432
|
-
.attr(o.attribute || 'id') || '')
|
433
|
-
.match(o.expression || (/(.+)[-=_](.+)/));
|
445
|
+
},
|
434
446
|
|
435
|
-
|
436
|
-
str.push(((o.key || res[1]) + '[' + (o.key && o.expression ? res[1] : res[2]) + ']')
|
437
|
-
+ '='
|
438
|
-
+ (pid ? (o.key && o.expression ? pid[1] : pid[2]) : o.rootID));
|
439
|
-
}
|
440
|
-
});
|
447
|
+
serialize: function(options) {
|
441
448
|
|
442
|
-
|
443
|
-
|
444
|
-
|
449
|
+
var o = $.extend({}, this.options, options),
|
450
|
+
items = this._getItemsAsjQuery(o && o.connected),
|
451
|
+
str = [];
|
445
452
|
|
446
|
-
|
453
|
+
$(items).each(function() {
|
454
|
+
var res = ($(o.item || this).attr(o.attribute || 'id') || '')
|
455
|
+
.match(o.expression || (/(.+)[-=_](.+)/)),
|
456
|
+
pid = ($(o.item || this).parent(o.listType)
|
457
|
+
.parent(o.items)
|
458
|
+
.attr(o.attribute || 'id') || '')
|
459
|
+
.match(o.expression || (/(.+)[-=_](.+)/));
|
447
460
|
|
448
|
-
|
461
|
+
if (res) {
|
462
|
+
str.push(((o.key || res[1]) + '[' + (o.key && o.expression ? res[1] : res[2]) + ']')
|
463
|
+
+ '='
|
464
|
+
+ (pid ? (o.key && o.expression ? pid[1] : pid[2]) : o.rootID));
|
465
|
+
}
|
466
|
+
});
|
449
467
|
|
450
|
-
|
468
|
+
if(!str.length && o.key) {
|
469
|
+
str.push(o.key + '=');
|
470
|
+
}
|
451
471
|
|
452
|
-
|
453
|
-
sDepth = o.startDepthCount || 0,
|
454
|
-
ret = [];
|
472
|
+
return str.join('&');
|
455
473
|
|
456
|
-
|
457
|
-
var level = _recursiveItems(this);
|
458
|
-
ret.push(level);
|
459
|
-
});
|
474
|
+
},
|
460
475
|
|
461
|
-
|
476
|
+
toHierarchy: function(options) {
|
462
477
|
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
var level = _recursiveItems(this);
|
471
|
-
currentItem.children.push(level);
|
478
|
+
var o = $.extend({}, this.options, options),
|
479
|
+
sDepth = o.startDepthCount || 0,
|
480
|
+
ret = [];
|
481
|
+
|
482
|
+
$(this.element).children(o.items).each(function () {
|
483
|
+
var level = _recursiveItems(this);
|
484
|
+
ret.push(level);
|
472
485
|
});
|
473
|
-
}
|
474
|
-
return currentItem;
|
475
|
-
}
|
476
|
-
}
|
477
|
-
},
|
478
|
-
|
479
|
-
toArray: function(options) {
|
480
|
-
|
481
|
-
var o = $.extend({}, this.options, options),
|
482
|
-
sDepth = o.startDepthCount || 0,
|
483
|
-
ret = [],
|
484
|
-
left = 1;
|
485
|
-
|
486
|
-
if (!o.excludeRoot) {
|
487
|
-
ret.push({
|
488
|
-
"item_id": o.rootID,
|
489
|
-
"parent_id": null,
|
490
|
-
"depth": sDepth,
|
491
|
-
"left": left,
|
492
|
-
"right": ($(o.items, this.element).length + 1) * 2
|
493
|
-
});
|
494
|
-
left++
|
495
|
-
}
|
496
|
-
|
497
|
-
$(this.element).children(o.items).each(function () {
|
498
|
-
left = _recursiveArray(this, sDepth + 1, left);
|
499
|
-
});
|
500
|
-
|
501
|
-
ret = ret.sort(function(a,b){ return (a.left - b.left); });
|
502
|
-
|
503
|
-
return ret;
|
504
|
-
|
505
|
-
function _recursiveArray(item, depth, left) {
|
506
|
-
|
507
|
-
var right = left + 1,
|
508
|
-
id,
|
509
|
-
pid;
|
510
|
-
|
511
|
-
if ($(item).children(o.listType).children(o.items).length > 0) {
|
512
|
-
depth ++;
|
513
|
-
$(item).children(o.listType).children(o.items).each(function () {
|
514
|
-
right = _recursiveArray($(this), depth, right);
|
515
|
-
});
|
516
|
-
depth --;
|
517
|
-
}
|
518
486
|
|
519
|
-
|
487
|
+
return ret;
|
488
|
+
|
489
|
+
function _recursiveItems(item) {
|
490
|
+
var id = ($(item).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
|
491
|
+
if (id) {
|
492
|
+
var currentItem = {"id" : id[2]};
|
493
|
+
if ($(item).children(o.listType).children(o.items).length > 0) {
|
494
|
+
currentItem.children = [];
|
495
|
+
$(item).children(o.listType).children(o.items).each(function() {
|
496
|
+
var level = _recursiveItems(this);
|
497
|
+
currentItem.children.push(level);
|
498
|
+
});
|
499
|
+
}
|
500
|
+
return currentItem;
|
501
|
+
}
|
502
|
+
}
|
503
|
+
},
|
504
|
+
|
505
|
+
toArray: function(options) {
|
506
|
+
|
507
|
+
var o = $.extend({}, this.options, options),
|
508
|
+
sDepth = o.startDepthCount || 0,
|
509
|
+
ret = [],
|
510
|
+
left = 1;
|
511
|
+
|
512
|
+
if (!o.excludeRoot) {
|
513
|
+
ret.push({
|
514
|
+
"item_id": o.rootID,
|
515
|
+
"parent_id": null,
|
516
|
+
"depth": sDepth,
|
517
|
+
"left": left,
|
518
|
+
"right": ($(o.items, this.element).length + 1) * 2
|
519
|
+
});
|
520
|
+
left++
|
521
|
+
}
|
520
522
|
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
var parentItem = ($(item).parent(o.listType)
|
525
|
-
.parent(o.items)
|
526
|
-
.attr(o.attribute || 'id'))
|
527
|
-
.match(o.expression || (/(.+)[-=_](.+)/));
|
528
|
-
pid = parentItem[2];
|
529
|
-
}
|
523
|
+
$(this.element).children(o.items).each(function () {
|
524
|
+
left = _recursiveArray(this, sDepth + 1, left);
|
525
|
+
});
|
530
526
|
|
531
|
-
|
532
|
-
ret.push({"item_id": id[2], "parent_id": pid, "depth": depth, "left": left, "right": right});
|
533
|
-
}
|
527
|
+
ret = ret.sort(function(a,b){ return (a.left - b.left); });
|
534
528
|
|
535
|
-
|
536
|
-
return left;
|
537
|
-
}
|
529
|
+
return ret;
|
538
530
|
|
539
|
-
|
531
|
+
function _recursiveArray(item, depth, left) {
|
540
532
|
|
541
|
-
|
542
|
-
|
533
|
+
var right = left + 1,
|
534
|
+
id,
|
535
|
+
pid;
|
543
536
|
|
544
|
-
|
537
|
+
if ($(item).children(o.listType).children(o.items).length > 0) {
|
538
|
+
depth ++;
|
539
|
+
$(item).children(o.listType).children(o.items).each(function () {
|
540
|
+
right = _recursiveArray($(this), depth, right);
|
541
|
+
});
|
542
|
+
depth --;
|
543
|
+
}
|
545
544
|
|
546
|
-
|
547
|
-
o.isTree && $(item).removeClass(o.branchClass + ' ' + o.expandedClass).addClass(o.leafClass);
|
548
|
-
emptyList.remove();
|
549
|
-
} else if (o.isTree && emptyList.length && emptyList.children().length && emptyList.is(':visible')) {
|
550
|
-
$(item).removeClass(o.leafClass).addClass(o.branchClass + ' ' + o.expandedClass);
|
551
|
-
} else if (o.isTree && emptyList.length && emptyList.children().length && !emptyList.is(':visible')) {
|
552
|
-
$(item).removeClass(o.leafClass).addClass(o.branchClass + ' ' + o.collapsedClass);
|
553
|
-
}
|
545
|
+
id = ($(item).attr(o.attribute || 'id')).match(o.expression || (/(.+)[-=_](.+)/));
|
554
546
|
|
555
|
-
|
547
|
+
if (depth === sDepth + 1) {
|
548
|
+
pid = o.rootID;
|
549
|
+
} else {
|
550
|
+
var parentItem = ($(item).parent(o.listType)
|
551
|
+
.parent(o.items)
|
552
|
+
.attr(o.attribute || 'id'))
|
553
|
+
.match(o.expression || (/(.+)[-=_](.+)/));
|
554
|
+
pid = parentItem[2];
|
555
|
+
}
|
556
556
|
|
557
|
-
|
557
|
+
if (id) {
|
558
|
+
ret.push({"item_id": id[2], "parent_id": pid, "depth": depth, "left": left, "right": right});
|
559
|
+
}
|
558
560
|
|
559
|
-
|
561
|
+
left = right + 1;
|
562
|
+
return left;
|
563
|
+
}
|
560
564
|
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
565
|
+
},
|
566
|
+
|
567
|
+
_clearEmpty: function(item) {
|
568
|
+
var o = this.options;
|
569
|
+
|
570
|
+
var emptyList = $(item).children(o.listType);
|
571
|
+
|
572
|
+
if (emptyList.length && !emptyList.children().length && !o.doNotClear) {
|
573
|
+
o.isTree && $(item).removeClass(o.branchClass + ' ' + o.expandedClass).addClass(o.leafClass);
|
574
|
+
emptyList.remove();
|
575
|
+
} else if (o.isTree && emptyList.length && emptyList.children().length && emptyList.is(':visible')) {
|
576
|
+
$(item).removeClass(o.leafClass).addClass(o.branchClass + ' ' + o.expandedClass);
|
577
|
+
} else if (o.isTree && emptyList.length && emptyList.children().length && !emptyList.is(':visible')) {
|
578
|
+
$(item).removeClass(o.leafClass).addClass(o.branchClass + ' ' + o.collapsedClass);
|
579
|
+
}
|
580
|
+
|
581
|
+
},
|
582
|
+
|
583
|
+
_getLevel: function(item) {
|
584
|
+
|
585
|
+
var level = 1;
|
586
|
+
|
587
|
+
if (this.options.listType) {
|
588
|
+
var list = item.closest(this.options.listType);
|
589
|
+
while (list && list.length > 0 &&
|
590
|
+
!list.is('.ui-sortable')) {
|
591
|
+
level++;
|
592
|
+
list = list.parent().closest(this.options.listType);
|
593
|
+
}
|
594
|
+
}
|
595
|
+
|
596
|
+
return level;
|
597
|
+
},
|
598
|
+
|
599
|
+
_getChildLevels: function(parent, depth) {
|
600
|
+
var self = this,
|
601
|
+
o = this.options,
|
602
|
+
result = 0;
|
603
|
+
depth = depth || 0;
|
604
|
+
|
605
|
+
$(parent).children(o.listType).children(o.items).each(function (index, child) {
|
606
|
+
result = Math.max(self._getChildLevels(child, depth + 1), result);
|
607
|
+
});
|
608
|
+
|
609
|
+
return depth ? result + 1 : result;
|
610
|
+
},
|
611
|
+
|
612
|
+
_isAllowed: function(parentItem, level, levels) {
|
613
|
+
var o = this.options,
|
614
|
+
maxLevels = this.placeholder.closest('.ui-sortable').nestedSortable('option', 'maxLevels'); // this takes into account the maxLevels set to the recipient list
|
615
|
+
|
616
|
+
// mjs - is the root protected?
|
617
|
+
// mjs - are we nesting too deep?
|
618
|
+
if ( ! o.isAllowed(this.placeholder, parentItem, this.currentItem)) {
|
619
|
+
this.placeholder.addClass(o.errorClass);
|
620
|
+
if (maxLevels < levels && maxLevels != 0) {
|
621
|
+
this.beyondMaxLevels = levels - maxLevels;
|
622
|
+
} else {
|
623
|
+
this.beyondMaxLevels = 1;
|
624
|
+
}
|
625
|
+
} else {
|
626
|
+
if (maxLevels < levels && maxLevels != 0) {
|
627
|
+
this.placeholder.addClass(o.errorClass);
|
628
|
+
this.beyondMaxLevels = levels - maxLevels;
|
629
|
+
} else {
|
630
|
+
this.placeholder.removeClass(o.errorClass);
|
631
|
+
this.beyondMaxLevels = 0;
|
632
|
+
}
|
633
|
+
}
|
606
634
|
}
|
607
|
-
}
|
608
|
-
}
|
609
635
|
|
610
|
-
|
636
|
+
}));
|
611
637
|
|
612
|
-
|
613
|
-
})(jQuery);
|
638
|
+
$.mjs.nestedSortable.prototype.options = $.extend({}, $.ui.sortable.prototype.options, $.mjs.nestedSortable.prototype.options);
|
639
|
+
})(jQuery);
|
@@ -86,6 +86,9 @@
|
|
86
86
|
min-height: 30px;
|
87
87
|
background: #f2fbff;
|
88
88
|
border: 1px dashed #b6bcbf;
|
89
|
+
&.mjs-nestedSortable-error {
|
90
|
+
border: 1px solid red;
|
91
|
+
}
|
89
92
|
}
|
90
93
|
|
91
94
|
.dd3-content {
|
@@ -179,6 +182,7 @@
|
|
179
182
|
|
180
183
|
#rails_admin_nestable {
|
181
184
|
position: relative;
|
185
|
+
margin-bottom: 100px;
|
182
186
|
}
|
183
187
|
|
184
188
|
.nestable-flash {
|
@@ -53,7 +53,7 @@ module RailsAdminNestedSet
|
|
53
53
|
children = tree.select{|elem| elem.parent_id == node.id}
|
54
54
|
output = content_tag(:div, output)
|
55
55
|
if children.any?
|
56
|
-
|
56
|
+
output += content_tag(:ol, rails_admin_nested_set_builder(children, tree), class: 'dd-list')
|
57
57
|
end
|
58
58
|
|
59
59
|
output
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_admin_nested_set
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gleb Tv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Rails admin nested set
|
14
14
|
email:
|