I would like to over ride the function associated with an elements onclick event when the screen is in "edit" mode. Then when done editing put the original function back.
So, originally I have the following:
<script type="text/javascript">
var showAddNewForum = function(){
dojo.byId("NewForum").className = dojo.byId("NewForum").className == 'hidden'?'':'hidden';
}
</script>
<a onclick="showAddNewForum()" class="editable" id="AddNewForum" name="AddNewForum" style="cursor:pointer;">New Forum</a>
<div class="hidden" id="NewForum" name="NewForum">
<form action="">
<table>
<tr><td><label>Title</label></td><td><input type="text" id="newForumTitle"/></td></tr>
<tr><td><label>Description</label></td><td><input type="text" id="newForumDescription"/></td></tr>
<tr><td><label>Moderators</label></td><td><input type="text" id="newForumnModerators"/></td></tr>
</table>
<input type="button" value="submit"/>
</form>
</div>
At the top of the page there is an Admin button that will put the page in configuration mode. All elements with a class of editable will be in configuration mode so the element can be configure through a little form. The idea is certain controls on the screen will have different behavior based on a users role. example: If administrator show it other wise do not display the control.
This is done with the following:
activateAdministration = function() {
if (editOnClickHandle.length>0) {
dojo.forEach(editOnClickHandle,function(item){dojo.disconnect(item)});
editOnClickHandle = [];
}else {
dojo.query(".editable").forEach(function(node,idx,arr){
var handler = dojo.connect(node,"onclick",function(e){
console.debug(node.onclick);
var adminWindow = document.getElementById("adminWindow");
adminWindow.className = "displayInline";
adminWindow.style.top = (e.layerY + 0) + "px";
adminWindow.style.left = (e.layerX + 0) + "px";
document.getElementById("adminElementId").value = node.id;
document.getElementById("adminCurrentUrl").value = location.href;
document.getElementById("adminClass").value = node.className;
});
editOnClickHandle.push(handler);
});
}
}
<a class="tool" style="cursor:pointer;" onclick="activateAdministration();">Admin</a>
So the problem is the original onclick function is still attached to the event. If it were a submit function or something like that then it would also fire which is not desired.
Can I set a handler to the original function, dissconnect it, add the new function, and then when done editing remove the new function and add the original one back?
Thanks for any tips, I hope the question is clear (probably not) happy to add more info if needed.