Skip to content

Commit

Permalink
Prevent sortable nested group being able to be moved outside of its p…
Browse files Browse the repository at this point in the history
…arent.
  • Loading branch information
rilwis committed Jan 22, 2018
1 parent 8c1ed58 commit 3ee0b91
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions js/clone.js
Expand Up @@ -188,6 +188,29 @@ jQuery( function ( $ ) {
$button.toggle( isNaN( maxClone ) || ( maxClone && numClone < maxClone ) );
}

/**
* Initialize clone sorting.
*/
function initSortable() {
$( '.rwmb-input' ).each( function () {
var $container = $( this );

if ( undefined !== $container.sortable( 'instance' ) ) {
return;
}

$container.sortable( {
handle: '.rwmb-clone-icon',
placeholder: ' rwmb-clone rwmb-sortable-placeholder',
items: '.rwmb-clone',
start: function ( event, ui ) {
// Make the placeholder has the same height as dragged item
ui.placeholder.height( ui.item.outerHeight() );
}
} );
} );
}

$( document )
// Add clones
.on( 'click', '.add-clone', function ( e ) {
Expand All @@ -198,6 +221,7 @@ jQuery( function ( $ ) {

toggleRemoveButtons( $container );
toggleAddButton( $container );
initSortable();
} )
// Remove clones
.on( 'click', '.remove-clone', function ( e ) {
Expand Down

0 comments on commit 3ee0b91

Please sign in to comment.