var droppedelem = "empty" ; var removed = [] ; addProduct = function(event, ui ) { var id = ui.draggable.attr('rel') ; _uri = window.location.protocol + '//' + window.location.host ; $('#cart_drop').load(_uri + '/' + 'ajax', { "action" : "add", "id" : id }) ; } removeAll = function() { _uri = window.location.protocol + '//' + window.location.host ; $('#cart_drop').load(_uri + '/' + 'ajax', { "action" : "clear" }) ; } $(document).ready( function() { $('.dragable').draggable( { "helper" : "clone", "opacity" : .65 }); $("#cart_drop").droppable( { "accept" : ".dragable", "tolerance" : "touch", "activeClass" : "droppable-active", "hoverClass" : "droppable-hover", "drop" : addProduct }); setCart(); }) ; removeProduct = function(event, ui ) { var id = ui.draggable.attr('rel') ; if ($.inArray(id, removed) == -1) { removed.push(id) ; _uri = window.location.protocol + '//' + window.location.host ; $.post(_uri + '/' + 'ajax', { "action" : "remove", "id" : id }, function(data) { $("#cart_drop").html(data) ; if (window.location.pathname == "/cart") window.location = _uri + window.location.pathname ; }, 'text') ; } } setCart = function() { $('.cart_item').draggable( {"helper" : "clone", "opacity" : .65 }) ; $('.remove_product').droppable( {"accept" : ".cart_item", "tolerance" : "touch", "activeClass" : "droppable-active", "hoverClass" : "droppable-hover", "drop" : removeProduct }) ; removed = [] ; }