News:

Support the VirtueMart project and become a member

Main Menu

How do I trigger modal js function for Virtuemart child products?

Started by pibew84514, December 11, 2023, 14:13:13 PM

Previous topic - Next topic

pibew84514

I hope someone can help.

I need some help creating some js but I don't know the language, so please bare with me. I've created Virtuemart parent and child products using BreakDesigns 'Custom Fields For All' and 'Stockable Custom Fields' plugins. I have a few modal popups in the parent product description (anchor tags with class="modal_link" which open urls) which are inherited by the child products (I've also tried setting descriptions for the child products too). When a child product is loaded on the page (after different options/buttons are selected on the parent product), the modal links open in the browser window instead of in popups. The modals work ok on the parent product page.

BreakDesigns have told me that any javascript related functionality needs to be instantiated after the page update. The same that happens after the page load. They've told me the place I need to trigger any js function, but I don't understand js at all so I don't know how to get the modals to work. The file is in components/com_virtuemart/assets/js/dynupdate.js. I'm using Joomla 3.10.12, Virtuemart 4.2.4 and PHP 8.0.30. https://SPAMx.com/ Vidmate

This is an extract from the file, with what should be the correct position shown for the js to be inserted:

Virtuemart.updateContent = function(url, callback) {
    if(Virtuemart.isUpdatingContent) return false;
    Virtuemart.isUpdatingContent = true;
    urlSuf='tmpl=component&format=html&dynamic=1';
    var glue = '&';
    if(url.indexOf('&') == -1 && url.indexOf('?') == -1){
        glue = '?';
    }
    url += glue+urlSuf;
    $(this).vm2front("startVmLoading");
    $.ajax({
        url: url,
        dataType: 'html',
        success: function(data) {
            var title = $(data).filter('title').text();
            $('title').text(title);
            var el = $(data).find(Virtuemart.containerSelector);
            if (! el.length) el = $(data).filter(Virtuemart.containerSelector);
            if (el.length) {
                Virtuemart.container.html(el.html());

                Virtuemart.updateCartListener();
                Virtuemart.updateDynamicUpdateListeners();

                if (Virtuemart.updateImageEventListeners) Virtuemart.updateImageEventListeners();
                if (Virtuemart.updateChosenDropdownLayout) Virtuemart.updateChosenDropdownLayout();
                if (typeof vm2tabs === 'function') {
                    vm2tabs($("#ui-tabs .tabs"));
                }
                //Virtuemart.product($("form.product"));

                if(Virtuemart.recalculate) {
                    $("form.js-recalculate").each(function(){
                        if ($(this).find(".product-fields").length && !$(this).find(".no-vm-bind").length) {
                            var id= $(this).find('input[name="virtuemart_product_id[]"]').val();
                            Virtuemart.setproducttype($(this),id);
                        }
                    });
                }
                /*********** INSERT JS HERE ***********/
            }
            Virtuemart.isUpdatingContent = false;
            if (callback && typeof(callback) === "function") {
                callback();
            }
            $(this).vm2front("stopVmLoading");
        },
       
        error: function(datas) {
            alert('Error updating page');
            Virtuemart.isUpdatingContent = false;
            $(this).vm2front("stopVmLoading");
        },
        statusCode: {
            404: function() {
                Virtuemart.isUpdatingContent = false;
                $(this).vm2front("stopVmLoading");
                alert( "page not found" );
            }
        }
    });
    Virtuemart.isUpdatingContent = false;
}[/img]
Does anyone know how to call the js needed to make the modals work?

Many thanks!