rails_admin_nested_set 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eaca614b321bd75f019961125d72f029934c634c
4
- data.tar.gz: 9b7a9a427601f078c45af3463f93c18f5147ff25
3
+ metadata.gz: 0a4a55e99dae219aafadeda6117da3f3770825ad
4
+ data.tar.gz: fc9288e602c3e15cb01ba5f45726d154e64da934
5
5
  SHA512:
6
- metadata.gz: c6c0547158f84e74c8d6d3011fe6873603343b5bb772a43cccb235e0226ba4fca676cf8e0c88d8d4f9f57b8023c09ed9685623d8967ce7431036e57990f23788
7
- data.tar.gz: aab28c14ec9e03696cf0b52b6b517462481b1fb255274087daca047d7d7f781ae0c92bbd129d1a1c7afdb6078f0ebbca764832a304cd07c125937cac7c5b37f9
6
+ metadata.gz: 5b856a13acbd8d25fbd92dc20ddaacd8a59f8be40cc559a8ee650499df16b6b122ab571f7a91834da8a5c1bb5d868e0c197d2462f39083da48bffc63f71d1b1e
7
+ data.tar.gz: c55759046b21fe3f835923f4b39f65e12f038f0cf37b639a23b3b23acbe24169edf5e2ce6995fe7ea1269b110acc40c76cb4737ccc848bf810ff10f402e613fd
@@ -13,601 +13,627 @@
13
13
 
