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) {
140 $draggable = $(draggable);
141 if (!$draggable.is(".draggable")) return false;
142 return self.draggable_accept($draggable, $(this));
144 drop: function(ev, ui) {
147 added = $(ui.draggable).clone();
149 $added.data("original", ui.draggable);
151 $(ui.draggable).addClass('disabled').draggable('disable');
153 $(ev.target).after(added);
154 if (!$(ev.target).hasClass('multiple')) $(ev.target).hide();
155 $added.append('<span class="remove">x</span>');
156 return $('.remove', added).click(function(ev) {
157 $added.prev(".placeholder:not(.multiple)").show();
159 $added.data('original').removeClass('disabled').draggable('enable');
161 return $(added).remove();
172 Wybor = (function(_super) {
174 __extends(Wybor, _super);
176 function Wybor(element) {
177 Wybor.__super__.constructor.call(this, element);
180 Wybor.prototype.check_question = function(question) {
181 var all, good, solution,
185 solution = this.get_value_list(question, 'solution');
186 $(".question-piece", question).each(function(i, qpiece) {
187 var is_checked, piece_name, piece_no, should_be_checked;
188 piece_no = $(qpiece).attr('data-no');
189 piece_name = $(qpiece).attr('data-name');
191 should_be_checked = solution.indexOf(piece_name) >= 0;
193 should_be_checked = solution.indexOf(piece_no) >= 0;
195 is_checked = $("input", qpiece).is(":checked");
196 if (should_be_checked) all += 1;
198 if (should_be_checked) {
200 return _this.piece_correct(qpiece);
202 return _this.piece_incorrect(qpiece);
205 return $(qpiece).removeClass("correct,incorrect");
211 Wybor.prototype.show_solutions = function() {};
217 Uporzadkuj = (function(_super) {
219 __extends(Uporzadkuj, _super);
221 function Uporzadkuj(element) {
222 Uporzadkuj.__super__.constructor.call(this, element);
223 $('ol, ul', this.element).sortable({
228 Uporzadkuj.prototype.check_question = function(question) {
229 var all, correct, pkt, pkts, positions, sorted, _ref;
230 positions = this.get_value_list(question, 'original', true);
231 sorted = positions.sort();
232 pkts = $('.question-piece', question);
235 for (pkt = 0, _ref = pkts.length; 0 <= _ref ? pkt < _ref : pkt > _ref; 0 <= _ref ? pkt++ : pkt--) {
237 if (pkts.eq(pkt).data('pos') === sorted[pkt]) {
239 this.piece_correct(pkts.eq(pkt));
241 this.piece_incorrect(pkts.eq(pkt));
244 return [correct, all];
251 Luki = (function(_super) {
253 __extends(Luki, _super);
255 function Luki(element) {
256 Luki.__super__.constructor.call(this, element);
257 this.dragging(false, false);
260 Luki.prototype.check = function() {
265 $(".placeholder + .question-piece", this.element).each(function(i, qpiece) {
267 $placeholder = $(qpiece).prev(".placeholder");
268 if ($placeholder.data('solution') === $(qpiece).data('no')) {
269 _this.piece_correct(qpiece);
272 _this.piece_incorrect(qpiece);
276 return this.show_score([correct, all]);
283 Zastap = (function(_super) {
285 __extends(Zastap, _super);
287 function Zastap(element) {
289 Zastap.__super__.constructor.call(this, element);
290 $(".paragraph", this.element).each(function(i, par) {
292 _this.wrap_words($(par), $('<span class="zastap question-piece"/>'));
293 spans = $("> span", par).attr("contenteditable", "true");
294 return spans.click(function(ev) {
295 spans.filter(':not(:empty)').removeClass('editing');
296 return $(ev.target).addClass('editing');
301 Zastap.prototype.check = function() {
306 $(".question-piece", this.element).each(function(i, qpiece) {
307 var should_be_changed, txt;
308 txt = $(qpiece).data('original');
309 should_be_changed = false;
310 if (!(txt != null)) {
311 txt = $(qpiece).data('solution');
312 should_be_changed = true;
314 if (!(txt != null)) return;
315 if (should_be_changed) all += 1;
316 if (txt !== $(qpiece).text()) {
317 return _this.piece_incorrect(qpiece);
319 if (should_be_changed) {
320 _this.piece_correct(qpiece);
325 return this.show_score([correct, all]);
328 Zastap.prototype.wrap_words = function(element, wrapper) {
329 var chld, i, ignore, insertWrapped, j, len, space, wordb, _ref, _results;
330 ignore = /^[ \t.,:;()]+/;
331 insertWrapped = function(txt, elem) {
333 nw = wrapper.clone();
334 return $(document.createTextNode(txt)).wrap(nw).parent().attr("data-original", txt).insertBefore(elem);
337 for (j = _ref = element.get(0).childNodes.length - 1; _ref <= 0 ? j <= 0 : j >= 0; _ref <= 0 ? j++ : j--) {
338 chld = element.get(0).childNodes[j];
339 if (chld.nodeType === document.TEXT_NODE) {
340 len = chld.textContent.length;
344 space = ignore.exec(chld.textContent.substr(i));
347 insertWrapped(chld.textContent.substr(wordb, i - wordb), chld);
349 $(document.createTextNode(space[0])).insertBefore(chld);
350 i += space[0].length;
356 if (wordb < len - 1) {
357 insertWrapped(chld.textContent.substr(wordb, len - 1 - wordb), chld);
359 _results.push($(chld).remove());
361 _results.push(void 0);
371 Przyporzadkuj = (function(_super) {
373 __extends(Przyporzadkuj, _super);
375 Przyporzadkuj.prototype.is_multiple = function() {
376 var qp, _i, _len, _ref;
377 _ref = $(".question-piece", this.element);
378 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
380 if ($(qp).data('solution').split(/[ ,]+/).length > 1) return true;
385 function Przyporzadkuj(element) {
386 Przyporzadkuj.__super__.constructor.call(this, element);
387 this.multiple = this.is_multiple();
388 this.dragging(this.multiple, true);
391 Przyporzadkuj.prototype.draggable_equal = function(d1, d2) {
392 return d1.data("no") === d2.data("no");
395 Przyporzadkuj.prototype.check_question = function(question) {
396 var all, all_multiple, count, mandatory, optional, pn, pred, qp, v, _i, _j, _len, _len2, _ref, _ref2;
400 _ref = $(".predicate .question-piece", question);
401 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
403 pred = $(qp).closest("[data-predicate]");
404 v = this.get_value_optional_list(qp, 'solution');
407 all_multiple += mandatory.length + optional.length;
408 pn = pred.data('predicate');
409 if (mandatory.indexOf(pn) >= 0 || optional.indexOf(pn) >= 0) {
411 this.piece_correct(qp);
413 this.piece_incorrect(qp);
418 _ref2 = $(".subject .question-piece", question);
419 for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
421 v = this.get_value_optional_list(qp, 'solution');
424 all_multiple += mandatory.length + optional.length;
426 return [count, all_multiple];
432 return Przyporzadkuj;
436 PrawdaFalsz = (function(_super) {
438 __extends(PrawdaFalsz, _super);
440 function PrawdaFalsz(element) {
441 var qp, _i, _len, _ref;
442 PrawdaFalsz.__super__.constructor.call(this, element);
443 _ref = $(".question-piece", this.element);
444 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
446 $(".true", qp).click(function(ev) {
448 $(this).closest(".question-piece").data("value", "true");
449 return $(this).addClass('chosen').siblings('a').removeClass('chosen');
451 $(".false", qp).click(function(ev) {
453 $(this).closest(".question-piece").data("value", "false");
454 return $(this).addClass('chosen').siblings('a').removeClass('chosen');
459 PrawdaFalsz.prototype.check_question = function() {
460 var all, good, qp, _i, _len, _ref;
463 _ref = $(".question-piece", this.element);
464 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
466 if ($(qp).data("solution").toString() === $(qp).data("value")) {
468 this.piece_correct(qp);
470 this.piece_incorrect(qp);
481 excercise = function(ele) {
485 uporzadkuj: Uporzadkuj,
488 przyporzadkuj: Przyporzadkuj,
489 prawdafalsz: PrawdaFalsz
491 cls = es[$(ele).attr('data-type')];
496 'EduModule': EduModule
499 $(document).ready(function() {
500 new EduModule($("#book-text"));
501 return $(".excercise").each(function(i, el) {
502 return excercise(this);