jQuery UI 1.10: dialog and zIndex option - javascript

I have to make an dialog to apear when an image onclick. The problem is that I have some realy big z-index there (500 for example) and the ui dialog is on the back of that elements.
Here is the page, you need to log in, user: "raducup" and pass:"1". Another problem is that when I click close ont the dialog, the object desapears.
This is the function I call when a image is click:
function openItem(obiect){
$( obiect ).css('zIndex',9999);
$( obiect ).dialog({
dialogClass: "no-close",
modal: true,
draggable: true,
overlay: "background-color: red; opacity: 0.5",
buttons: [
{
text: "OK",
click: function() {
$( this ).dialog( "close" );
}
}
]
});
reparaZindex();
}

You don't tell it, but you are using jQuery UI 1.10.
In jQuery UI 1.10 the zIndex option is removed:
Removed zIndex option
Similar to the stack option, the zIndex option is unnecessary with a
proper stacking implementation. The z-index is defined in CSS and
stacking is now controlled by ensuring the focused dialog is the last
"stacking" element in its parent.
you have to use pure css to set the dialog "on the top":
.ui-dialog { z-index: 1000 !important ;}
you need the key !important to override the default styling of the element; this affects all your dialogs if you need to set it only for a dialog use the dialogClass option and style it.
If you need a modal dialog set the modal: true option see the docs:
If set to true, the dialog will have modal behavior; other items on
the page will be disabled, i.e., cannot be interacted with. Modal
dialogs create an overlay below the dialog but above other page
elements.
You need to set the modal overlay with an higher z-index to do so use:
.ui-front { z-index: 1000 !important; }
for this element too.

You may want to try jQuery dialog method:
$( ".selector" ).dialog( "moveToTop" );
reference: http://api.jqueryui.com/dialog/#method-moveToTop

Add in your CSS:
.ui-dialog { z-index: 1000 !important ;}

There are multiple suggestions here, but as far as I can see the jQuery UI guys have broken the dialogue control at present.
I say this because I include a dialogue on my page, and its semi transparent and the modal blanking div is behind some other elements. That can't be right!
In the end based on some other posts I developed this global solution, as an extension to the dialogue widget. It works for me but I'm not sure what it would do if I opened a dialogue from within a dialogue.
Basically it looks for the zIndex of everything else on the page and moves the .ui-widget-overlay to be one higher, and the dialogue itself to be one higher than that.
$.widget("ui.dialog", $.ui.dialog,
{
open: function ()
{
var $dialog = $(this.element[0]);
var maxZ = 0;
$('*').each(function ()
{
var thisZ = $(this).css('zIndex');
thisZ = (thisZ === 'auto' ? (Number(maxZ) + 1) : thisZ);
if (thisZ > maxZ) maxZ = thisZ;
});
$(".ui-widget-overlay").css("zIndex", (maxZ + 1));
$dialog.parent().css("zIndex", (maxZ + 2));
return this._super();
}
});
Thanks to the following, as this is where I got the info from of how to do this:
https://stackoverflow.com/a/20942857
http://learn.jquery.com/jquery-ui/widget-factory/extending-widgets/

Add this before calling dialog
$( obiect ).css('zIndex',9999);
And remove
zIndex: 700,
from dialog

moveToTop is the proper way.
z-Index is not correct. It works initially, but multiple dialogs will continue to float underneath the one you altered with z-index. No good.

To sandwich an my element between the modal screen and a dialog, I need to lift my element above the modal-screen, and then lift the dialog above my element.
I had a small success by doing the following after creating the dialog on element $dlg.
$dlg.closest('.ui-dialog').css('zIndex',adjustment);
Since each dialog has a different starting z-index (they incrementally get larger) I make adjustment a string with a boost value, like this:
const adjustment = "+=99";
However, jQuery just keeps increasing the zIndex value on the modal screen, so by the second dialog, the sandwich no longer worked. I gave up on ui-dialog "modal", made it "false", and just created my own modal. It imitates jQueryUI exactly. Here it is:
CoverAll = {};
CoverAll.modalDiv = null;
CoverAll.modalCloak = function(zIndex) {
var div = CoverAll.modalDiv;
if(!CoverAll.modalDiv) {
div = CoverAll.modalDiv = document.createElement('div');
div.style.background = '#aaaaaa';
div.style.opacity = '0.3';
div.style.position = 'fixed';
div.style.top = '0';
div.style.left = '0';
div.style.width = '100%';
div.style.height = '100%';
}
if(!div.parentElement) {
document.body.appendChild(div);
}
if(zIndex == null)
zIndex = 100;
div.style.zIndex = zIndex;
return div;
}
CoverAll.modalUncloak = function() {
var div = CoverAll.modalDiv;
if(div && div.parentElement) {
document.body.removeChild(div);
}
return div;
}

