Uploaded image for project: 'Confluence Data Center'
  1. Confluence Data Center
  2. CONFSERVER-27357

Anchors should link to an expanded content instead of staying closed

    • 6
    • 4
    • We collect Confluence feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.

      NOTE: This suggestion is for Confluence Server. Using Confluence Cloud? See the corresponding suggestion.

      Summary

      An anchor that linked to some content in Expand macro should expand the content automatically instead of expanding it manually.

      Steps to reproduce

      1. Create some content in one page and add an anchor.
      2. Create a new page and add a link to the anchor.
      3. Click the link to the anchor.

      Screenshots

        1. anchor.jpg
          anchor.jpg
          421 kB
        2. link_to_anchor.jpg
          link_to_anchor.jpg
          137 kB
        3. result.jpg
          result.jpg
          77 kB

            [CONFSERVER-27357] Anchors should link to an expanded content instead of staying closed

            I found a problem with the script above.

            This script is causing this issue: Confluence displays a second "Delete page" pop up for a parent page when deleting a child page.

            See: https://confluence.atlassian.com/confkb/confluence-displays-a-second-delete-page-pop-up-for-a-parent-page-when-deleting-a-child-page-1062240816.html

            I'm not sure if we need to maintain code which was originally designed in 2014...

            In order to fix this, just remove the redirect: 
            window.location.href=hash;
            This will cause the page to reload.

            Elward Bosman added a comment - I found a problem with the script above. This script is causing this issue: Confluence displays a second "Delete page" pop up for a parent page when deleting a child page. See: https://confluence.atlassian.com/confkb/confluence-displays-a-second-delete-page-pop-up-for-a-parent-page-when-deleting-a-child-page-1062240816.html I'm not sure if we need to maintain code which was originally designed in 2014... In order to fix this, just remove the redirect:  window.location.href=hash; This will cause the page to reload.

            No, unfortunately not.
            The Table of Contents does not work at all when the Heading is placed in Expand macro.
            Semms like there's no workaround solution for Confluence Server then

            jaroslaw_bartoszuk added a comment - No, unfortunately not. The Table of Contents does not work at all when the Heading is placed in Expand macro. Semms like there's no workaround solution for Confluence Server then

            f8a5494ffe6a Do the Table of Contents macro links work? You might have luck looking at how those are constructed in your version.

            David Pezet added a comment - f8a5494ffe6a Do the Table of Contents macro links work? You might have luck looking at how those are constructed in your version.

            Tested on Confluence Server 7.13.7, unfortunately, the [inlineExtension] does not work for me.
            The whole anchor mechanism seems not to be working at all when it's inside the expand macro - it doesn't even navigate to the proper section of the page, just stays at the top.

            jaroslaw_bartoszuk added a comment - Tested on Confluence Server 7.13.7, unfortunately, the [inlineExtension] does not work for me. The whole anchor mechanism seems not to be working at all when it's inside the expand macro - it doesn't even navigate to the proper section of the page, just stays at the top.

            David Pezet added a comment - - edited

            Although I haven't tried this in the Server version, the following it what I had noticed in the Cloud version (as commented on CONFCLOUD-27357) If any Server users could try, it might help!

            "To have the link expand, the link needs a little [inlineExtension] after the #. e.g., https://site.atlassian.net/wiki/spaces/FOO/pages/123456789/bar#[inlineExtension]heading

            The native heading anchors don't seem to add this and adding the anchor macro tries adding that little function in there, but it converts the brackets in the link which makes it not work. Seems like a bug on the Atlassian side.

            The easiest way to grab a working link is to use the TOC links from the published page. Looks like those don’t convert the brackets."

            David Pezet added a comment - - edited Although I haven't tried this in the Server version, the following it what I had noticed in the Cloud version (as commented on  CONFCLOUD-27357 ) If any Server users could try, it might help! "To have the link expand, the link needs a little [inlineExtension]  after the # . e.g.,  https://site.atlassian.net/wiki/spaces/FOO/pages/123456789/bar # [inlineExtension] heading The native heading anchors don't seem to add this and adding the anchor macro tries adding that little function in there, but it converts the brackets in the link which makes it not work. Seems like a bug on the Atlassian side. The easiest way to grab a working link is to use the TOC links from the published page. Looks like those don’t convert the brackets."

            I am quite sure this issue will not win any more attention since it's create for server versions. Someone with the permissions has to link it to a datacenter issue...?

            Tobias Peter added a comment - I am quite sure this issue will not win any more attention since it's create for server versions. Someone with the permissions has to link it to a datacenter issue...?

            Craig Senior added a comment - - edited

            Until you are able to have people who are able to implement excellent suggestions made in this forum for this almost decade old problem, perhaps you could add a couple of lines to the documentation on the Expand macro, indicating the limitation and how best to workaround the problem? This would demonstrate that you "appreciate the benefits of such requests." If you don't plan to work on this for the foreseeable future, can you detail how foreseeable your future is, because you are now part of our risk management considerations.

            Craig Senior added a comment - - edited Until you are able to have people who are able to implement excellent suggestions made in this forum for this almost decade old problem, perhaps you could add a couple of lines to the documentation on the Expand macro, indicating the limitation and how best to workaround the problem? This would demonstrate that you "appreciate the benefits of such requests." If you don't plan to work on this for the foreseeable future, can you detail how foreseeable your future is, because you are now part of our risk management considerations.

            This is such a fundamental flaw I can't believe it made it into production. You present a user with links for the express and (justifiably) expected purpose of navigating the page but some just don't work? And for no identifiable reason, not even a clue, from the user's perspective.

            Either don't include headings in the TOC that are inside collapsed content on the page, or make all the TOC links work as users expect from 30+ years of ubiquitous and uniform digital interaction. 

            Sorry to be harsh but as space owners, we bare the brunt of the fallout, looking incompetent and facing the understandably frustrated users.  

            claire.eager added a comment - This is such a fundamental flaw I can't believe it made it into production. You present a user with links for the express and (justifiably) expected purpose of navigating the page but some just don't work? And for no identifiable reason, not even a clue, from the user's perspective. Either don't include headings in the TOC that are inside collapsed content on the page, or make all the TOC links work as users expect from 30+ years of ubiquitous and uniform digital interaction.  Sorry to be harsh but as space owners, we bare the brunt of the fallout, looking incompetent and facing the understandably frustrated users.  

            Like a previous comment mentioned, pages with lots of information packed in expand macros are hard to link to from other pages - quite frankly, the anchor functionality is a bit broken, as it is now.

            I therefore urge the implementation of this feature. 

            Kyrre Amanaborg added a comment - Like a previous comment mentioned, pages with lots of information packed in expand macros are hard to link to from other pages - quite frankly, the anchor functionality is a bit broken, as it is now. I therefore urge the implementation of this feature. 

            The original workaround script wasn't working for me because chrome wasn't firing `haschange` event on the window object for some reason.  I switched the script to use polling and everything works.  See below:

            <script>
            var expandAnchor = function() {
              var hash = decodeURIComponent(window.location.hash);
              if (hash) {
                var hashPageTitle = AJS.params.pageTitle.split(" ").join("");
                if (hash.indexOf(hashPageTitle) === -1) {
                  if (jQuery.isNumeric(hashPageTitle.substring(0,1))) {
                    hash = "#id-" + hashPageTitle + "-" + hash.slice(1);
                  } else {
                    hash = "#" + hashPageTitle + "-" + hash.slice(1);
                  }
                }
                var escapedId = hash.replace(/[!"$%&'()*+,.\/:;<=>?@[\\\]^`{|}~]/g, "\\$&");
                jQuery(escapedId).parents('.expand-container').children('.expand-hidden').prev().click();
                window.location.href=hash;
              }
            }
            AJS.toInit(function() {
              // handle initial page load
              expandAnchor();
            
            
              // use polling because hashchange event doesn't fire for some reason
              function hashHandler(){
                this.oldHash = window.location.hash;
                this.Check;
            
                var that = this;
                var detect = function(){
                    if(that.oldHash!=window.location.hash){
                        console.log("HASH CHANGED - new has" + window.location.hash);
            			expandAnchor();
                        that.oldHash = window.location.hash;
                    }
                };
                this.Check = setInterval(function(){ detect() }, 100);
            }
            
            var hashDetection = new hashHandler();
            });
            </script>
            

            Alex Feldman added a comment - The original workaround script wasn't working for me because chrome wasn't firing `haschange` event on the window object for some reason.  I switched the script to use polling and everything works.  See below: <script> var expandAnchor = function() { var hash = decodeURIComponent(window.location.hash); if (hash) { var hashPageTitle = AJS.params.pageTitle.split( " " ).join(""); if (hash.indexOf(hashPageTitle) === -1) { if (jQuery.isNumeric(hashPageTitle.substring(0,1))) { hash = "#id-" + hashPageTitle + "-" + hash.slice(1); } else { hash = "#" + hashPageTitle + "-" + hash.slice(1); } } var escapedId = hash.replace(/[! "$%&'()*+,.\/:;<=>?@[\\\]^`{|}~]/g, " \\$&"); jQuery(escapedId).parents( '.expand-container' ).children( '.expand-hidden' ).prev().click(); window.location.href=hash; } } AJS.toInit(function() { // handle initial page load expandAnchor(); // use polling because hashchange event doesn't fire for some reason function hashHandler(){ this .oldHash = window.location.hash; this .Check; var that = this ; var detect = function(){ if (that.oldHash!=window.location.hash){ console.log( "HASH CHANGED - new has" + window.location.hash); expandAnchor(); that.oldHash = window.location.hash; } }; this .Check = setInterval(function(){ detect() }, 100); } var hashDetection = new hashHandler(); }); </script>

              Unassigned Unassigned
              cchan Chung Park Chan
              Votes:
              184 Vote for this issue
              Watchers:
              101 Start watching this issue

                Created:
                Updated: