Created
July 3, 2011 05:34
-
-
Save rafarubert/1061978 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
var _new_li = new String(); | |
var _element = new Object(); | |
$( "#draggable > li" ).draggable({ revert: true }); | |
$( "#droppable").droppable({ | |
accept: "#draggable > li", | |
drop: function(event, ui){ | |
console.log(ui); | |
_new_li = $('<li>'+ui.draggable.context.innerHTML+'<input name="campaign[employee_ids][]" type="hidden" value="'+ui.draggable.context.id+'" /> <span><img src="/assets/cancel.jpg" alt="Remover" title="Remover"></span></li>') | |
.attr('id', ui.draggable.context.id); | |
$('#droppable').append(_new_li); | |
$(ui.draggable).remove(); | |
} | |
}); | |
$("#droppable > li > span").live("click", function(event){ | |
var _element = $(this).parent(); | |
_element.children().remove(); | |
_new_li = $("<li>"+_element.text()+"</li>").attr('id', _element.attr('id')).attr('class', 'draggable'); | |
_new_li.draggable({ revert: true }); | |
$("#draggable").append(_new_li); | |
_element.remove(); | |
}); | |
}); |
I don't want to need initialialize again the variables
But you overwrite the values of _new_li
on lines 10 and 24, and of _element
on line 20. The String and Object are thrown away there. And I don't see any need for the variables to be actually instatiated in other places.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any reason for initializing
_new_li
and_element
?