New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jquery-sortable-lists

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jquery-sortable-lists - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

3

CHANGELOG.md
<h1><a href="http://camohub.github.io/jquery-sortable-lists/index.html">jquery-sortable-lists</a></h1>
<h2 style="font-size:17px">Changelog</h2>
<h3>v1.3.0</h3>
<p>Added insertZonePlus option. Fixed bug with ol lists.</p>
<h3>v1.2.0</h3>

@@ -5,0 +8,0 @@ <p>Added opener.as option to opener. Now is possible to use opener.as html or class option.</p>

319

jquery-sortable-lists.js

@@ -7,3 +7,3 @@ /**

( function ( $ )
( function( $ )
{

@@ -19,4 +19,3 @@

// Local variables. This scope is available for all the functions in this closure.
var jQBody = $( 'body' )
.css( 'position', 'relative' ),
var jQBody = $( 'body' ).css( 'position', 'relative' ),

@@ -63,8 +62,9 @@ defaults = {

insertZone: 50,
insertZonePlus: false,
scroll: 20,
ignoreClass: '',
isAllowed: function( cEl, hint, target ) { return true; }, // Params: current el., hint el.
onDragStart: function( e, cEl ) { return true; }, // Params: e jQ. event obj., current el.
onChange: function( cEl ) { return true; }, // Params: current el.
complete: function( cEl ) { return true; } // Params: current el.
isAllowed: function( cEl, hint, target ) { return true; }, // Params: current el., hint el.
onDragStart: function( e, cEl ) { return true; }, // Params: e jQ. event obj., current el.
onChange: function( cEl ) { return true; }, // Params: current el.
complete: function( cEl ) { return true; } // Params: current el.
},

@@ -74,3 +74,3 @@

// base element from which is counted position of draged element
// base element from which is counted position of draged element
base = $( '<' + setting.listSelector + ' />' )

@@ -82,4 +82,4 @@ .prependTo( jQBody )

// placeholder != state.placeholderNode
// placeholder is document fragment and state.placeholderNode is document node
// placeholder != state.placeholderNode
// placeholder is document fragment and state.placeholderNode is document node
placeholder = $( '<li />' )

@@ -90,3 +90,3 @@ .attr( 'id', 'sortableListsPlaceholder' )

// hint is document fragment
// hint is document fragment
hint = $( '<li />' )

@@ -97,3 +97,3 @@ .attr( 'id', 'sortableListsHint' )

// Is document fragment used as wrapper if hint is inserted to the empty li
// Is document fragment used as wrapper if hint is inserted to the empty li
hintWrapper = $( '<' + setting.listSelector + ' />' )

@@ -105,3 +105,3 @@ .attr( 'id', 'sortableListsHintWrapper' )

// Is +/- ikon to open/close nested lists
// Is +/- ikon to open/close nested lists
opener = $( '<span />' )

@@ -114,11 +114,27 @@ .addClass( 'sortableListsOpener ' + setting.opener.openerClass )

if ( li.hasClass( 'sortableListsClosed' ) ) { open( li ); }
else { close( li ); }
if ( li.hasClass( 'sortableListsClosed' ) )
{
open( li );
}
else
{
close( li );
}
return false; // Prevent default
});
} );
if ( setting.opener.as == 'class' ) { opener.addClass( setting.opener.close ); }
else if ( setting.opener.as == 'html' ) { opener.html( setting.opener.close ); }
else { opener.css( 'background-image', 'url(' + setting.opener.close + ')' ); console.error( 'jQuerySortableLists opener as background image is deprecated. In version 2.0.0 it will be removed. Use html instead please.' ); }
if ( setting.opener.as == 'class' )
{
opener.addClass( setting.opener.close );
}
else if ( setting.opener.as == 'html' )
{
opener.html( setting.opener.close );
}
else
{
opener.css( 'background-image', 'url(' + setting.opener.close + ')' );
console.error( 'jQuerySortableLists opener as background image is deprecated. In version 2.0.0 it will be removed. Use html instead please.' );
}

@@ -157,6 +173,12 @@ // Container with all actual elements and parameters

if ( ! li.hasClass( 'sortableListsOpen' ) ) { close( li ); }
else { open( li ); }
if ( ! li.hasClass( 'sortableListsOpen' ) )
{
close( li );
}
else
{
open( li );
}
}
});
} );
}

@@ -175,7 +197,7 @@

// El must be li in jQuery object
var el = target.is( 'li' ) ? target : target.closest( 'li' ),
var el = target.closest( 'li' ),
rEl = $( this );
// Check if el is not empty
if ( el[0] )
if ( el[ 0 ] )
{

@@ -213,3 +235,3 @@ setting.onDragStart( e, el );

el: el,
mT: elMT, mL: elML, mB: elMB, mR: elMR,
mT: elMT, mL: elML, mB: elMB, mR: elMR,
offset: elXY

@@ -225,3 +247,3 @@ };

el.css({
el.css( {
'width': el.width(),

@@ -231,8 +253,8 @@ 'position': 'absolute',

'left': elXY.left - elML
}).prependTo( base );
} ).prependTo( base );
placeholderNode.css({
placeholderNode.css( {
'display': 'block',
'height': elIH
});
} );

@@ -275,3 +297,6 @@ hint.css( 'height', elIH );

e.pageY = e.pageY - setting.scroll;
$( 'html, body' ).each( function(i) { $( this ).scrollTop( $( this ).scrollTop() - setting.scroll); } );
$( 'html, body' ).each( function( i )
{
$( this ).scrollTop( $( this ).scrollTop() - setting.scroll );
} );
setCursorPos( e );

@@ -290,3 +315,6 @@ }

e.pageY = e.pageY + setting.scroll;
$( 'html, body' ).each( function(i) { $( this ).scrollTop( $( this ).scrollTop() + setting.scroll); } );
$( 'html, body' ).each( function( i )
{
$( this ).scrollTop( $( this ).scrollTop() + setting.scroll );
} );
setCursorPos( e );

@@ -303,5 +331,5 @@ }

cEl.el[0].style.visibility = 'hidden'; // This is important for the next row
cEl.el[ 0 ].style.visibility = 'hidden'; // This is important for the next row
state.oEl = oEl = elFromPoint( e.pageX, e.pageY );
cEl.el[0].style.visibility = 'visible';
cEl.el[ 0 ].style.visibility = 'visible';

@@ -323,3 +351,3 @@ showHint( e, state );

hintNode = $( '#sortableListsHint', state.rootEl.el ),
hintStyle = hint[0].style,
hintStyle = hint[ 0 ].style,
targetEl = null, // hintNode/placeholderNode

@@ -342,3 +370,3 @@ isHintTarget = false, // if cEl will be placed to the hintNode

cEl.el.animate( {left: offset.left - state.cEl.mL, top: offset.top - state.cEl.mT}, 250,
cEl.el.animate( { left: offset.left - state.cEl.mL, top: offset.top - state.cEl.mT }, 250,
function() // complete callback

@@ -348,4 +376,4 @@ {

targetEl.after( cEl.el[0] );
targetEl[0].style.display = 'none';
targetEl.after( cEl.el[ 0 ] );
targetEl[ 0 ].style.display = 'none';
hintStyle.display = 'none';

@@ -374,3 +402,3 @@ // This have to be document node, not hint as a part of documentFragment.

state.isDragged = false;
});
} );
}

@@ -385,3 +413,3 @@ else

});
} );

@@ -397,7 +425,7 @@ scrollStop( state );

//////////////////////////////////////////////////////////////////////////////////////////////////////
////////Helpers///////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
////////Helpers///////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////// Scroll handlers /////////////////////////////////////////////////////////////////////////////
//////// Scroll handlers /////////////////////////////////////////////////////////////////////////////

@@ -416,3 +444,3 @@ /**

state.doc.trigger( 'mousemove' );
}, 50);
}, 50 );

@@ -429,6 +457,7 @@ }

if ( state.downScroll ) return;
state.downScroll = setInterval( function()
{
state.doc.trigger( 'mousemove' );
}, 50);
}, 50 );

@@ -476,3 +505,3 @@ }

/////// Scroll handlers end ///////////////////////////////////////////////////////////////////
/////// End of Scroll handlers //////////////////////////////////////////////////////////////

@@ -489,6 +518,6 @@ /**

cEl.el.css({
cEl.el.css( {
'top': e.pageY - cEl.xyOffsetDiff.Y - cEl.mT,
'left': e.pageX - cEl.xyOffsetDiff.X - cEl.mL
})
} )

@@ -517,3 +546,3 @@ }

{
isRelEFP = ( (res = document.elementFromPoint( 0, s + $( window ).height() -1) ) == null
isRelEFP = ( (res = document.elementFromPoint( 0, s + $( window ).height() - 1 ) ) == null
|| res.tagName.toUpperCase() == 'HTML'); // IE8 returns html

@@ -523,3 +552,3 @@ }

{
isRelEFP = ( (res = document.elementFromPoint( s + $( window ).width() - 1, 0) ) == null
isRelEFP = ( (res = document.elementFromPoint( s + $( window ).width() - 1, 0 ) ) == null
|| res.tagName.toUpperCase() == 'HTML'); // IE8 returns html

@@ -536,3 +565,3 @@ }

// Returns jQuery object
var el = $( document.elementFromPoint( x,y ) );
var el = $( document.elementFromPoint( x, y ) );

@@ -550,3 +579,3 @@ if ( ! state.rootEl.el.find( el ).length ) // el is outside the rootEl

el = el.closest( 'li' );
return el[0] ? el : null;
return el[ 0 ] ? el : null;
}

@@ -560,2 +589,4 @@ else if ( el.is( 'li' ) ) // el is most wanted li

//////// Show hint handlers //////////////////////////////////////////////////////
/**

@@ -574,14 +605,27 @@ * @desc Shows or hides or does not show hint element

var oElH = oEl.outerHeight( false ),
var oElH = oEl.outerHeight( false ),
relY = e.pageY - oEl.offset().top;
if ( 5 > relY ) // Inserting before
if ( setting.insertZonePlus )
{
showHintBefore( e, oEl );
if ( 14 > relY ) // Inserting on top
{
showOnTopPlus( e, oEl, 7 > relY ); // Last bool param express if hint insert outside/inside
}
else if ( oElH - 14 < relY ) // Inserting on bottom
{
showOnBottomPlus( e, oEl, oElH - 7 < relY );
}
}
else if ( oElH - 5 < relY ) // Inserting after
else
{
showHintAfter( e, oEl );
if ( 5 > relY ) // Inserting on top
{
showOnTop( e, oEl );
}
else if ( oElH - 5 < relY ) // Inserting on bottom
{
showOnBottom( e, oEl );
}
}
}

@@ -595,3 +639,3 @@

*/
function showHintBefore( e, oEl )
function showOnTop( e, oEl )
{

@@ -618,3 +662,3 @@ if ( $( '#sortableListsHintWrapper', state.rootEl.el ).length )

var children = oEl.children(),
list = oEl.children( 'ul' ).first();
list = oEl.children( setting.listSelector ).first();

@@ -642,2 +686,3 @@ if ( list.children().first().is( '#sortableListsPlaceholder' ) )

}
}

