2 var $, Binding, EduModule, Excercise, Luki, 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).droppable({
341 accept: function(draggable) {
342 var $draggable, $predicate, added, _i, _len, _ref;
343 $draggable = $(draggable);
344 if (!$draggable.is(".draggable")) return false;
345 $predicate = $(this);
346 _ref = $predicate.find("li");
347 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
349 if ($(added).text() === $draggable.text()) return false;
353 drop: function(ev, ui) {
355 added = ui.draggable.clone();
356 added.attr('style', '');
357 $(ev.target).append(added);
358 added.draggable(draggable_opts);
359 if (!_this.multiple || ui.draggable.closest(".predicate").length > 0) {
360 return ui.draggable.remove();
364 return $(".subject", question).droppable({
365 accept: ".draggable",
366 drop: function(ev, ui) {
368 if ($(ui.draggable).closest(".subject").length > 0) return;
369 added = ui.draggable.clone();
370 added.attr('style', '');
371 if (!_this.multiple) {
372 $(ev.target).append(added);
373 added.draggable($.extend({}, draggable_opts, helper_opts));
375 return ui.draggable.remove();
381 Przyporzadkuj.prototype.check_question = function(question) {
382 var all, all_multiple, count, mandatory, optional, pn, pred, qp, v, _i, _j, _len, _len2, _ref, _ref2;
386 _ref = $(".predicate .question-piece", question);
387 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
389 pred = $(qp).closest("[data-predicate]");
390 v = this.get_value_optional_list(qp, 'solution');
393 all_multiple += mandatory.length + optional.length;
394 pn = pred.data('predicate');
395 if (mandatory.indexOf(pn) >= 0 || optional.indexOf(pn) >= 0) {
397 this.piece_correct(qp);
399 this.piece_incorrect(qp);
404 _ref2 = $(".subject .question-piece", question);
405 for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
407 v = this.get_value_optional_list(qp, 'solution');
410 all_multiple += mandatory.length + optional.length;
412 return [count, all_multiple];
418 return Przyporzadkuj;
422 excercise = function(ele) {
426 uporzadkuj: Uporzadkuj,
429 przyporzadkuj: Przyporzadkuj
431 cls = es[$(ele).attr('data-type')];
436 'EduModule': EduModule
439 $(document).ready(function() {
440 new EduModule($("#book-text"));
441 return $(".excercise").each(function(i, el) {
442 return excercise(this);