tooltip.phps
#!/usr/bin/php
<?php
/**
* Makes a customizable CSS tooltips for the linked example / project.
*
* @author Erik Andersson
* @link http://sixrevisions.com/css/css-only-tooltips/
*
* @param string $text Anchor text or image
* @param string $message Contents of the ToolTip popup
* @param string $type Optional ToolTip style: classic(default),info,help,warning,critical
* @param string $title Optional title / heading before message
* @return string
*/
function makeToolTip($text, $message, $type = 'classic', $title = null) {
$types = array(
'classic'=>array('classic',''),
'critical'=>array('custom critical','<img src="ikoner/tooltip_critical.png" alt="Critical" height="48" width="48" />'),
'help'=>array('custom help','<img src="ikoner/tooltip_help.png" alt="Help" height="48" width="48" />'),
'info'=>array('custom info','<img src="ikoner/tooltip_info.png" alt="Info" height="48" width="48" />'),
'warning'=>array('custom warning','<img src="ikoner/tooltip_warning.png" alt="Warning" height="48" width="48" />')
);
if(empty($text) || empty($message)) { return ""; }
if(!array_key_exists($type,$types)) { $type = 'classic'; }
return '<a class="tooltip" href="#">'.$text.'<span class="'.$types[$type][0].'">'.(!empty($types[$type][1]) ? $types[$type][1] : '').(!empty($title) ? '<em>'.$title.'</em>' : '').$message.'</span></a></div>'.PHP_EOL;
}
echo '<b>ToolTip test:</b> ';
echo makeToolTip('classic','Lorem ipsum dolor sit amet, ad tantas scripta docendi vis, vel consul reformidans ei. Quo no amet euismod. Ei duis mucius eum. Ex idque electram duo.').', '.PHP_EOL;
echo makeToolTip('info','Lorem ipsum dolor sit amet, oporteat senserit eos an. Ne quo paulo fierent. Et mea dicam antiopam. No sint homero mea, est ex ferri senserit. Error graecis placerat ne vis.','info').', '.PHP_EOL;
echo makeToolTip('help','Lorem ipsum dolor sit amet, has in consul referrentur. In pri aliquip inimicus, eam consulatu scriptorem in. In prima minim placerat duo. In cum.','help').', '.PHP_EOL;
echo makeToolTip('warning','Lorem ipsum dolor sit amet, singulis platonem eu sed. Ad mea minim admodum. Cu mei melius conceptam, at ridens.','warning').', '.PHP_EOL;
echo makeToolTip('critical','Lorem ipsum dolor sit amet, ex pro reque dignissim, ex vix erat percipitur, ea enim.','critical').'<br>'.PHP_EOL;
echo '<b>med "title":</b> ';
echo makeToolTip('classic','Lorem ipsum dolor sit amet, ad tantas scripta docendi vis, vel consul reformidans ei. Quo no amet euismod. Ei duis mucius eum. Ex idque electram duo.',null,'Klassisk').', '.PHP_EOL;
echo makeToolTip('info','Lorem ipsum dolor sit amet, oporteat senserit eos an. Ne quo paulo fierent. Et mea dicam antiopam. No sint homero mea, est ex ferri senserit. Error graecis placerat ne vis.','info','Info').', '.PHP_EOL;
echo makeToolTip('help','Lorem ipsum dolor sit amet, has in consul referrentur. In pri aliquip inimicus, eam consulatu scriptorem in. In prima minim placerat duo. In cum.','help','Hjälp').', '.PHP_EOL;
echo makeToolTip('warning','Lorem ipsum dolor sit amet, singulis platonem eu sed. Ad mea minim admodum. Cu mei melius conceptam, at ridens.','warning','Varning').', '.PHP_EOL;
echo makeToolTip('critical','Lorem ipsum dolor sit amet, ex pro reque dignissim, ex vix erat percipitur, ea enim.','critical','Kritisk').'<br>'.PHP_EOL;
?>