PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / trunk
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel vtrunk
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / static / js / jquery / jquery.mjs.pmxe_nestedSortable.js
wp-all-export / static / js / jquery Last commit date
css 8 years ago chosen.jquery.js 8 years ago chosen.jquery.min.js 10 years ago jquery.ddslick.min.js 3 years ago jquery.mjs.pmxe_nestedSortable.js 4 years ago jquery.timepicker.js 8 years ago jquery.tipsy.js 5 years ago select2.min.js 12 years ago ui.autocomplete.js 12 years ago ui.datepicker.js 12 years ago
jquery.mjs.pmxe_nestedSortable.js
437 lines
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.pmxe_nestedSortable", $.extend({}, $.ui.sortable.prototype, {
17
18 options: {
19 tabSize: 20,
20 disableNesting: 'mjs-pmxe_nestedSortable-no-nesting',
21 errorClass: 'mjs-pmxe_nestedSortable-error',
22 listType: 'ol',
23 maxLevels: 0,
24 protectRoot: false,
25 rootID: null,
26 rtl: false,
27 isAllowed: function(item, parent) { return true; }
28 },
29
30 _create: function() {
31 this.element.data('sortable', this.element.data('pmxe_nestedSortable'));
32
33 if (!this.element.is(this.options.listType))
34 throw new Error('pmxe_nestedSortable: Please check the listType option is set to your actual list type');
35
36 return $.ui.sortable.prototype._create.apply(this, arguments);
37 },
38
39 destroy: function() {
40 this.element
41 .removeData("pmxe_nestedSortable")
42 .unbind(".pmxe_nestedSortable");
43 return $.ui.sortable.prototype.destroy.apply(this, arguments);
44 },
45
46 _mouseDrag: function(event) {
47
48 //Compute the helpers position
49 this.position = this._generatePosition(event);
50 this.positionAbs = this._convertPositionTo("absolute");
51
52 if (!this.lastPositionAbs) {
53 this.lastPositionAbs = this.positionAbs;
54 }
55
56 //Do scrolling
57 if(this.options.scroll) {
58 var o = this.options, scrolled = false;
59 if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') {
60
61 if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
62 this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
63 else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity)
64 this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
65
66 if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity)
67 this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
68 else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity)
69 this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
70
71 } else {
72
73 if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
74 scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
75 else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
76 scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
77
78 if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
79 scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
80 else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
81 scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
82
83 }
84
85 if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
86 $.ui.ddmanager.prepareOffsets(this, event);
87 }
88
89 this.dragDirection = {
90 vertical: this._getDragVerticalDirection(),
91 horizontal: this._getDragHorizontalDirection()
92 };
93
94 //Regenerate the absolute position used for position checks
95 this.positionAbs = this._convertPositionTo("absolute");
96
97 // Find the top offset before rearrangement,
98 var previousTopOffset = this.placeholder.offset().top;
99
100 //Set the helper position
101 if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
102 if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
103
104 //Rearrange
105 for (var i = this.items.length - 1; i >= 0; i--) {
106
107 //Cache variables and intersection, continue if no intersection
108 var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item);
109 if (!intersection) continue;
110
111 if(itemElement != this.currentItem[0] //cannot intersect with itself
112 && this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before
113 && !$.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked
114 && (this.options.type == 'semi-dynamic' ? !$.contains(this.element[0], itemElement) : true)
115 //&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container
116 ) {
117
118 $(itemElement).mouseenter();
119
120 this.direction = intersection == 1 ? "down" : "up";
121
122 if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) {
123 $(itemElement).mouseleave();
124 this._rearrange(event, item);
125 } else {
126 break;
127 }
128
129 // Clear emtpy ul's/ol's
130 this._clearEmpty(itemElement);
131
132 this._trigger("change", event, this._uiHash());
133 break;
134 }
135 }
136
137 var parentItem = (this.placeholder[0].parentNode.parentNode &&
138 $(this.placeholder[0].parentNode.parentNode).closest('.ui-sortable').length)
139 ? $(this.placeholder[0].parentNode.parentNode)
140 : null,
141 level = this._getLevel(this.placeholder),
142 childLevels = this._getChildLevels(this.helper);
143
144 // To find the previous sibling in the list, keep backtracking until we hit a valid list item.
145 var previousItem = this.placeholder[0].previousSibling ? $(this.placeholder[0].previousSibling) : null;
146 if (previousItem != null) {
147 while (previousItem[0].nodeName.toLowerCase() != 'li' || previousItem[0] == this.currentItem[0] || previousItem[0] == this.helper[0]) {
148 if (previousItem[0].previousSibling) {
149 previousItem = $(previousItem[0].previousSibling);
150 } else {
151 previousItem = null;
152 break;
153 }
154 }
155 }
156
157 // To find the next sibling in the list, keep stepping forward until we hit a valid list item.
158 var nextItem = this.placeholder[0].nextSibling ? $(this.placeholder[0].nextSibling) : null;
159 if (nextItem != null) {
160 while (nextItem[0].nodeName.toLowerCase() != 'li' || nextItem[0] == this.currentItem[0] || nextItem[0] == this.helper[0]) {
161 if (nextItem[0].nextSibling) {
162 nextItem = $(nextItem[0].nextSibling);
163 } else {
164 nextItem = null;
165 break;
166 }
167 }
168 }
169
170 var newList = document.createElement(o.listType);
171
172 this.beyondMaxLevels = 0;
173
174 // If the item is moved to the left, send it to its parent's level unless there are siblings below it.
175 if (parentItem != null && nextItem == null &&
176 (o.rtl && (this.positionAbs.left + this.helper.outerWidth() > parentItem.offset().left + parentItem.outerWidth()) ||
177 !o.rtl && (this.positionAbs.left < parentItem.offset().left))) {
178 parentItem.after(this.placeholder[0]);
179 this._clearEmpty(parentItem[0]);
180 this._trigger("change", event, this._uiHash());
181 }
182 // If the item is below a sibling and is moved to the right, make it a child of that sibling.
183 else if (previousItem != null &&
184 (o.rtl && (this.positionAbs.left + this.helper.outerWidth() < previousItem.offset().left + previousItem.outerWidth() - o.tabSize) ||
185 !o.rtl && (this.positionAbs.left > previousItem.offset().left + o.tabSize))) {
186 this._isAllowed(previousItem, level, level+childLevels+1);
187 if (!previousItem.children(o.listType).length) {
188 previousItem[0].appendChild(newList);
189 }
190 // If this item is being moved from the top, add it to the top of the list.
191 if (previousTopOffset && (previousTopOffset <= previousItem.offset().top)) {
192 previousItem.children(o.listType).prepend(this.placeholder);
193 }
194 // Otherwise, add it to the bottom of the list.
195 else {
196 previousItem.children(o.listType)[0].appendChild(this.placeholder[0]);
197 }
198 this._trigger("change", event, this._uiHash());
199 }
200 else {
201 this._isAllowed(parentItem, level, level+childLevels);
202 }
203
204 //Post events to containers
205 this._contactContainers(event);
206
207 //Interconnect with droppables
208 if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
209
210 //Call callbacks
211 this._trigger('sort', event, this._uiHash());
212
213 this.lastPositionAbs = this.positionAbs;
214 return false;
215
216 },
217
218 _mouseStop: function(event, noPropagation) {
219
220 // If the item is in a position not allowed, send it back
221 if (this.beyondMaxLevels) {
222
223 this.placeholder.removeClass(this.options.errorClass);
224
225 if (this.domPosition.prev) {
226 $(this.domPosition.prev).after(this.placeholder);
227 } else {
228 $(this.domPosition.parent).prepend(this.placeholder);
229 }
230
231 this._trigger("revert", event, this._uiHash());
232
233 }
234
235 // Clean last empty ul/ol
236 for (var i = this.items.length - 1; i >= 0; i--) {
237 var item = this.items[i].item[0];
238 this._clearEmpty(item);
239 }
240
241 $.ui.sortable.prototype._mouseStop.apply(this, arguments);
242
243 },
244
245 serialize: function(options) {
246
247 var o = $.extend({}, this.options, options),
248 items = this._getItemsAsjQuery(o && o.connected),
249 str = [];
250
251 $(items).each(function() {
252 var res = ($(o.item || this).attr(o.attribute || 'id') || '')
253 .match(o.expression || (/(.+)[-=_](.+)/)),
254 pid = ($(o.item || this).parent(o.listType)
255 .parent(o.items)
256 .attr(o.attribute || 'id') || '')
257 .match(o.expression || (/(.+)[-=_](.+)/));
258
259 if (res) {
260 str.push(((o.key || res[1]) + '[' + (o.key && o.expression ? res[1] : res[2]) + ']')
261 + '='
262 + (pid ? (o.key && o.expression ? pid[1] : pid[2]) : o.rootID));
263 }
264 });
265
266 if(!str.length && o.key) {
267 str.push(o.key + '=');
268 }
269
270 return str.join('&');
271
272 },
273
274 toHierarchy: function(options) {
275
276 var o = $.extend({}, this.options, options),
277 sDepth = o.startDepthCount || 0,
278 ret = [];
279
280 $(this.element).children(o.items).each(function () {
281 var level = _recursiveItems(this);
282 ret.push(level);
283 });
284
285 return ret;
286
287 function _recursiveItems(item) {
288 var id = ($(item).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
289 if (id) {
290 var currentItem = {"id" : id[2]};
291 if ($(item).children(o.listType).children(o.items).length > 0) {
292 currentItem.children = [];
293 $(item).children(o.listType).children(o.items).each(function() {
294 var level = _recursiveItems(this);
295 currentItem.children.push(level);
296 });
297 }
298 return currentItem;
299 }
300 }
301 },
302
303 toArray: function(options) {
304
305 var o = $.extend({}, this.options, options),
306 sDepth = o.startDepthCount || 0,
307 ret = [],
308 left = 2;
309
310 /*ret.push({
311 "item_id": o.rootID,
312 "parent_id": 'none',
313 "depth": sDepth,
314 "left": '1',
315 "right": ($(o.items, this.element).length + 1) * 2
316 });*/
317
318 $(this.element).children(o.items).each(function () {
319 left = _recursiveArray(this, sDepth + 1, left);
320 });
321
322 ret = ret.sort(function(a,b){ return (a.left - b.left); });
323
324 return ret;
325
326 function _recursiveArray(item, depth, left) {
327
328 var right = left + 1,
329 id,
330 pid;
331
332 if ($(item).children(o.listType).children(o.items).length > 0) {
333 depth ++;
334 $(item).children(o.listType).children(o.items).each(function () {
335 right = _recursiveArray($(this), depth, right);
336 });
337 depth --;
338 }
339
340 id = ($(item).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
341
342 if (depth === sDepth + 1) {
343 pid = o.rootID;
344 } else {
345 var parentItem = ($(item).parent(o.listType)
346 .parent(o.items)
347 .attr(o.attribute || 'id'))
348 .match(o.expression || (/(.+)[-=_](.+)/));
349 pid = parentItem[2];
350 }
351
352 if (id) {
353
354 if(($(item).find('.condition:first').hasClass('last_condition')) ? false : $(item).find('input.rule_condition:checked').val()) {
355 var clause = ($(item).find('.condition:first').hasClass('last_condition')) ? false : $(item).find('input.rule_condition:checked').val().toUpperCase();
356
357 ret.push({"item_id": id[2], "left": left, "right": right, "parent_id": pid, "element":$(item).find('input.wp_all_export_xml_element').val(), "title" : $(item).find('input.wp_all_export_xml_element_title').val(), "condition" : $(item).find('input.wp_all_export_rule').val(), "value" : $(item).find('input.wp_all_export_value').val(), "clause" : clause });
358 }
359 }
360
361 left = right + 1;
362 return left;
363 }
364
365 },
366
367 _clearEmpty: function(item) {
368
369 var emptyList = $(item).children(this.options.listType);
370 if (emptyList.length && !emptyList.children().length) {
371 emptyList.remove();
372 }
373
374 },
375
376 _getLevel: function(item) {
377
378 var level = 1;
379
380 if (this.options.listType) {
381 var list = item.closest(this.options.listType);
382 while (list && list.length > 0 &&
383 !list.is('.ui-sortable')) {
384 level++;
385 list = list.parent().closest(this.options.listType);
386 }
387 }
388
389 return level;
390 },
391
392 _getChildLevels: function(parent, depth) {
393 var self = this,
394 o = this.options,
395 result = 0;
396 depth = depth || 0;
397
398 $(parent).children(o.listType).children(o.items).each(function (index, child) {
399 result = Math.max(self._getChildLevels(child, depth + 1), result);
400 });
401
402 return depth ? result + 1 : result;
403 },
404
405 _isAllowed: function(parentItem, level, levels) {
406 var o = this.options,
407 isRoot = $(this.domPosition.parent).hasClass('ui-sortable') ? true : false,
408 maxLevels = this.placeholder.closest('.ui-sortable').pmxe_nestedSortable('option', 'maxLevels'); // this takes into account the maxLevels set to the recipient list
409
410 // Is the root protected?
411 // Are we trying to nest under a no-nest?
412 // Are we nesting too deep?
413 if (!o.isAllowed(parentItem, this.placeholder) ||
414 parentItem && parentItem.hasClass(o.disableNesting) ||
415 o.protectRoot && (parentItem == null && !isRoot || isRoot && level > 1)) {
416 this.placeholder.addClass(o.errorClass);
417 if (maxLevels < levels && maxLevels != 0) {
418 this.beyondMaxLevels = levels - maxLevels;
419 } else {
420 this.beyondMaxLevels = 1;
421 }
422 } else {
423 if (maxLevels < levels && maxLevels != 0) {
424 this.placeholder.addClass(o.errorClass);
425 this.beyondMaxLevels = levels - maxLevels;
426 } else {
427 this.placeholder.removeClass(o.errorClass);
428 this.beyondMaxLevels = 0;
429 }
430 }
431 }
432
433 }));
434
435 $.mjs.pmxe_nestedSortable.prototype.options = $.extend({}, $.ui.sortable.prototype.options, $.mjs.pmxe_nestedSortable.prototype.options);
436 })(jQuery);
437