Say you load via ajax another product on the product page.
There are some mage scripts that do not run and you need to run elem.trigger('contentUpdated')
to make magento evaluate the <script type=“text/x-magento-init”>
code.
But the issue is that magento will evaluate the entire page again. So doing it like this:
$.when(ajaxCall(productUrl)).done(function(response){
//parse response
container.append(parsedResponse); //append in container
container.trigger('contentUpdated'); //trigger update
})
Magento will change the product image for current product too, loading the image from the product just loaded.
I want the current product to stay as it is obviously, and just insert the newly loaded product somewhere else (with its image and other data i.e buy, description).
The only issue that I see is with the images that gets regenerated for the current product too if I run .trigger('contentUpdated')
.
Being more specific with the element on which I trigger does not help, as on whatever element I trigger the update magento will reinterpret the body: https://github.com/magento/magento2/blob/develop/lib/web/mage/mage.js#L93
triggerHandler
since it does not bubble, unliketrigger
which bubbles up the DOM.triggerHandler
doesn't do anything on any elements except if I attach it to$('body')
. But if I do this obviously everything runs. I guesscontentUpdated
event is attached only to body?