X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plekit%2Fphp%2Ftoggle.php;h=ee0dc0cc49d243d4e85fbc3586eb80f4f5da583f;hb=7d4971597397caa302b9caf5d38c016139ab5b00;hp=aac3c9d206f31d7b6ca16aac85dae87560452f01;hpb=f99cfc8401815836073effa34c5cda024e77a3a9;p=plewww.git diff --git a/plekit/php/toggle.php b/plekit/php/toggle.php index aac3c9d..ee0dc0c 100644 --- a/plekit/php/toggle.php +++ b/plekit/php/toggle.php @@ -1,12 +1,11 @@ - '); @@ -21,28 +20,33 @@ drupal_set_html_head(' // (*) trigger: the html text for the trigger // (*) options: a hash that can define // - trigger-tagname : to be used instead of for wrapping the trigger -// - trigger-bubble : might not work if trigger-tagname is redefined -// - init-hidden : start hidden rather than visible +// - bubble : might not work if trigger-tagname is redefined +// - 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 // (*) image_html (): returns the html code for the image -// (*) area_start (): because we have too many places where php 'prints' code instead +// (*) area_start (): because we have too many places where php 'prints' code: instead // (*) area_end(): of returning it, we do not expect the code for the area to be passed // so these methods can be used to delimit the area in question class PlekitToggle { // mandatory var $id; + var $nifty; function PlekitToggle ($id,$trigger,$options=NULL) { $this->id = $id; $this->trigger=$trigger; if ( ! $options ) $options = array(); - if (array_key_exists ('start-visible',$options)) { - $options['start-hidden'] = ! $options['start-visible']; - unset ($options['start-visible']); + 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; } @@ -54,6 +58,7 @@ class PlekitToggle { $html .= $this->container_start(); $html .= $this->trigger_html(); $html .= $this->area_start_html(); + $html .= $this->info_html(); return $html; } @@ -62,9 +67,23 @@ class PlekitToggle { $html = ""; $html .= $this->area_end_html(); $html .= $this->container_end(); + // turn or or off from local storage + $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 () { @@ -84,20 +103,52 @@ class PlekitToggle { function trigger_html () { $trigger_id=$this->id_name('trigger'); if (array_key_exists ('trigger-tagname',$this->options)) $tagname=$this->options['trigger-tagname']; - if (array_key_exists ('trigger-bubble',$this->options)) $bubble=$this->options['trigger-bubble']; if (empty($tagname)) $tagname="span"; + $bubble=""; + if (array_key_exists ('bubble',$this->options)) $bubble=$this->options['bubble']; $html="<$tagname"; $html .= " id='$trigger_id'"; $html .= " class='plc-toggle-trigger'"; if ($bubble) $html .= " title='$bubble'"; - $html .= " onclick=\"plc_toggle('$this->id')\""; + $html .= " onclick=\"plekit_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 () { @@ -120,19 +171,12 @@ class PlekitToggle { function container_start () { print $this->container_start_html(); } function container_start_html () { $id=$this->id_name('container'); - - // side-effects on the header - $nifty_init = ""; - drupal_set_html_head($nifty_init); - - $html="
nifty=new PlekitNifty ($id,'plc-toggle-container','medium'); + return $this->nifty->start_html(); } function container_end () { print $this->container_end_html(); } - function container_end_html () { return "
"; } + function container_end_html () { return $this->nifty->end_html(); } // build id names function id_name ($zonename) { return "toggle-$zonename-$this->id"; }