+
+ show_solutions: ->
+ @reset()
+ $(".question", @element).each (i, question) =>
+ @solve_question question
+
+ # Parses a list of values, separated by space or comma.
+ # The list is read from data attribute of elem using data_key
+ # Returns a list with elements
+ # eg.: things_i_need: "house bike tv playstation"
+ # yields ["house", "bike", "tv", "playstation"]
+ # If optional numbers argument is true, returns list of numbers
+ # instead of strings
+ get_value_list: (elem, data_key, numbers) ->
+ vl = $(elem).attr("data-" + data_key).split(/[ ,]+/).map($.trim) #.map((x) -> parseInt(x))
+ if numbers
+ vl = vl.map((x) -> parseInt(x))
+ return vl
+
+ # Parses a list of values, separated by space or comma.
+ # The list is read from data attribute of elem using data_key
+ # Returns a 2-element list with mandatory and optional
+ # items. optional items are marked with a question mark on the end
+ # eg.: things_i_need: "house bike tv? playstation?"
+ # yields [[ "house", "bike"], ["tv", "playstation"]]
+ get_value_optional_list: (elem, data_key) ->
+ vals = @get_value_list(elem, data_key)
+ mandat = []
+ opt = []
+ for v in vals
+ if v.slice(-1) == "?"
+ opt.push v.slice(0, -1)
+ else
+ mandat.push v
+ return [mandat, opt]
+
+ show_score: (score) ->
+ $(".message", @element).text("Wynik: #{score[0]} / #{score[1]}")
+
+
+ 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()
+
+
+ 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'
+
+
+
+class Wybor extends Excercise
+ constructor: (element) ->
+ super element
+
+