id=$p_id;
$this->item=array();
$this->value=$value;
$this->cnt=0;
$this->default_value=-1;
$this->style_box="";
}
function input()
{
// Show when click
$javascript=sprintf('$("%s_bt").onclick=function() {
try {
var newDiv=$("select_box%s");
var pos=$("%s_bt").cumulativeOffset();
newDiv.setStyle({display:"block",position:"fixed",top:pos.top+25+"px",left:pos.left+5+"px"});
} catch(e) {
alert(e.message);
}
}
', $this->id, $this->id, $this->id, $this->id);
// Hide when out of the zone
$javascript.=sprintf('$("select_box%s").onmouseleave=function() {
try {
var newDiv=$("select_box%s");
newDiv.setStyle({display:"none"});
} catch(e) {
alert(e.message);
}
}',$this->id,$this->id);
// display the button
printf('',
$this->id, $this->value);
printf('', $this->id,
$this->id, $this->default_value);
printf('
',
$this->id, $this->style_box);
// Print the list of possible options
printf('
',$this->id);
for ($i=0; $iitem); $i++)
{
if ($this->item[$i]['type']=="url")
{
printf('- %s
', $this->item[$i]['url'],
$this->item[$i]['label']);
}
else // For javascript
if ($this->item[$i]['type']=="javascript")
{
printf('- %s
',
$this->item[$i]['javascript'], $this->item[$i]['label']);
}
else if ($this->item[$i]['type']=="value")
{
printf('- %s
',
$this->item[$i]['javascript'], $this->item[$i]['label']);
}
else if ($this->item[$i]['type']=="input") {
$ok=new IButton("ok");
$ok->value=$this->item[$i]['label'];
$ok->javascript=$this->item[$i]['input']->javascript;
printf('- %s %s
',
$this->item[$i]['input']->input(),
$ok->input()
);
}
}
echo "
";
echo "
";
// javascript : onclick on button
echo "";
}
function add_url($label, $url)
{
$this->item[$this->cnt]['label']=$label;
$this->item[$this->cnt]['url']=$url;
$this->item[$this->cnt]['type']="url";
$this->cnt++;
}
function add_javascript($label, $javascript)
{
$this->item[$this->cnt]['label']=$label;
$this->item[$this->cnt]['javascript']=$javascript.";$('select_box{$this->id}').hide()";
$this->item[$this->cnt]['type']="javascript";
$this->cnt++;
}
function add_value($label, $value)
{
$this->item[$this->cnt]['label']=$label;
$this->item[$this->cnt]['update']=$value;
$this->item[$this->cnt]['javascript']=sprintf(" $('%s').value='%s';$('%s_bt').value='%s';$('select_box%s').hide()",
$this->id, $value, $this->id, $label, $this->id);
$this->item[$this->cnt]['type']='value';
$this->cnt++;
}
function add_input($p_label,HtmlInput $p_element) {
/* $this->item[$this->cnt]['label']=$p_element->label;
$this->item[$this->cnt]['value']=$p_element->value;
$this->item[$this->cnt]['javascript']=$p_element->javascript;
*
*/
$this->item[$this->cnt]['label']=$p_label;
$this->item[$this->cnt]['input']=clone $p_element;
$this->item[$this->cnt]['type']='input';
$this->cnt++;
}
}