$(".ui-dialog").css("zIndex", 10000);

Add zIndex property to dialog object:
$(elm).dialog(
zIndex: 10000
);

Related

How to get the Height of a popup Before loading - Jquery

$("[data-toggle=popover]").popover({
html: true,
trigger: 'touchstart',
animation: true,
content: function () {
return ShowPopup();
}
});
ShowPopup() function returns popup Html.The popup size is dynamic according to image in the popup.
So I want the total height of the popup before loading as popup window.
Use height() function of jquery
var height = $("#poppupidorselector").height()
Lets us know if it helps
PS:In your case you can put the html of poppup in hidden div and then get the height

Change div height with buttons

I need some scripting like the TYPO3 extension / module that runs on this site : http://nyati-safari.dk/index.php?id=125 (Scroll to: Detaljeret Dagsprogram (inkluderet)).
The div is shown with a pixelspecific height and when the arrow is clicked the div changes to contentspecific height also the arrow changes when the div toggles.
Do this:
var div = $('#div');
$('#arrow').click(function () {
if (div.height() == 100) {
autoHeight = div.css('height', 'auto').height();
div.height(100).animate({
height: autoHeight
}, 500);
} else {
$('#div').animate({
height: '100'
}, 500);
}
});
JSFiddle: http://jsfiddle.net/ZG8ug/5/
Can even do something like this: http://jsfiddle.net/ZG8ug/6/ where the 'hidden' div is small on page load but when viewed and returned it is bigger. Might be useful to help users distinguish what has already been viewed. Could even do it the other way around too so the div takes up even less space when it has been viewed.

How to get past a bug in IE6 with an YUI Overlay?

Going to play with an Overlay from YUI 2 and IE6 (old stuff, but I have to deal with these)... and encouter a problem. So, can you help with an idea or two ? :D
Suppose the Overlay is created :
var newOverlay = new YAHOO.widget.Overlay("myOverlay" ,
{
context: [someObjectToAttachTo, "tl", "bl"],
monitorresize: false,
iframe: false,
zIndex: 900 });
some content is initalized (inside a div) :
var content = new StringBuffer();
content.append('<div id="containerDiv">');
content.append('whatever! some text for the overlay');
content.append('</div>');
an event is attached to the inner div so we know when it's got the mouse over it :
YAHOO.util.Event.addListener('containerDiv', "mouseover",
function() { alert('mouse in') });
"pour" the div into the overlay :
newOverlay.setBody( content.toString() );
render the overlay, but invisible :
newOverlay.render( document.body );
newOverlay.hide();
Problem : even if the overlay is hidden, if you move the mouse in his area, you will get an alert saying "mouse in".
This does not happen in IE7 or Mozilla. Seems that it is a bug and is related to IE not repainting the DOM until after the execution context is complete Source and some info here, another StackOverflow question
the Overlay is shown and hidden by this mechanism (note: the code described above is being updated here) :
newOverlay.hideTimer = null; // new code
YAHOO.util.Event.addListener('containerDiv', "mouseover", //event existed in above code
function() {
alert('mouse in'); // line existed
clearTimeout(newOverlay.hideTimer) }); // added functionality
YAHOO.util.Event.addListener('containerDiv', "mouseout", // new event
function() { timedHide(newOverlay) });
newOverlay.setBody( content.toString() ); //old code
newOverlay.render( document.body ); //old code
newOverlay.hide(); //old code
the functions used above are :
function customShow(overlayName) {
var overlay = document.getElementById(overlayName);
clearTimeout(overlay.hideTimer);
overlay.syncPosition();
overlay.show();
}
function timedHide(overlayName) {
var overlay = document.getElementById(overlayName);
overlay.hideTimer = setTimeout(function() {overlay.hide() }, 200);
}
here is part two of the hide/show mechanism - the trigger div; please ignore the mix of html and js; you still can read it :P
<span id="triggerSpan">I will show an Overlay</span>
and its events :
YAHOO.util.Event.addListener('triggerSpan', "mouseover",
function() { customShow('myOverlay') });
YAHOO.util.Event.addListener('triggerSpan', "mouseout",
function() { timedHide('myOverlay') });
the object used in the creation of the overlay is :
var someObjectToAttachTo = document.getElementById('triggerSpan');
Long stuff...
now, can you see another way of passing by this IE bug ?
so the overlay does not take my mouse... I have stuff under that overlay that needs to be clicked and hovered (that part is not mentioned in the above code)
Can you see another way of creating/initiazing/showing/hidding that overlay ?
The solution was to change the display style of the containerDiv to none or to block when hiding/showing the overlay.
Add some functions to the Overlay that change the style of the inner div:
newOverlay.showOverlay = function() {
document.getElementById('containerDiv').style.display="block";
newOverlay.show(); };
newOverlay.hideOverlay = function() {
document.getElementById('containerDiv').style.display="none";
newOverlay.hide(); };
and call those functions instead of calling overlay.show() or overlay.hide(), inside the functions customShow and timedHide

