+ Exercise.prototype.draggable_move = function($draggable, $placeholder, ismultiple) {
+ var $added,
+ _this = this;
+ $added = $draggable.clone();
+ $added.data("original", $draggable.get(0));
+ if (!ismultiple) {
+ $draggable.addClass('disabled').draggable('disable');
+ }
+ $placeholder.after($added);
+ if (!$placeholder.hasClass('multiple')) {
+ $placeholder.hide();
+ }
+ if ($added.is(".add-li")) {
+ $added.wrap("<li/>");
+ }
+ $added.append('<span class="remove">x</span><div class="clr"></div>');
+ return $('.remove', $added).click(function(ev) {
+ _this.retry();
+ if (!ismultiple) {
+ $($added.data('original')).removeClass('disabled').draggable('enable');
+ }
+ if ($added.is(".add-li")) {
+ $added = $added.closest('li');
+ }
+ $added.prev(".placeholder:not(.multiple)").show();
+ return $added.remove();
+ });
+ };
+
+ Exercise.prototype.dragging = function(ismultiple, issortable) {
+ var _this = this;
+ return $(".question", this.element).each(function(i, question) {
+ var draggable_opts, self;
+ draggable_opts = {
+ revert: 'invalid',
+ helper: 'clone',
+ start: _this.retry
+ };
+ $(".draggable", question).draggable(draggable_opts);
+ self = _this;
+ return $(".placeholder", question).droppable({
+ accept: function(draggable) {
+ var $draggable, is_accepted;
+ $draggable = $(draggable);
+ is_accepted = true;
+ if (!$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: function(ev, ui) {
+ $(ev.target).removeClass('accepting dragover');
+ return _this.draggable_move($(ui.draggable), $(ev.target), ismultiple);
+ },
+ over: function(ev, ui) {
+ return $(ev.target).addClass('dragover');
+ },
+ out: function(ev, ui) {
+ return $(ev.target).removeClass('dragover');
+ }
+ });
+ });
+ };
+
+ return Exercise;