PDA

View Full Version : Basic Dialog, is this possible....



peter_n
22 Dec 2006, 10:15 AM
is it possible to have a link in a basic dialog and when you click on the link to have the dialog animate out before loading the new page into the browser?

thanks
Peter

Animal
22 Dec 2006, 1:29 PM
Yes. Add a Listener for "click" to the dialog's Element (getEl())

In the handler, see if the event's target has a tagName of "a". If so, stop the event, hide the BasicDialog with animation, and set the document's href to the "a" element's href in the handler of the "hide" event.

That's the recipe, now read the docs, and hack!

http://www.yui-ext.com/docs/

gfraser
22 Dec 2006, 1:35 PM
Here's some code I've ripped from a dialog I'm working on...

First, set up an event handler (in my case it will deal with clicks on addresses in an east panel):

[code]
// event handler for when a past address is clicked
var addressClicked = function(e){
var a = e.findTarget(null, 'a'); // find the "a" element that was clicked
if (a) {
e.preventDefault();
ContactEditor.setAddress(pastAddresses[Number(a.href.split('$')[1])]);
}
};

....
[code]

Next, listen to your panel:

[code]
....

east = layout.add('east', new YAHOO.ext.ContentPanel(YAHOO.util.Dom.generateId(), {
autoCreate: true,
fitToFrame: true,
autoScroll: true,
title: 'Previous Addresses'
}));

layout.endUpdate();

pastAddrPanel = east.getEl();
pastAddrPanel.mon('click', addressClicked);
[code]

Any URL's clicked in that panel (a tags) will end up triggering the event listener shown earlier and that will stop the URL from being followed. From there you can do whatever you want :)

Animal
22 Dec 2006, 1:40 PM
I think a user would get pretty annoyed if clicking on a link waited for some animation to happen before being actioned. I wouldn't visit the site again. I'm impatient.