briank

Hide/Show Kartra Sections Using Link URLs

Jun 26th, 2023 (edited)
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.29 KB | None | 0 0
  1. <!--
  2. Use <a href> links to control hiding and showing of Kartra sections (and/or classes).
  3. Author: Brian Katzung <[email protected]>
  4. <a href='#hide,item,item,...'>
  5. <a href='#hide,item,item,...,show,item,item,...'>
  6. <a href='#show,item,item,...'
  7. Each item may be a section id (omit #, it will be added) or a .class name (note leading period).
  8. Use "Hide section from leads not assigned tag 'Unassigned' for default-hidden sections" and
  9. make sure that no leads are ever assigned that tag.
  10. If you're using the Kartra button UI, use URL https://published_page_url#hide,...,show,...
  11. -->
  12. <script>
  13. function procHideShowLink (src) {
  14.     var a = src.href ? src : src?.target;
  15.     if (!a?.href) return;
  16.     var hash = ',' + (new URL(a.href).hash.substring(1)) + ',';
  17.     var m = hash.match(/^(?:,hide,(.*?))?(?:,show,(.*?))?,$/);
  18.     var hide = (m && m[1] && m[1] && m[1].split(',').map(i => i.replace(/^[^.]/, '#$&')) || []);
  19.     var show = (m && m[2] && m[2] && m[2].split(',').map(i => i.replace(/^[^.]/, '#$&')) || []);
  20.     if ((hide.length || show.length) && src.preventDefault) src.preventDefault();
  21.     if (hide.length) jQuery(hide.join(',')).hide();
  22.     if (show.length) jQuery(show.join(',')).show();
  23. }
  24. jQuery(() => {
  25. jQuery('a[href*="#hide,"],a[href*="#show,"]').click(procHideShowLink);
  26. });
  27. </script>
Advertisement
Add Comment
Please, Sign In to add comment