+ draggable_equal: ($draggable1, $draggable2) ->
+ return false
+
+ draggable_accept: ($draggable, $droppable) ->
+ dropped = $droppable.closest("ul, ol").find(".draggable")
+ for d in dropped
+ if @draggable_equal $draggable, $(d)
+ return false
+ return true
+
+ draggable_dropped: ($draggable) ->
+ $draggable.append('<span class="close">x</span>')
+
+ dragging: (ismultiple, issortable) ->
+ $(".question", @element).each (i, question) =>
+ draggable_opts =
+ revert: 'invalid'
+ helper: 'clone'
+
+ $(".draggable", question).draggable(draggable_opts)
+ self = this
+ $(".placeholder", question).droppable
+ accept: (draggable) ->
+ $draggable = $(draggable)
+ if not $draggable.is(".draggable")
+ return false
+ return self.draggable_accept $draggable, $(this)
+
+ drop: (ev, ui) ->
+ added = $(ui.draggable).clone()
+ $added = added
+ $added.data("original", ui.draggable)
+ if not ismultiple
+ $(ui.draggable).addClass('disabled').draggable('disable')
+
+ $(ev.target).after(added)
+ if not $(ev.target).hasClass('multiple')
+ $(ev.target).hide()
+ $added.append('<span class="remove">x</span>')
+ $('.remove', added).click (ev) =>
+ $added.prev(".placeholder:not(.multiple)").show()
+ if not ismultiple
+ $added.data('original').removeClass('disabled').draggable('enable')
+ $(added).remove()
+
+
+
+# $(".droppable", question).each (i, droppable) =>
+# $droppable = $(droppable)
+# $droppable.droppable
+# accept: (draggable) =>
+# return false
+# $draggable = $(draggable)
+# if not $draggable.is(".draggable")
+# console.log('not draggable?')
+# return false
+
+# for added in $droppable.children(".draggable")
+# if @draggable_equal($(added), $draggable)
+# console.log('already here:' + $draggable.text())
+# return false
+
+# return @draggable_accept $draggable
+
+# drop: (ev, ui) =>
+# added = ui.draggable.clone()
+# # added.attr('style', '')
+# $(ev.target).append(added)
+# added.draggable(draggable_opts)
+# @draggable_dropped added
+
+# if not @multiple
+# $(ui.draggable).draggable("disable")
+
+
+ # if issortable
+ # $(".droppable", question).sortable
+ # items: "> li"
+
+ # receive: (event, ui) =>
+ # console.log("receive " + $(ui.item).text())
+ # if not accept(ui.item, event.target)
+ # console.log("REVERT")
+ # $(event.target).sortable('cancel')
+
+ # over: (event, ui) =>
+ # if not accept(ui.item, event.target)
+ # $(event.target).sortable('disable')
+ # out: (event, ui) =>
+ # $(event.target).sortable('enable')
+
+