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]);
113 Wybor = (function(_super) {
115 __extends(Wybor, _super);
117 function Wybor(element) {
118 Wybor.__super__.constructor.call(this, element);
121 Wybor.prototype.check_question = function(question) {
122 var all, good, solution,
126 solution = this.get_value_list(question, 'solution');
127 $(".question-piece", question).each(function(i, qpiece) {
128 var is_checked, piece_name, piece_no, should_be_checked;
129 piece_no = $(qpiece).attr('data-no');
130 piece_name = $(qpiece).attr('data-name');
132 should_be_checked = solution.indexOf(piece_name) >= 0;
134 should_be_checked = solution.indexOf(piece_no) >= 0;
136 is_checked = $("input", qpiece).is(":checked");
137 if (should_be_checked) all += 1;
139 if (should_be_checked) {
141 return _this.piece_correct(qpiece);
143 return _this.piece_incorrect(qpiece);
146 return $(qpiece).removeClass("correct,incorrect");
152 Wybor.prototype.show_solutions = function() {};
158 Uporzadkuj = (function(_super) {
160 __extends(Uporzadkuj, _super);
162 function Uporzadkuj(element) {
163 Uporzadkuj.__super__.constructor.call(this, element);
164 $('ol, ul', this.element).sortable({
169 Uporzadkuj.prototype.check_question = function(question) {
170 var all, correct, pkt, pkts, positions, sorted, _ref;
171 positions = this.get_value_list(question, 'original', true);
172 sorted = positions.sort();
173 pkts = $('.question-piece', question);
176 for (pkt = 0, _ref = pkts.length; 0 <= _ref ? pkt < _ref : pkt > _ref; 0 <= _ref ? pkt++ : pkt--) {
178 if (pkts.eq(pkt).data('pos') === sorted[pkt]) {
180 this.piece_correct(pkts.eq(pkt));
182 this.piece_incorrect(pkts.eq(pkt));
185 return [correct, all];
192 Luki = (function(_super) {
194 __extends(Luki, _super);
196 function Luki(element) {
197 Luki.__super__.constructor.call(this, element);
200 Luki.prototype.check = function() {
205 $(".question-piece", this.element).each(function(i, qpiece) {
206 if ($(qpiece).data('solution') === $(qpiece).val()) {
207 _this.piece_correct(qpiece);
210 _this.piece_incorrect(qpiece);
214 return this.show_score([correct, all]);
221 Zastap = (function(_super) {
223 __extends(Zastap, _super);
225 function Zastap(element) {
227 Zastap.__super__.constructor.call(this, element);
228 $(".paragraph", this.element).each(function(i, par) {
230 _this.wrap_words($(par), $('<span class="zastap question-piece"/>'));
231 spans = $("> span", par).attr("contenteditable", "true");
232 return spans.click(function(ev) {
233 spans.filter(':not(:empty)').removeClass('editing');
234 return $(ev.target).addClass('editing');
239 Zastap.prototype.check = function() {
244 $(".question-piece", this.element).each(function(i, qpiece) {
245 var should_be_changed, txt;
246 txt = $(qpiece).data('original');
247 should_be_changed = false;
248 if (!(txt != null)) {
249 txt = $(qpiece).data('solution');
250 should_be_changed = true;
252 if (!(txt != null)) return;
253 if (should_be_changed) all += 1;
254 if (txt !== $(qpiece).text()) {
255 return _this.piece_incorrect(qpiece);
257 if (should_be_changed) {
258 _this.piece_correct(qpiece);
263 return this.show_score([correct, all]);
266 Zastap.prototype.wrap_words = function(element, wrapper) {
267 var chld, i, ignore, insertWrapped, j, len, space, wordb, _ref, _results;
268 ignore = /^[ \t.,:;()]+/;
269 insertWrapped = function(txt, elem) {
271 nw = wrapper.clone();
272 return $(document.createTextNode(txt)).wrap(nw).parent().attr("data-original", txt).insertBefore(elem);
275 for (j = _ref = element.get(0).childNodes.length - 1; _ref <= 0 ? j <= 0 : j >= 0; _ref <= 0 ? j++ : j--) {
276 chld = element.get(0).childNodes[j];
277 if (chld.nodeType === document.TEXT_NODE) {
278 len = chld.textContent.length;
282 space = ignore.exec(chld.textContent.substr(i));
285 insertWrapped(chld.textContent.substr(wordb, i - wordb), chld);
287 $(document.createTextNode(space[0])).insertBefore(chld);
288 i += space[0].length;
294 if (wordb < len - 1) {
295 insertWrapped(chld.textContent.substr(wordb, len - 1 - wordb), chld);
297 _results.push($(chld).remove());
299 _results.push(void 0);
309 Przyporzadkuj = (function(_super) {
311 __extends(Przyporzadkuj, _super);
313 Przyporzadkuj.prototype.is_multiple = function() {
314 var qp, _i, _len, _ref;
315 _ref = $(".question-piece", this.element);
316 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
318 if ($(qp).data('solution').split(/[ ,]+/).length > 1) return true;
323 function Przyporzadkuj(element) {
325 Przyporzadkuj.__super__.constructor.call(this, element);
326 this.multiple = this.is_multiple();
327 $(".question", this.element).each(function(i, question) {
328 var draggable_opts, helper_opts;
332 if (_this.multiple) {
339 $(".draggable", question).draggable($.extend({}, draggable_opts, helper_opts));
340 $(".predicate .droppable", question).parent().droppable({
341 accept: function(draggable) {
342 var $draggable, $predicate, added, _i, _len, _ref;
343 $draggable = $(draggable);
344 if (!$draggable.is(".draggable")) {
345 console.log('not draggable?');
348 $predicate = $(this);
349 _ref = $predicate.find("li");
350 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
352 if ($(added).text() === $draggable.text()) {
353 console.log('already here:' + $draggable.text());
359 drop: function(ev, ui) {
361 added = ui.draggable.clone();
362 added.attr('style', '');
363 $(ev.target).find(".droppable").append(added);
364 added.draggable(draggable_opts);
365 if (!_this.multiple || ui.draggable.closest(".predicate").length > 0) {
366 return ui.draggable.remove();
370 $(".predicate .droppable", question).sortable({
373 return $(".subject", question).droppable({
374 accept: ".draggable",
375 drop: function(ev, ui) {
377 if ($(ui.draggable).closest(".subject").length > 0) return;
378 added = ui.draggable.clone();
379 added.attr('style', '');
380 if (!_this.multiple) {
381 $(ev.target).append(added);
382 added.draggable($.extend({}, draggable_opts, helper_opts));
384 return ui.draggable.remove();
390 Przyporzadkuj.prototype.check_question = function(question) {
391 var all, all_multiple, count, mandatory, optional, pn, pred, qp, v, _i, _j, _len, _len2, _ref, _ref2;
395 _ref = $(".predicate .question-piece", question);
396 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
398 pred = $(qp).closest("[data-predicate]");
399 v = this.get_value_optional_list(qp, 'solution');
402 all_multiple += mandatory.length + optional.length;
403 pn = pred.data('predicate');
404 if (mandatory.indexOf(pn) >= 0 || optional.indexOf(pn) >= 0) {
406 this.piece_correct(qp);
408 this.piece_incorrect(qp);
413 _ref2 = $(".subject .question-piece", question);
414 for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
416 v = this.get_value_optional_list(qp, 'solution');
419 all_multiple += mandatory.length + optional.length;
421 return [count, all_multiple];
427 return Przyporzadkuj;
431 PrawdaFalsz = (function(_super) {
433 __extends(PrawdaFalsz, _super);
435 function PrawdaFalsz(element) {
436 var qp, _i, _len, _ref;
437 PrawdaFalsz.__super__.constructor.call(this, element);
438 _ref = $(".question-piece", this.element);
439 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
441 $(".true", qp).click(function(ev) {
443 $(this).closest(".question-piece").data("value", "true");
444 return $(this).addClass('chosen').siblings('a').removeClass('chosen');
446 $(".false", qp).click(function(ev) {
448 $(this).closest(".question-piece").data("value", "false");
449 return $(this).addClass('chosen').siblings('a').removeClass('chosen');
454 PrawdaFalsz.prototype.check_question = function() {
455 var all, good, qp, _i, _len, _ref;
458 _ref = $(".question-piece", this.element);
459 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
461 if ($(qp).data("solution").toString() === $(qp).data("value")) {
463 this.piece_correct(qp);
465 this.piece_incorrect(qp);
476 excercise = function(ele) {
480 uporzadkuj: Uporzadkuj,
483 przyporzadkuj: Przyporzadkuj,
484 prawdafalsz: PrawdaFalsz
486 cls = es[$(ele).attr('data-type')];
491 'EduModule': EduModule
494 $(document).ready(function() {
495 new EduModule($("#book-text"));
496 return $(".excercise").each(function(i, el) {
497 return excercise(this);