How can I control where a jquery-ui Dialog displays? - jquery-ui

Here's what I'm doing:
1) Add a "hide" CSS class:
.hide {
visibility: hidden;
display: none;
}
2) Add some HTML to where the Dialog should display, hiding it by default, such as:
<div class="hide" id="postTSec4" name="postTSec4">
<h2>Post-Travel Bottom</h2>
<img id="imgPostTravelBottom" name="imgPostTravelBottom" src="images/4_PTE_Bottom_Jig.png" alt="post Travel image" height="275" width="350">
</div>
<div class="hide" id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
3) In response to some event, unhide the div and call dialog() on it, such as:
$( "#dialog" ).removeClass('hide');
$( "#dialog" ).dialog();
The problem is that this causes the dialog to display in the middle of the page; I want the dialog to display with its NW corner at the tip of the cursor/pointer/finger.
So how can I control where the dialog appears?
UPDATE
I used the linked-to, supposedly-the-answer code as a basis, but no, it doesn't quite work in my situation.
UPDATE 2
With this code (adapted from meteorBuzz's answer):
CSS
.outer {
width: 100%;
height: 700px;
border: 2px green solid;
padding: 10px;
}
#dialog {
height: 100px;
max-width: 100px;
border: 3px black solid;
padding: 5px;
z-index: 100;
}
HTML:
<template name="postTravelSection5">
<div class="outer hide" id="postTSec5" name="postTSec5">
<div id="dialog" name="dialog" title="Basic dialog">
<p>This is dialog content area...</p>
</div>
</div>
</template>
JavaScript:
Template.postTravelSection5.events({
'click #postTSec5': function(event) {
var x = event.pageX;
var y = event.pageY;
$("#dialog")
.offset({
'left': x,
'top': y
});
}
});
Template.postTravel.events({
'click #imgPostTravel': function() {
. . .
$('#postTSec5').removeClass('hide');
}
});
("outer" and "dialog" are seen after "imgPostTravel" is clicked).
...it does not work; I see the two divs (the outer one with the green border, and the div dialog within it), but clicking does nothing.

You can have full control of the div behaviour by simply creating your own behaviour model instead of using jquery-ui for this particular matter.
Also, you can make the dialog look unique instead of having to over-ride jquery-ui default styling and positioning.
You may move the div to where the click event took place in two steps:
Capture x/y coordinates of the click event
Set these values to the styling of the div using javascript.
Notice, I've created an #outer div that spans most of the web page to allow the #dialog div to move within such a space.
HTML
<template name="postTravelSection4">
<div class="outer">
<div id="dialog" title="Basic dialog">
<p>This is dialog content area...</p>
</div>
</div>
</template>
JS
Template.postTravelSection4.events({
'click': function(event) { // you may add which element fires this function when you click it.
var x = event.pageX; // x coordinates
var y = event.pageY; // y coordinates
$( "#dialog" )
.offset({
'left': x,
'top': y
});
}
});
}
CSS
.outer {
width: 100%;
height: 700px;
border: 2px green solid;
padding: 10px;
}
#dialog {
height: 100px;
max-width: 100px;
border: 3px black solid;
padding: 5px;
z-index: 100; // incase of overlaps of divs, this one will remain on top
}
// create your hide/show classes to display and remove the div from display in the way you wish

Related

Workaround for overflow restriction affecting fixed-positioned elements in iOS?

