Based on Raphael demo: http://raphaeljs.com/australia.html I have created objects that changes their colour. But I need to add action onclick will change it colour (to orange). And then it will stay orange until it will be clicked again.
I want those objects to show selected state (by having different colour). If you click on object it changes colour. If you click again it goes back to normal. And again If you click it changes colour and shows that is selected.
This is part of my code:
var current = null;
for (var state in bodyParts) {
bodyParts[state].color = Raphael.getColor();
(function (st, state) {
st[0].style.cursor = "pointer";
st[0].onmouseover = function () {
current && bodyParts[current].animate({ fill: "#EEC7C3", stroke: "#E0B6B2" }, 500) && (document.getElementById(current).style.display = "");
st.animate({ fill: st.color, stroke: "#ccc" }, 500);
st.toFront();
R.safari();
document.getElementById(state).style.display = "block";
current = state;
};
st[0].onmouseout = function () {
st.animate({ fill: "#EEC7C3", stroke: "#E0B6B2" }, 500);
st.toFront();
R.safari();
};
st[0].onclick = function () {
st.animate({ fill: "#C05219", stroke: "#E0B6B2" }, 500);
st.toFront();
R.safari();
};
})(bodyParts[state], state);
Onclick it changes colour but after I take mouse out from object it comes back to normal and is not selected. How can I add this 'selected' behavior to this code?