Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Ben C on Mar 06, 2009 10:57
open dhtmlx forum
ToolBar Button Image Change when Clicked

Ok, now I'm gettin fancy. How do I make a toolbar button's image change when the button is clicked (mousedown)? and then change back when released (mouseup)?
Answer posted by Alex (support) on Mar 09, 2009 05:19

In case of using two-state buttons it is possible to define both images. 

For example if you intialize toolbar from the xml. The "mousedown" image is set by imgdis attribute: 

...

<item id="btn_1" type="button" img="some.gif" imgdis="some_dis.gif" title="Some text"/>

...

Answer posted by Ben C on Mar 09, 2009 07:30
That doesn't work because this is not a two-state button.  That does change the image when I disable the button via myToolbar.disableItem("btn0").  However, the image does not change when mousedown on that image.  I've tried dhtmlxEvent(buttonElem, "mousedown", fnThatSetsButtonImg); but that doesn't seem to work either.  Basically, if I could figure out a way to throw a onMouseDown event onto the button, I could take care of it.  Does the button element in the toolbar support onMouseDown in any way?



Answer posted by Alex (support) on Mar 09, 2009 08:07

There is setItemImage(itemId, url) method which allows to change item image. 

Just for example:

toolbar.attachEvent("onClick",function(id){

toolbar.setItemImage(id,new_path);

})




Answer posted on Mar 09, 2009 08:53
You haven't answered my question.  toolbar.attachEvent("onClick"... is not what I'm looking for.  The onClick event fires after mouse button is released.  I want an event when mousebutton is pressed (fire event before release).


Answer posted by Alex (support) on Mar 09, 2009 09:27

Unfortunately, a simple button doesn't provide any other event handler.

Two-state buttons have both onBeforeStateChange and onStateChange events.