2 var $, Binding, EduModule, Excercise, Luki, PrawdaFalsz, Przyporzadkuj, Uporzadkuj, Wybor, Zastap, excercise,
3 __hasProp = Object.prototype.hasOwnProperty,
4 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
8 Binding = (function() {
10 function Binding(handler, element) {
11 this.handler = handler;
12 this.element = element;
13 $(this.element).data(this.handler, this);
20 EduModule = (function(_super) {
22 __extends(EduModule, _super);
24 function EduModule(element) {
26 EduModule.__super__.constructor.call(this, 'edumodule', element);
27 $("[name=teacher-toggle]").change(function(ev) {
28 if ($(ev.target).is(":checked")) {
29 return $(".teacher", _this.element).addClass("show");
31 return $(".teacher", _this.element).removeClass("show");
40 Excercise = (function(_super) {
42 __extends(Excercise, _super);
44 function Excercise(element) {
46 Excercise.__super__.constructor.call(this, 'excercise', element);
47 $(".check", this.element).click(function() {
50 $('.solutions', this.element).click(function() {
51 return _this.show_solutions();
55 Excercise.prototype.piece_correct = function(qpiece) {
56 return $(qpiece).removeClass('incorrect').addClass('correct');
59 Excercise.prototype.piece_incorrect = function(qpiece) {
60 return $(qpiece).removeClass('correct').addClass('incorrect');
63 Excercise.prototype.check = function() {
67 $(".question", this.element).each(function(i, question) {
68 return scores.push(_this.check_question(question));
71 $.each(scores, function(i, s) {
73 return score[1] += s[1];
75 return this.show_score(score);
78 Excercise.prototype.get_value_list = function(elem, data_key, numbers) {
80 vl = $(elem).attr("data-" + data_key).split(/[ ,]+/).map($.trim);
82 vl = vl.map(function(x) {
89 Excercise.prototype.get_value_optional_list = function(elem, data_key) {
90 var mandat, opt, v, vals, _i, _len;
91 vals = this.get_value_list(elem, data_key);
94 for (_i = 0, _len = vals.length; _i < _len; _i++) {
96 if (v.slice(-1) === "?") {
97 opt.push(v.slice(0, -1));
102 return [mandat, opt];
105 Excercise.prototype.show_score = function(score) {
106 return $(".message", this.element).text("Wynik: " + score[0] + " / " + score[1]);
109 Excercise.prototype.draggable_equal = function($draggable1, $draggable2) {
113 Excercise.prototype.draggable_accept = function($draggable, $droppable) {
114 var d, dropped, _i, _len;
115 dropped = $droppable.closest("ul, ol").find(".draggable");
116 for (_i = 0, _len = dropped.length; _i < _len; _i++) {
118 if (this.draggable_equal($draggable, $(d))) return false;
123 Excercise.prototype.draggable_dropped = function($draggable) {
124 return $draggable.append('<span class="close">x</span>');
127 Excercise.prototype.dragging = function(ismultiple, issortable) {
129 return $(".question", this.element).each(function(i, question) {
130 var draggable_opts, self;
135 $(".draggable", question).draggable(draggable_opts);
137 return $(".placeholder", question).droppable({
138 accept: function(draggable) {
139 var $draggable, is_accepted;
140 $draggable = $(draggable);
142 if (!$draggable.is(".draggable")) is_accepted = false;
144 is_accepted = self.draggable_accept($draggable, $(this));
147 $(this).addClass('accepting');
149 $(this).removeClass('accepting');
153 drop: function(ev, ui) {
156 $(ev.target).removeClass('accepting');
157 added = $(ui.draggable).clone();
159 $added.data("original", ui.draggable);
161 $(ui.draggable).addClass('disabled').draggable('disable');
163 $(ev.target).after(added);
164 if (!$(ev.target).hasClass('multiple')) $(ev.target).hide();
165 $added.append('<span class="remove">x</span>');
166 return $('.remove', added).click(function(ev) {
167 $added.prev(".placeholder:not(.multiple)").show();
169 $added.data('original').removeClass('disabled').draggable('enable');
171 return $(added).remove();
174 over: function(ev, ui) {
175 return $(ev.target).addClass('dragover');
177 out: function(ev, ui) {
178 return $(ev.target).removeClass('dragover');
188 Wybor = (function(_super) {
190 __extends(Wybor, _super);
192 function Wybor(element) {
193 Wybor.__super__.constructor.call(this, element);
196 Wybor.prototype.check_question = function(question) {
197 var all, good, solution,
201 solution = this.get_value_list(question, 'solution');
202 $(".question-piece", question).each(function(i, qpiece) {
203 var is_checked, piece_name, piece_no, should_be_checked;
204 piece_no = $(qpiece).attr('data-no');
205 piece_name = $(qpiece).attr('data-name');
207 should_be_checked = solution.indexOf(piece_name) >= 0;
209 should_be_checked = solution.indexOf(piece_no) >= 0;
211 is_checked = $("input", qpiece).is(":checked");
212 if (should_be_checked) all += 1;
214 if (should_be_checked) {
216 return _this.piece_correct(qpiece);
218 return _this.piece_incorrect(qpiece);
221 return $(qpiece).removeClass("correct,incorrect");
227 Wybor.prototype.show_solutions = function() {};
233 Uporzadkuj = (function(_super) {
235 __extends(Uporzadkuj, _super);
237 function Uporzadkuj(element) {
238 Uporzadkuj.__super__.constructor.call(this, element);
239 $('ol, ul', this.element).sortable({
244 Uporzadkuj.prototype.check_question = function(question) {
245 var all, correct, pkt, pkts, positions, sorted, _ref;
246 positions = this.get_value_list(question, 'original', true);
247 sorted = positions.sort();
248 pkts = $('.question-piece', question);
251 for (pkt = 0, _ref = pkts.length; 0 <= _ref ? pkt < _ref : pkt > _ref; 0 <= _ref ? pkt++ : pkt--) {
253 if (pkts.eq(pkt).data('pos') === sorted[pkt]) {
255 this.piece_correct(pkts.eq(pkt));
257 this.piece_incorrect(pkts.eq(pkt));
260 return [correct, all];
267 Luki = (function(_super) {
269 __extends(Luki, _super);
271 function Luki(element) {
272 Luki.__super__.constructor.call(this, element);
273 this.dragging(false, false);
276 Luki.prototype.check = function() {
281 $(".placeholder + .question-piece", this.element).each(function(i, qpiece) {
283 $placeholder = $(qpiece).prev(".placeholder");
284 if ($placeholder.data('solution') === $(qpiece).data('no')) {
285 _this.piece_correct(qpiece);
288 _this.piece_incorrect(qpiece);
292 return this.show_score([correct, all]);
299 Zastap = (function(_super) {
301 __extends(Zastap, _super);
303 function Zastap(element) {
305 Zastap.__super__.constructor.call(this, element);
306 $(".paragraph", this.element).each(function(i, par) {
307 return _this.wrap_words($(par), $('<span class="placeholder zastap"/>'));
309 this.dragging(false, false);
312 Zastap.prototype.check = function() {
317 $(".paragraph", this.element).each(function(i, par) {
318 return $(".placeholder", par).each(function(j, qpiece) {
319 var $dragged, $qp, should_be_checked;
320 should_be_checked = false;
322 $dragged = $qp.next(".draggable");
323 if ($qp.data("solution")) {
324 if ($dragged && $qp.data("solution") === $dragged.data("no")) {
325 _this.piece_correct($dragged);
332 return this.show_score([correct, all]);
335 Zastap.prototype.wrap_words = function(element, wrapper) {
336 var chld, i, ignore, insertWrapped, j, len, space, wordb, _ref, _results;
337 ignore = /^[ \t.,:;()]+/;
338 insertWrapped = function(txt, elem) {
340 nw = wrapper.clone();
341 return $(document.createTextNode(txt)).wrap(nw).parent().attr("data-original", txt).insertBefore(elem);
344 for (j = _ref = element.get(0).childNodes.length - 1; _ref <= 0 ? j <= 0 : j >= 0; _ref <= 0 ? j++ : j--) {
345 chld = element.get(0).childNodes[j];
346 if (chld.nodeType === document.TEXT_NODE) {
347 len = chld.textContent.length;
351 space = ignore.exec(chld.textContent.substr(i));
354 insertWrapped(chld.textContent.substr(wordb, i - wordb), chld);
356 $(document.createTextNode(space[0])).insertBefore(chld);
357 i += space[0].length;
363 if (wordb < len - 1) {
364 insertWrapped(chld.textContent.substr(wordb, len - 1 - wordb), chld);
366 _results.push($(chld).remove());
368 _results.push(void 0);
378 Przyporzadkuj = (function(_super) {
380 __extends(Przyporzadkuj, _super);
382 Przyporzadkuj.prototype.is_multiple = function() {
383 var qp, _i, _len, _ref;
384 _ref = $(".question-piece", this.element);
385 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
387 if ($(qp).data('solution').split(/[ ,]+/).length > 1) return true;
392 function Przyporzadkuj(element) {
393 Przyporzadkuj.__super__.constructor.call(this, element);
394 this.multiple = this.is_multiple();
395 this.dragging(this.multiple, true);
398 Przyporzadkuj.prototype.draggable_equal = function(d1, d2) {
399 return d1.data("no") === d2.data("no");
402 Przyporzadkuj.prototype.check_question = function(question) {
403 var all, all_multiple, count, mandatory, optional, pn, pred, qp, v, _i, _j, _len, _len2, _ref, _ref2;
407 _ref = $(".predicate .question-piece", question);
408 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
410 pred = $(qp).closest("[data-predicate]");
411 v = this.get_value_optional_list(qp, 'solution');
414 all_multiple += mandatory.length + optional.length;
415 pn = pred.data('predicate');
416 if (mandatory.indexOf(pn) >= 0 || optional.indexOf(pn) >= 0) {
418 this.piece_correct(qp);
420 this.piece_incorrect(qp);
425 _ref2 = $(".subject .question-piece", question);
426 for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
428 v = this.get_value_optional_list(qp, 'solution');
431 all_multiple += mandatory.length + optional.length;
433 return [count, all_multiple];
439 return Przyporzadkuj;
443 PrawdaFalsz = (function(_super) {
445 __extends(PrawdaFalsz, _super);
447 function PrawdaFalsz(element) {
448 var qp, _i, _len, _ref;
449 PrawdaFalsz.__super__.constructor.call(this, element);
450 _ref = $(".question-piece", this.element);
451 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
453 $(".true", qp).click(function(ev) {
455 $(this).closest(".question-piece").data("value", "true");
456 return $(this).addClass('chosen').siblings('a').removeClass('chosen');
458 $(".false", qp).click(function(ev) {
460 $(this).closest(".question-piece").data("value", "false");
461 return $(this).addClass('chosen').siblings('a').removeClass('chosen');
466 PrawdaFalsz.prototype.check_question = function() {
467 var all, good, qp, _i, _len, _ref;
470 _ref = $(".question-piece", this.element);
471 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
473 if ($(qp).data("solution").toString() === $(qp).data("value")) {
475 this.piece_correct(qp);
477 this.piece_incorrect(qp);
488 excercise = function(ele) {
492 uporzadkuj: Uporzadkuj,
495 przyporzadkuj: Przyporzadkuj,
496 prawdafalsz: PrawdaFalsz
498 cls = es[$(ele).attr('data-type')];
503 'EduModule': EduModule
506 $(document).ready(function() {
507 new EduModule($("#book-text"));
508 return $(".excercise").each(function(i, el) {
509 return excercise(this);