<?php if (!defined('PmWiki')) exit(); /* +----------------------------------------------------------------------+ | csstooltipstogo.php for PmWiki. Copyright 2010 Joan Vilaseca | This program is free software; you can redistribute it and/or modify | it under the terms of the GNU Affero General Public License, as | published by the Free Software Foundation. | http://www.gnu.org/licenses/agpl.html | This program is distributed in the hope that it will be useful, | but WITHOUT ANY WARRANTY; without even the implied warranty of | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | GNU Affero General Public License for more details. +----------------------------------------------------------------------+ | Inspired on the previous work : linkcsstooltip.php of Hans Bracker | | Adds markup (:tooltips class='classname' aspect='css-text' hover='css-hover' popup='css-tooltip' [add[.*]='css-extra'] :) | Adds markup [| classname instance-params ||text||tooltip|] | for css popups/tooltips. The popup/tooltip contents can be styled using wiki styles, PTVs or (:inlude :) text | Markup example: | (:tooltips class='CN' aspect='color: red;' hover='font-weight: bold;' popup='left:2em; top:2em;':) | [|CN||Hover over this||tooltip text|] | produces html structure: | head | // css class definitions | span.tttgCN {position:relative;} | span.tttgCN:hover span.LtttgCN {font-weight: bold;} | span.tttgCN:hover div.PtttgCN {display:block;position:absolute;z-index:1001; left:2em; top:2em;} | span.LtttgCN {color: red;} | div.PtttgCN {display:none;} | body | <span class="CtttgN"><span class="LtttgCN">Hover over this</span><div class="PtttgCN">tooltip text</div></span> +----------------------------------------------------------------------+ */ $RecipeInfo['CSSToolTipsToGo']['Version'] = '2011-01-01.v0.2'; # $pagename declaration only inside de CSSToolTipsToGo() function #$RecipeInfo['CSSToolTipsToGo']['Version'] = '2010-10-09.v0.1'; # # # CSS Tool Tips To Go # # define a class of tooltips # # (:tooltips class='classname' aspect='css-text' hover='css-hover' popup='css-popup' [add[.*]='extra-css'] :) # Markup("TTTGDEF","_begin","/\\(:tooltips (.*?):\\)/se", "CSSToolTipsToGoDefine('$1')"); # # # to change behaviour of links (<a> tags) inside the text field use the add.* field(s) notation # ie: # # (:tooltips class=classname # aspect='color: #000;' # hover='background:#ccc;' # popup='left:2em; top:2em; border:solid; background: #fff;' # # add='span.L@CLASS@ a:visited {color: red;}' # add0='span.L@CLASS@ a:link {color: red;}' # add1='span.L@CLASS@ a:active {color: red;}' # add2='span.L@CLASS@ a:hover {color: black; text-decoration: none;}' # # :) # or # (:tooltips class=classname # aspect='color: #000;' # hover='background:#ccc;' # popup='left:2em; top:2em; border:solid; background: #fff;' # # add='span.L@CLASS@ a:visited {color: red;} # span.L@CLASS@ a:link {color: red;} # span.L@CLASS@ a:active {color: red;} # span.L@CLASS@ a:hover {color: black; text-decoration: none;}' # # :) # # (note that markup processing will replace '@CLASS@' with a derivartion of the supplied classname value) # # every '(:tooltips params :)' markup creates/replaces an HTMLStylesFmt['classname'] entry # function CSSToolTipsToGoDefine($str) { global $HTMLStylesFmt; $defaults = array('class'=>'tttg' , 'aspect'=>'', 'hover'=>'' , 'popup'=>'left:1em; top:1em;' , 'css'=>'' , 'add'=>''); $t = array_merge($defaults, ParseArgs($str)); $css=" span.@CLASS@ {position:relative;} span.@CLASS@:hover span.L@CLASS@ {@HOVER@} span.@CLASS@:hover div.P@CLASS@ {display:block;position:absolute;z-index:1001; @POPUP@} span.L@CLASS@ {@ASPECT@} div.P@CLASS@ {display:none;} "; if ($t['css']!='') $css=$t['css']; $css=$css.$t['add']."\n"; reset($t); while(list($k,$v) = each($t)) { if (preg_match('/^add/',$k) > 0) $css=$css.$v."\n"; } $class="tttg".trim($t['class']); $css=str_replace("@CLASS@",$class,$css); $css=str_replace("@ASPECT@",$t['aspect'],$css); $css=str_replace("@HOVER@",$t['hover'],$css); $css=str_replace("@POPUP@",$t['popup'],$css); $HTMLStylesFmt[$class]=$css; }; # # create a tooltip of a given class # # [|classname instance-params||text||popup|] # classname is optional, if not defined, the instance belongs to the default (noname=tttg) class. # instance-params is optional. Follows the semantics of (:include :) markup, but restictted to three keys: # aspect='css code' to change/refine the aspect of the text of that instance # popup='css code' to change/refine the aspect of the popup of that instance # absolute=0/1. Defaults to 0 for relative positioning of the tooltip. # set to 1 (not 0) for absolute positioning, # Markup("CSSTTTG", "_begin", "/\\[\\|(.*?)\\|\\|(.*?)\\|\\|(.*?)\\|\\]/se", "Keep(CSSToolTipsToGo('$1',PSS('$2'),PSS('$3')))"); # # # # Generate html tags from markup : [|classname||text||tooltip|] # the html struct is: # <span> // markup span, class=classname , position=relative/ optionally absolute in if absolute=1 specified in local 'aspect' css param. # <span> // text span, class=Lclassname, on hover changes span.div display to block, and position=absolute (relative to markup span) to show the popup. Each instance optionally modeled by local 'aspect' css param. # text // text area where hover occurs # </span> # <div> // tooltip div, class=Pclassname, display=none invisible. Each instance optionally modeled by local 'popup' css param. # tooltip // popup/tooltip contents # </div> # </span> # # function CSSToolTipsToGo($class='' , $text='', $tool='') { global $pagename; $defaults = array('class'=>'' , 'aspect'=>'', 'popup'=>'' , 'absolute'=>'0'); $t = array_merge($defaults, ParseArgs($class)); $textcss=$t['aspect']; $popupcss=$t['popup']; $classname=trim($t['class']); if ($classname=='') $classname=trim($t[''][0]); $classname="tttg".$classname; $htext=MarkupToHTML($pagename,$text); # elimina <p> </p> que engloben l'html $htext=preg_replace('/^<p>/','',$htext); $htext=preg_replace('/<\/p>$/','',$htext); $htool=MarkupToHTML($pagename,$tool); if ($textcss!='') $textcss="style=\"".$textcss."\""; if ($popupcss!='') $popupcss="style=\"".$popupcss."\""; $absolutepos= ($t['absolute']!='0') ? 'style=position:static;' : ''; $out="<span class=\"".$classname."\" ".$absolutepos."><span class=\"L".$classname."\" ".$textcss." >".$htext."</span><div class=\"P".$classname."\" ".$popupcss." >".$htool."</div></span>"; return $out; }; # # define default class with basic hide/show semantics # you can override those minimal settings by calling (:tooltips params:) without a class param # CSSToolTipsToGoDefine(''); # #