Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • wdiggles Friend
    #1062168

    Hello,

    Is it possible to trigger custom scripts when JA Megafilter loads? I am trying to get the items to open in a modal window when clicked.

    The modal plugin I use is Modals by Regular Labs. This is what he had to say about the topic:

    That JA Megafilter seems to load the results via ajax. So these links are not in the content the moment Modals gets to look at the content. For this to work, JA Megafilter would have to trigger the Modals initialization script every time it pushes new content to the page.

    The script that needs to be triggered:

    RegularLabsModals:init();

    Is this possible with JA Megafilter? or is there any other way to get the items to open in a modal window?

    Thanks!
    Warren

    Mr.Cat Moderator
    #1062215

    @wdiggles

    You can use one of two events to trigger your custom script. Try and let me know if it works 🙂

    jQuery(document).on('afterRender', function (e) {
       #Your code goes here!
    });

    or

    jQuery(document).on('afterUpdateRender', function (e) {
        #your code goes here        
    })
    • This reply was modified 6 years, 7 months ago by  Mr.Cat.
    • This reply was modified 6 years, 7 months ago by  Mr.Cat.

    Wisdom is not a product of schooling but of the lifelong attempt to acquire it.

    wdiggles Friend
    #1062310

    Hello,

    Thank you for your reply. What file do I need to add the code to? And where?

    Is this exactly how the code should be written?

    jQuery(document).on('afterRender', function (e) {
       RegularLabsModals:init();
    });

    Thanks!
    Warren

    Mr.Cat Moderator
    #1062523

    @wdiggles

    Yes, any where. But you should put it in layout file

    /plugins/jamegafilter/content/default.php

    Regards

    Wisdom is not a product of schooling but of the lifelong attempt to acquire it.

    wdiggles Friend
    #1062684

    Hello,

    Thank you again for your help on this, but it is not working yet. This is what is happening:

    I added the code at the end of this file right before the /script tag:

    /plugins/jamegafilter/content/tmpl/default.php
    
    ...
    
    jQuery(document).ready(function() {
    
      var UBLNConfig = {};
    
      UBLNConfig.dataUrl = "<?php echo JUri::base(true).$this->config->json;  ?>";
    
      UBLNConfig.fields = <?php echo json_encode($this->config->fields); ?>;
    
      UBLNConfig.sortByOptions = <?php echo str_replace('.value','.frontend_value',json_encode($this->config->sorts)); ?>;
    
      UBLNConfig.defaultSortBy = "<?php echo $this->config->default_sort; ?>";
    
      UBLNConfig.productsPerPageAllowed = [<?php echo implode(',', $this->config->paginate); ?>];
    
      UBLNConfig.autopage = <?php echo $this->config->autopage ? 'true':'false' ?>;
    
      UBLNConfig.sticky = <?php echo $this->config->sticky ? 'true':'false' ?>;
    
      UBLN.main(UBLNConfig);
    
      MegaFilterCallback();
    
    });
    
    jQuery(document).on('afterUpdateRender', function (e) {
       RegularLabsModals:init();
    });
    
    &lt;/script&gt;

    I started with ‘afterRender’ in the script but that breaks something and the page is blank. I changed it to ‘afterUpdateRender’ and the page renders like it is supposed but still the modal links do not work.

    Mr.Cat Moderator
    #1062751

    @wdiggles

    Can you show me what RegularLabsModals:init(); does? Look likes it’s more complicated than i thought. 🙂

    Wisdom is not a product of schooling but of the lifelong attempt to acquire it.

    wdiggles Friend
    #1062986

    Hello,

    I asked Peter at RegularLabs to explain what is happening when the custom script is triggered and this is what he said:

    "Essentially that script searches through the DOM for links that should be handled as modal links and adds the correct functionality to those links."

    He also realized that the original code he sent me had a typo, it should have a period before init not a comma.

    jQuery(document).on('afterRender', function (e) {
       RegularLabsModals.init();
    });

    I tried adding the correct code to the default.php file but it still doesn’t work. On a positive note, the afterRender option does not break the page anymore.

    Thanks!
    Warren

    Mr.Cat Moderator
    #1063018

    @wdiggles

    As i see, RegularLabsModals uses Colorbox js to create modal. You can use Colorbox js also.

    But in my opinion, if you’re not familar with javascript, you should hire some one to help you. It takes a lot of works even with me. That’s the reason why event ‘afterRender’ does not solve any thing ( my bad ).

    Wisdom is not a product of schooling but of the lifelong attempt to acquire it.

    wdiggles Friend
    #1063437

    Hello,

    It turns out we were on the right track. Instead of adding the code directly to the default.php file we added it to the custom javascript field of the template area in the admin.

    jQuery(document).on('afterRender', function (e) {
        RegularLabsModals.init();
    });

    We also added an additional .modal_link class to the links in the product-item.php file.

    Hope that helps someone else out there.

    Thank you again for the help!

    Mr.Cat Moderator
    #1063446

    @wdiggles

    That’s great!

    Wisdom is not a product of schooling but of the lifelong attempt to acquire it.

Viewing 10 posts - 1 through 10 (of 10 total)

This topic contains 9 replies, has 2 voices, and was last updated by  Mr.Cat 6 years, 6 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum