>id=divisionname<< text can be hidden/shown >><< Necessary parameters: (:toggle id=divname:) Alternative: (:toggle divname:) Alternative with options: (:toggle hide divname:) initial hide (:toggle hide divname button:) initial hide, button (:toggle name1 name2:) toggle between name1 and name2 Optional parameters: init=hide hides the division initially (default is show) show=labelname label of link or button when div is hidden (default is Show) hide=labelname label of link or button when div is shown (default is Hide) label=labelname label of link or button for both toggle states id2=objname second object (div), for toggling betwen first and second object set=1 sets a cookie to remember toggle state */ # Version date $RecipeInfo['Toggle']['Version'] = '2015-12-23'; # SteP's interim bug fix # declare $Toggle for (:if enabled $Toggle:) recipe installation check global $Toggle; $Toggle = 1; Markup_e('toggle', 'directives', '/\\(:toggle\\s*(.*?):\\)/i', "ToggleMarkup(\$pagename, \$m[1])"); # all in one function function ToggleMarkup($pagename, $opt) { # javascript for toggling and cookie setting global $HTMLFooterFmt, $HTMLStylesFmt, $ToggleConfig, $ToggleLinks, $UploadUrlFmt, $UploadPrefixFmt; SDVA($ToggleConfig, array( 'init' => 'show', //show div 'show' => XL("Show"), //link text 'Show' 'hide' => XL("Hide"), //link text 'Hide' 'ttshow' => XL("Show"), //tooltip text 'Show' 'tthide' => XL("Hide"), //tooltip text 'Hide' 'id' => '', //no default div name 'id2' => '', //no default div2 name 'set' => false, //set no cookie to remember toggle state 'printhidden' => true, // hidden divs get printed 'nojs' => false, //in no jsbrowser links are not shown, initial hidden divs are shown )); $HTMLStylesFmt['toggle'] = " @media print{.toggle{display:none;}} .toggle img{border:none;} "; $HTMLFooterFmt['toggleobj'] = " "; $opt = ParseArgs($opt); if ($opt['group'] && $opt['init']!='show') $opt['init'] = 'hide'; //get parameters without keys if(is_array($opt[''])) { while (count($opt['']) > 0) { $par = array_shift($opt['']); if($par == 'button') $opt['button'] = 1; elseif($par == 'hide') $opt['init'] = 'hide'; elseif($par == 'show') $opt['init'] = 'show'; elseif(!isset($opt['id'])) $opt['id'] = $par; elseif(!isset($opt['id2'])) $opt['id2'] = $par; } } $opt = array_merge($ToggleConfig, $opt); $id = (isset($opt['div'])) ? $opt['div'] : $opt['id']; $id2 = (isset($opt['div2'])) ? $opt['div2'] : $opt['id2']; if ($id == '') return "//!Error:// no object id specified!"; $ts = array(); if(isset($opt['label'])) $ts['show'] = $ts['hide'] = $opt['label']; else { $ts['show'] = (isset($opt['lshow'])) ? $opt['lshow'] : $opt['show']; $ts['hide'] = (isset($opt['lhide'])) ? $opt['lhide'] : $opt['hide']; } $ipat = "/\.png|\.gif|\.jpg|\.jpeg|\.ico/"; foreach($ts as $k => $val) { //check for image, make image tag if(preg_match($ipat, $val)) { $prefix = (strstr($val, '/')) ? '/' : $UploadPrefixFmt; $path = FmtPageName($UploadUrlFmt.$prefix, $pagename); $ts[$k] = ""; $opt['button'] = ''; } //apostrophe encoding else $ts[$k] = str_replace("'","’",$val); } $show = $ts['show']; $hide = $ts['hide']; $tog = $opt['init']; //check cookie if set=1 if($opt['set'] == 1) { global $CookiePrefix, $SkinName; $cook = $CookiePrefix.$SkinName.'_toggle_'.$id; if (isset($_COOKIE[$cook])) $tog = $_COOKIE[$cook]; } //toggle state if($tog == 'show') { $style = 'block'; $altstyle = 'none'; $label = $hide; $tooltip = $opt['tthide']; $tog = 'hide'; } else { $style = 'none'; $altstyle = 'block'; $label = $show; $tooltip = $opt['ttshow']; $tog = 'show'; } //set initial toggle link or button (later it is build with javascript) $act = "javascript:toggleObj('{$id}','{$tog}','{$show}','{$hide}','{$opt['ttshow']}','{$opt['tthide']}','{$id2}','{$opt['set']}','{$cook}','{$opt['button']}','{$opt['group']}')"; $out = ""; if ($opt['button']==1) { $out .= ''; if ($opt['nojs']>=1) $out .= ''; } else { $out .= ' '; if ($opt['nojs']>=1) $out .= ''; } $out .= ""; $HTMLFooterFmt[] = ""; if ($style=='none') if ($id2 || $opt['nojs']>1) $HTMLStylesFmt[] = " #$id {display:none;}"; if ($opt['printhidden']==1) $HTMLStylesFmt[] = " @media print{ #{$id}{ display:block; } } "; if ($id2) { $HTMLStylesFmt[] = " #{$id2}{display:{$altstyle};} "; $HTMLFooterFmt[] = ""; if ($opt['printhidden'] == 1) $HTMLStylesFmt[] = " @media print { #{$id2}{ display:block; } } "; } return Keep($out); } #EOF