View Single Post
Old 02-06-2008, 03:03 PM   #1 (permalink)
Gibou
The Contributor
 
Gibou's Avatar
 
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
Gibou is on a distinguished road
Plugin/Addon dynamic accesskeys

Hi everybody !

This topic, just for sharing a practical use of php5 to make dynamic accesskeys.

For those who don't know what are accesskeys:
In order to validate the accessibility of your website, it could be useful to give access to your menu links without needing the mouse (i.e. only keyboard). It's very simple in xhtml. For instance, your have a link named "my super link of death" and it's the first one in your menu. The code can be:

HTML Code:
<a href="target page" accesskey="a">my super link of death</a>
Thanks to this code, on Firefox, pressing Alt+Shift+a will equival to clic on the link. The accesskeys are generaly letters so menu mustn't have more than 26 links :p
The first link has the accesskey 'a', the second, 'b' and so on.
Ex: Wedus.org :: Système d'information d'aide à l'éducation .::. Politique d'accessibilité


The aim of the php5 class:
The problem is when you insert a link between two of them in the menu, you have to change the others accesskeys to keep the order. And you have to modify the page containing the list of accesskeys with their description and the page where the link redirects.
The class manages that.

PHP Code:
<?php

class Accessibility
{
    private static 
$key 'a';
    private static 
$tableKeys = Array();

    public function 
makeAccesskey($linkName null$desc null)
    {
        
$tmp = Array(
        
"key" => self::$key,
        
"linkName" => $linkName,
        
"desc" => $desc
        
);
        
self::$tableKeys[] = $tmp;
        unset(
$tmp);
        return(
'accesskey="'.self::$key++.'"');
    }
    
    public function 
getTableKeys()
    {
        return(
self::$tableKeys);
    }
}

?>
In the menu, you just have to insert your links like that:

PHP Code:
<a href="index.php" <?php echo Accessibility::makeAccesskey("Home","Go back to home page");?>>Home</a>
It will insert the good accesskey and save a list with the association of letters / links names / description of the page targeted.
To create the page listing the accesskeys, you just have to create a short script parsing the hashtable $tableKeys.
For instance:

PHP Code:
<?php
$tableKeys 
Accessibility::getTableKeys();
foreach(
$tableKeys as $row)
{
    echo
'
    <tr>
        <td>Alt + Shift + '
.$row["key"].'</td>
        <td>'
.$row["page"].'</td>
        <td>'
.$row["desc"].'</td>
    </tr>'
;
}
?>
Now, if you want to insert a link, just insert the line in the menu and the rest will be automatic

Hoping it can be useful :)
__________________
Wedus project's Website
Send a message via MSN to Gibou
Gibou is offline  
Reply With Quote
The Following 2 Users Say Thank You to Gibou For This Useful Post:
ReSpawN (02-07-2008), Tanax (02-06-2008)