14
14
  (function($) {
15
15
 
16
- function isOverAxis( x, reference, size ) {
17
- return ( x > reference ) && ( x < ( reference + size ) );
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
- if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
128
- $.ui.ddmanager.prepareOffsets(this, event);
129
- }
130
-
131
- //Regenerate the absolute position used for position checks
132
- this.positionAbs = this._convertPositionTo("absolute");
133
-
134
- // mjs - find the top offset before rearrangement,
135
- var previousTopOffset = this.placeholder.offset().top;
136
-
137
- //Set the helper position
138
- if(!this.options.axis || this.options.axis !== "y") {
139
- this.helper[0].style.left = this.position.left+"px";
140
- }
141
- if(!this.options.axis || this.options.axis !== "x") {
142
- this.helper[0].style.top = this.position.top+"px";
143
- }
144
-
145
- // mjs - check and reset hovering state at each cycle
146
- this.hovering = this.hovering ? this.hovering : null;
147
- this.mouseentered = this.mouseentered ? this.mouseentered : false;
148
-
149
- // mjs - let's start caching some variables
150
- var parentItem = (this.placeholder[0].parentNode.parentNode &&
151
- $(this.placeholder[0].parentNode.parentNode).closest('.ui-sortable').length)
152
- ? $(this.placeholder[0].parentNode.parentNode)
153
- : null,
154
- level = this._getLevel(this.placeholder),
155
- childLevels = this._getChildLevels(this.helper);
156
-
157
- var newList = document.createElement(o.listType);
158
-
159
- //Rearrange
160
- for (i = this.items.length - 1; i >= 0; i--) {
161
-
162
- //Cache variables and intersection, continue if no intersection
163
- item = this.items[i];
164
- itemElement = item.item[0];
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
- // Only put the placeholder inside the current Container, skip all
171
- // items form other containers. This works because when moving
172
- // an item from one container to another the
173
- // currentContainer is switched before the placeholder is moved.
174
- //
175
- // Without this moving items in "sub-sortables" can cause the placeholder to jitter
176
- // beetween the outer and inner container.
177
- if (item.instance !== this.currentContainer) {
178
- continue;
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
- // cannot intersect with itself
182
- // no useless actions that have been done before
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
- this.direction = intersection == 1 ? "down" : "up";
136
+ //Regenerate the absolute position used for position checks
137
+ this.positionAbs = this._convertPositionTo("absolute");
210
138
 
211
- // mjs - rearrange the elements and reset timeouts and hovering state
212
- if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) {
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
- // mjs - do not switch container if it's a root item and 'protectRoot' is true
220
- // or if it's not a root item but we are trying to make it root
221
- if (o.protectRoot
222
- && ! (this.currentItem[0].parentNode == this.element[0] // it's a root item
223
- && itemElement.parentNode != this.element[0]) // it's intersecting a non-root item
224
- ) {
225
- if (this.currentItem[0].parentNode != this.element[0]
226
- && itemElement.parentNode == this.element[0]
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
- if ( ! $(itemElement).children(o.listType).length) {
230
- itemElement.appendChild(newList);
231
- o.isTree && $(itemElement).removeClass(o.leafClass).addClass(o.branchClass + ' ' + o.expandedClass);
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
- var a = this.direction === "down" ? $(itemElement).prev().children(o.listType) : $(itemElement).children(o.listType);
235
- if (a[0] !== undefined) {
236
- this._rearrange(event, null, a);
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
- } else {
240
- this._rearrange(event, item);
241
- }
242
- } else if ( ! o.protectRoot) {
243
- this._rearrange(event, item);
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
- // Clear emtpy ul's/ol's
250
- this._clearEmpty(itemElement);
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
- this._trigger("change", event, this._uiHash());
253
- break;
254
- }
255
- }
256
-
257
- // mjs - to find the previous sibling in the list, keep backtracking until we hit a valid list item.
258
- var previousItem = this.placeholder[0].previousSibling ? $(this.placeholder[0].previousSibling) : null;
259
- if (previousItem != null) {
260
- while (previousItem[0].nodeName.toLowerCase() != $(o.listType)[0].nodeName.toLowerCase() || previousItem[0] == this.currentItem[0] || previousItem[0] == this.helper[0]) {
261
- if (previousItem[0].previousSibling) {
262
- previousItem = $(previousItem[0].previousSibling);
263
- } else {
264
- previousItem = null;
265
- break;
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 this item is being moved from the top, add it to the top of the list.
322
- if (previousTopOffset && (previousTopOffset <= previousItem.offset().top)) {
323
- previousItem.children(o.listType).prepend(this.placeholder);
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 - otherwise, add it to the bottom of the list.
326
- else if(previousItem.children(o.listType).length) {
327
- previousItem.children(o.listType)[0].appendChild(this.placeholder[0]);
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
- this._trigger("change", event, this._uiHash());
331
- }
332
- else {
333
- this._isAllowed(parentItem, level, level+childLevels);
334
- }
340
+ this._isAllowed(previousItem, level, level+childLevels+1);
335
341
 
336
- //Post events to containers
337
- this._contactContainers(event);
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
- //Interconnect with droppables
340
- if($.ui.ddmanager) {
341
- $.ui.ddmanager.drag(this, event);
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
- //Call callbacks
345
- this._trigger('sort', event, this._uiHash());
356
+ this._trigger("change", event, this._uiHash());
357
+ }
358
+ else {
359
+ this._isAllowed(parentItem, level, level+childLevels);
360
+ }
346
361
 
347
- this.lastPositionAbs = this.positionAbs;
348
- return false;
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
- _mouseStop: function(event, noPropagation) {
370
+ //Call callbacks
371
+ this._trigger('sort', event, this._uiHash());
353
372
 
354
- // mjs - if the item is in a position not allowed, send it back
355
- if (this.beyondMaxLevels) {
373
+ this.lastPositionAbs = this.positionAbs;
374
+ return false;
356
375
 
357
- this.placeholder.removeClass(this.options.errorClass);
376
+ },
358
377
 
359
- if (this.domPosition.prev) {
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
- this._trigger("revert", event, this._uiHash());
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
- // mjs - clear the hovering timeout, just to be sure
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
- $.ui.sortable.prototype._mouseStop.apply(this, arguments);
393
+ }
377
394
 
378
- },
379
395
 
380
- // mjs - this function is slightly modified to make it easier to hover over a collapsed element and have it expand
381
- _intersectsWithSides: function(item) {
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
- var half = this.options.isTree ? .8 : .5;
402
+ $.ui.sortable.prototype._mouseStop.apply(this, arguments);
384
403
 
385
- var isOverBottomHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height*half), item.height),
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
- if (this.floating && horizontalDirection) {
392
- return ((horizontalDirection == "right" && isOverRightHalf) || (horizontalDirection == "left" && !isOverRightHalf));
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
- _contactContainers: function(event) {
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
- if (this.options.protectRoot && this.currentItem[0].parentNode == this.element[0] ) {
402
- return;
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
- $.ui.sortable.prototype._contactContainers.apply(this, arguments);
423
+ },
406
424
 
407
- },
425
+ _contactContainers: function(event) {
408
426
 
409
- _clear: function(event, noPropagation) {
427
+ if (this.options.protectRoot && this.currentItem[0].parentNode == this.element[0] ) {
428
+ return;
429
+ }
410
430
 
411
- $.ui.sortable.prototype._clear.apply(this, arguments);
431
+ $.ui.sortable.prototype._contactContainers.apply(this, arguments);
412
432
 
413
- // mjs - clean last empty ul/ol
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
- serialize: function(options) {
437
+ $.ui.sortable.prototype._clear.apply(this, arguments);
422
438
 
423
- var o = $.extend({}, this.options, options),
424
- items = this._getItemsAsjQuery(o && o.connected),
425
- str = [];
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
- $(items).each(function() {
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
- if (res) {
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
- if(!str.length && o.key) {
443
- str.push(o.key + '=');
444
- }
449
+ var o = $.extend({}, this.options, options),
450
+ items = this._getItemsAsjQuery(o && o.connected),
451
+ str = [];
445
452
 
446
- return str.join('&');
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
- toHierarchy: function(options) {
468
+ if(!str.length && o.key) {
469
+ str.push(o.key + '=');
470
+ }
451
471
 
452
- var o = $.extend({}, this.options, options),
453
- sDepth = o.startDepthCount || 0,
454
- ret = [];
472
+ return str.join('&');
455
473
 
456
- $(this.element).children(o.items).each(function () {
457
- var level = _recursiveItems(this);
458
- ret.push(level);
459
- });
474
+ },
460
475
 
461
- return ret;
476
+ toHierarchy: function(options) {
462
477
 
463
- function _recursiveItems(item) {
464
- var id = ($(item).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
465
- if (id) {
466
- var currentItem = {"id" : id[2]};
467
- if ($(item).children(o.listType).children(o.items).length > 0) {
468
- currentItem.children = [];
469
- $(item).children(o.listType).children(o.items).each(function() {
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
- id = ($(item).attr(o.attribute || 'id')).match(o.expression || (/(.+)[-=_](.+)/));
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
- if (depth === sDepth + 1) {
522
- pid = o.rootID;
523
- } else {
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
- if (id) {
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
- left = right + 1;
536
- return left;
537
- }
529
+ return ret;
538
530
 
539
- },
531
+ function _recursiveArray(item, depth, left) {
540
532
 
541
- _clearEmpty: function(item) {
542
- var o = this.options;
533
+ var right = left + 1,
534
+ id,
535
+ pid;
543
536
 
544
- var emptyList = $(item).children(o.listType);
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
- if (emptyList.length && !emptyList.children().length && !o.doNotClear) {
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
- _getLevel: function(item) {
557
+ if (id) {
558
+ ret.push({"item_id": id[2], "parent_id": pid, "depth": depth, "left": left, "right": right});
559
+ }
558
560
 
559
- var level = 1;
561
+ left = right + 1;
562
+ return left;
563
+ }
560
564
 
561
- if (this.options.listType) {
562
- var list = item.closest(this.options.listType);
563
- while (list && list.length > 0 &&
564
- !list.is('.ui-sortable')) {
565
- level++;
566
- list = list.parent().closest(this.options.listType);
567
- }
568
- }
569
-
570
- return level;
571
- },
572
-
573
- _getChildLevels: function(parent, depth) {
574
- var self = this,
575
- o = this.options,
576
- result = 0;
577
- depth = depth || 0;
578
-
579
- $(parent).children(o.listType).children(o.items).each(function (index, child) {
580
- result = Math.max(self._getChildLevels(child, depth + 1), result);
581
- });
582
-
583
- return depth ? result + 1 : result;
584
- },
585
-
586
- _isAllowed: function(parentItem, level, levels) {
587
- var o = this.options,
588
- maxLevels = this.placeholder.closest('.ui-sortable').nestedSortable('option', 'maxLevels'); // this takes into account the maxLevels set to the recipient list
589
-
590
- // mjs - is the root protected?
591
- // mjs - are we nesting too deep?
592
- if ( ! o.isAllowed(this.placeholder, parentItem, this.currentItem)) {
593
- this.placeholder.addClass(o.errorClass);
594
- if (maxLevels < levels && maxLevels != 0) {
595
- this.beyondMaxLevels = levels - maxLevels;
596
- } else {
597
- this.beyondMaxLevels = 1;
598
- }
599
- } else {
600
- if (maxLevels < levels && maxLevels != 0) {
601
- this.placeholder.addClass(o.errorClass);
602
- this.beyondMaxLevels = levels - maxLevels;
603
- } else {
604
- this.placeholder.removeClass(o.errorClass);
605
- this.beyondMaxLevels = 0;
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
- $.mjs.nestedSortable.prototype.options = $.extend({}, $.ui.sortable.prototype.options, $.mjs.nestedSortable.prototype.options);
613
- })(jQuery);
638
+ $.mjs.nestedSortable.prototype.options = $.extend({}, $.ui.sortable.prototype.options, $.mjs.nestedSortable.prototype.options);
639
+ })(jQuery);
@@ -12,7 +12,6 @@ window.rails_admin_nested_set = (tree_config) ->
12
12
  $ ->
13
13
  $("#" + tree_config["id"]).nestedSortable
14
14
  handle: '.dd-handle',
15
- #helper: "clone"
16
15
  items: ".dd-item"
17
16
  maxLevels: tree_config["max_depth"]
18
17
  placeholder: "dd-placeholder"
@@ -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
- output += content_tag(:ol, rails_admin_nested_set_builder(children, tree), class: 'dd-list')
56
+ output += content_tag(:ol, rails_admin_nested_set_builder(children, tree), class: 'dd-list')
57
57
  end
58
58
 
59
59
  output
@@ -1,3 +1,3 @@
1
1
  module RailsAdminNestedSet
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
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.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-02-26 00:00:00.000000000 Z
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rails admin nested set
14
14
  email: