Joomla popup button

Joomla 1.5 has a nice pop up button class. This will dim the webpage and popup a smaller page over it. I found that it doesn’t work quite right outside a toolbar, so here’s how to manually do it.

First we must load the modal behavior. Take note that in the examples I split some code over multiple lines for display purposes in the article.

JHTML::_('behavior.modal');

Then simply put in this link with the information you want.

<a href="http://www.google.com'" mce_href="http://www.google.com'"
    rel="{handler: 'iframe', size: {x: 500, y: 400}}">
        <span title="<some title>">
            <img src="<path to image file>" border="0" name="<name>" title="<title>" alt="<alt text>" />
        </span>
</a>

You can even combine this with tooltips! Of course you must load the proper behavior.

 JHTML::_('behavior.tooltip');

Then put in this link.

<a href="http://www.google.com'" mce_href=http://www.google.com'/
    rel="{handler: 'iframe', size: {x: 500, y: 400}}">
        <span title="tip title::tip text">
            <img src="<path to image file>" border="0" name="<name>" title="<title>" alt="<alt text>" />
        </span>
</a>

Now to make this more useful, what if you wanted to load some code from a view? This example calls a function in a view to display the page. Here’s the function.

function displayPopup() {
 ?>
 <!-- The HTML for the page goes here. -->
<?php
}

We can call this function using the controller.

function popup() {
 	$view = & $this->getView('<view name>', 'html');

	// Get/Create the model
	$model = & $this->getModel('<model name>');

	// Push the model into the view (as default)
	$view->setModel($model, true);

	// Display the view
	$view->displayPopup();
}

Now here is the link that could trigger this popup. This assumes that you are using $task to trigger methods in your controller. Take note that the last tmpl=component should appear exactly as that. This makes the popup be only the code you put in the view.

$mainframe->getCfg('live_site').'/index.php?option=<your component>&
controller=<controller if no default>&task=popup&tmpl=component

About Adam Oliver

Adam Oliver has been working in the IT field for over 10 years and is a Sales Engineer for Citrix Systems, Inc. Follow Adam on twitter at http://twitter.com/theadamoliver. Find out more about Citrix at www.citrix.com.
This entry was posted in Web Development and tagged , , . Bookmark the permalink.

5 Responses to Joomla popup button

  1. _vesna says:

    it was very interesting to read wordpress.aikidokatech.com
    I want to quote your post in my blog. It can?
    And you et an account on Twitter?

    Author response: You are more than welcome to quote the article. I just ask you link back to it with the quote. At this time I do not have a twitter account.

  2. Allan says:

    I got the modal to work using the iframe. Do you Know how to popup a div. If so can you post an example. Thanx

  3. Rafael says:

    please, how can i send some variables in php to the back page, i mean, if the user is in the main page then he clicks on “select yourcoutry” (for exemple) then the popou (modal) opens showing some countrys with a link that will send back to the main page the country selected. i tried to do this with opener.location=’page.php?country=$idcountry’ but didn’t work. i guess i just can do this if the window are a popup (window.open()). sorry about poor english. pleeeeeeeeeeeease help me…

  4. petitpao says:

    Hello,
    your blog is very interesting.
    I tested your code in my project, but this did not work.
    Is it possible to see one real example ?
    How this will work with the toolbar you mentionned at the top of the article ?
    Thanks for the answer.

  5. Marcus says:

    When I use rel=”{handler: ‘iframe’, size: {x: 500, y: 400}}” the popup window won’t close when I press send when I have a form in the popup…if I don’t use rel=”{handler: ‘iframe’, size: {x: 500, y: 400}}” the popup closes on submit…?? I want to have the opportunity to resize the window AND have the popup close on submit…any idea??

Leave a Reply

Your email address will not be published. Required fields are marked *