Is there a way to copy dragula element from one container to another using double click (double tap) for mobile views only? The dragging is not working great on mobiles, as the screen scrolls when you press and hold element with your finger.
To make things even more interesting, my draggable elements are divs 'btn-group' which have drop-down buttons such as:
<div class="btn-group">
<button type="button" class="btn dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="dropdownMenuButton1">
OPTIONS
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<a class="dropdown-item" href="#!">OPTION 1</a>
<a class="dropdown-item" href="#!">OPTION 2</a>
<a class="dropdown-item" href="#!">OPTION 3</a>
</div>
</div>
I am copying the divs (btn-group) not the dropdown-items.
That is why double tap seems a better solution. One tap to select dropdown item, double tap to copy across.
You can disable the default dropdown item click by using event.preventDefault()
in the click event. And then on doubleclick, you can move the clicked item.
$("#copyfrom .dropdown-item").on("click", function(e){
e.preventDefault();
return false;
});
$("#copyfrom .dropdown-item").on("dblclick", function(){
$(this).clone().appendTo("#copyto");
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/js/bootstrap.bundle.min.js"></script>
Dropdown Source:<div class="dropdown">
<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink" id="copyfrom">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
Dropdown Target:<div class="dropdown">
<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink" id="copyto">
</div>
</div>
And for the mobile detection, you can wrap these methods inside something like this:
$( document ).ready(function() {
var isMobile = window.matchMedia("only screen and (max-width: 760px)");
if (isMobile.matches) {
// Run the code above.
}
});
Taken from here: