clearing xml object or traversing fix needed
The code below works fine except the xml code returned by 'data' doesn't seem to reset itself with clicks on new lines. If I alert out the value of "snip_content" it DOES change with new clicks, but the inserted text in the insertAtCaret() function does not change...it always shows the first value of snip_content from the first click. It feels to me kinda like the xlm is being appended or somewhere else a var is not being reset. I've tried resetting with every function and re assignment I can think of to no avail. Help greatly appreciated.
$(".snips"). //find snips
click(
function() {
$('.snip_tip').empty(); //clear out existing snip tips
var my_snip = $(this); //identify the snip clicked on
var my_id = parseInt($(this).text()); //extract the snip_id from the text
$(".snips").css("background-color","white"); //reset highlighting to white
$(my_snip).css({"background-color":"lightgreen"}); //highlight the snip we're describing
$.post("index.php?action=snip_service", {"id" : my_id}, function(data) { //ajax call to snip service
$(data).find('snip').each(function() { //xml dom find your snip
var description = $(this).find('description').text(); //find the description attribute
var snip_content = $(this).find('text').text(); //get the snip_text content
var html = '<span class="snip_tip"> - ' + description + '</span>'; //make the text
$(my_snip).append(html); //add html snippet to end of snip line
//make snip draggable/droppable
$(my_snip).draggable({
helper : "clone"
});
$("#letter_body").droppable({
accept : ".snips",
drop : function(ev,ui) {
$(this).insertAtCaret(snip_content); //call insert function to put snip content in at cursor
}
});
});
}, "xml");
}
);
[code][/code]