X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plekit%2Fphp%2Ftoggle.php;h=d43cc785b61590943035f0add410264c6dd73929;hb=317faed8b1987a72c22b5b8611cd395a9988bc03;hp=acc9fe5bdd37c9253e01486345ce90b5535c8271;hpb=232e3e3ce1e8f07de912ba0d5302b03bfe71f283;p=plewww.git diff --git a/plekit/php/toggle.php b/plekit/php/toggle.php index acc9fe5..d43cc78 100644 --- a/plekit/php/toggle.php +++ b/plekit/php/toggle.php @@ -1,8 +1,7 @@ for wrapping the trigger // - bubble : might not work if trigger-tagname is redefined -// - init-hidden : start hidden rather than visible +// - visible : if set to false, start hidden rather than visible +// - info-text : the text for help on the tab +// - info-visible : whether info needs to be visible at startup // // methods are as follows // (*) trigger_html (): return the html code for the trigger @@ -40,10 +41,15 @@ class PlekitToggle { $this->id = $id; $this->trigger=$trigger; if ( ! $options ) $options = array(); + // 'visible' may be set or not; if set to NULL it's considered as undefined + // so using NULL as the default means 'select from local storage i.e. last status' + if (array_key_exists ('visible',$options) && $options['visible']==NULL) + unset ($options['visible']); + // start-hidden is internal and is always set if (array_key_exists ('visible',$options)) { $options['start-hidden'] = ! $options['visible']; - unset ($options['visible']); } + if (!isset ($options['start-hidden'])) $options['start-hidden']=false; $this->options = $options; } @@ -56,6 +62,7 @@ class PlekitToggle { $html .= $this->container_start(); $html .= $this->trigger_html(); $html .= $this->area_start_html(); + $html .= $this->info_html(); return $html; } @@ -64,9 +71,24 @@ class PlekitToggle { $html = ""; $html .= $this->area_end_html(); $html .= $this->container_end(); + // if 'visible' is not set, set or or off from local storage + if ( ! array_key_exists('visible',$this->options) ) + $html .= $this->visible_from_store_html(); return $html; } + function visible_from_store_html() { + $id=$this->id; + $html = ""; + $html .= ""; + return $html; + } // create two images that get shown/hidden - could not find a better way to do it function image_html () { @@ -94,14 +116,45 @@ class PlekitToggle { $html .= " id='$trigger_id'"; $html .= " class='plc-toggle-trigger'"; if ($bubble) $html .= " title='$bubble'"; - $html .= " onclick=\"plc_toggle('$this->id')\""; + $html .= " onclick=\"pletoggle_toggle('$this->id')\""; $html .= ">"; $html .= $this->image_html(); $html .= $this->trigger; $html .= ""; + if (array_key_exists ('info-text',$this->options)) { + $id=$this->id; + $html .= "close info"; + } return $html; } + function info() { print $this->info_html();} + function info_html () { + if (! array_key_exists ('info-text',$this->options)) return ""; + + // compute if info should be visible at startup + // xxx in fact the default should be fetched in the browser storage xxx + $info_visible=TRUE; + // if info-visible is set, use this value + if (array_key_exists ('info-visible',$this->options)) + $info_visible=$this->options['info-visible']; + + $id=$this->id; + $div_id=$this->id_name('info'); + $html=""; + $html .= "
options['info-text']; + $html .= "toggle info"; + $html .= "
"; + return $html; + } + + function area_start () { print $this->area_start_html(); } function area_start_html () { $area_id=$this->id_name('area');