TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-06-2008, 03:03 PM   #1 (permalink)
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)
Old 02-06-2008, 06:55 PM   #2 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

Awesome mate, was wondering how OGame did it. I'll try it out a.s.a.p.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 02-06-2008, 09:36 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Very good article!

Althought.. what is this good for?
I mean.. what will it create, that is better than just having a regular link like
HTML Code:
<a href="index.php">Home</a>
??

Sorry if it's a newbie question..
__________________
Tanax is offline  
Reply With Quote
Old 02-06-2008, 09:53 PM   #4 (permalink)
The Contributor
 
Gibou's Avatar
 
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
Gibou is on a distinguished road
Default

Yes,

Do not forget that some peoples in front of the screen don't have your mobility.
Accesskeys and tabindexes have been created for them because, sometimes, they can not use both the keyboard and the mouse in the same time.
Shortcuts for links have so been invented.

In fact, mani criticizes are made to accesskeys because:
- all browsers don't manage them by the same way (on IE, you have to press Alt+Shift+letter AND press enter).
- the combination is awful and with one arm, try to press Alt+Shift+M on an azerty keyboard

But it's a good way to don't exclude some peoples :)
__________________
Wedus project's Website
Send a message via MSN to Gibou
Gibou is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:19 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design