Two sortables stacked using z-index - jquery-ui

I have this setup. JSFiddle link.
$('.item').draggable({
helper: 'clone',
connectToSortable: '.first-sortable, .second-sortable',
});
$('.first-sortable').sortable({
connectWith: '.second-sortable',
receive: function () {
$('.logger1').addClass('animated');
setTimeout(function () {
$('.logger1').removeClass('animated');
}, 300);
}
});
$('.second-sortable').sortable({
connectWith: '.first-sortable',
receive: function () {
$('.logger2').addClass('animated');
setTimeout(function () {
$('.logger2').removeClass('animated');
}, 300);
}
});
.item {
width: 50px;
height: 50px;
background: red;
display: inline-block;
margin-right: 5px;
}
.container {
position: relative;
margin-bottom: 20px;
}
.first-sortable {
height: 100px;
background: blue;
}
.second-sortable {
position: absolute;
left: 50%;
width: 200px;
transform: translateX(-50%);
top: 0;
bottom: 0;
background: rgba(3, 3, 3, .8);
z-index: 10;
padding-left: 20px;
}
.logger2,
.logger1 {
transition: all .3s color;
}
.animated {
color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div class="container">
<div class="first-sortable"></div>
<div class="second-sortable"></div>
</div>
<div class="item"></div>
<div class="logger1">Blue Sortable Receive</div>
<div class="logger2">Dark Sortable Receive</div>
The main idea is that, as you can see, is that the dark sortable is above the first one, it is positioned using position: absolute and z-index. I have a little bit of opacity for the black one, just so I can look what happens with the first sortable.
Below the bottom red square we have two indicators that shows when receive event is fired on the specific sortable.
Please note the fact that when you drop an item onto the blue sortable, only indicator for this sortable is fired. When I drop a new item onto the black a receive event is fired on both sortables.
Is this behavior a desired one? I think, in this case just the dark one have to receive this event.
I wonder if this is not jQuery UI bug. Ticket.

Related

iOS 10 Safari fixed menu button unclickable after scrolling

I'm having an issue with a fixed menu on iOS 10 Safari where the button sometimes becomes unclickable after scrolling. From debugging, the best I can tell is that the menu button's position isn't always updated properly after the scroll.
position bug screenshot
Sometimes it takes several clicks for the button to become responsive, and occasionally it forces the screen to scroll or zoom before the menu will open.
The issue only seems to be occurring on iPhone 7 using Safari, from what I've seen, but it may be present somewhere else I haven't found yet.
I've created a simplified version of the page with the issue here: http://meghandove.com/test.html
jQuery(document).ready(function() {
jQuery('a.menu-trigger').click(function(e) {
e.stopPropagation();
e.preventDefault();
if (jQuery('.menu').hasClass('menu-open')) {
jQuery('.menu').removeClass('menu-open');
jQuery('.menu').addClass('menu-close');
} else {
jQuery('.menu').removeClass('menu-close');
jQuery('.menu').addClass('menu-open');
}
});
});
body {
padding-top: 60px;
}
header {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 60px;
background: #FFFFFF;
transform: translate3d(0, 0, 0);
}
header .menu-trigger {
padding: 20px;
display: block;
text-align: center;
}
.menu ul {
height: 100%;
background: #FFFFFF;
margin: 0;
padding: 30px 0 0;
list-style: none;
position: fixed;
top: 50px;
right: 0;
}
.menu ul li,
.menu ul li a {
display: block;
}
.menu ul li {
display: none;
opacity: 0;
}
.menu.menu-open ul li {
display: list-item;
opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<header class="navbar">
<span>Menu</span>
<nav class="menu">
<div class="menu-ul">
<ul>
<li class="menu-item">About</li>
<li class="menu-item">Something</li>
<li class="menu-item">Something Else</li>
</ul>
</div>
</nav>
</header>

jQuery UI draggable locking divs

I wrote some kind of that: http://jsfiddle.net/py3DE/203/ but when element is dragged into proper container, we can override it by dragging other div into its area. Could you tel me how i can block dragged elements, and if someone will try to override any element, div returns back into area with undragged divs?
if (!ui.draggable.closest('.empty').length) item = item.draggable()'
There is a simple way to do this. Basically, we'll remove the class empty and use the disable method.
Working Example: http://jsfiddle.net/Twisty/5rdxmp4p/
Minor CSS Change
.filled .item .closer {
display: block;
}
Drop Function
drop: function(ev, ui) {
if ($(this).hasClass("empty")) {
$(this).removeClass("empty").addClass("filled");
$(this).droppable("disable");
} else {
return false;
}
var item = ui.draggable;
if (!ui.draggable.closest('.empty').length) item = item.draggable(); // if item was dragged from the source list - clone it
this.innerHTML = ''; // clean the placeholder
item.css({
top: 0,
left: 0
}).appendTo(this); // append item to placeholder
}
Swapping the class allows the X button to appear. We then run the disable method to ensure that this specific item will no longer accept a dragged item. If the user drags an item to this spot, it is then reverted.
Update
Using Sortable: http://jsfiddle.net/Twisty/5rdxmp4p/2/
HTML
<div id="dragItems" class="source">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
<div class="item">Item 4</div>
<div class="item">Item 5</div>
</div>
<div id="sortItems" class="target">
</div>
CSS
body {
background: #fff;
}
.source,
.target {
margin: 20px;
min-height: 190px;
width: 400px;
border: 1px solid green;
}
.target {
border: 1px solid blue;
}
.item {
height: 20px;
margin: 5px;
padding: 5px;
border: 1px solid gray;
background-color: #cd8;
position: relative;
}
.closer {
float: right;
width: 20px;
height: 20px;
border: 0;
background-color: transparent;
}
.closer:hover {
background-color: transparent;
border: 0;
}
.empty {
height: 30px;
margin: 5px;
background: #eee;
border: 1px dashed #999;
}
.highlight {
border: 1px solid red;
background: #fff;
}
.highlight .item {
opacity: 0.3;
}
.ui-draggable-dragging {
z-index: 99;
opacity: 1 !important;
width: 378px;
}
jQuery
$(function() {
$("#sortItems").sortable({
axis: "y",
items: "> div",
placeholder: "empty",
dropOnEmpty: true,
stop: function(e, ui) {
var $it = ui.item;
if ($it.find(".closer").length == 0) {
var closeBtn = $("<span>", {
class: "closer"
});
$it.append(closeBtn);
closeBtn.button({
icon: "ui-icon-close",
label: "Close",
showLabel: false
}).click(function(ev) {
console.log("[INFO]: Closing ", $it);
$it.fadeTo(200, 0.0, function() {
$it.remove();
$("#sortItems").sortable("refresh");
});
});
}
}
});
$("#dragItems .item").draggable({
connectToSortable: "#sortItems",
revert: "invalid"
});
$("#sortItems").disableSelection();
});

OpenLayers 2.12+ and JQueryUI draggable panel

I have a problem with Openlayers 2.12+ and JQueryUI draggable panel that contains OL tools. The panel locks drag.
CSS:
herramientas {
position: absolute; top: 15px; left: 45px; width: 250px; height: 35px; z-index:99999; cursor: move;
background: #000000; }
#herramientas div {
float: left;
margin: 5px; }
HTML:
<body>
<div id="mapcontainer" style="width: 650px; height: 500px; position: relative">
<div id="map" style="width:100%; height:100%"></div>
<div id="herramientas"></div>
</div>
</body>
JavaScript:
var map, layer;
$(document).ready(function () {
$("#herramientas").draggable({containment: "#mapcontainer"});
map = new OpenLayers.Map( 'map' );
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0",
{layers: 'basic'} );
map.addLayer(layer);
map.zoomToMaxExtent();
nav = new OpenLayers.Control.NavigationHistory();
map.addControl(nav);
panel = new OpenLayers.Control.Panel(
{div: document.getElementById("herramientas")}
);
panel.addControls([nav.next, nav.previous]);
map.addControl(panel);
});
The code demo can see in http://jsfiddle.net/leal33/49bP9/
The same example with OpenLayers 2.11 working perfectly --> http://jsfiddle.net/leal33/49bP9/1
It's a bug of OpenLayers? Any solution?
Thanks

jQueryUI draggable disables mouseover/mouseout events for elements with "z-index" values < 0

If a jQuery UI draggable element (#box1) is dragged over an element (#box2) that has z-index set to -1 or below, mouseover and mouseout events won't fire. With z-index set to 0 or above they fire.
CSS:
#box1 {
position: absolute;
top: 100px;
left: 100px;
width: 100px;
height: 100px;
border: 1px solid blue;
}
#box2 {
position: absolute;
top: 100px;
left: 300px;
width: 100px;
height: 100px;
border: 1px solid red;
z-index: -1;
}
JavaScript:
$(function() {
$("#box1").draggable();
$("#box2").mouseover(function(e) {
$("#box2").css({
backgroundColor: "green"
});
});
$("#box2").mouseout(function(e) {
$("#box2").css({
backgroundColor: "transparent"
});
});
});
See: http://jsfiddle.net/TTwPj/11/
Without dragging mouseover and mouseout work fine with all z-index-values.
Is there a reason for this behaviour or is it a bug?
This "problem" has nothing todo with negative or positiv values of your z-index.
In this updated fiddle: http://jsfiddle.net/TTwPj/23/
#box1 {
z-index: 2;
}
#box2 {
z-index: 1;
}
you can see I set some positive values and the mousover still not firing. This is how z-index work.
If you want to achive a mouseover while dragging over the droppable element you can use the droppable event:
over: function( event, ui ) {}
to add a CSS class or style to show some visible "mouseover" effect.

can't get iScroll to properly scroll the div with jQuery Mobile

I'm using jQuery Mobile to build up a mobile website.
On one page I have a bunch of texts to display in a div.
I coded according to the simple example of iScroll 4.
I get it right in my Chrome Browser, but when I test it in mobile safari, I can swipe down the text a bit but it will bounce back, rather than scroll down.
Here's the HTML Markup:
<div data-role="content">
<div class="text-content-wrapper">
<div id="scroll-wrapper">
<ul>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
</ul>
</div>
</div>
and the CSS is:
.text-content-wrapper {
width: 80%;
height: 240px;
position: absolute;
left: 35px;
top: 65px;
overflow: auto;
padding: 10px 0;
background-color: white;
opacity: 0.8;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
z-index: 1;
}
#scroll-wrapper ul{
position: absolute;
z-index: 1;
width: 100%;
list-style: none;
text-align: left;
height: 360px;
}
If I move the position: absolute to #scroll-wrapper, it won't even work in the chrome.
And use the iScroll:
var myScroll1;
function loaded() {
myScroll1 = new iScroll('scroll-wrapper');
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false);

Resources