activa 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
data/lib/activa/version.rb
CHANGED
@@ -0,0 +1,427 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery UI Nested Sortable
|
3
|
+
* v 1.3.5 / 21 jun 2012
|
4
|
+
* http://mjsarfatti.com/code/nestedSortable
|
5
|
+
*
|
6
|
+
* Depends on:
|
7
|
+
* jquery.ui.sortable.js 1.8+
|
8
|
+
*
|
9
|
+
* Copyright (c) 2010-2012 Manuele J Sarfatti
|
10
|
+
* Licensed under the MIT License
|
11
|
+
* http://www.opensource.org/licenses/mit-license.php
|
12
|
+
*/
|
13
|
+
|
14
|
+
(function($) {
|
15
|
+
|
16
|
+
$.widget("mjs.nestedSortable", $.extend({}, $.ui.sortable.prototype, {
|
17
|
+
|
18
|
+
options: {
|
19
|
+
tabSize: 20,
|
20
|
+
disableNesting: 'mjs-nestedSortable-no-nesting',
|
21
|
+
errorClass: 'mjs-nestedSortable-error',
|
22
|
+
doNotClear: false,
|
23
|
+
listType: 'ol',
|
24
|
+
maxLevels: 0,
|
25
|
+
protectRoot: false,
|
26
|
+
rootID: null,
|
27
|
+
rtl: false,
|
28
|
+
isAllowed: function(item, parent) { return true; }
|
29
|
+
},
|
30
|
+
|
31
|
+
_create: function() {
|
32
|
+
this.element.data('sortable', this.element.data('nestedSortable'));
|
33
|
+
|
34
|
+
if (!this.element.is(this.options.listType))
|
35
|
+
throw new Error('nestedSortable: Please check the listType option is set to your actual list type');
|
36
|
+
|
37
|
+
return $.ui.sortable.prototype._create.apply(this, arguments);
|
38
|
+
},
|
39
|
+
|
40
|
+
destroy: function() {
|
41
|
+
this.element
|
42
|
+
.removeData("nestedSortable")
|
43
|
+
.unbind(".nestedSortable");
|
44
|
+
return $.ui.sortable.prototype.destroy.apply(this, arguments);
|
45
|
+
},
|
46
|
+
|
47
|
+
_mouseDrag: function(event) {
|
48
|
+
|
49
|
+
//Compute the helpers position
|
50
|
+
this.position = this._generatePosition(event);
|
51
|
+
this.positionAbs = this._convertPositionTo("absolute");
|
52
|
+
|
53
|
+
if (!this.lastPositionAbs) {
|
54
|
+
this.lastPositionAbs = this.positionAbs;
|
55
|
+
}
|
56
|
+
|
57
|
+
//Do scrolling
|
58
|
+
if(this.options.scroll) {
|
59
|
+
var o = this.options, scrolled = false;
|
60
|
+
if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') {
|
61
|
+
|
62
|
+
if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
|
63
|
+
this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
|
64
|
+
else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity)
|
65
|
+
this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
|
66
|
+
|
67
|
+
if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity)
|
68
|
+
this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
|
69
|
+
else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity)
|
70
|
+
this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
|
71
|
+
|
72
|
+
} else {
|
73
|
+
|
74
|
+
if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
|
75
|
+
scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
|
76
|
+
else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
|
77
|
+
scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
|
78
|
+
|
79
|
+
if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
|
80
|
+
scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
|
81
|
+
else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
|
82
|
+
scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
|
83
|
+
|
84
|
+
}
|
85
|
+
|
86
|
+
if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
|
87
|
+
$.ui.ddmanager.prepareOffsets(this, event);
|
88
|
+
}
|
89
|
+
|
90
|
+
//Regenerate the absolute position used for position checks
|
91
|
+
this.positionAbs = this._convertPositionTo("absolute");
|
92
|
+
|
93
|
+
// Find the top offset before rearrangement,
|
94
|
+
var previousTopOffset = this.placeholder.offset().top;
|
95
|
+
|
96
|
+
//Set the helper position
|
97
|
+
if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
|
98
|
+
if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
|
99
|
+
|
100
|
+
//Rearrange
|
101
|
+
for (var i = this.items.length - 1; i >= 0; i--) {
|
102
|
+
|
103
|
+
//Cache variables and intersection, continue if no intersection
|
104
|
+
var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item);
|
105
|
+
if (!intersection) continue;
|
106
|
+
|
107
|
+
if(itemElement != this.currentItem[0] //cannot intersect with itself
|
108
|
+
&& this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before
|
109
|
+
&& !$.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked
|
110
|
+
&& (this.options.type == 'semi-dynamic' ? !$.contains(this.element[0], itemElement) : true)
|
111
|
+
//&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container
|
112
|
+
) {
|
113
|
+
|
114
|
+
$(itemElement).mouseenter();
|
115
|
+
|
116
|
+
this.direction = intersection == 1 ? "down" : "up";
|
117
|
+
|
118
|
+
if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) {
|
119
|
+
$(itemElement).mouseleave();
|
120
|
+
this._rearrange(event, item);
|
121
|
+
} else {
|
122
|
+
break;
|
123
|
+
}
|
124
|
+
|
125
|
+
// Clear emtpy ul's/ol's
|
126
|
+
this._clearEmpty(itemElement);
|
127
|
+
|
128
|
+
this._trigger("change", event, this._uiHash());
|
129
|
+
break;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
var parentItem = (this.placeholder[0].parentNode.parentNode &&
|
134
|
+
$(this.placeholder[0].parentNode.parentNode).closest('.ui-sortable').length)
|
135
|
+
? $(this.placeholder[0].parentNode.parentNode)
|
136
|
+
: null,
|
137
|
+
level = this._getLevel(this.placeholder),
|
138
|
+
childLevels = this._getChildLevels(this.helper);
|
139
|
+
|
140
|
+
// To find the previous sibling in the list, keep backtracking until we hit a valid list item.
|
141
|
+
var previousItem = this.placeholder[0].previousSibling ? $(this.placeholder[0].previousSibling) : null;
|
142
|
+
if (previousItem != null) {
|
143
|
+
while (previousItem[0].nodeName.toLowerCase() != 'li' || previousItem[0] == this.currentItem[0] || previousItem[0] == this.helper[0]) {
|
144
|
+
if (previousItem[0].previousSibling) {
|
145
|
+
previousItem = $(previousItem[0].previousSibling);
|
146
|
+
} else {
|
147
|
+
previousItem = null;
|
148
|
+
break;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
// To find the next sibling in the list, keep stepping forward until we hit a valid list item.
|
154
|
+
var nextItem = this.placeholder[0].nextSibling ? $(this.placeholder[0].nextSibling) : null;
|
155
|
+
if (nextItem != null) {
|
156
|
+
while (nextItem[0].nodeName.toLowerCase() != 'li' || nextItem[0] == this.currentItem[0] || nextItem[0] == this.helper[0]) {
|
157
|
+
if (nextItem[0].nextSibling) {
|
158
|
+
nextItem = $(nextItem[0].nextSibling);
|
159
|
+
} else {
|
160
|
+
nextItem = null;
|
161
|
+
break;
|
162
|
+
}
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
var newList = document.createElement(o.listType);
|
167
|
+
|
168
|
+
this.beyondMaxLevels = 0;
|
169
|
+
|
170
|
+
// If the item is moved to the left, send it to its parent's level unless there are siblings below it.
|
171
|
+
if (parentItem != null && nextItem == null &&
|
172
|
+
(o.rtl && (this.positionAbs.left + this.helper.outerWidth() > parentItem.offset().left + parentItem.outerWidth()) ||
|
173
|
+
!o.rtl && (this.positionAbs.left < parentItem.offset().left))) {
|
174
|
+
parentItem.after(this.placeholder[0]);
|
175
|
+
this._clearEmpty(parentItem[0]);
|
176
|
+
this._trigger("change", event, this._uiHash());
|
177
|
+
}
|
178
|
+
// If the item is below a sibling and is moved to the right, make it a child of that sibling.
|
179
|
+
else if (previousItem != null &&
|
180
|
+
(o.rtl && (this.positionAbs.left + this.helper.outerWidth() < previousItem.offset().left + previousItem.outerWidth() - o.tabSize) ||
|
181
|
+
!o.rtl && (this.positionAbs.left > previousItem.offset().left + o.tabSize))) {
|
182
|
+
this._isAllowed(previousItem, level, level+childLevels+1);
|
183
|
+
if (!previousItem.children(o.listType).length) {
|
184
|
+
previousItem[0].appendChild(newList);
|
185
|
+
}
|
186
|
+
// If this item is being moved from the top, add it to the top of the list.
|
187
|
+
if (previousTopOffset && (previousTopOffset <= previousItem.offset().top)) {
|
188
|
+
previousItem.children(o.listType).prepend(this.placeholder);
|
189
|
+
}
|
190
|
+
// Otherwise, add it to the bottom of the list.
|
191
|
+
else {
|
192
|
+
previousItem.children(o.listType)[0].appendChild(this.placeholder[0]);
|
193
|
+
}
|
194
|
+
this._trigger("change", event, this._uiHash());
|
195
|
+
}
|
196
|
+
else {
|
197
|
+
this._isAllowed(parentItem, level, level+childLevels);
|
198
|
+
}
|
199
|
+
|
200
|
+
//Post events to containers
|
201
|
+
this._contactContainers(event);
|
202
|
+
|
203
|
+
//Interconnect with droppables
|
204
|
+
if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
|
205
|
+
|
206
|
+
//Call callbacks
|
207
|
+
this._trigger('sort', event, this._uiHash());
|
208
|
+
|
209
|
+
this.lastPositionAbs = this.positionAbs;
|
210
|
+
return false;
|
211
|
+
|
212
|
+
},
|
213
|
+
|
214
|
+
_mouseStop: function(event, noPropagation) {
|
215
|
+
|
216
|
+
// If the item is in a position not allowed, send it back
|
217
|
+
if (this.beyondMaxLevels) {
|
218
|
+
|
219
|
+
this.placeholder.removeClass(this.options.errorClass);
|
220
|
+
|
221
|
+
if (this.domPosition.prev) {
|
222
|
+
$(this.domPosition.prev).after(this.placeholder);
|
223
|
+
} else {
|
224
|
+
$(this.domPosition.parent).prepend(this.placeholder);
|
225
|
+
}
|
226
|
+
|
227
|
+
this._trigger("revert", event, this._uiHash());
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
// Clean last empty ul/ol
|
232
|
+
for (var i = this.items.length - 1; i >= 0; i--) {
|
233
|
+
var item = this.items[i].item[0];
|
234
|
+
this._clearEmpty(item);
|
235
|
+
}
|
236
|
+
|
237
|
+
$.ui.sortable.prototype._mouseStop.apply(this, arguments);
|
238
|
+
|
239
|
+
},
|
240
|
+
|
241
|
+
serialize: function(options) {
|
242
|
+
|
243
|
+
var o = $.extend({}, this.options, options),
|
244
|
+
items = this._getItemsAsjQuery(o && o.connected),
|
245
|
+
str = [];
|
246
|
+
|
247
|
+
$(items).each(function() {
|
248
|
+
var res = ($(o.item || this).attr(o.attribute || 'id') || '')
|
249
|
+
.match(o.expression || (/(.+)[-=_](.+)/)),
|
250
|
+
pid = ($(o.item || this).parent(o.listType)
|
251
|
+
.parent(o.items)
|
252
|
+
.attr(o.attribute || 'id') || '')
|
253
|
+
.match(o.expression || (/(.+)[-=_](.+)/));
|
254
|
+
|
255
|
+
if (res) {
|
256
|
+
str.push(((o.key || res[1]) + '[' + (o.key && o.expression ? res[1] : res[2]) + ']')
|
257
|
+
+ '='
|
258
|
+
+ (pid ? (o.key && o.expression ? pid[1] : pid[2]) : o.rootID));
|
259
|
+
}
|
260
|
+
});
|
261
|
+
|
262
|
+
if(!str.length && o.key) {
|
263
|
+
str.push(o.key + '=');
|
264
|
+
}
|
265
|
+
|
266
|
+
return str.join('&');
|
267
|
+
|
268
|
+
},
|
269
|
+
|
270
|
+
toHierarchy: function(options) {
|
271
|
+
|
272
|
+
var o = $.extend({}, this.options, options),
|
273
|
+
sDepth = o.startDepthCount || 0,
|
274
|
+
ret = [];
|
275
|
+
|
276
|
+
$(this.element).children(o.items).each(function () {
|
277
|
+
var level = _recursiveItems(this);
|
278
|
+
ret.push(level);
|
279
|
+
});
|
280
|
+
|
281
|
+
return ret;
|
282
|
+
|
283
|
+
function _recursiveItems(item) {
|
284
|
+
var id = ($(item).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
|
285
|
+
if (id) {
|
286
|
+
var currentItem = {"id" : id[2]};
|
287
|
+
if ($(item).children(o.listType).children(o.items).length > 0) {
|
288
|
+
currentItem.children = [];
|
289
|
+
$(item).children(o.listType).children(o.items).each(function() {
|
290
|
+
var level = _recursiveItems(this);
|
291
|
+
currentItem.children.push(level);
|
292
|
+
});
|
293
|
+
}
|
294
|
+
return currentItem;
|
295
|
+
}
|
296
|
+
}
|
297
|
+
},
|
298
|
+
|
299
|
+
toArray: function(options) {
|
300
|
+
|
301
|
+
var o = $.extend({}, this.options, options),
|
302
|
+
sDepth = o.startDepthCount || 0,
|
303
|
+
ret = [],
|
304
|
+
left = 2;
|
305
|
+
|
306
|
+
ret.push({
|
307
|
+
"item_id": o.rootID,
|
308
|
+
"parent_id": 'none',
|
309
|
+
"depth": sDepth,
|
310
|
+
"left": '1',
|
311
|
+
"right": ($(o.items, this.element).length + 1) * 2
|
312
|
+
});
|
313
|
+
|
314
|
+
$(this.element).children(o.items).each(function () {
|
315
|
+
left = _recursiveArray(this, sDepth + 1, left);
|
316
|
+
});
|
317
|
+
|
318
|
+
ret = ret.sort(function(a,b){ return (a.left - b.left); });
|
319
|
+
|
320
|
+
return ret;
|
321
|
+
|
322
|
+
function _recursiveArray(item, depth, left) {
|
323
|
+
|
324
|
+
var right = left + 1,
|
325
|
+
id,
|
326
|
+
pid;
|
327
|
+
|
328
|
+
if ($(item).children(o.listType).children(o.items).length > 0) {
|
329
|
+
depth ++;
|
330
|
+
$(item).children(o.listType).children(o.items).each(function () {
|
331
|
+
right = _recursiveArray($(this), depth, right);
|
332
|
+
});
|
333
|
+
depth --;
|
334
|
+
}
|
335
|
+
|
336
|
+
id = ($(item).attr(o.attribute || 'id')).match(o.expression || (/(.+)[-=_](.+)/));
|
337
|
+
|
338
|
+
if (depth === sDepth + 1) {
|
339
|
+
pid = o.rootID;
|
340
|
+
} else {
|
341
|
+
var parentItem = ($(item).parent(o.listType)
|
342
|
+
.parent(o.items)
|
343
|
+
.attr(o.attribute || 'id'))
|
344
|
+
.match(o.expression || (/(.+)[-=_](.+)/));
|
345
|
+
pid = parentItem[2];
|
346
|
+
}
|
347
|
+
|
348
|
+
if (id) {
|
349
|
+
ret.push({"item_id": id[2], "parent_id": pid, "depth": depth, "left": left, "right": right});
|
350
|
+
}
|
351
|
+
|
352
|
+
left = right + 1;
|
353
|
+
return left;
|
354
|
+
}
|
355
|
+
|
356
|
+
},
|
357
|
+
|
358
|
+
_clearEmpty: function(item) {
|
359
|
+
|
360
|
+
var emptyList = $(item).children(this.options.listType);
|
361
|
+
if (emptyList.length && !emptyList.children().length && !this.options.doNotClear) {
|
362
|
+
emptyList.remove();
|
363
|
+
}
|
364
|
+
|
365
|
+
},
|
366
|
+
|
367
|
+
_getLevel: function(item) {
|
368
|
+
|
369
|
+
var level = 1;
|
370
|
+
|
371
|
+
if (this.options.listType) {
|
372
|
+
var list = item.closest(this.options.listType);
|
373
|
+
while (list && list.length > 0 &&
|
374
|
+
!list.is('.ui-sortable')) {
|
375
|
+
level++;
|
376
|
+
list = list.parent().closest(this.options.listType);
|
377
|
+
}
|
378
|
+
}
|
379
|
+
|
380
|
+
return level;
|
381
|
+
},
|
382
|
+
|
383
|
+
_getChildLevels: function(parent, depth) {
|
384
|
+
var self = this,
|
385
|
+
o = this.options,
|
386
|
+
result = 0;
|
387
|
+
depth = depth || 0;
|
388
|
+
|
389
|
+
$(parent).children(o.listType).children(o.items).each(function (index, child) {
|
390
|
+
result = Math.max(self._getChildLevels(child, depth + 1), result);
|
391
|
+
});
|
392
|
+
|
393
|
+
return depth ? result + 1 : result;
|
394
|
+
},
|
395
|
+
|
396
|
+
_isAllowed: function(parentItem, level, levels) {
|
397
|
+
var o = this.options,
|
398
|
+
isRoot = $(this.domPosition.parent).hasClass('ui-sortable') ? true : false,
|
399
|
+
maxLevels = this.placeholder.closest('.ui-sortable').nestedSortable('option', 'maxLevels'); // this takes into account the maxLevels set to the recipient list
|
400
|
+
|
401
|
+
// Is the root protected?
|
402
|
+
// Are we trying to nest under a no-nest?
|
403
|
+
// Are we nesting too deep?
|
404
|
+
if (!o.isAllowed(this.placeholder, parentItem) ||
|
405
|
+
parentItem && parentItem.hasClass(o.disableNesting) ||
|
406
|
+
o.protectRoot && (parentItem == null && !isRoot || isRoot && level > 1)) {
|
407
|
+
this.placeholder.addClass(o.errorClass);
|
408
|
+
if (maxLevels < levels && maxLevels != 0) {
|
409
|
+
this.beyondMaxLevels = levels - maxLevels;
|
410
|
+
} else {
|
411
|
+
this.beyondMaxLevels = 1;
|
412
|
+
}
|
413
|
+
} else {
|
414
|
+
if (maxLevels < levels && maxLevels != 0) {
|
415
|
+
this.placeholder.addClass(o.errorClass);
|
416
|
+
this.beyondMaxLevels = levels - maxLevels;
|
417
|
+
} else {
|
418
|
+
this.placeholder.removeClass(o.errorClass);
|
419
|
+
this.beyondMaxLevels = 0;
|
420
|
+
}
|
421
|
+
}
|
422
|
+
}
|
423
|
+
|
424
|
+
}));
|
425
|
+
|
426
|
+
$.mjs.nestedSortable.prototype.options = $.extend({}, $.ui.sortable.prototype.options, $.mjs.nestedSortable.prototype.options);
|
427
|
+
})(jQuery);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -650,6 +650,7 @@ files:
|
|
650
650
|
- lib/activa/version.rb
|
651
651
|
- lib/activa/engine.rb
|
652
652
|
- lib/activa/default_permissions.rb
|
653
|
+
- vendor/assets/javascripts/jquery.mjs.nestedSortable.js
|
653
654
|
- MIT-LICENSE
|
654
655
|
- Rakefile
|
655
656
|
- README.rdoc
|