Never come across this before can anyone give me any pointers?
I'm creating a web app for making notes like post it notes onto a whiteboard. At the moment the spawn button will spawn notes but I want to make it so that the user can click anywhere on the canvas (whiteboard) and it will spawn a new note at that position.
Here is the code for that: -
$("#canvas").bind('click', function(e){
// Calculate offset for width, put box to the left top corner of the mouse click.
var x = e.pageX + "px";
var y = e.pageY + "px";
$("#note").clone().insertBefore("#insertAfter").attr("id", "note" + noteID).show();
$("#note" + noteID).children(".title").text("Note " + noteID);
$("#note" + noteID).css({left:x, top:y, "z-index" : zindex});
noteID++;
zindex++;
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
});
The problem arises when the user clicks on one of the notes, because the notes are cloned into the canvas each time the user clicks on the note its creating another note. I want to stop this behaviour and ONLY create a note when a user clicks on a blank canvas area. I have tried preventDefauly, stopPropagation and stopImmediate... but none of them seem to have any influence.
I have also tried them on other actions such as the note click but just can't seem to get the right one in the right place? or am I going about this completely the wrong way?
example here:
http://www.kryptonite-dove.com/sandbox/animate
UPDATE:
$('#canvas').on('click', '.note', function(e) {
e.stopPropagation();
});
This solved the problem of the notes bubbling up however it now prevents any click actions on the note class, I'm in uncharted waters here! would appreciate any pointers on how to get the click actions back working for the note title and text :)