New Icon_Action for hidding or showing a DIV

This commit is contained in:
sparkyx 2022-10-16 23:10:31 +02:00
parent 50dcb029ff
commit b382455dd0
3 changed files with 38 additions and 5 deletions

View file

@ -369,22 +369,34 @@ function format_date(p_object)
*@brief check if the object is hidden or show and perform the opposite, *@brief check if the object is hidden or show and perform the opposite,
* show the hidden obj or hide the shown one * show the hidden obj or hide the shown one
*@param name of the object *@param name of the object
* @param button id of the button
* @param rotate : if true with rotate the object of p_button otherwise
*/ */
function toggleHideShow(p_obj, p_button) function toggleHideShow(p_obj, p_button,rotate)
{ {
var stat = g(p_obj).style.display; var stat = g(p_obj).style.display;
var str = g(p_button).value; var str = g(p_button).value??"";
if (stat === 'none') if (stat === 'none')
{ {
show(p_obj); $(p_obj).show()
str = str.replace(/Afficher/, content[62]); str = str.replace(/Afficher/, content[62]);
g(p_button).value = str; g(p_button).value = str;
} else } else
{ {
hide(p_obj); $(p_obj).hide();
str = str.replace(/Cacher/, content[63]); str = str.replace(/Cacher/, content[63]);
g(p_button).value = str; g(p_button).value = str;
} }
if ( ! rotate ) return;
if ( stat == "none") {
g(p_button).addClassName ("icon-up-open-1")
g(p_button).removeClassName(" icon-down-open-2")
} else {
g(p_button).removeClassName("icon-up-open-1")
g(p_button).addClassName(" icon-down-open-2")
}
} }
/** /**
*@brief open popup with the search windows *@brief open popup with the search windows

View file

@ -471,4 +471,19 @@ class Icon_Action
$r='<span id="'.uniqid().'" class="smallicon icon" style="background-color:yellow" onclick="document.getElementById(\''.$p_domid.'\').show()">&#xf0f6;</span>'; $r='<span id="'.uniqid().'" class="smallicon icon" style="background-color:yellow" onclick="document.getElementById(\''.$p_domid.'\').show()">&#xf0f6;</span>';
return $r; return $r;
} }
/**
* @brief hide or display an element, to be used for an accordon
* @param $p_id ip of the icon
* @param $p_id_to_hide element to hide or show
* @return HTML string
*/
static function toggle_hide($p_id,$p_id_to_hide)
{
$javascript=sprintf("toggleHideShow('%s','%s',true)",$p_id_to_hide,$p_id);
$r=sprintf('<i id="%s" onclick="%s" class="smallicon icon icon-down-open-2" style="margin-left:5px"></i>',
$p_id,$javascript
);
return $r;
}
} }

View file

@ -111,4 +111,10 @@ include_once NOALYSS_INCLUDE."/lib/icon_action.class.php";
<p> <p>
Increase INPUT TEXT Element Increase INPUT TEXT Element
<input type="text" id="text_element" size="20"><?php echo Icon_Action::longer("text_element",50)?> <input type="text" id="text_element" size="20"><?php echo Icon_Action::longer("text_element",50)?>
</p> </p>
<p>
<?php echo \Icon_Action::toggle_hide(uniqid(),"example_div")?>
<div id="example_div" style="display:none">
Ceci est caché
</div>
</div>