jquery dialog: drag dialog at any point

Is there a trick to make a jquery dialog be draggable at any point? (i mean not only in the title bar)
As opposed to a sortable item, dialog items doesn't have that functionality (I'm not sure why). If needed, you might be able to do something like this:
$(document).ready(function() {
var
// Create dialog
dialog = $('div')
.dialog({ title: "I'm a dialog" })
.css({cursor: 'move'}),
// Get the options manually
options = dialog
.data("dialog")
.uiDialog
.data('draggable')
.options;
// Finally, extend the draggable modal box's
// options and remove any restrictions
$.extend(options, {cancel: '', handle: ''});
});
​
See a working example here: http://jsfiddle.net/gMP2d/
$("#div_id")
.dialog({
position: [3,442],
width: 300,
height: 90
})
.css({cursor: 'move'})
.parent()
.draggable({cancel:'',handle:''});

How to refactor from using window.open(...) to an unobtrusive modal dhtml window?

I have a function which launches a javascript window, like this
function genericPop(strLink, strName, iWidth, iHeight) {
var parameterList = "location=0,directories=0,status=0,menubar=0,resizable=no, scrollbars=no,toolbar=0,maximize=0,width=" + iWidth + ", height=" + iHeight;
var new_window="";
new_window = open(strLink, strName, parameterList);
window.self.name = "main";
new_window.moveTo(((screen.availWidth/2)-(iWidth/2)),((screen.availHeight/2)-(iHeight/2)));
new_window.focus();
}
This function is called about 52 times from different places in my web application.
I want to re-factor this code to use a DHTML modal pop-up window. The change should be as unobtrusive as possible.
To keep this solution at par with the old solution, I think would also need to do the following
Provide a handle to "Close" the window.
Ensure the window cannot be moved, and is positioned at the center of the screen.
Blur the background as an option.
I thought this solution is the closest to what I want, but I could not understand how to incorporate it.
Edit: A couple of you have given me a good lead. Thank you. But let me re-state my problem here. I am re-factoring existing code. I should avoid any change to the present HTML or CSS. Ideally I would like to achieve this effect by keeping the function signature of the genericPop(...) same as well.
Here is my solution using jQuery and jQuery UI libraries. Your API is not changed , but parameter 'name' is ignored. I use iframe to load content from given strLink and then display that iframe as a child to generated div, which is then converted to modal pop-up using jQuery:
function genericPop(strLink, strName, iWidth, iHeight) {
var dialog = $('#dialog');
if (dialog.length > 0) {
dialog.parents('div.ui-dialog').eq(0).remove();
}
dialog = $(document.createElement('div'))
.attr('id', 'dialog')
.css('display', 'none')
.appendTo('body');
$(document.createElement('iframe'))
.attr('src', strLink)
.css('width', '100%')
.css('height', '100%')
.appendTo(dialog);
dialog.dialog({
draggable: false,
modal: true,
width: iWidth,
height: iHeight,
title: strName,
overlay: {
opacity: 0.5,
background: "black"
}
});
dialog.css('display', 'block');
}
// example of use
$(document).ready(function() {
$('#google').click(function() {
genericPop('http://www.google.com/', 'Google', 640, 480);
return false;
});
$('#yahoo').click(function() {
genericPop('http://www.yahoo.com/', 'Yahoo', 640, 480);
return false;
});
});
Documentation for jQuery UI/Dialog.
I use this dialog code to do pretty much the same thing.
If i remember correctly the default implementation does not support resizing the dialog. If you cant make with just one size you can modify the code or css to display multiple widths.
usage is easy:
showDialog('title','content (can be html if encoded)','dialog_style/*4 predefined styles to choose from*/');
Modifying the js to support multiple widths:
Add width and height as attributes to show dialog function and the set them to the dialog and dialog-content elements on line 68
Try Control.Window, which requires Prototype
Here's how I use it:
New Message
And in my Javascript file:
$(document).observe("dom:loaded", function() {
$$("a.popup_window").each(function(element) {
new Control.Modal(element, { overlayOpacity: 0.75,
className: 'modal',
method: 'get',
position: 'center' });
});
});
Now if you want to close the currently open popup do:
Control.Modal.current.close()

Categories

Resources