+ 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_move: ($draggable, $placeholder, ismultiple) ->
+ $added = $draggable.clone()
+ $added.data("original", $draggable.get(0))
+ if not ismultiple
+ $draggable.addClass('disabled').draggable('disable')
+
+ $placeholder.after($added)
+ if not $placeholder.hasClass('multiple')
+ $placeholder.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()
+
+## XXX co z issortable?
+ 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)
+ is_accepted = true
+
+ if not $draggable.is(".draggable")
+ is_accepted = false
+
+ if is_accepted
+ is_accepted= self.draggable_accept $draggable, $(this)
+
+ if is_accepted
+ $(this).addClass 'accepting'
+ else
+ $(this).removeClass 'accepting'
+ return is_accepted
+
+ drop: (ev, ui) =>
+ $(ev.target).removeClass 'accepting dragover'
+
+ @draggable_move $(ui.draggable), $(ev.target), ismultiple
+
+ # $added = $(ui.draggable).clone()
+ # $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()
+
+ over: (ev, ui) ->
+ $(ev.target).addClass 'dragover'
+
+
+ out: (ev, ui) ->
+ $(ev.target).removeClass 'dragover'
+
+
+