From: Thierry Parmentelat Date: Wed, 30 Mar 2011 17:41:59 +0000 (+0200) Subject: minor fixes for the toggle building block - arrows should be right, X-Git-Tag: plewww-4.3-64~15 X-Git-Url: http://git.onelab.eu/?p=plewww.git;a=commitdiff_plain;h=317faed8b1987a72c22b5b8611cd395a9988bc03 minor fixes for the toggle building block - arrows should be right, and status from storage used only if 'visible' is not set or NULL --- diff --git a/plekit/php/toggle.php b/plekit/php/toggle.php index ee0dc0c..d43cc78 100644 --- a/plekit/php/toggle.php +++ b/plekit/php/toggle.php @@ -41,9 +41,13 @@ 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; @@ -67,8 +71,9 @@ 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(); + // 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; } @@ -78,9 +83,9 @@ class PlekitToggle { $html .= ""; return $html; } @@ -111,14 +116,14 @@ class PlekitToggle { $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 .= ""; if (array_key_exists ('info-text',$this->options)) { $id=$this->id; - $html .= "close info"; + $html .= "close info"; } return $html; } @@ -144,7 +149,7 @@ class PlekitToggle { // tmp $html .= "
"; $html .= $this->options['info-text']; - $html .= "toggle info"; + $html .= "toggle info"; $html .= "
"; return $html; } diff --git a/plekit/toggle/toggle.js b/plekit/toggle/toggle.js index 8ac69af..8c2cb1c 100644 --- a/plekit/toggle/toggle.js +++ b/plekit/toggle/toggle.js @@ -1,24 +1,25 @@ ////////// 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(); @@ -31,17 +32,17 @@ function plekit_toggle(id){ 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); @@ -52,7 +53,7 @@ function plekit_toggle_info(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(); } }