Custom interaction script randomly broke when using Powerful Rich Text

While using the powerful rich text attribute to insert CTA’s into rich text, we recently had a interaction with the CTA’s interaction trigger button break.

Our dev team can’t figure out the reason because it was working the morning of Dec. 2 and broke after we republished the site a few hours later, despite making no changes to the code or page.

The script below triggers a pop-up modal to appear after a user clicks a CTA button. The CTA blocks were placed into our rich text as expected, but the button trigger for the pop-up no longer worked.

<script>
	$(document).ready(function() {
    setTimeout(() => {
      $('.cta-dropdown_link, .button.is-device-trigger, .swiper-box').on('click', function() {
        const phoneId = $(this).data('phone-id');
        $('#deal-modal').find('.details-modal--widget-wrap>div').remove();
        $('#deal-modal').find('.details-modal--widget-wrap').append('<div id="navi-phone-onboarding-widget-3-'+phoneId+'"></div>');

        createWidget(
          '#navi-phone-onboarding-widget-3-'+phoneId,
          'prod',
          phoneId,
          {
            getUtms: true,
            contentId: 'post-cta_{{wf {&quot;path&quot;:&quot;slug&quot;,&quot;type&quot;:&quot;PlainText&quot;\} }}',
            style: 'min-height: 625px'
          }
        );
        $('#deal-modal').show();

      })

      $('.details-modal--background-overlay').on('click', function() {
        $('#deal-modal').hide();
        closeModal();
      });
      $('.close-modal').on('click', function() {
        $('#deal-modal').hide();
        closeModal();
      });

      function closeModal() {
        $('#deal-modal').find('.details-modal--widget-wrap>div').remove();
      }
    }, 0)
  	
  });
</script>

This same type of button->pop up script is used on another page on our site, and that stayed working, and the difference is it isn’t placed inside rich text using attributes. So we suspect there’s some problem with the mechanics of the attribute.

We can’t figure out what changed to make it break, as our site activity logs show no changes made between publishes. We’ve ruled out a lot of culprits and are wondering if anything was updated on Finsweet’s side to cause a change.

Finsweet’s attributes update log shows some changes to Powerful Rich Text, but Finsweet curiously offers no dates, so we can’t determine the relevancy.

One of our developers was able to find a hot fix that gets the pop-up working again using the script below. Below I’m also placing links to a page where the pop-up works on our live site, and a page from a duplicate project I created where it doesn’t work.

In addition to this fix, we’d like to understand why it broke to prevent/troubleshoot in the future.

<!-- POPUP INSIDE RTE -->
<script>
    window.fsAttributes = window.fsAttributes || [];
    window.fsAttributes.push(['richtext', () => {
        window.Webflow?.destroy();
        window.Webflow?.ready();
        window.Webflow?.require('ix2').init();
        initSidebarWidget();
        document.dispatchEvent(new Event('readystatechange'));
    }]);
    function initSidebarWidget() {
        $('.deals-eligibility--dark').on('click', function() {
          const phoneId = $(this).data('phone-id');
          $('#deal-modal').find('.details-modal--widget-wrap>div').remove();
          $('#deal-modal').find('.details-modal--widget-wrap').append('<div id="navi-phone-onboarding-widget-3-'+phoneId+'"></div>');
          createWidget(
            '#navi-phone-onboarding-widget-3-'+phoneId,
            'prod',
            phoneId,
            {
              getUtms: true,
              contentId: 'carrier-phones-deal }}',
              style: 'min-height: 625px'
            }
          );
          $('#deal-modal').show();
        })
        $('.details-modal--background-overlay').on('click', function() {
          $('#deal-modal').hide();
          closeModal();
        });
        $('.close-modal').on('click', function() {
          $('#deal-modal').hide();
          closeModal();
        });
        function closeModal() {
          $('#deal-modal').find('.details-modal--widget-wrap>div').remove();
        }
  };
</script>

Project read-only link: https://preview.webflow.com/preview/navi-t?utm_medium=preview_link&utm_source=designer[…]bf1cfecba2&pageId=66bf9b740b99953252f78f79&workflow=preview

Page with buttons working: iPhone Text Effects: A How-to Guide

Page with buttons not working: iPhone Text Effects: A How-to Guide

Hello @Navi!

Can you please re-share your read-only link? It seems to be broken and I would like to take a closer look at the setup

@Support-Luis Whoops, created a new one that should work Webflow - Navi

Also putting a read-only for the same page in a duplicate project where the CTA component doesn’t work in case that’s helpful to compare

https://preview.webflow.com/preview/navi-t-0935c88a38eaeda8c0e051829bb25913?utm_medium=preview_link&utm_source=designer&utm_content=navi-t-0935c88a38eaeda8c0e051829bb25913&preview=b6dbe0212bf989dc4cd8522c477e3ceb&pageId=674e2206c3634b0618f9ded6&itemId=674e2206c3634b0618f9e6ac&locale=en&workflow=preview

Hey @Navi!

There are a couple of issues that may be causing this.

I noticed while inspecting the page that the are several Richtext API callbacks doing different things, I would recommend consolidating all of them into a unique callback.

<script>
  window.fsAttributes = window.fsAttributes || [];
  window.fsAttributes.push([
    'richtext',
    () => {
      console.log('richtext Successfully loaded!');
      // Add all your code here
    },
  ]);
</script>

Also noticed the Attributes script is set on the </body> section of custom code, this should be moved to the <head> section

And finally, there is an error for an undeclared function on the console whenever I click on the CTA buttons, overriding and removing the function made the sidebar pop up as expected.

Let me know if the issue persists after these changes!