Edit: The main issue is this: overflow: hidden and overflow: auto affect fixed positioned elements in iOS.
So if I have a fixed positioned modal dialog in a component within a scrolling feature of the page, that element is not displayed wherever it exceeds the bounds of its parent. This is really messed up, as it's not how fixed positioning works on any other system. So what's the official response to this?
Original post:
I have a modal dialog that works fine on desktop and Android, but on any browser on my iPad, the modal dialog, including the modal overlay, gets hidden wherever it exceeds the boundaries of its parent container (even though it is fixed positioned). I know that this isn't how overflow: auto is supposed to work, because it works just fine on all other devices. Anyone else experienced this? I'm sure it has something to do with how iOS handles fixed positions.
Anyway, here's some code:
HTML:
<confirm-dialog ng-if="$ctrl.confirmDlgShowing" on-close="$ctrl.closeDlgs()" on-confirm="$ctrl.deleteInstance()" class="ng-scope ng-isolate-scope">
<div class="modal general modal"><div class="modal-window"><div class="modal-inner" ng-transclude="">
<div style="position:relative" class="ng-scope">
<label class="modal-close" ng-click="$ctrl.onClose()"></label>
<div class="page-heading">
<h2>Are you sure?</h2>
</div>
<input class="btn" type="button" value="Yes" ng-click="$ctrl.confirm()">
<input class="btn" type="button" value="No" ng-click="$ctrl.onClose()">
</div>
</div></div></div>
</confirm-dialog>
SASS:
.container {
overflow: auto;
.modal-window {
// overlay
#include transition(opacity 0.25s ease);
#include position(fixed, 0px 0px 0px 0px);
background: rgba(0,0,0, 0.6);
padding-top: 0.6em;
text-align: left;
z-index: 999999999;
margin: 0 !important;
.modal-bg {
#include position(absolute, 0px 0px 0px 0px);
cursor: pointer;
}
}
.modal-inner {
#include transition(opacity 0.25s ease);
background: $modal-background;
border-radius: $base-border-radius;
display: table;
margin: 70px auto;
max-height: 80%;
overflow: auto;
padding: $modal-padding / 2;
z-index: 1000000000;
min-width: 400px;
#media(max-width: $medium-screen) {
max-height: 70%;
padding: $modal-padding;
}
}
}
Here's the workaround we finally came up with--a new directive to replace ng-if on our modals that places the object on the body. Plays nicely with other Angular bindings too.
angular.module('app').directive('rootIf', function()
{
return {
restrict: 'A',
link: function (scope, $elm, attrs)
{
scope.$watch(attrs.rootIf, onChangeRootIf);
function onChangeRootIf()
{
if (scope.$eval(attrs.rootIf))
$("body").children().first().before($elm);
else
$elm.detach();
}
}
}
});

Two sortables stacked using z-index

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.

Display div over canvas in Dojo mobile app

