PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.3.1
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.3.1
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 10 years ago jquery.mjs.pmxe_nestedSortable.js 7 years ago jquery.timepicker.js 8 years ago jquery.tipsy.js 5 years ago moment.js 9 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
431 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 //Regenerate the absolute position used for position checks
90 this.positionAbs = this._convertPositionTo("absolute");
91
92 // Find the top offset before rearrangement,
93 var previousTopOffset = this.placeholder.offset().top;
94
95 //Set the helper position
96 if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
97 if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
98
99 //Rearrange
100 for (var i = this.items.length - 1; i >= 0; i--) {
101
102 //Cache variables and intersection, continue if no intersection
103 var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item);
104 if (!intersection) continue;
105
106 if(itemElement != this.currentItem[0] //cannot intersect with itself
107 && this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before
108 && !$.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked
109 && (this.options.type == 'semi-dynamic' ? !$.contains(this.element[0], itemElement) : true)
110 //&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container
111 ) {
112
113 $(itemElement).mouseenter();
114
115 this.direction = intersection == 1 ? "down" : "up";
116
117 if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) {
118 $(itemElement).mouseleave();
119 this._rearrange(event, item);
120 } else {
121 break;
122 }
123
124 // Clear emtpy ul's/ol's
125 this._clearEmpty(itemElement);
126
127 this._trigger("change", event, this._uiHash());
128 break;
129 }
130 }
131
132 var parentItem = (this.placeholder[0].parentNode.parentNode &&
133 $(this.placeholder[0].parentNode.parentNode).closest('.ui-sortable').length)
134 ? $(this.placeholder[0].parentNode.parentNode)
135 : null,
136 level = this._getLevel(this.placeholder),
137 childLevels = this._getChildLevels(this.helper);
138
139 // To find the previous sibling in the list, keep backtracking until we hit a valid list item.
140 var previousItem = this.placeholder[0].previousSibling ? $(this.placeholder[0].previousSibling) : null;
141 if (previousItem != null) {
142 while (previousItem[0].nodeName.toLowerCase() != 'li' || previousItem[0] == this.currentItem[0] || previousItem[0] == this.helper[0]) {
143 if (previousItem[0].previousSibling) {
144 previousItem = $(previousItem[0].previousSibling);
145 } else {
146 previousItem = null;
147 break;
148 }
149 }
150 }
151
152 // To find the next sibling in the list, keep stepping forward until we hit a valid list item.
153 var nextItem = this.placeholder[0].nextSibling ? $(this.placeholder[0].nextSibling) : null;
154 if (nextItem != null) {
155 while (nextItem[0].nodeName.toLowerCase() != 'li' || nextItem[0] == this.currentItem[0] || nextItem[0] == this.helper[0]) {
156 if (nextItem[0].nextSibling) {
157 nextItem = $(nextItem[0].nextSibling);
158 } else {
159 nextItem = null;
160 break;
161 }
162 }
163 }
164
165 var newList = document.createElement(o.listType);
166
167 this.beyondMaxLevels = 0;
168
169 // If the item is moved to the left, send it to its parent's level unless there are siblings below it.
170 if (parentItem != null && nextItem == null &&
171 (o.rtl && (this.positionAbs.left + this.helper.outerWidth() > parentItem.offset().left + parentItem.outerWidth()) ||
172 !o.rtl && (this.positionAbs.left < parentItem.offset().left))) {
173 parentItem.after(this.placeholder[0]);
174 this._clearEmpty(parentItem[0]);
175 this._trigger("change", event, this._uiHash());
176 }
177 // If the item is below a sibling and is moved to the right, make it a child of that sibling.
178 else if (previousItem != null &&
179 (o.rtl && (this.positionAbs.left + this.helper.outerWidth() < previousItem.offset().left + previousItem.outerWidth() - o.tabSize) ||
180 !o.rtl && (this.positionAbs.left > previousItem.offset().left + o.tabSize))) {
181 this._isAllowed(previousItem, level, level+childLevels+1);
182 if (!previousItem.children(o.listType).length) {
183 previousItem[0].appendChild(newList);
184 }
185 // If this item is being moved from the top, add it to the top of the list.
186 if (previousTopOffset && (previousTopOffset <= previousItem.offset().top)) {
187 previousItem.children(o.listType).prepend(this.placeholder);
188 }
189 // Otherwise, add it to the bottom of the list.
190 else {
191 previousItem.children(o.listType)[0].appendChild(this.placeholder[0]);
192 }
193 this._trigger("change", event, this._uiHash());
194 }
195 else {
196 this._isAllowed(parentItem, level, level+childLevels);
197 }
198
199 //Post events to containers
200 this._contactContainers(event);
201
202 //Interconnect with droppables
203 if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
204
205 //Call callbacks
206 this._trigger('sort', event, this._uiHash());
207
208 this.lastPositionAbs = this.positionAbs;
209 return false;
210
211 },
212
213 _mouseStop: function(event, noPropagation) {
214
215 // If the item is in a position not allowed, send it back
216 if (this.beyondMaxLevels) {
217
218 this.placeholder.removeClass(this.options.errorClass);
219
220 if (this.domPosition.prev) {
221 $(this.domPosition.prev).after(this.placeholder);
222 } else {
223 $(this.domPosition.parent).prepend(this.placeholder);
224 }
225
226 this._trigger("revert", event, this._uiHash());
227
228 }
229
230 // Clean last empty ul/ol
231 for (var i = this.items.length - 1; i >= 0; i--) {
232 var item = this.items[i].item[0];
233 this._clearEmpty(item);
234 }
235
236 $.ui.sortable.prototype._mouseStop.apply(this, arguments);
237
238 },
239
240 serialize: function(options) {
241
242 var o = $.extend({}, this.options, options),
243 items = this._getItemsAsjQuery(o && o.connected),
244 str = [];
245
246 $(items).each(function() {
247 var res = ($(o.item || this).attr(o.attribute || 'id') || '')
248 .match(o.expression || (/(.+)[-=_](.+)/)),
249 pid = ($(o.item || this).parent(o.listType)
250 .parent(o.items)
251 .attr(o.attribute || 'id') || '')
252 .match(o.expression || (/(.+)[-=_](.+)/));
253
254 if (res) {
255 str.push(((o.key || res[1]) + '[' + (o.key && o.expression ? res[1] : res[2]) + ']')
256 + '='
257 + (pid ? (o.key && o.expression ? pid[1] : pid[2]) : o.rootID));
258 }
259 });
260
261 if(!str.length && o.key) {
262 str.push(o.key + '=');
263 }
264
265 return str.join('&');
266
267 },
268
269 toHierarchy: function(options) {
270
271 var o = $.extend({}, this.options, options),
272 sDepth = o.startDepthCount || 0,
273 ret = [];
274
275 $(this.element).children(o.items).each(function () {
276 var level = _recursiveItems(this);
277 ret.push(level);
278 });
279
280 return ret;
281
282 function _recursiveItems(item) {
283 var id = ($(item).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
284 if (id) {
285 var currentItem = {"id" : id[2]};
286 if ($(item).children(o.listType).children(o.items).length > 0) {
287 currentItem.children = [];
288 $(item).children(o.listType).children(o.items).each(function() {
289 var level = _recursiveItems(this);
290 currentItem.children.push(level);
291 });
292 }
293 return currentItem;
294 }
295 }
296 },
297
298 toArray: function(options) {
299
300 var o = $.extend({}, this.options, options),
301 sDepth = o.startDepthCount || 0,
302 ret = [],
303 left = 2;
304
305 /*ret.push({
306 "item_id": o.rootID,
307 "parent_id": 'none',
308 "depth": sDepth,
309 "left": '1',
310 "right": ($(o.items, this.element).length + 1) * 2
311 });*/
312
313 $(this.element).children(o.items).each(function () {
314 left = _recursiveArray(this, sDepth + 1, left);
315 });
316
317 ret = ret.sort(function(a,b){ return (a.left - b.left); });
318
319 return ret;
320
321 function _recursiveArray(item, depth, left) {
322
323 var right = left + 1,
324 id,
325 pid;
326
327 if ($(item).children(o.listType).children(o.items).length > 0) {
328 depth ++;
329 $(item).children(o.listType).children(o.items).each(function () {
330 right = _recursiveArray($(this), depth, right);
331 });
332 depth --;
333 }
334
335 id = ($(item).attr(o.attribute || 'id')).match(o.expression || (/(.+)[-=_](.+)/));
336
337 if (depth === sDepth + 1) {
338 pid = o.rootID;
339 } else {
340 var parentItem = ($(item).parent(o.listType)
341 .parent(o.items)
342 .attr(o.attribute || 'id'))
343 .match(o.expression || (/(.+)[-=_](.+)/));
344 pid = parentItem[2];
345 }
346
347 if (id) {
348
349 if(($(item).find('.condition:first').hasClass('last_condition')) ? false : $(item).find('input.rule_condition:checked').val()) {
350 var clause = ($(item).find('.condition:first').hasClass('last_condition')) ? false : $(item).find('input.rule_condition:checked').val().toUpperCase();
351
352 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 });
353 }
354 }
355
356 left = right + 1;
357 return left;
358 }
359
360 },
361
362 _clearEmpty: function(item) {
363
364 var emptyList = $(item).children(this.options.listType);
365 if (emptyList.length && !emptyList.children().length) {
366 emptyList.remove();
367 }
368
369 },
370
371 _getLevel: function(item) {
372
373 var level = 1;
374
375 if (this.options.listType) {
376 var list = item.closest(this.options.listType);
377 while (list && list.length > 0 &&
378 !list.is('.ui-sortable')) {
379 level++;
380 list = list.parent().closest(this.options.listType);
381 }
382 }
383
384 return level;
385 },
386
387 _getChildLevels: function(parent, depth) {
388 var self = this,
389 o = this.options,
390 result = 0;
391 depth = depth || 0;
392
393 $(parent).children(o.listType).children(o.items).each(function (index, child) {
394 result = Math.max(self._getChildLevels(child, depth + 1), result);
395 });
396
397 return depth ? result + 1 : result;
398 },
399
400 _isAllowed: function(parentItem, level, levels) {
401 var o = this.options,
402 isRoot = $(this.domPosition.parent).hasClass('ui-sortable') ? true : false,
403 maxLevels = this.placeholder.closest('.ui-sortable').pmxe_nestedSortable('option', 'maxLevels'); // this takes into account the maxLevels set to the recipient list
404
405 // Is the root protected?
406 // Are we trying to nest under a no-nest?
407 // Are we nesting too deep?
408 if (!o.isAllowed(parentItem, this.placeholder) ||
409 parentItem && parentItem.hasClass(o.disableNesting) ||
410 o.protectRoot && (parentItem == null && !isRoot || isRoot && level > 1)) {
411 this.placeholder.addClass(o.errorClass);
412 if (maxLevels < levels && maxLevels != 0) {
413 this.beyondMaxLevels = levels - maxLevels;
414 } else {
415 this.beyondMaxLevels = 1;
416 }
417 } else {
418 if (maxLevels < levels && maxLevels != 0) {
419 this.placeholder.addClass(o.errorClass);
420 this.beyondMaxLevels = levels - maxLevels;
421 } else {
422 this.placeholder.removeClass(o.errorClass);
423 this.beyondMaxLevels = 0;
424 }
425 }
426 }
427
428 }));
429
430 $.mjs.pmxe_nestedSortable.prototype.options = $.extend({}, $.ui.sortable.prototype.options, $.mjs.pmxe_nestedSortable.prototype.options);
431 })(jQuery);