is it possible to drag the entire parent div in to child div. Dragula jQuery

54 Views Asked by At

I created an HTML page with Dragula jQuery plugin. in this page there is 2 parent-div with peach color and each parent-div includes a child-div with blue color. is it possible to drag the entire parent-div in to another child-div. Currently the parent div not moving inside to a child div. looking for a solution.

[jsfiddle](https://jsfiddle.net/unni2003pj/2h5Lks0d/18/)

in this fiddle the parent-div and child-div are adding dynamically by button click.

[Dragula Documentation](https://github.com/bevacqua/dragula)
[references](https://codepen.io/gabouh/pen/ZXrMzW)
[references](https://codepen.io/trzmaxim/pen/GppXGE)
[references](https://codepen.io/zeedoti/pen/wgpxPV)

JS:

// item drag and drop

// Initialize Dragula on the container
var dragulaContainer = [].slice.apply(document.querySelectorAll('.bloc'));
var drake;

function itemDrag() {
    drake = dragula([].slice.apply(document.querySelectorAll('.bloc')), {
        direction: 'horizontal'
    });
}

function destroyitemDrag() {
    drake.destroy();
}

function dragulaInt() {
    dragula([document.querySelector('.container')], {
        moves: function(el, container, handle) {
        return !handle.classList.contains('bloc--inner');
        }
    }); 
}

(function() {
    
    dragulaInt()
    //itemDrag();
})();
  
// Add Column
  
var i=0;
var j=0;

let newColNode = null;

function addRow() {    
    const row = document.createElement('div');
    row.className = 'bloc';
    row.id = "b" + ++i;
    document.getElementById('contentBox').append(row);
    itemDrag()

    row.addEventListener('click', function (event) {
        console.log(newColNode)
        console.log(row)
        if(newColNode != null ){
           
            destroyitemDrag()
            itemDrag()
            
        }
        row.appendChild(newColNode);        
        newColNode = null
    });
}
  
// Column Addition

function addCol() {
    const col = document.createElement('div');
    col.className = 'bloc--inner';
    col.id = "c" + ++j;
    col.textContent = `Column ${j}`;
    newColNode = col;
}

HTML:

<div class="wrapper">


  <div class="main-content">

    <div class="header">
      <button class="add-row" onclick="addRow()">Add Row +</button>
      <button class="add-column" onclick="addCol()">Add Column +</button>
    </div>

    <div class="content-box" >

      <div class="container" id="contentBox">
      </div>
      
      <p>
      Note: Click add row then to add column, click add column button and select a added row box at bottom
      </p>
    </div>

  </div>
</div>

CSS:

* {
    box-sizing: border-box;
}

.wrapper {
    float: left;
    width: 100%;
    height: 100vh;
}

body {
    padding: 0;
    margin: 0;
    position: relative;
}
.main-content {
    float: left;
    width: calc(100%);
    height: 100%;
    background: #fafafa;
}
.header {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 20px;
}
.content-box {
    width: 100%;
    height: calc(100% - 60px);
    padding: 15px;
}
button {
    background: #000;
    border: 0;
    padding: 0 20px;
    height: 40px;
    margin-left: 10px;
    font-weight: 600;
    color: white;
    cursor: pointer;
}
.row-block {
    width: 100%;
    border: 2px dashed #848484;
    padding: 20px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    margin-bottom: 20px;

}
.row-block:hover {
    border-color: #2654d1;
}
.column-block {
    position: relative;
    width: 100%;
    min-height: 1px;
    padding-right: 10px;
    padding-left: 10px;
    margin: 0 10px;
    -ms-flex-preferred-size: 0;
    flex-basis: 0;
    -webkit-box-flex: 1;
    -ms-flex-positive: 1;
    flex-grow: 1;
    max-width: 100%;
    border: 2px dashed #848484;

    background-color: #dedede;
    padding: 20px;
}
.column-block:first-child {
    margin-left: 0;
}
.column-block:last-child {
    margin-right: 0;
}
.row-block .each-draggable-item {
    position: relative;
    width: 100%;
    min-height: 1px;
    padding-right: 10px;
    padding-left: 10px;
    -ms-flex-preferred-size: 0;
    flex-basis: 0;
    -webkit-box-flex: 1;
    -ms-flex-positive: 1;
    flex-grow: 1;
    max-width: 100%;
    margin-bottom: 0;
}
.gu-mirror {
    cursor: grabbing;
}
.container .ex-moved {
    background-color: #e74c3c;
}
.container.ex-over {
    background-color: rgba(255, 255, 255, 0.3);
}
.handle {
    background-color: rgba(0, 0, 0, 0.4);
    cursor: move;
    margin-right: 5px;
    padding: 0 5px;
}
.column-block h5 {
    margin: 0;
}
.gu-transit {
    opacity: 0.4;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=20)";
    filter: alpha(opacity=20);
    transition: .3s ease-out;
}

.container {
    width: 100%;
}
.bloc {
    width: 100%;
    border: 2px dashed #848484;
    background: #ffefef;
    margin-bottom: 20px;
    padding: 20px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
}
 .bloc--inner {
    margin: 0 10px;
    -ms-flex-preferred-size: 0;
    flex-basis: 0;
    -webkit-box-flex: 1;
    -ms-flex-positive: 1;
    flex-grow: 1;
    max-width: 100%;
    border: 2px dashed #848484;
    background-color: #d4ecff;
    padding: 20px;
}
.bloc--inner:first-child {
    margin-left: 0;
}
.bloc--inner:last-child {
    margin-right: 0;
}
.bloc--inner .bloc {
    margin: 0;
}
0

There are 0 best solutions below