I know this question have been asked many times but I still can't manage to get it to work.
I am developing apps on iPad and generate a globe 3D in WebGL, some of the elements are created with Dojo (like the splitpane).
I basically have a top pane with a canvas and a bottom pane with different stuffs.
<div id="splitArea" data-dojo-type="dojox.mobile.FixedSplitter" data-dojo-props="orientation:'V'">
<div id="topDiv" data-dojo-type="dojox.mobile.ContentPane">
<div id="globePane">
<button class="globeItem" id="metButton" data-dojo-type="dojox.mobile.Button" onclick="displayOptions('MET')">MET</button>
<canvas id="globeCanvas"></canvas>
<script type="text/javascript" src="js/Globe.js"></script>
<div id="globeOptions"></div>
</div>
</div>
<div id="infosPane" data-dojo-type="dojox.mobile.ContentPane">
</div>
</div>
Here is the top pane elements CSS :
#topDiv {
top: 0px;
width: 100%; height: 50%;
}
#globePane {
width: 100%; height: 100%;
position:relative;
}
#globeCanvas {
position: absolute;
z-index: 0;
width: 100%;
height: 100%;
}
#globeOptions {
width: 150px; height: 150px;
position: absolute;
top: 40px; right: 200px;
z-index: 4;
}
.globeItem {
position: absolute;
z-index: 3;
}
And the Javascript that injects globe in the canvas :
var container= document.getElementById('globeCanvas');
if ( Detector.webgl )
renderer = new THREE.WebGLRenderer( { canvas: globeCanvas , antialias:true} );
else
renderer = new THREE.CanvasRenderer( { canvas: globeCanvas } );
renderer.setSize(container.offsetWidth,container.offsetHeight);
renderer.setClearColor(0x000000, 1);
...
}
Now question is : I want a Div (id="globeOptions") to appear on screen when I click a button named "MET", I got at first to create it (what is done in the code), but once created, the div isn't displayed.
The button was created with Dojo and is displayed well on canvas (I didn't do anything special so it must be Dojo auto config that lets it being displayed on canvas), but the div stays under canvas whatever I try.
I tried lots of solutions I found but nothing works (even the relative/absolute positions).
Why does it work on Fiddle but doesn't in device, am I doing something wrong?

Problem with jquery draggable and div with bottom fix position

I have a problem with a div that at the begin is fixed in the bottom-left corner. I need to do it draggable but when I use jquery to do it the bottom position remains and the size of the div changes.
You can see the behavior in this page: http://paraguasparados.com
The div css code is:
.fcp-cpanel{
position:fixed;
bottom:20px;
left:10px;
z-index: 99999;
padding: 5px;
color: #000;
text-align: left;
font-size: 11px;
background:url('../img/blueicons/background.jpg') repeat-x;
border:1px solid #000;
}
The jquery code is:
$jn("#fcp-cpanel").draggable({
containment:"body",
scroll: false,
opacity: 0.35
});
When in firebug I remove the 'bottom' css style it works like it should.
Thanks for any help.
The easiest solution to this is to add a width and height to your fixed draggable <div> to stop it from resizing on drag.
The problem is that you are making a fixed element draggable and so the bottom css attribute is messing it up when you start moving it. A fix for this is to create a container div that has the fixed css attributes and inside you can add the draggable element. Something like this:
css:
.fcp-cpanel-container{
position:fixed;
bottom: 10px;
left:10px;
}
.fcp-cpanel{
padding: 5px;
color: #000;
text-align: left;
font-size: 11px;
background:url('http://paraguasparados.com/modules/mod_friendchatppd/img/blueicons/background.jpg') repeat-x;
border:1px solid #000;
}
html:
<div class="fcp-cpanel-container">
<div class="draggable fcp-cpanel">
<p><b>Amigos Online</b>
<span id="onlusers" class="onlusers">0</span><span onclick="register()"><img title="Registrar" alt="Registrar" src="http://paraguasparados.com//modules/mod_friendchatppd/img/blueicons/visible.jpg"></span>
<span onclick="maximize()" id="fcp-micon">
<img title="Maximizar" alt="Maximizar" src="http://paraguasparados.com//modules/mod_friendchatppd/img/blueicons/max.jpeg">
<img style="display:none;" title="Minimizar" alt="Minimizar" src="http://paraguasparados.com//modules/mod_friendchatppd/img/blueicons/min.jpeg">
</span>
</p>
</div>
</div>
I set up a working example with your code here: http://jsfiddle.net/NdUNu/.
I tried this and it did what I wanted
$(function() {
$("#draggable").draggable({ containment: "window" });
});

blinking Images

i have dynamic images from a database...i want to have a couple of images on top of each other..like a banner ad, when one image fades the other one displays...
When you click on the image it should redirect to a specific link
This solution uses jQuery and the jQuery Cycle plugin. It basically runs it as a slide show, displaying one image at a time. The CSS puts a nice border around it, but you could eliminate that by adjusting the CSS. The cycle plugin has a number of options that you can use to adjust how the images transition.
<style>
.pics
{
padding: 0;
margin: 0;
margin-left: 48px;
}
.pics img
{
padding: 15px;
border: 1px solid #ccc;
background-color: #eee;
top: 0;
left: 0;
}
</style>
<script type="text/javascript">
$(function() {
$(window).load( function() { $(".pics").cycle() } );
});
</script>
<div class="pics">
<img alt="Banner Ad" onclick="location.href='/url/to/ad-site1.htm';" src="/url/to/img1.jpg" />
<img alt="Banner Ad" onclick="location.href='/url/to/ad-site2.htm';" src="/url/to/img2.jpg" style="display: none;" />
<img alt="Banner Ad" onclick="location.href='/url/to/ad-site3.htm';" src="/url/to/img3.jpg" style="display: none;" />
</div>

Resources