What I'm trying to do
I was here but the problem was different to what I first thought.
I'm using a CMS that has set options for the sortable group already and I don't want to change them. What I do want to do is exclude a <div>
with the class
of "not-sortable"
from being sortable.
Current settings included in the CMS
$('.meta-box-sortables').sortable({
placeholder: 'sortable-placeholder',
connectWith: '.meta-box-sortables',
items: '.postbox',
handle: '.hndle',
cursor: 'move',
delay: ( isMobile ? 200 : 0 ),
distance: 2,
tolerance: 'pointer',
forcePlaceholderSize: true,
helper: 'clone',
opacity: 0.65,
});
As stated above, I've set one of the 'postbox'
sections with an additional class of 'not-sortable'
. Then in a custom .js
file I have the following.
My custom settings
jQuery(function($) {
$(".meta-box-sortables").sortable({
items : ':not(.not-sortable)'
});
});
This then removes the ability to move any previously draggable sections. Therefore it seems as though I'm overriding the items:
option.
Is there a way I can do this without overriding the original settings, or am I wrong in my train of thought here?
You can use the form of the option method that takes an object:
This way, the settings you don't specify will be preserved.
The elaborate upon the selector previously stored in the
item
option, you unfortunately have to specify it again:Concatenating to the previous value is feasible:
It will, however, fail if
items
contains a more complex selector (such as a multiple selector):