0

I have that url:

<a onClick="showDialog({$product['id']});">More Info...</a>

In Addition I have:

function showDialog(productID)
{
    $( "#dialog-modal_"+productID ).html( "<iframe src='index.php?act=showProduct&amp;id="+productID+"' width='100%' height='100%' frameborder='0' scrolling='no'></iframe>" );
    $( "#dialog-modal_"+productID ).dialog({
    width: 810,
    height: 590,
    resizable: false,
    modal: true,
    open: function(event, ui)
    {
        event.preventDefault();
    }
    });
    container
        .dialog('option', 'title', 'Your Title')
        .dialog('option', 'buttons', {
            Close: function() {
                $(this).dialog('close');
            }
        })
        .dialog('open');

    var stateObj = { foo: "bar" };
    window.history.pushState(stateObj, "page 2", "{$info['siteurl']}/index.html#product-"+productID);

}

if I open it once it's working, but if I try once again, it is not opening. I need to find a way to "clear" the last dialog of the current ID. for different dialogs its working, but only once.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1936192
  • 335
  • 2
  • 4
  • 10

1 Answers1

2

Inside the product loop:

<a href="javascript:" class="productOpener" data-id="{$product['id']}">more info...</a>

And your javascript:

$(".productOpener").click(function() {
    showDialog($(this).data("id"));
});

And modify your showDialog to just create the modal div when you need it:

function showDialog(productID) {
    var _modal = $("<div/>"); //add whatever styling you need
    _modal.html( "<iframe src='index.php?act=showProduct&amp;id="+productID+"' width='100%' height='100%' frameborder='0' scrolling='no'></iframe>" );
    _modal.dialog({ ... });
    ...
}
TimDog
  • 8,758
  • 5
  • 41
  • 50
  • why should i edit showDialog() as written? how does it make change? – user1936192 Jan 07 '13 at 19:33
  • Adding `_modal` dynamically was just a suggestion; without knowing much about the `dialog` plugin that you're using, it's hard to say why the subsequent dialogs are not showing up. Regardless, though, creating `_modal` dynamically should make it work. Another note: using `onClick` inside DOM elements is [considered bad practice](http://stackoverflow.com/questions/5871640/why-is-using-onclick-in-html-a-bad-practice). – TimDog Jan 07 '13 at 21:15