Adding Access Keys in 1.5

Forum closed, please submit your tips and tricks to: http://docs.joomla.org/Category:Tips_and_tricks
Locked
itsthetaste
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Fri Jan 18, 2008 2:32 am

Adding Access Keys in 1.5

Post by itsthetaste » Mon Mar 31, 2008 12:40 am

Heres a quick way to add access keys to joomla 1.5.

Note, This involves hacking the core code.

Firstly edit the component.xml parameter definiton file in \administrator\components\com_menus\models\metadata
and add to it an accesskey parameter

Code: Select all

<param name="accesskey" type="text" size="1" default="" label="Accessibility Access Key" description="Accessibility Access Key for the page which this Menu item points to" />
Your file should now look something like

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<metadata>
	<state>
		<name>Component</name>
		<description>Component Parameters</description>
		<params>
			<param name="page_title" type="text" size="30" default="" label="Page Title" description="PARAMPAGETITLE" />
			<param name="show_page_title" type="radio" default="1" label="Show Page Title" description="SHOW/HIDE THE PAGES TITLE">
				<option value="0">No</option>
				<option value="1">Yes</option>
			</param>
			<param name="pageclass_sfx" type="text" size="20" default="" label="Page Class Suffix" description="PARAMPAGECLASSSFX" /> 
			<param name="@spacer" type="spacer" default="" label="" description="" />
			<param name="menu_image" type="imagelist" directory="/images/stories" hide_default="1" default="" label="Menu Image" description="PARAMMENUIMAGE" />
			<param name="@spacer" type="spacer" default="" label="" description="" />
			<param name="secure" type="radio" default="0" label="SSL Enabled" description="PARAMSECURE">
				<option value="-1">Off</option>
				<option value="0">Ignore</option>
				<option value="1">On</option>
			</param>
			<param name="@spacer" type="spacer" default="" label="" description="" />
			<param name="accesskey" type="text" size="1" default="" label="Accessibility Access Key" description="Accessibility Access Key for the page which this Menu item points to" />
		</params>
		<advanced />
	</state>
</metadata>
Now edit the frontend file \modules\mod_mainmenu\helper.php

Add

Code: Select all

// ACCESS KEY HACK - Part 1
$accessKey = $iParams->get('accesskey');
$tmp->accessKey = $accessKey;
and

Code: Select all

// ACCESS KEY HACK - Part 2
if ($tmp->accessKey)
$data = '<a href="'.$tmp->url.'" accesskey="'.$tmp->accessKey.'">'.$image.$tmp->name.'</a>';
else 
$data = '<a href="'.$tmp->url.'" >'.$image.$tmp->name.'</a>';
into the _getItemData($item) function so that it looks like this

Code: Select all

function _getItemData($item)
	{
		$data = null;

		// Menu Link is a special type that is a link to another item
		if ($item->type == 'menulink')
		{
			$menu = &JSite::getMenu();
			if ($tmp = clone($menu->getItem($item->query['Itemid']))) {
				$tmp->name	 = '<span><![CDATA['.$item->name.']]></span>';
				$tmp->mid	 = $item->id;
				$tmp->parent = $item->parent;
			} else {
				return false;
			}
		} else {
			$tmp = clone($item);
			$tmp->name = '<span><![CDATA['.$item->name.']]></span>';
		}

		$iParams = new JParameter($tmp->params);
		if ($iParams->get('menu_image') && $iParams->get('menu_image') != -1) {
			$image = '<img src="'.JURI::base(true).'/images/stories/'.$iParams->get('menu_image').'" alt="" />';
		} else {
			$image = null;
		}


		// ACCESS KEY HACK - Part 1
		$accessKey = $iParams->get('accesskey');
		$tmp->accessKey = $accessKey;

		switch ($tmp->type)
		{
			case 'separator' :
				return '<span class="separator">'.$image.$tmp->name.'</span>';
				break;

			case 'url' :
				if ((strpos($tmp->link, 'index.php?') !== false) && (strpos($tmp->link, 'Itemid=') === false)) {
					$tmp->url = $tmp->link.'&Itemid='.$tmp->id;
				} else {
					$tmp->url = $tmp->link;
				}
				break;

			default :
				$router = JSite::getRouter();
				$tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id;
				break;
		}

		// Print a link if it exists
		if ($tmp->url != null)
		{
			// Handle SSL links
			$iSecure = $iParams->def('secure', 0);
			if ($tmp->home == 1) {
				$tmp->url = JURI::base();
			} elseif (strcasecmp(substr($tmp->url, 0, 4), 'http') && (strpos($tmp->link, 'index.php?') !== false)) {
				$tmp->url = JRoute::_($tmp->url, true, $iSecure);
			} else {
				$tmp->url = str_replace('&', '&', $tmp->url);
			}

			switch ($tmp->browserNav)
			{
				default:
				case 0:
					// _top
					// ACCESS KEY HACK - Part 2			 ###############################
					if ($tmp->accessKey)
						$data = '<a href="'.$tmp->url.'" accesskey="'.$tmp->accessKey.'">'.$image.$tmp->name.'</a>';
					else 
						$data = '<a href="'.$tmp->url.'" >'.$image.$tmp->name.'</a>';
					break;
				case 1:
					// _blank
					$data = '<a href="'.$tmp->url.'" target="_blank">'.$image.$tmp->name.'</a>';
					break;
				case 2:
					// window.open
					$attribs = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,'.$this->_params->get('window_open');

					// hrm...this is a bit dickey
					$link = str_replace('index.php', 'index2.php', $tmp->url);
					$data = '<a href="'.$link.'" onclick="window.open(this.href,\'targetWindow\',\''.$attribs.'\');return false;">'.$image.$tmp->name.'</a>';
					break;
			}
		} else {
			$data = '<a>'.$image.$tmp->name.'</a>';
		}

		return $data;
		
	}
