wiki:LoggedInScript

Add link to the user's home page

Description

Ever wonder why Trac doesn't link to the user's home page from the first metanav "logged in as" item?

Of course you could do this sort of thing with Genshi, something I'm still trying to wrap my head around and, frankly, I'm not a big fan of these XML/XSLT-based templating languages.

Since Trac loads jQuery, I thought, why not let the browser do some of the work? You might think, since you are parsing the DOM and checking for certain attributes and values, won't your code break if Trac changes something in the future? While this concern certainly has some merit, it's essentially the same as a Python/Genshi approach by manipulating the page on the fly.

This hack has no repository or download link and offers only a code snippet. This goes in your site.html template and it does use Genshi template markup.

Javascript code implementation

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/" py:strip="">
 <head py:match="head" py:attrs="select('@*')">
  ${select('*')}
  <script type="text/javascript">
   jQuery(document).ready(function($) {
     $('#metanav li.first:contains("logged in as")').each(function() {
       var path = $('#mainnav li.first a').attr('href').split('/')[1];
       var user = $(this).text().split(' ').pop();
       var link = '<a href="/' + path + '/wiki/' + user + '">' + user + '</a>';
       $(this).html('logged in as ' + link);
       return false;
     });
   });
  </script>
 </head>
</html>

Bugs/Feature Requests

Existing bugs and feature requests for LoggedInScript are here.

If you have any issues, create a new ticket.

defect

0 / 1

Recent Changes

5048 by dwclifton on 2008-12-22 23:11:12
New hack LoggedInScript, created by dwclifton
(more)

Author/Contributors

Author: dwclifton
Maintainer: none (needsadoption)
Contributors: John Resig

Last modified 14 months ago Last modified on Jun 9, 2015, 12:43:23 PM