wiki:LoggedInScript

Version 4 (modified by anonymous, 4 years ago) (diff)

--

LoggedInScript

Description

Ever wonder why Trac doesn't link to the user's home page from the first metanav "logged in as" item? I sure did. I cannot recall having an account on a site of some kind that didn't have this feature. So of course I set out to create a hack to add it to Trac.

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, a JavaScript library I happen to be a huge fan of, I thought, why not let the browser do some of the work for a change?

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 (remember the bad old days of "screen scraping")? While this concern certainly has some merit, if you think about it it's essentially doing the same thing as a Python/Genshi approach by manipulating the page on the fly.

At any rate, this hack has no repository or download link or any of that. Just a simple code snippet. Ironically, this goes in your site.html template and it does use Genshi template markup.

Code

<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.

Recent Changes

[5048] by dwclifton on 2008-12-22 23:11:12
New hack LoggedInScript, created by dwclifton

Author/Contributors