JHtml Behavior.Modal to apply on dynamically added elements

This forum is for general questions about extensions for Joomla! 2.5.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
izharaazmi
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Sun Apr 10, 2011 9:31 am

JHtml Behavior.Modal to apply on dynamically added elements

Post by izharaazmi » Fri Dec 16, 2011 11:42 pm

The

Code: Select all

 Jhtml::_('behavior.modal');
applies to all the element placed in the document with specified selector.

e.g.

Code: Select all

<?php JHTML::_('behavior.modal', 'a.modal'); ?>
<a  class="modal" rel="{handler: 'iframe', size: {x: 750, y: 600}}" href="index.php">Click me</a>
This will create a link that opens a modal window (or flybox, squeezebox etc.)

Now, the problem is, that I am creating such links on my page dynamically (using jQuery). I want these links behave the same way, but they don't.

This is because the elements are created after the behavior assignment, which occurs just after page load finishes.

So can anyone please help me out, so that i can have some alternative way to add this behavior to new dynamically created links.

gen9studio
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Sun Apr 01, 2012 1:26 am

Re: JHtml Behavior.Modal to apply on dynamically added elem

Post by gen9studio » Sun Apr 01, 2012 1:30 am

Execute this every time you add a new element:

Code: Select all

SqueezeBox.assign($$('a.modal'), {
    parse: 'rel'
});

izharaazmi
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Sun Apr 10, 2011 9:31 am

Re: JHtml Behavior.Modal to apply on dynamically added eleme

Post by izharaazmi » Wed Apr 04, 2012 10:43 am

Yeah that works, thanks!
But I found that by looking on the joomla produced html in the browser at last, coz it was so urgent I couldn't wait. And sorry for I forgot to post it back.

Well, may be someone else gets the benefit from this some day. Cheers!

parassahu
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Wed Apr 23, 2014 1:28 pm

Re: JHtml Behavior.Modal to apply on dynamically added elem

Post by parassahu » Wed Apr 23, 2014 1:31 pm

Thanks, i have suffered from the same problem, and it helps me too.... :)


Locked

Return to “Extensions for Joomla! 2.5”