@@ -647,3 +692,3 @@

// Ensures posible formating of elements. Second call is in the endDrag method.
state.isAllowed = setting.isAllowed( state.cEl.el, hint, hint.parents('li').first() );
state.isAllowed = setting.isAllowed( state.cEl.el, hint, hint.parents( 'li' ).first() );

@@ -653,2 +698,63 @@ }

/**
* @desc Called from showHint method. Displays or hides hint element
* @param e event
* @param oEl oElement
* @param outside bool
* @return No value
*/
function showOnTopPlus( e, oEl, outside )
{
if ( $( '#sortableListsHintWrapper', state.rootEl.el ).length )
{
hint.unwrap(); // If hint is wrapped by ul/ol #sortableListsHintWrapper
}
// Hint inside the oEl
if ( ! outside && e.pageX - oEl.offset().left > setting.insertZone )
{
var children = oEl.children(),
list = oEl.children( setting.listSelector ).first();
if ( list.children().first().is( '#sortableListsPlaceholder' ) )
{
hint.css( 'display', 'none' );
return;
}
// Find out if is necessary to wrap hint by hintWrapper
if ( ! list.length )
{
children.first().after( hint );
hint.wrap( hintWrapper );
}
else
{
list.prepend( hint );
}
if ( state.oEl )
{
open( oEl ); // TODO:animation??? .children('ul,ol').css('display', 'block');
}
}
// Hint outside the oEl
else
{
// Ensure display:none if hint will be next to the placeholder
if ( oEl.prev( '#sortableListsPlaceholder' ).length )
{
hint.css( 'display', 'none' );
return;
}
oEl.before( hint );
}
hint.css( 'display', 'block' );
// Ensures posible formating of elements. Second call is in the endDrag method.
state.isAllowed = setting.isAllowed( state.cEl.el, hint, hint.parents( 'li' ).first() );
}
/**
* @desc Called from showHint function. Displays or hides hint element.

@@ -659,3 +765,3 @@ * @param e event

*/
function showHintAfter( e, oEl )
function showOnBottom( e, oEl )
{

@@ -710,3 +816,3 @@ if ( $( '#sortableListsHintWrapper', state.rootEl.el ).length )

// Ensures posible formating of elements. Second call is in the endDrag method.
state.isAllowed = setting.isAllowed( state.cEl.el, hint, hint.parents('li').first() );
state.isAllowed = setting.isAllowed( state.cEl.el, hint, hint.parents( 'li' ).first() );

@@ -716,2 +822,67 @@ }

