Skip to content

Commit fa89b7c

Browse files
committed
More Clean Up
1 parent 7458a35 commit fa89b7c

File tree

2 files changed

+39
-42
lines changed

2 files changed

+39
-42
lines changed

jquery.nested-sortable.js

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* 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
55
*
66
* Depends on:
77
* jquery.ui.sortable.js 1.10+
@@ -14,14 +14,12 @@
1414
"use strict";
1515

1616
if ( typeof define === "function" && define.amd ) {
17-
1817
// AMD. Register as an anonymous module.
1918
define([
2019
"jquery",
2120
"jquery-ui/sortable"
2221
], factory );
2322
} else {
24-
2523
// Browser globals
2624
factory( window.jQuery );
2725
}
@@ -32,7 +30,7 @@
3230
return ( x > reference ) && ( x < ( reference + size ) );
3331
}
3432

35-
$.widget("mjs.nestedSortable", $.extend({}, $.ui.sortable.prototype, {
33+
$.widget("qccf.nestedSortable", $.extend({}, $.ui.sortable.prototype, {
3634

3735
options: {
3836
disableParentChange: false,
@@ -52,26 +50,25 @@
5250
right: "rght",
5351
attribute: "id",
5452

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"
6361
},
6462

6563
_create: function() {
6664
var self = this;
6765
var err;
6866

69-
this.element.data("ui-sortable", this.element.data("mjs-nestedSortable"));
67+
this.element.data("ui-sortable", this.element.data("qccf.nestedSortable"));
7068

71-
// mjs - prevent browser from freezing if the HTML is not correct
69+
// prevent browser from freezing if the HTML is not correct
7270
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.";
7572

7673
throw new Error(err);
7774
}
@@ -112,7 +109,7 @@
112109

113110
_destroy: function() {
114111
this.element
115-
.removeData("mjs-nestedSortable")
112+
.removeData("qccf.nestedSortable")
116113
.removeData("ui-sortable");
117114
return $.ui.sortable.prototype._destroy.apply(this, arguments);
118115
},
@@ -238,7 +235,7 @@
238235
//Regenerate the absolute position used for position checks
239236
this.positionAbs = this._convertPositionTo("absolute");
240237

241-
// mjs - find the top offset before rearrangement,
238+
// find the top offset before rearrangement,
242239
previousTopOffset = this.placeholder.offset().top;
243240

244241
//Set the helper position
@@ -249,11 +246,11 @@
249246
this.helper[0].style.top = (this.position.top) + "px";
250247
}
251248

252-
// mjs - check and reset hovering state at each cycle
249+
// check and reset hovering state at each cycle
253250
this.hovering = this.hovering ? this.hovering : null;
254251
this.mouseentered = this.mouseentered ? this.mouseentered : false;
255252

256-
// mjs - let's start caching some variables
253+
// let's start caching some variables
257254
(function() {
258255
var _parentItem = this.placeholder.parent().parent();
259256
if (_parentItem && _parentItem.closest(".ui-sortable").length) {
@@ -282,7 +279,7 @@
282279
// currentContainer is switched before the placeholder is moved.
283280
//
284281
// 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.
286283
if (item.instance !== this.currentContainer) {
287284
continue;
288285
}
@@ -323,14 +320,14 @@
323320
)
324321
) {
325322

326-
// mjs - we are intersecting an element:
323+
// we are intersecting an element:
327324
// trigger the mouseenter event and store this state
328325
if (!this.mouseentered) {
329326
$(itemElement).mouseenter();
330327
this.mouseentered = true;
331328
}
332329

333-
// mjs - if the element has children and they are hidden,
330+
// if the element has children and they are hidden,
334331
// show them after a delay (CSS responsible)
335332
if (o.isTree && $(itemElement).hasClass(o.collapsedClass) && o.expandOnHover) {
336333
if (!this.hovering) {
@@ -348,7 +345,7 @@
348345

349346
this.direction = intersection === 1 ? "down" : "up";
350347

351-
// mjs - rearrange the elements and reset timeouts and hovering state
348+
// rearrange the elements and reset timeouts and hovering state
352349
if (this.options.tolerance === "pointer" || this._intersectsWithSides(item)) {
353350
$(itemElement).mouseleave();
354351
this.mouseentered = false;
@@ -358,7 +355,7 @@
358355
}
359356
this.hovering = null;
360357

361-
// mjs - do not switch container if
358+
// do not switch container if
362359
// it's a root item and 'protectRoot' is true
363360
// or if it's not a root item but we are trying to make it root
364361
if (o.protectRoot &&
@@ -410,7 +407,7 @@
410407
}
411408
}
412409

413-
// mjs - to find the previous sibling in the list,
410+
// to find the previous sibling in the list,
414411
// keep backtracking until we hit a valid list item.
415412
(function() {
416413
var _previousItem = this.placeholder.prev();
@@ -437,7 +434,7 @@
437434
}
438435
}
439436

440-
// mjs - to find the next sibling in the list,
437+
// to find the next sibling in the list,
441438
// keep stepping forward until we hit a valid list item.
442439
(function() {
443440
var _nextItem = this.placeholder.next();
@@ -466,7 +463,7 @@
466463

467464
this.beyondMaxLevels = 0;
468465

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
470467
// but only if it's at the bottom of the list
471468
if (parentItem !== null &&
472469
parentItem !== undefined &&
@@ -496,7 +493,7 @@
496493
if(typeof parentItem !== 'undefined')
497494
this._clearEmpty(parentItem[0]);
498495
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,
500497
// make it a child of that sibling
501498
} else if (previousItem !== null && previousItem !== undefined &&
502499
!previousItem.hasClass(o.disableNestingClass) &&
@@ -531,11 +528,11 @@
531528
}
532529
}
533530

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.
535532
if (previousTopOffset && (previousTopOffset <= previousItem.offset().top)) {
536533
previousItem.children(o.listType).prepend(this.placeholder);
537534
} else {
538-
// mjs - otherwise, add it to the bottom of the list.
535+
// otherwise, add it to the bottom of the list.
539536
previousItem.children(o.listType)[0].appendChild(this.placeholder[0]);
540537
}
541538
if(typeof parentItem !== 'undefined')
@@ -562,7 +559,7 @@
562559
},
563560

564561
_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
566563
if (this.beyondMaxLevels) {
567564

568565
this.placeholder.removeClass(this.options.errorClass);
@@ -577,7 +574,7 @@
577574

578575
}
579576

580-
// mjs - clear the hovering timeout, just to be sure
577+
// clear the hovering timeout, just to be sure
581578
$("." + this.options.hoveringClass)
582579
.mouseleave()
583580
.removeClass(this.options.hoveringClass);
@@ -591,10 +588,10 @@
591588
this._relocate_event = event;
592589
this._pid_current = $(this.domPosition.parent).parent().attr("id");
593590
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.
595592
},
596593

597-
// mjs - this function is slightly modified
594+
// this function is slightly modified
598595
// to make it easier to hover over a collapsed element and have it expand
599596
_intersectsWithSides: function(item) {
600597
var half = this.options.isTree ? 0.8 : 0.5,
@@ -649,7 +646,7 @@
649646
this._trigger("relocate", this._relocate_event, this._uiHash());
650647
}
651648

652-
// mjs - clean last empty ul/ol
649+
// clean last empty ul/ol
653650
for (i = this.items.length - 1; i >= 0; i--) {
654651
item = this.items[i].item[0];
655652
this._clearEmpty(item);
@@ -798,8 +795,8 @@
798795
typeof parentItem !== 'undefined' && !oldParent.is(parentItem) ||
799796
typeof parentItem === 'undefined' && oldParent.is("li") //From somewhere to the root
800797
);
801-
// mjs - is the root protected?
802-
// mjs - are we nesting too deep?
798+
// is the root protected?
799+
// are we nesting too deep?
803800
if (
804801
disabledByParentchange ||
805802
!o.isAllowed(this.placeholder, parentItem, this.currentItem)
@@ -822,9 +819,9 @@
822819
}
823820
}));
824821

825-
$.mjs.nestedSortable.prototype.options = $.extend(
822+
$.qccf.nestedSortable.prototype.options = $.extend(
826823
{},
827824
$.ui.sortable.prototype.options,
828-
$.mjs.nestedSortable.prototype.options
825+
$.qccf.nestedSortable.prototype.options
829826
);
830827
}));

0 commit comments

Comments
 (0)