| Joomla! http://forum.joomla.org/ |
|
| Skip links in templates *SOLVED* http://forum.joomla.org/viewtopic.php?f=42&t=245 |
Page 1 of 1 |
| Author: | blue-kiwi [ Thu Aug 18, 2005 10:34 pm ] |
| Post subject: | Skip links in templates *SOLVED* |
I posted this on the other boards, but it went unnoticed with all the uproar! (or just nobody could help..). Hopefully someone here can.. (Please excuse the cut n paste job!) --------------------------------------------- OK, I've just come across a bit of a problem. I've included generic accessibility skip links in my template, the usual, skip to content, skip to menu, and top of page stuff. Using the normal top of page sort of thing. Problem is mambo automatically whacks the root address, i.e. yourcompanyhere.com in front of the hash mark, so those skip links look like, http://www.yourcompanyhere.com/#top. This nullifies the usefulness of these links, as it then always points to the front page, and requires a page reload. Not cool. I've tried putting these links in as static URLS in a menu but to no avail. Anyone else have this problem, and hopefully a solution? ************************** Just a thought: If it were possible to add some code to output the current address, either through php or a moscode sort of thing then that could be tacked onto the beginning? |
|
| Author: | de [ Thu Aug 18, 2005 10:41 pm ] |
| Post subject: | Re: Skip links in templates |
If you are not 100% sure that Mambo changes the HTML code (using a Mambot for example) then I would claim this is a general issue... the browser makes the link relative to the current path excluding the file. The following snipped I am using within my TOC: Code: $link = $_SERVER['REQUEST_URI']; $i = strpos($link, '#'); if ($i !== FALSE) { $link = substr($link, 0, $i); } if ((strlen($link) > strlen($mosConfig_live_site)) && (substr($link, 0, strlen($mosConfig_live_site)) == $mosConfig_live_site)) { $link = substr($link, strlen($mosConfig_live_site) + 1); } $link = sefRelToAbs($link); $link .= '#'.$name; But maybe someone knows another simpler way. |
|
| Author: | blue-kiwi [ Thu Aug 18, 2005 10:46 pm ] |
| Post subject: | Re: Skip links in templates |
Thanks for your reply mate! I'm not sure how to check if mambo is changing the code (although I'm failry certain it is), and I have no idea what the code snippet means, or is meant to do, but I appreciate the effort! |
|
| Author: | de [ Thu Aug 18, 2005 10:50 pm ] |
| Post subject: | Re: Skip links in templates |
blue-kiwi wrote: Thanks for your reply mate! I'm not sure how to check if mambo is changing the code (although I'm failry certain it is), and I have no idea what the code snippet means, or is meant to do, but I appreciate the effort! Well, you could just view the page source within your browser and then search for #top to find that link... I am quite sure it is there as you wrote it but when you hover your mouse over the link or even click on it the browser jumps to the page you mention. As for the code snipped... you asked for some php code... it expects the $name variable to be set to the anchor so "top"... and $link will then in the end contain the absolute URL containing that anchor. I could even tell you the exact steps if you would want to use my component moslate if that is what you want. |
|
| Author: | rcarver [ Thu Aug 18, 2005 10:51 pm ] |
| Post subject: | Re: Skip links in templates |
Seems to work for me, what version are you using? Are you using SEO? I did a quick test of this by adding the following to an index.php test: Code: <body > <a name="top"></a> blech ... more blech <a href=#top>return to top</a> </body> And on the frontpage the url for return to top is: http://localhost/index.php#top And on the license page its: http://localhost/index.php?option=com_c ... emid=6#top this is for version 4.5.2 |
|
| Author: | blue-kiwi [ Thu Aug 18, 2005 10:58 pm ] |
| Post subject: | Re: Skip links in templates |
de wrote: blue-kiwi wrote: Thanks for your reply mate! I'm not sure how to check if mambo is changing the code (although I'm failry certain it is), and I have no idea what the code snippet means, or is meant to do, but I appreciate the effort! Well, you could just view the page source within your browser and then search for #top to find that link... I am quite sure it is there as you wrote it but when you hover your mouse over the link or even click on it the browser jumps to the page you mention. As for the code snipped... you asked for some php code... it expects the $name variable to be set to the anchor so "top"... and $link will then in the end contain the absolute URL containing that anchor. I could even tell you the exact steps if you would want to use my component moslate if that is what you want. That looks good mate, a step by step idots guide would be much appreciated! Have you already wrapped this up in a mambot/component or something? What is moslate? The site in question is http://www.3tc4u.co.uk, if you look at the source the links look like top, correlating to , yet on any page mambo is putting the root address in front of it. I tried both in IE and Firefox, and get the same thing... |
|
| Author: | de [ Thu Aug 18, 2005 11:15 pm ] |
| Post subject: | Re: Skip links in templates |
Ok, partially what I said was incorrect... I just knew I had a problem and now I know again where it actually comes from... you will find in your page source However, the step by step guide comes here (but as said I don't know whether there is a simpler way)... ahh just realize this is inside your template right? (then forget about my component) In your template write in the beginning (somewhere between ): Code: function getRelativeAnchorLink($name) { global $mosConfig_live_site; $link = $_SERVER['REQUEST_URI']; $i = strpos($link, '#'); if ($i !== FALSE) { $link = substr($link, 0, $i); } if ((strlen($link) > strlen($mosConfig_live_site)) && (substr($link, 0, strlen($mosConfig_live_site)) == $mosConfig_live_site)) { $link = substr($link, strlen($mosConfig_live_site) + 1); } if ((strlen($link) > 0) && (substr($link, 0, 1) == '/')) { $link = substr($link, 1); } $link = sefRelToAbs($link); $link .= '#'.$name; return $link; } And then whereever you want to use it within your template write something like this: Code: <a href="<?php echo getRelativeAnchorLink('top'); ?>">top of page</a>
|
|
| Author: | blue-kiwi [ Thu Aug 18, 2005 11:17 pm ] |
| Post subject: | Re: Skip links in templates |
Excellent, give me a min to try it out, will report back!
|
|
| Author: | de [ Thu Aug 18, 2005 11:21 pm ] |
| Post subject: | Re: Skip links in templates |
I forgot the "global $mosConfig_live_site;" in the beginning of the function (changed my previous post). |
|
| Author: | vavroom [ Thu Aug 18, 2005 11:27 pm ] |
| Post subject: | Re: Skip links in templates |
Sweeeeet I'll have to implement that when I have a moment. Couple of my sites "puke out" with local anchors.
|
|
| Author: | blue-kiwi [ Fri Aug 19, 2005 1:28 pm ] |
| Post subject: | Re: Skip links in templates |
This is excellent!! Thank you so much for your time and skill de.. I have a few sites that need this and I'm putting them in now! If I could give you reputation or good karma on these boards rest assured I would! Thanks a lot, kiwi |
|
| Author: | toubkal [ Tue Jan 10, 2006 1:57 pm ] |
| Post subject: | Re: Skip links in templates *SOLVED* |
Aahhh - after an age searching, I find the answer. Thanks de. Is this not considered a bug? surely basic anchors should work with SEF? |
|
| Author: | vavroom [ Tue Jan 10, 2006 9:44 pm ] |
| Post subject: | Re: Skip links in templates *SOLVED* |
toubkal, when I discussed this with MasterChief a few weeks back, he was flabbergasted. Said things "should" work properly. And sure enough, tried it, it works... Hmmm. //Edit: FWIW, mosconfig_whatever doesn't exist in 1.1 anymore... Still left as legacy stuff, so it should work, but it's not native anymore
|
|
| Author: | de [ Tue Jan 10, 2006 9:55 pm ] |
| Post subject: | Re: Skip links in templates *SOLVED* |
vavroom wrote: toubkal, when I discussed this with MasterChief a few weeks back, he was flabbergasted. Said things "should" work properly. And sure enough, tried it, it works... With SEF turned on (SEF URL contains a new sub directory compared to the base), a proper base URL set for the document and not inside an content item (where a Mambot could grab it)? Not tested now by myself... but I think that are the "error conditions". (Side note: added "flabbergasted" to the list of known words) |
|
| Author: | toubkal [ Tue Jan 10, 2006 10:02 pm ] |
| Post subject: | Re: Skip links in templates *SOLVED* |
I am actually tring to use an anchor in the template, not within content. This is for a "skip to main content" link for accessability (and it helps with usability on for e.g. mobile phones) should I be doing something different to make it work in the template? the code I originally tried was: Code: <a href="#maincontent" class="skip">Skip to main content</a>
and ..... <a name="maincontent" id="maincontent"></a> |
|
| Author: | fabrice@55thinking [ Wed Mar 29, 2006 1:11 pm ] |
| Post subject: | Re: Skip links in templates *SOLVED* |
Had some problems to make the code above work with openSEF (on 1.0.7). Here's another option : function getRelativeAnchorLink($name) { global $mosConfig_live_site; if ($_SERVER['QUERY_STRING']) $link = sefRelToAbs( "index.php?" . str_replace("&", "&", $_SERVER['QUERY_STRING'] ) ); else $link = $mosConfig_live_site . "/"; $link .= '#'.$name; return $link; } It work with openSEF, partially tested with standard joomla SEF, seems ok |
|
| Author: | axoi [ Sun Jan 07, 2007 10:58 am ] |
| Post subject: | Re: Skip links in templates |
de wrote: Ok, partially what I said was incorrect... I just knew I had a problem and now I know again where it actually comes from... you will find in your page source However, the step by step guide comes here (but as said I don't know whether there is a simpler way)... ahh just realize this is inside your template right? (then forget about my component) In your template write in the beginning (somewhere between ): Code: function getRelativeAnchorLink($name) { global $mosConfig_live_site; $link = $_SERVER['REQUEST_URI']; $i = strpos($link, '#'); if ($i !== FALSE) { $link = substr($link, 0, $i); } if ((strlen($link) > strlen($mosConfig_live_site)) && (substr($link, 0, strlen($mosConfig_live_site)) == $mosConfig_live_site)) { $link = substr($link, strlen($mosConfig_live_site) + 1); } if ((strlen($link) > 0) && (substr($link, 0, 1) == '/')) { $link = substr($link, 1); } $link = sefRelToAbs($link); $link .= '#'.$name; return $link; } And then whereever you want to use it within your template write something like this: Code: <a href="<?php echo getRelativeAnchorLink('top'); ?>">top of page</a> you're my hero as well ![]() thanx a lot for this fix! |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|