/**
* @desc Called from showHint function. Displays or hides hint element.
* @param e event
* @param oEl oElement
* @param outside bool
* @return No value
*/
function showOnBottomPlus( e, oEl, outside )
{
if ( $( '#sortableListsHintWrapper', state.rootEl.el ).length )
{
hint.unwrap(); // If hint is wrapped by ul/ol sortableListsHintWrapper
}
// Hint inside the oEl
if ( ! outside && e.pageX - oEl.offset().left > setting.insertZone )
{
var children = oEl.children(),
list = oEl.children( setting.listSelector ).last(); // ul/ol || empty jQuery obj
if ( list.children().last().is( '#sortableListsPlaceholder' ) )
{
hint.css( 'display', 'none' );
return;
}
// Find out if is necessary to wrap hint by hintWrapper
if ( list.length )
{
children.last().append( hint );
}
else
{
oEl.append( hint );
hint.wrap( hintWrapper );
}
if ( state.oEl )
{
open( oEl ); // TODO: animation???
}
}
// Hint outside the oEl
else
{
// Ensure display:none if hint will be next to the placeholder
if ( oEl.next( '#sortableListsPlaceholder' ).length )
{
hint.css( 'display', 'none' );
return;
}
oEl.after( hint );
}
hint.css( 'display', 'block' );
// Ensures posible formating of elements. Second call is in the endDrag method.
state.isAllowed = setting.isAllowed( state.cEl.el, hint, hint.parents( 'li' ).first() );
}
//////// End of show hint handlers ////////////////////////////////////////////////////
//////// Open/close handlers //////////////////////////////////////////////////////////
/**
* @desc Handles opening nested lists

@@ -767,2 +938,4 @@ * @param li

/////// Enf of open/close handlers //////////////////////////////////////////////
/**

@@ -774,3 +947,3 @@ * @desc Places the currEl to the target place

{
var cElStyle = cEl.el[0].style;
var cElStyle = cEl.el[ 0 ].style;

@@ -792,3 +965,3 @@ cEl.el.removeClass( setting.currElClass + ' ' + 'sortableListsCurrent' );

// hintWrapper can not be removed before the hint
$( setting.listSelector, state.rootEl.el ).each( function(i)
$( setting.listSelector, state.rootEl.el ).each( function( i )
{

@@ -808,3 +981,3 @@ if ( ! $( this ).children().length )

//// toArray /////////////////////////////////////////////////////////////////////////////////////
//// toArray /////////////////////////////////////////////////////////////////////////////////////

@@ -838,4 +1011,4 @@ /**

li.children( 'ul,ol' ).sortableListsToArray( arr, id );
order++;
});
order ++;
} );

@@ -871,4 +1044,4 @@ return arr;

listItem.children = li.children( 'ul,ol' ).sortableListsToHierarchy();
order++;
});
order ++;
} );

@@ -900,6 +1073,6 @@ return arr;

arr.push( matches[1] + '[' + matches[2] + ']=' + parentId );
$( this ).children( 'ul,ol' ).sortableListsToString( arr, matches[2] );
arr.push( matches[ 1 ] + '[' + matches[ 2 ] + ']=' + parentId );
$( this ).children( 'ul,ol' ).sortableListsToString( arr, matches[ 2 ] );
});
} );

@@ -906,0 +1079,0 @@ return arr.join( '&' );

/*
MIT
*/
(function(f){f.fn.sortableLists=function(g){function n(a){if(b.isDragged){var m=b.cEl,e=b.doc,h=b.win;a.pageX||z(a);e.scrollTop()>b.rootEl.offset.top-10&&50>a.clientY?b.upScroll?(a.pageY-=c.scroll,f("html, body").each(function(a){f(this).scrollTop(f(this).scrollTop()-c.scroll)}),p(a)):d(a):e.scrollTop()+h.height()<b.rootEl.offset.top+b.rootEl.el.outerHeight(!1)+10&&50>h.height()-a.clientY?b.downScroll?(a.pageY+=c.scroll,f("html, body").each(function(a){f(this).scrollTop(f(this).scrollTop()+c.scroll)}),
p(a)):k(a):v(b);b.oElOld=b.oEl;m.el[0].style.visibility="hidden";b.oEl=oEl=A(a.pageX,a.pageY);m.el[0].style.visibility="visible";B(a,b);C(a,b)}}function l(a){var m=b.cEl,e=f("#sortableListsHint",b.rootEl.el),d=h[0].style,u=null,g=!1,k=f("#sortableListsHintWrapper");"block"==d.display&&e.length&&b.isAllowed?(u=e,g=!0):(u=b.placeholderNode,g=!1);offset=u.offset();m.el.animate({left:offset.left-b.cEl.mL,top:offset.top-b.cEl.mT},250,function(){D(m);u.after(m.el[0]);u[0].style.display="none";d.display=
"none";e.remove();k.removeAttr("id").removeClass(c.hintWrapperClass);k.length&&k.prev("div").append(r.clone(!0));g?b.placeholderNode.slideUp(150,function(){b.placeholderNode.remove();w();c.onChange(m.el);c.complete(m.el);b.isDragged=!1}):(b.placeholderNode.remove(),w(),c.complete(m.el),b.isDragged=!1)});v(b);b.doc.unbind("mousemove",n).unbind("mouseup",l)}function d(a){b.upScroll||(b.upScroll=setInterval(function(){b.doc.trigger("mousemove")},50))}function k(a){b.downScroll||(b.downScroll=setInterval(function(){b.doc.trigger("mousemove")},
50))}function p(a){b.pY=a.pageY;b.pX=a.pageX;b.cY=a.clientY;b.cX=a.clientX}function z(a){a.pageY=b.pY;a.pageX=b.pX;a.clientY=b.cY;a.clientX=b.cX}function v(a){clearInterval(a.upScroll);clearInterval(a.downScroll);a.upScroll=a.downScroll=!1}function C(a,b){var c=b.cEl;c.el.css({top:a.pageY-c.xyOffsetDiff.Y-c.mT,left:a.pageX-c.xyOffsetDiff.X-c.mL})}function A(a,c){if(!document.elementFromPoint)return null;var e=b.isRelEFP;if(null===e){var h,d;0<(h=b.doc.scrollTop())&&(e=null==(d=document.elementFromPoint(0,
h+f(window).height()-1))||"HTML"==d.tagName.toUpperCase());0<(h=b.doc.scrollLeft())&&(e=null==(d=document.elementFromPoint(h+f(window).width()-1,0))||"HTML"==d.tagName.toUpperCase())}e&&(a-=b.doc.scrollLeft(),c-=b.doc.scrollTop());e=f(document.elementFromPoint(a,c));if(b.rootEl.el.find(e).length){if(e.is("#sortableListsPlaceholder")||e.is("#sortableListsHint"))return null;if(!e.is("li"))return e=e.closest("li"),e[0]?e:null;if(e.is("li"))return e}else return null}function B(a,m){var e=m.oEl;if(e&&
m.oElOld){var d=e.outerHeight(!1),g=a.pageY-e.offset().top;if(5>g)a:{f("#sortableListsHintWrapper",b.rootEl.el).length&&h.unwrap();if(a.pageX-e.offset().left<c.insertZone){if(e.prev("#sortableListsPlaceholder").length){h.css("display","none");break a}e.before(h)}else{d=e.children();g=e.children("ul").first();if(g.children().first().is("#sortableListsPlaceholder")){h.css("display","none");break a}g.length?g.prepend(h):(d.first().after(h),h.wrap(x));b.oEl&&q(e)}h.css("display","block");b.isAllowed=
c.isAllowed(b.cEl.el,h,h.parents("li").first())}else if(d-5<g)a:{f("#sortableListsHintWrapper",b.rootEl.el).length&&h.unwrap();if(a.pageX-e.offset().left<c.insertZone){if(e.next("#sortableListsPlaceholder").length){h.css("display","none");break a}e.after(h)}else{d=e.children();g=e.children(c.listSelector).last();if(g.children().last().is("#sortableListsPlaceholder")){h.css("display","none");break a}g.length?d.last().append(h):(e.append(h),h.wrap(x));b.oEl&&q(e)}h.css("display","block");b.isAllowed=
c.isAllowed(b.cEl.el,h,h.parents("li").first())}}}function q(a){a.removeClass("sortableListsClosed").addClass("sortableListsOpen");a.children(c.listSelector).css("display","block");a=a.children("div").children(".sortableListsOpener").first();"html"==c.opener.as?a.html(c.opener.close):"class"==c.opener.as?a.addClass(c.opener.close).removeClass(c.opener.open):a.css("background-image","url("+c.opener.close+")")}function y(a){a.removeClass("sortableListsOpen").addClass("sortableListsClosed");a.children(c.listSelector).css("display",
"none");a=a.children("div").children(".sortableListsOpener").first();"html"==c.opener.as?a.html(c.opener.open):"class"==c.opener.as?a.addClass(c.opener.open).removeClass(c.opener.close):a.css("background-image","url("+c.opener.open+")")}function D(a){var b=a.el[0].style;a.el.removeClass(c.currElClass+" sortableListsCurrent");b.top="0";b.left="0";b.position="relative";b.width="auto"}function w(){f(c.listSelector,b.rootEl.el).each(function(a){f(this).children().length||(f(this).prev("div").children(".sortableListsOpener").first().remove(),
f(this).remove())})}var t=f("body").css("position","relative"),E={currElClass:"",placeholderClass:"",placeholderCss:{position:"relative",padding:0},hintClass:"",hintCss:{display:"none",position:"relative",padding:0},hintWrapperClass:"",hintWrapperCss:{},baseClass:"",baseCss:{position:"absolute",top:0-parseInt(t.css("margin-top")),left:0-parseInt(t.css("margin-left")),margin:0,padding:0,"z-index":2500},opener:{active:!1,open:"",close:"",openerCss:{"float":"left",display:"inline-block","background-position":"center center",
"background-repeat":"no-repeat"},openerClass:""},listSelector:"ul",listsClass:"",listsCss:{},insertZone:50,scroll:20,ignoreClass:"",isAllowed:function(a,b,c){return!0},onDragStart:function(a,b){return!0},onChange:function(a){return!0},complete:function(a){return!0}},c=f.extend(!0,{},E,g),F=f("<"+c.listSelector+" />").prependTo(t).attr("id","sortableListsBase").css(c.baseCss).addClass(c.listsClass+" "+c.baseClass),G=f("<li />").attr("id","sortableListsPlaceholder").css(c.placeholderCss).addClass(c.placeholderClass),
h=f("<li />").attr("id","sortableListsHint").css(c.hintCss).addClass(c.hintClass),x=f("<"+c.listSelector+" />").attr("id","sortableListsHintWrapper").addClass(c.listsClass+" "+c.hintWrapperClass).css(c.listsCss).css(c.hintWrapperCss),r=f("<span />").addClass("sortableListsOpener "+c.opener.openerClass).css(c.opener.openerCss).on("mousedown",function(a){a=f(this).closest("li");a.hasClass("sortableListsClosed")?q(a):y(a);return!1});"class"==c.opener.as?r.addClass(c.opener.close):"html"==c.opener.as?
r.html(c.opener.close):(r.css("background-image","url("+c.opener.close+")"),console.error("jQuerySortableLists opener as background image is deprecated. In version 2.0.0 it will be removed. Use html instead please."));var b={isDragged:!1,isRelEFP:null,oEl:null,rootEl:null,cEl:null,upScroll:!1,downScroll:!1,pX:0,pY:0,cX:0,cY:0,isAllowed:!0,e:{pageX:0,pageY:0,clientX:0,clientY:0},doc:f(document),win:f(window)};if(c.opener.active){if(!c.opener.open)throw"Opener.open value is not defined. It should be valid url, html or css class.";
if(!c.opener.close)throw"Opener.close value is not defined. It should be valid url, html or css class.";f(this).find("li").each(function(){var a=f(this);a.children(c.listSelector).length&&(r.clone(!0).prependTo(a.children("div").first()),a.hasClass("sortableListsOpen")?q(a):y(a))})}return this.on("mousedown",function(a){var d=f(a.target);if(!(!1!==b.isDragged||c.ignoreClass&&d.hasClass(c.ignoreClass))){a.preventDefault();var d=d.is("li")?d:d.closest("li"),e=f(this);if(d[0]){c.onDragStart(a,d);b.isDragged=
!0;var g=parseInt(d.css("margin-top")),k=parseInt(d.css("margin-bottom")),p=parseInt(d.css("margin-left")),r=parseInt(d.css("margin-right")),q=d.offset(),t=d.innerHeight();b.rootEl={el:e,offset:e.offset(),rootElClass:e.attr("class")};b.cEl={el:d,mT:g,mL:p,mB:k,mR:r,offset:q};b.cEl.xyOffsetDiff={X:a.pageX-b.cEl.offset.left,Y:a.pageY-b.cEl.offset.top};b.cEl.el.addClass("sortableListsCurrent "+c.currElClass);d.before(G);a=b.placeholderNode=f("#sortableListsPlaceholder");d.css({width:d.width(),position:"absolute",
top:q.top-g,left:q.left-p}).prependTo(F);a.css({display:"block",height:t});h.css("height",t);b.doc.on("mousemove",n).on("mouseup",l)}}})};f.fn.sortableListsToArray=function(g,n){g=g||[];var l=0;this.children("li").each(function(){var d=f(this),k={},p=d.attr("id");if(!p)throw console.log(d),"Previous item in console.log has no id. It is necessary to create the array.";k.id=p;k.parentId=n;k.value=d.data("value");k.order=l;g.push(k);d.children("ul,ol").sortableListsToArray(g,p);l++});return g};f.fn.sortableListsToHierarchy=
function(){var g=[],n=0;f(this).children("li").each(function(){var l=f(this),d={},k=l.attr("id");if(!k)throw console.log(l),"Previous item in console.log has no id. It is necessary to create the array.";d.id=k;d.value=l.data("value");d.order=n;g.push(d);d.children=l.children("ul,ol").sortableListsToHierarchy();n++});return g};f.fn.sortableListsToString=function(g,n){g=g||[];n=n||"no-parent";f(this).children("li").each(function(){var l=f(this),d=l.attr("id"),d=d?d.match(/(.+)[-=_](.+)/):null;if(!d)throw console.log(l),
"Previous item in console.log has no id or id is not in required format xx_yy, xx-yy or xx=yy. It is necessary to create valid string.";g.push(d[1]+"["+d[2]+"]="+n);f(this).children("ul,ol").sortableListsToString(g,d[2])});return g.join("&")}})(jQuery);
(function(g){g.fn.sortableLists=function(k){function n(a){if(b.isDragged){var f=b.cEl,d=b.doc,u=b.win;a.pageX||A(a);d.scrollTop()>b.rootEl.offset.top-10&&50>a.clientY?b.upScroll?(a.pageY-=c.scroll,g("html, body").each(function(a){g(this).scrollTop(g(this).scrollTop()-c.scroll)}),r(a)):e(a):d.scrollTop()+u.height()<b.rootEl.offset.top+b.rootEl.el.outerHeight(!1)+10&&50>u.height()-a.clientY?b.downScroll?(a.pageY+=c.scroll,g("html, body").each(function(a){g(this).scrollTop(g(this).scrollTop()+c.scroll)}),
r(a)):l(a):x(b);b.oElOld=b.oEl;f.el[0].style.visibility="hidden";b.oEl=oEl=B(a.pageX,a.pageY);f.el[0].style.visibility="visible";C(a,b);D(a,b)}}function m(a){var q=b.cEl,d=g("#sortableListsHint",b.rootEl.el),u=f[0].style,h=null,e=!1,k=g("#sortableListsHintWrapper");"block"==u.display&&d.length&&b.isAllowed?(h=d,e=!0):(h=b.placeholderNode,e=!1);offset=h.offset();q.el.animate({left:offset.left-b.cEl.mL,top:offset.top-b.cEl.mT},250,function(){E(q);h.after(q.el[0]);h[0].style.display="none";u.display=
"none";d.remove();k.removeAttr("id").removeClass(c.hintWrapperClass);k.length&&k.prev("div").append(t.clone(!0));e?b.placeholderNode.slideUp(150,function(){b.placeholderNode.remove();y();c.onChange(q.el);c.complete(q.el);b.isDragged=!1}):(b.placeholderNode.remove(),y(),c.complete(q.el),b.isDragged=!1)});x(b);b.doc.unbind("mousemove",n).unbind("mouseup",m)}function e(a){b.upScroll||(b.upScroll=setInterval(function(){b.doc.trigger("mousemove")},50))}function l(a){b.downScroll||(b.downScroll=setInterval(function(){b.doc.trigger("mousemove")},
50))}function r(a){b.pY=a.pageY;b.pX=a.pageX;b.cY=a.clientY;b.cX=a.clientX}function A(a){a.pageY=b.pY;a.pageX=b.pX;a.clientY=b.cY;a.clientX=b.cX}function x(a){clearInterval(a.upScroll);clearInterval(a.downScroll);a.upScroll=a.downScroll=!1}function D(a,b){var c=b.cEl;c.el.css({top:a.pageY-c.xyOffsetDiff.Y-c.mT,left:a.pageX-c.xyOffsetDiff.X-c.mL})}function B(a,c){if(!document.elementFromPoint)return null;var d=b.isRelEFP;if(null===d){var f,h;0<(f=b.doc.scrollTop())&&(d=null==(h=document.elementFromPoint(0,
f+g(window).height()-1))||"HTML"==h.tagName.toUpperCase());0<(f=b.doc.scrollLeft())&&(d=null==(h=document.elementFromPoint(f+g(window).width()-1,0))||"HTML"==h.tagName.toUpperCase())}d&&(a-=b.doc.scrollLeft(),c-=b.doc.scrollTop());d=g(document.elementFromPoint(a,c));if(b.rootEl.el.find(d).length){if(d.is("#sortableListsPlaceholder")||d.is("#sortableListsHint"))return null;if(!d.is("li"))return d=d.closest("li"),d[0]?d:null;if(d.is("li"))return d}else return null}function C(a,q){var d=q.oEl;if(d&&
q.oElOld){var e=d.outerHeight(!1),h=a.pageY-d.offset().top;if(c.insertZonePlus)if(14>h)a:{e=7>h;g("#sortableListsHintWrapper",b.rootEl.el).length&&f.unwrap();if(!e&&a.pageX-d.offset().left>c.insertZone){e=d.children();h=d.children(c.listSelector).first();if(h.children().first().is("#sortableListsPlaceholder")){f.css("display","none");break a}h.length?h.prepend(f):(e.first().after(f),f.wrap(v));b.oEl&&p(d)}else{if(d.prev("#sortableListsPlaceholder").length){f.css("display","none");break a}d.before(f)}f.css("display",
"block");b.isAllowed=c.isAllowed(b.cEl.el,f,f.parents("li").first())}else{if(e-14<h)a:{e=e-7<h;g("#sortableListsHintWrapper",b.rootEl.el).length&&f.unwrap();if(!e&&a.pageX-d.offset().left>c.insertZone){e=d.children();h=d.children(c.listSelector).last();if(h.children().last().is("#sortableListsPlaceholder")){f.css("display","none");break a}h.length?e.last().append(f):(d.append(f),f.wrap(v));b.oEl&&p(d)}else{if(d.next("#sortableListsPlaceholder").length){f.css("display","none");break a}d.after(f)}f.css("display",
"block");b.isAllowed=c.isAllowed(b.cEl.el,f,f.parents("li").first())}}else if(5>h)a:{g("#sortableListsHintWrapper",b.rootEl.el).length&&f.unwrap();if(a.pageX-d.offset().left<c.insertZone){if(d.prev("#sortableListsPlaceholder").length){f.css("display","none");break a}d.before(f)}else{e=d.children();h=d.children(c.listSelector).first();if(h.children().first().is("#sortableListsPlaceholder")){f.css("display","none");break a}h.length?h.prepend(f):(e.first().after(f),f.wrap(v));b.oEl&&p(d)}f.css("display",
"block");b.isAllowed=c.isAllowed(b.cEl.el,f,f.parents("li").first())}else if(e-5<h)a:{g("#sortableListsHintWrapper",b.rootEl.el).length&&f.unwrap();if(a.pageX-d.offset().left<c.insertZone){if(d.next("#sortableListsPlaceholder").length){f.css("display","none");break a}d.after(f)}else{e=d.children();h=d.children(c.listSelector).last();if(h.children().last().is("#sortableListsPlaceholder")){f.css("display","none");break a}h.length?e.last().append(f):(d.append(f),f.wrap(v));b.oEl&&p(d)}f.css("display",
"block");b.isAllowed=c.isAllowed(b.cEl.el,f,f.parents("li").first())}}}function p(a){a.removeClass("sortableListsClosed").addClass("sortableListsOpen");a.children(c.listSelector).css("display","block");a=a.children("div").children(".sortableListsOpener").first();"html"==c.opener.as?a.html(c.opener.close):"class"==c.opener.as?a.addClass(c.opener.close).removeClass(c.opener.open):a.css("background-image","url("+c.opener.close+")")}function z(a){a.removeClass("sortableListsOpen").addClass("sortableListsClosed");
a.children(c.listSelector).css("display","none");a=a.children("div").children(".sortableListsOpener").first();"html"==c.opener.as?a.html(c.opener.open):"class"==c.opener.as?a.addClass(c.opener.open).removeClass(c.opener.close):a.css("background-image","url("+c.opener.open+")")}function E(a){var b=a.el[0].style;a.el.removeClass(c.currElClass+" sortableListsCurrent");b.top="0";b.left="0";b.position="relative";b.width="auto"}function y(){g(c.listSelector,b.rootEl.el).each(function(a){g(this).children().length||
(g(this).prev("div").children(".sortableListsOpener").first().remove(),g(this).remove())})}var w=g("body").css("position","relative"),F={currElClass:"",placeholderClass:"",placeholderCss:{position:"relative",padding:0},hintClass:"",hintCss:{display:"none",position:"relative",padding:0},hintWrapperClass:"",hintWrapperCss:{},baseClass:"",baseCss:{position:"absolute",top:0-parseInt(w.css("margin-top")),left:0-parseInt(w.css("margin-left")),margin:0,padding:0,"z-index":2500},opener:{active:!1,open:"",
close:"",openerCss:{"float":"left",display:"inline-block","background-position":"center center","background-repeat":"no-repeat"},openerClass:""},listSelector:"ul",listsClass:"",listsCss:{},insertZone:50,insertZonePlus:!1,scroll:20,ignoreClass:"",isAllowed:function(a,b,c){return!0},onDragStart:function(a,b){return!0},onChange:function(a){return!0},complete:function(a){return!0}},c=g.extend(!0,{},F,k),G=g("<"+c.listSelector+" />").prependTo(w).attr("id","sortableListsBase").css(c.baseCss).addClass(c.listsClass+
" "+c.baseClass),H=g("<li />").attr("id","sortableListsPlaceholder").css(c.placeholderCss).addClass(c.placeholderClass),f=g("<li />").attr("id","sortableListsHint").css(c.hintCss).addClass(c.hintClass),v=g("<"+c.listSelector+" />").attr("id","sortableListsHintWrapper").addClass(c.listsClass+" "+c.hintWrapperClass).css(c.listsCss).css(c.hintWrapperCss),t=g("<span />").addClass("sortableListsOpener "+c.opener.openerClass).css(c.opener.openerCss).on("mousedown",function(a){a=g(this).closest("li");a.hasClass("sortableListsClosed")?
p(a):z(a);return!1});"class"==c.opener.as?t.addClass(c.opener.close):"html"==c.opener.as?t.html(c.opener.close):(t.css("background-image","url("+c.opener.close+")"),console.error("jQuerySortableLists opener as background image is deprecated. In version 2.0.0 it will be removed. Use html instead please."));var b={isDragged:!1,isRelEFP:null,oEl:null,rootEl:null,cEl:null,upScroll:!1,downScroll:!1,pX:0,pY:0,cX:0,cY:0,isAllowed:!0,e:{pageX:0,pageY:0,clientX:0,clientY:0},doc:g(document),win:g(window)};
if(c.opener.active){if(!c.opener.open)throw"Opener.open value is not defined. It should be valid url, html or css class.";if(!c.opener.close)throw"Opener.close value is not defined. It should be valid url, html or css class.";g(this).find("li").each(function(){var a=g(this);a.children(c.listSelector).length&&(t.clone(!0).prependTo(a.children("div").first()),a.hasClass("sortableListsOpen")?p(a):z(a))})}return this.on("mousedown",function(a){var e=g(a.target);if(!(!1!==b.isDragged||c.ignoreClass&&e.hasClass(c.ignoreClass))){a.preventDefault();
var e=e.closest("li"),d=g(this);if(e[0]){c.onDragStart(a,e);b.isDragged=!0;var k=parseInt(e.css("margin-top")),h=parseInt(e.css("margin-bottom")),l=parseInt(e.css("margin-left")),r=parseInt(e.css("margin-right")),p=e.offset(),t=e.innerHeight();b.rootEl={el:d,offset:d.offset(),rootElClass:d.attr("class")};b.cEl={el:e,mT:k,mL:l,mB:h,mR:r,offset:p};b.cEl.xyOffsetDiff={X:a.pageX-b.cEl.offset.left,Y:a.pageY-b.cEl.offset.top};b.cEl.el.addClass("sortableListsCurrent "+c.currElClass);e.before(H);a=b.placeholderNode=
g("#sortableListsPlaceholder");e.css({width:e.width(),position:"absolute",top:p.top-k,left:p.left-l}).prependTo(G);a.css({display:"block",height:t});f.css("height",t);b.doc.on("mousemove",n).on("mouseup",m)}}})};g.fn.sortableListsToArray=function(k,n){k=k||[];var m=0;this.children("li").each(function(){var e=g(this),l={},r=e.attr("id");if(!r)throw console.log(e),"Previous item in console.log has no id. It is necessary to create the array.";l.id=r;l.parentId=n;l.value=e.data("value");l.order=m;k.push(l);
e.children("ul,ol").sortableListsToArray(k,r);m++});return k};g.fn.sortableListsToHierarchy=function(){var k=[],n=0;g(this).children("li").each(function(){var m=g(this),e={},l=m.attr("id");if(!l)throw console.log(m),"Previous item in console.log has no id. It is necessary to create the array.";e.id=l;e.value=m.data("value");e.order=n;k.push(e);e.children=m.children("ul,ol").sortableListsToHierarchy();n++});return k};g.fn.sortableListsToString=function(k,n){k=k||[];n=n||"no-parent";g(this).children("li").each(function(){var m=
g(this),e=m.attr("id"),e=e?e.match(/(.+)[-=_](.+)/):null;if(!e)throw console.log(m),"Previous item in console.log has no id or id is not in required format xx_yy, xx-yy or xx=yy. It is necessary to create valid string.";k.push(e[1]+"["+e[2]+"]="+n);g(this).children("ul,ol").sortableListsToString(k,e[2])});return k.join("&")}})(jQuery);
{
"name": "jquery-sortable-lists",
"version": "1.2.0",
"version": "1.2.1",
"description": "jQuery plugin to sorting lists also the tree structures",

@@ -5,0 +5,0 @@ "main": "jquery-sortable-lists.min.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc