$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;
$html = "";
$html .= $this->area_end_html();
$html .= $this->container_end();
- // turn or or off from local storage
- $html .= $this->visible_from_store_html();
+ // 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;
}
$html .= "<script type='text/javascript'>";
// javascript code can't take -
// $idj=str_replace('-','_',$id);
- // $html .= "function init_$idj () { plekit_toggle_from_store('$id');}";
+ // $html .= "function init_$idj () { pletoggle_from_store('$id');}";
// $html .= "Event.observe(window,'load',init_$idj);";
- $html .= "plekit_toggle_from_store('$id');";
+ $html .= "pletoggle_from_store('$id');";
$html .= "</script>";
return $html;
}
$html .= " id='$trigger_id'";
$html .= " class='plc-toggle-trigger'";
if ($bubble) $html .= " title='$bubble'";
- $html .= " onclick=\"plekit_toggle('$this->id')\"";
+ $html .= " onclick=\"pletoggle_toggle('$this->id')\"";
$html .= ">";
$html .= $this->image_html();
$html .= $this->trigger;
$html .= "</$tagname>";
if (array_key_exists ('info-text',$this->options)) {
$id=$this->id;
- $html .= "<span class='toggle-info-button' onClick='plekit_toggle_info(\"$id\");'><img height=20 src='/planetlab/icons/info.png' alt='close info'/></span>";
+ $html .= "<span class='toggle-info-button' onClick='pletoggle_toggle_info(\"$id\");'><img height=20 src='/planetlab/icons/info.png' alt='close info'/></span>";
}
return $html;
}
// tmp
$html .= "<table class='center'><tr><td class='top'>";
$html .= $this->options['info-text'];
- $html .= "</td><td class='top'><span onClick='plekit_toggle_info(\"$id\");'><img height=20 class='reset' src='/planetlab/icons/close.png' alt='toggle info' /></span>";
+ $html .= "</td><td class='top'><span onClick='pletoggle_toggle_info(\"$id\");'><img height=20 class='reset' src='/planetlab/icons/close.png' alt='toggle info' /></span>";
$html .= "</td></tr></table></div>";
return $html;
}
////////// use jstorage to remember open/closed toggles
// store current status
-function plekit_toggle_store(id) {
+function pletoggle_store(id) {
var area=$('toggle-area-'+id);
key='toggle.'+id;
// window.console.log('storing toggle status for '+id);
$.jStorage.set(key,area.visible());
}
// restore last status
-function plekit_toggle_from_store (id) {
- var area=$('toggle-area-'+id);
+function pletoggle_from_store (id) {
key='toggle.'+id;
- // on by default
-// window.console.log('retrieving toggle status for '+id+'=>got '+$.jStorage.get(key,undefined));
- if ($.jStorage.get(key,true)) area.show();
- else area.hide();
+ // don't do anything if nothing stored
+ var stored=$.jStorage.get(key,undefined);
+ if (stored==true || stored==false) {
+ // window.console.log('retrieved toggle status for '+id+'=> '+stored);
+ pletoggle_set_visible(id,stored);
+ }
}
////////// manage a toggle
// toggle it
-function plekit_toggle(id){
+function pletoggle_toggle(id){
var area=$('toggle-area-'+id);
area.toggle();
visible.hide();
hidden.show();
}
- plekit_toggle_store(id);
+ pletoggle_store(id);
}
-// make sure it's open
-function plekit_toggle_show(id) {
+// make sure it's open or closed
+function pletoggle_set_visible(id, status) {
var area=$('toggle-area-'+id);
- if (!area.visible()) plekit_toggle (id);
+ if (area.visible()!=status) pletoggle_toggle (id);
}
// toggle the attached info box
-function plekit_toggle_info(id){
+function pletoggle_toggle_info(id){
// need to take care of the area as well
var area=$('toggle-area-'+id);
} else {
// make sure area is visible, take of the triggers
// window.console.log('PTI showing');
- plekit_toggle_show(id);
+ pletoggle_set_visible(id,true);
info.show();
}
}