PDA

View Full Version : Replace standart Alert dialog with ext.BasicDialog



Timoshka
29 Dec 2006, 6:57 AM
Hello. I am a beginner with YAHOO.ext but can say that it is wonderful. Thanks Jack.

I have a question about Dialogs, particularly BasicDialog. I decided to replace standard Alert JS message dialog with an instance of BasicDialog. Everything is fine but one thing. I cannot make my dialog streching when alert is bigger than size of the dialog. What I have:

HTML:


<div id="alertDialog" style="visibility:hidden;">
<div id="alertHeader" class="ydlg-hd">Alert</div>
<div id="alertBody" class="ydlg-bd"></div>
</div>


JS:


alertEx = function(alertBody,alertHeader)
{
if(!alert_dialog){
alert_dialog = new YAHOO.ext.BasicDialog("alertDialog", {
resizable:false,
modal:true,
width:300,
height:150,
shadow:true,
minWidth:300,
minHeight:130
});
alert_dialog.addButton('Ok', dialog.hide, alert_dialog);
}

if (!alertHeader) alertHeader = 'Alert';
alert_dialog.title = alertHeader;
YAHOO.util.Dom.get('alertBody').innerHTML = alertBody;
alert_dialog.show();
};


Then simply calling alertEx('This is my alert!') I get that I want. But if alertBody is bigger than size of my dialog I get scrolling or hiding content depending on different params when I create the dialog.

Could you help me to make it strech?
May be you can suggest better way to do this?

Thanks in advance.

ojintoad
29 Dec 2006, 8:49 AM
I am just passing through so here are some quick thoughts. What you could possibly do is use the YAHOO.ext.Element class to get the width of your content ahead of time and try to resize your dialog to that. The methods you'll want to look at are YAHOO.ext.Element -> getWidth, getHight, and possibly beginMeasure/endMeasure. This will also probably warrant you wrapping AlertBody and AlertHeader ahead of time in a wrapping div, and YAHOO.ext.Element has a method for that convieniently called wrap.

Good luck.

Timoshka
29 Dec 2006, 9:07 AM
Thanks, I got the idea.

But may be someone know an easier way, for example using something like IE quirks mode behaviour when content stretches its container.

tryanDLS
29 Dec 2006, 11:52 AM
That's why it's called 'quirks mode' - it does stuff it shouldn't. ;)

If you're alerting long text, it's generally better to make it vertically scrollable, rather than making a box that spans the screen width and forces to the user to pan from left to right to read it. Also, depending on screen resolution, allowing a box to just expand - vertical or horizontal - is bad. It can become so big that it pushes the buttons of the screen.