4 Replies Latest reply on Apr 22, 2015 9:38 AM by MickT

    HTML widget that checks anonymous and shows username-enabled links when logged in

    MickT

      Hi all,

      I've been trying to rework some code for my cloud instance.

      This code worked in a hosted 6 environment, with the object window._jive_current_user.username. It would hide the my-widget-links div when you were not logged in and it would replace #{username} when you were.

       

      Reading that the call changed for cloud (https://community.jivesoftware.com/message/1396741#1396741), I updated my code like so:

       

       

      <p><a href="/content?filterID=all~objecttype~objecttype%5Bidea%5D~ideaStage%5B0%5D" target="_blank">View all ideas</a></p>
      
      
      <div class="my-widget-links"><p><a href="/people/#{username}/content?filterID=contentstatus%5Bpublished%5D~objecttype~objecttype%5Bidea%5D"
      target="_blank">My ideas</a> </p>
      
      
      <p><a href="/people/#{username}/places?filterID=member" target="_blank">My groups</a></p>
      
      
      </div>
      
      
      <p style="font-size: small;">If you are logged in, you will see links to your ideas and your groups above, also.</p>
      
      
      <script type="text/javascript">
      // Hide the div tag if the user is not logged in
      if (top.window.window._jive_current_user.anonymous) {
        $j('.my-widget-links').hide();
      } else {
      // Go through every link and change #{username} to the actual username
        $j('.my-widget-links a').each(function(){
          var link = $j(this);
          var url = link.attr('href');
          url = url.replace('#{username}', encodeURI(top.window.window._jive_current_user.username));
          link.attr('href',url);
        });
      }
      </script>
      
      

       

       

      The variable #{username} is not being replaced. Can anyone give me a hand with this? Would you have a moment to look, Ryan Rutan ?

       

      Thanks,
      Michael

        • Re: HTML widget that checks anonymous and shows username-enabled links when logged in
          Ryan Rutan

          A few things...you need to bring your JS into a separate JS file that is uploaded to the HTML widget, and reference the JS in your HTML.

           

          Overall, this should work...off the top of my head ... not sure about the top.window declarations ... but you will need to make sure you get the right DOM targets for the variables.

           

          Hope that helps.

            • Re: HTML widget that checks anonymous and shows username-enabled links when logged in
              MickT

              Replaced the top.widow declarations with window.parent._jive_current_user.username based on this providing the values I needed using that dom declaration:

               

              <script> 
              alert('Display Name: ' + window.parent._jive_current_user.displayName + 
              '\nAnonymous: ' + window.parent._jive_current_user.anonymous+ 
              '\nUsername: ' + window.parent._jive_current_user.username + 
              '\nID: ' + window.parent._jive_current_user.ID+ 
              '\nEnabled: ' + window.parent._jive_current_user.enabled + 
              '\nAvatar ID: ' + window.parent._jive_current_user.avatarID); 
              </script>
              

               

              and pulled the entire script file out to here https://community.lifesize.com/resources/statics/1002/hide.js.

               

              I still can't seem to replace #{username} in the URL.

               

              With only this left in the html widget:

              <script src="/resources/statics/1002/hide.js">
              </script>
              <p><a href="/content?filterID=all~objecttype~objecttype%5Bidea%5D~ideaStage%5B0%5D" target="_blank">View all ideas</a></p>
              
              <div class="my-widget-links"><p><a href="/people/#{username}/content?filterID=contentstatus%5Bpublished%5D~objecttype~objecttype%5Bidea%5D"
              target="_blank">My ideas</a> </p>
              
              
              <p><a href="/people/#{username}/places?filterID=member'" target="_blank">My groups</a></p>
              
              
              </div>
              
              
              <p style="font-size: small;">If you are logged in, you will see links to your ideas and your groups above, also.</p>
              

               

               

              Any ideas what I'm not referencing correctly? The URL is produced with the #{username} within it.

               

              Thank you for any help.

              Michael