|
1 | 1 | /*
|
2 | 2 | * jQuery UI Nested Sortable
|
3 |
| - * v 2.1a / 2016-02-04 |
4 |
| - * https://github.com/ilikenwf/nestedSortable |
| 3 | + * v2.1.0 / 2016-06-21 |
| 4 | + * https://github.com/QueenCityCodeFactory/nested-sortable |
5 | 5 | *
|
6 | 6 | * Depends on:
|
7 | 7 | * jquery.ui.sortable.js 1.10+
|
|
14 | 14 | "use strict";
|
15 | 15 |
|
16 | 16 | if ( typeof define === "function" && define.amd ) {
|
17 |
| - |
18 | 17 | // AMD. Register as an anonymous module.
|
19 | 18 | define([
|
20 | 19 | "jquery",
|
21 | 20 | "jquery-ui/sortable"
|
22 | 21 | ], factory );
|
23 | 22 | } else {
|
24 |
| - |
25 | 23 | // Browser globals
|
26 | 24 | factory( window.jQuery );
|
27 | 25 | }
|
|
32 | 30 | return ( x > reference ) && ( x < ( reference + size ) );
|
33 | 31 | }
|
34 | 32 |
|
35 |
| - $.widget("mjs.nestedSortable", $.extend({}, $.ui.sortable.prototype, { |
| 33 | + $.widget("qccf.nestedSortable", $.extend({}, $.ui.sortable.prototype, { |
36 | 34 |
|
37 | 35 | options: {
|
38 | 36 | disableParentChange: false,
|
|
52 | 50 | right: "rght",
|
53 | 51 | attribute: "id",
|
54 | 52 |
|
55 |
| - branchClass: "mjs-nestedSortable-branch", |
56 |
| - collapsedClass: "mjs-nestedSortable-collapsed", |
57 |
| - disableNestingClass: "mjs-nestedSortable-no-nesting", |
58 |
| - errorClass: "mjs-nestedSortable-error", |
59 |
| - expandedClass: "mjs-nestedSortable-expanded", |
60 |
| - hoveringClass: "mjs-nestedSortable-hovering", |
61 |
| - leafClass: "mjs-nestedSortable-leaf", |
62 |
| - disabledClass: "mjs-nestedSortable-disabled" |
| 53 | + branchClass: "nested-sortable-branch", |
| 54 | + collapsedClass: "nested-sortable-collapsed", |
| 55 | + disableNestingClass: "nested-sortable-no-nesting", |
| 56 | + errorClass: "nested-sortable-error", |
| 57 | + expandedClass: "nested-sortable-expanded", |
| 58 | + hoveringClass: "nested-sortable-hovering", |
| 59 | + leafClass: "nested-sortable-leaf", |
| 60 | + disabledClass: "nested-sortable-disabled" |
63 | 61 | },
|
64 | 62 |
|
65 | 63 | _create: function() {
|
66 | 64 | var self = this;
|
67 | 65 | var err;
|
68 | 66 |
|
69 |
| - this.element.data("ui-sortable", this.element.data("mjs-nestedSortable")); |
| 67 | + this.element.data("ui-sortable", this.element.data("qccf.nestedSortable")); |
70 | 68 |
|
71 |
| - // mjs - prevent browser from freezing if the HTML is not correct |
| 69 | + // prevent browser from freezing if the HTML is not correct |
72 | 70 | if (!this.element.is(this.options.listType)) {
|
73 |
| - err = "nestedSortable: " + |
74 |
| - "Please check that the listType option is set to your actual list type"; |
| 71 | + err = "NestedSortable: Please check that the listType option is set to your actual list type."; |
75 | 72 |
|
76 | 73 | throw new Error(err);
|
77 | 74 | }
|
|
112 | 109 |
|
113 | 110 | _destroy: function() {
|
114 | 111 | this.element
|
115 |
| - .removeData("mjs-nestedSortable") |
| 112 | + .removeData("qccf.nestedSortable") |
116 | 113 | .removeData("ui-sortable");
|
117 | 114 | return $.ui.sortable.prototype._destroy.apply(this, arguments);
|
118 | 115 | },
|
|
238 | 235 | //Regenerate the absolute position used for position checks
|
239 | 236 | this.positionAbs = this._convertPositionTo("absolute");
|
240 | 237 |
|
241 |
| - // mjs - find the top offset before rearrangement, |
| 238 | + // find the top offset before rearrangement, |
242 | 239 | previousTopOffset = this.placeholder.offset().top;
|
243 | 240 |
|
244 | 241 | //Set the helper position
|
|
249 | 246 | this.helper[0].style.top = (this.position.top) + "px";
|
250 | 247 | }
|
251 | 248 |
|
252 |
| - // mjs - check and reset hovering state at each cycle |
| 249 | + // check and reset hovering state at each cycle |
253 | 250 | this.hovering = this.hovering ? this.hovering : null;
|
254 | 251 | this.mouseentered = this.mouseentered ? this.mouseentered : false;
|
255 | 252 |
|
256 |
| - // mjs - let's start caching some variables |
| 253 | + // let's start caching some variables |
257 | 254 | (function() {
|
258 | 255 | var _parentItem = this.placeholder.parent().parent();
|
259 | 256 | if (_parentItem && _parentItem.closest(".ui-sortable").length) {
|
|
282 | 279 | // currentContainer is switched before the placeholder is moved.
|
283 | 280 | //
|
284 | 281 | // Without this moving items in "sub-sortables" can cause the placeholder to jitter
|
285 |
| - // beetween the outer and inner container. |
| 282 | + // between the outer and inner container. |
286 | 283 | if (item.instance !== this.currentContainer) {
|
287 | 284 | continue;
|
288 | 285 | }
|
|
323 | 320 | )
|
324 | 321 | ) {
|
325 | 322 |
|
326 |
| - // mjs - we are intersecting an element: |
| 323 | + // we are intersecting an element: |
327 | 324 | // trigger the mouseenter event and store this state
|
328 | 325 | if (!this.mouseentered) {
|
329 | 326 | $(itemElement).mouseenter();
|
330 | 327 | this.mouseentered = true;
|
331 | 328 | }
|
332 | 329 |
|
333 |
| - // mjs - if the element has children and they are hidden, |
| 330 | + // if the element has children and they are hidden, |
334 | 331 | // show them after a delay (CSS responsible)
|
335 | 332 | if (o.isTree && $(itemElement).hasClass(o.collapsedClass) && o.expandOnHover) {
|
336 | 333 | if (!this.hovering) {
|
|
348 | 345 |
|
349 | 346 | this.direction = intersection === 1 ? "down" : "up";
|
350 | 347 |
|
351 |
| - // mjs - rearrange the elements and reset timeouts and hovering state |
| 348 | + // rearrange the elements and reset timeouts and hovering state |
352 | 349 | if (this.options.tolerance === "pointer" || this._intersectsWithSides(item)) {
|
353 | 350 | $(itemElement).mouseleave();
|
354 | 351 | this.mouseentered = false;
|
|
358 | 355 | }
|
359 | 356 | this.hovering = null;
|
360 | 357 |
|
361 |
| - // mjs - do not switch container if |
| 358 | + // do not switch container if |
362 | 359 | // it's a root item and 'protectRoot' is true
|
363 | 360 | // or if it's not a root item but we are trying to make it root
|
364 | 361 | if (o.protectRoot &&
|
|
410 | 407 | }
|
411 | 408 | }
|
412 | 409 |
|
413 |
| - // mjs - to find the previous sibling in the list, |
| 410 | + // to find the previous sibling in the list, |
414 | 411 | // keep backtracking until we hit a valid list item.
|
415 | 412 | (function() {
|
416 | 413 | var _previousItem = this.placeholder.prev();
|
|
437 | 434 | }
|
438 | 435 | }
|
439 | 436 |
|
440 |
| - // mjs - to find the next sibling in the list, |
| 437 | + // to find the next sibling in the list, |
441 | 438 | // keep stepping forward until we hit a valid list item.
|
442 | 439 | (function() {
|
443 | 440 | var _nextItem = this.placeholder.next();
|
|
466 | 463 |
|
467 | 464 | this.beyondMaxLevels = 0;
|
468 | 465 |
|
469 |
| - // mjs - if the item is moved to the left, send it one level up |
| 466 | + // if the item is moved to the left, send it one level up |
470 | 467 | // but only if it's at the bottom of the list
|
471 | 468 | if (parentItem !== null &&
|
472 | 469 | parentItem !== undefined &&
|
|
496 | 493 | if(typeof parentItem !== 'undefined')
|
497 | 494 | this._clearEmpty(parentItem[0]);
|
498 | 495 | this._trigger("change", event, this._uiHash());
|
499 |
| - // mjs - if the item is below a sibling and is moved to the right, |
| 496 | + // if the item is below a sibling and is moved to the right, |
500 | 497 | // make it a child of that sibling
|
501 | 498 | } else if (previousItem !== null && previousItem !== undefined &&
|
502 | 499 | !previousItem.hasClass(o.disableNestingClass) &&
|
|
531 | 528 | }
|
532 | 529 | }
|
533 | 530 |
|
534 |
| - // mjs - if this item is being moved from the top, add it to the top of the list. |
| 531 | + // if this item is being moved from the top, add it to the top of the list. |
535 | 532 | if (previousTopOffset && (previousTopOffset <= previousItem.offset().top)) {
|
536 | 533 | previousItem.children(o.listType).prepend(this.placeholder);
|
537 | 534 | } else {
|
538 |
| - // mjs - otherwise, add it to the bottom of the list. |
| 535 | + // otherwise, add it to the bottom of the list. |
539 | 536 | previousItem.children(o.listType)[0].appendChild(this.placeholder[0]);
|
540 | 537 | }
|
541 | 538 | if(typeof parentItem !== 'undefined')
|
|
562 | 559 | },
|
563 | 560 |
|
564 | 561 | _mouseStop: function(event) {
|
565 |
| - // mjs - if the item is in a position not allowed, send it back |
| 562 | + // if the item is in a position not allowed, send it back |
566 | 563 | if (this.beyondMaxLevels) {
|
567 | 564 |
|
568 | 565 | this.placeholder.removeClass(this.options.errorClass);
|
|
577 | 574 |
|
578 | 575 | }
|
579 | 576 |
|
580 |
| - // mjs - clear the hovering timeout, just to be sure |
| 577 | + // clear the hovering timeout, just to be sure |
581 | 578 | $("." + this.options.hoveringClass)
|
582 | 579 | .mouseleave()
|
583 | 580 | .removeClass(this.options.hoveringClass);
|
|
591 | 588 | this._relocate_event = event;
|
592 | 589 | this._pid_current = $(this.domPosition.parent).parent().attr("id");
|
593 | 590 | this._sort_current = this.domPosition.prev ? $(this.domPosition.prev).next().index() : 0;
|
594 |
| - $.ui.sortable.prototype._mouseStop.apply(this, arguments); //asybnchronous execution, @see _clear for the relocate event. |
| 591 | + $.ui.sortable.prototype._mouseStop.apply(this, arguments); //asynchronous execution, @see _clear for the relocate event. |
595 | 592 | },
|
596 | 593 |
|
597 |
| - // mjs - this function is slightly modified |
| 594 | + // this function is slightly modified |
598 | 595 | // to make it easier to hover over a collapsed element and have it expand
|
599 | 596 | _intersectsWithSides: function(item) {
|
600 | 597 | var half = this.options.isTree ? 0.8 : 0.5,
|
|
649 | 646 | this._trigger("relocate", this._relocate_event, this._uiHash());
|
650 | 647 | }
|
651 | 648 |
|
652 |
| - // mjs - clean last empty ul/ol |
| 649 | + // clean last empty ul/ol |
653 | 650 | for (i = this.items.length - 1; i >= 0; i--) {
|
654 | 651 | item = this.items[i].item[0];
|
655 | 652 | this._clearEmpty(item);
|
|
798 | 795 | typeof parentItem !== 'undefined' && !oldParent.is(parentItem) ||
|
799 | 796 | typeof parentItem === 'undefined' && oldParent.is("li") //From somewhere to the root
|
800 | 797 | );
|
801 |
| - // mjs - is the root protected? |
802 |
| - // mjs - are we nesting too deep? |
| 798 | + // is the root protected? |
| 799 | + // are we nesting too deep? |
803 | 800 | if (
|
804 | 801 | disabledByParentchange ||
|
805 | 802 | !o.isAllowed(this.placeholder, parentItem, this.currentItem)
|
|
822 | 819 | }
|
823 | 820 | }));
|
824 | 821 |
|
825 |
| - $.mjs.nestedSortable.prototype.options = $.extend( |
| 822 | + $.qccf.nestedSortable.prototype.options = $.extend( |
826 | 823 | {},
|
827 | 824 | $.ui.sortable.prototype.options,
|
828 |
| - $.mjs.nestedSortable.prototype.options |
| 825 | + $.qccf.nestedSortable.prototype.options |
829 | 826 | );
|
830 | 827 | }));
|
0 commit comments