Login to your admin site and edit a menu item. Now open the "Parameters - System" accordion item on the right and you will see your accesskey parameter. Set a value, save the menu item and voila.

Palmis
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Wed Apr 09, 2008 7:30 am

Re: Adding Access Keys in 1.5

Post by Palmis » Wed Apr 09, 2008 11:52 am

Hi itsthetaste,
I have implemented your suggestion, but I'm unable to use it.
Login to your admin site and edit a menu item. Now open the "Parameters - System" accordion item on the right and you will see your accesskey parameter. Set a value, save the menu item and voila.
I tried to insert values as 'H' or 'Alt+H' as accesskey parameter for the menu item HOME, but with no success.

Could you help me?
Thanks in advance
Palmis

itsthetaste
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Fri Jan 18, 2008 2:32 am

Re: Adding Access Keys in 1.5

Post by itsthetaste » Wed Apr 09, 2008 11:06 pm

Hi Palmis,

How far are you getting. Does the accesskey attribute now show in the html for your frontend?
And if so, are you using IE as you will need to hit the enterkey after ALT+H.

When entering you just need to enter the letter H.

Cheers
Richard

Palmis
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Wed Apr 09, 2008 7:30 am

Re: Adding Access Keys in 1.5

Post by Palmis » Thu Apr 10, 2008 7:52 am

Hi Richard,

I checked. This is the result: the accesskey attribute is not shown in the html and I don't understand the why.
I don't know where I'm wrong.
I hope you could help me. ;)

Thanks
Palmis

Note: attached you can find the screenshot.
You do not have the required permissions to view the files attached to this post.

adbox27
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Jun 17, 2008 10:48 pm

Re: Adding Access Keys in 1.5

Post by adbox27 » Tue Jul 01, 2008 5:56 pm

this worked fine for me. using firefox used shift+alt+ accesskey to get the keys to work.

To finish it off it would be fantastic to get the first letter of each menu item name to be underlined. Is there a simple way to do that? Or is more php stuff required?

Nog
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Fri Sep 28, 2007 10:47 am

Re: Adding Access Keys in 1.5

Post by Nog » Fri Jul 04, 2008 10:42 am

I'm getting the same problem as Palmis. The admin function works perfectly, but the accesskey parameter isn't being added to the <a> tag when I check the source code.
Gary Brindley
QLUE
http://www.qlue.co.uk
If you can keep your head when people all around you are losing theirs then maybe you've misunderstood the situation.

lcascant
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Fri Apr 11, 2008 10:31 am

Re: Adding Access Keys in 1.5

Post by lcascant » Mon Jul 14, 2008 11:29 am

My problem is more or less the same as Palmis.
At the back end I can add the accesskey without any problem to all the menus that I want.
However, when I am in the frontend just the menus, which are situated on left column, are working alright. All the other menus, which are on the top, when I press ALT plus D, or E, or 1, it is like nothing.
There is anybody who can solve it.

Thank you in advance,

Lorena Cascant

Gergo Erdosi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4031
Joined: Sat Nov 11, 2006 9:34 pm
Location: Hungary

Re: Adding Access Keys in 1.5

Post by Gergo Erdosi » Thu Jul 17, 2008 3:57 pm

I added this post the the Docs site:
http://docs.joomla.org/Adding_Access_Keys


Locked

Return to “Submit Your Suggested Tips & Tricks to Docs.joomla.org now please.”