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).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', true);
127 $(".question-piece", question).each(function(i, qpiece) {
128 var is_checked, piece_no, should_be_checked;
129 piece_no = parseInt($(qpiece).attr('data-no'));
130 should_be_checked = solution.indexOf(piece_no) >= 0;
131 is_checked = $("input", qpiece).is(":checked");
132 if (should_be_checked) all += 1;
134 if (should_be_checked) {
136 return _this.piece_correct(qpiece);
138 return _this.piece_incorrect(qpiece);
141 return $(qpiece).removeClass("correct,incorrect");
147 Wybor.prototype.show_solutions = function() {};
153 Uporzadkuj = (function(_super) {
155 __extends(Uporzadkuj, _super);
157 function Uporzadkuj(element) {
158 Uporzadkuj.__super__.constructor.call(this, element);
159 $('ol, ul', this.element).sortable({
164 Uporzadkuj.prototype.check_question = function(question) {
165 var all, correct, pkt, pkts, positions, sorted, _ref;
166 positions = this.get_value_list(question, 'original', true);
167 sorted = positions.sort();
168 pkts = $('.question-piece', question);
171 for (pkt = 0, _ref = pkts.length; 0 <= _ref ? pkt < _ref : pkt > _ref; 0 <= _ref ? pkt++ : pkt--) {
173 if (pkts.eq(pkt).data('pos') === sorted[pkt]) {
175 this.piece_correct(pkts.eq(pkt));
177 this.piece_incorrect(pkts.eq(pkt));
180 return [correct, all];
187 Luki = (function(_super) {
189 __extends(Luki, _super);
191 function Luki(element) {
192 Luki.__super__.constructor.call(this, element);
195 Luki.prototype.check = function() {
200 $(".question-piece", this.element).each(function(i, qpiece) {
201 if ($(qpiece).data('solution') === $(qpiece).val()) {
202 _this.piece_correct(qpiece);
205 _this.piece_incorrect(qpiece);
209 return this.show_score([correct, all]);
216 Zastap = (function(_super) {
218 __extends(Zastap, _super);
220 function Zastap(element) {
222 Zastap.__super__.constructor.call(this, element);
223 $(".paragraph", this.element).each(function(i, par) {
225 _this.wrap_words($(par), $('<span class="zastap question-piece"/>'));
226 spans = $("> span", par).attr("contenteditable", "true");
227 return spans.click(function(ev) {
228 spans.filter(':not(:empty)').removeClass('editing');
229 return $(ev.target).addClass('editing');
234 Zastap.prototype.check = function() {
239 $(".question-piece", this.element).each(function(i, qpiece) {
240 var should_be_changed, txt;
241 txt = $(qpiece).data('original');
242 should_be_changed = false;
243 if (!(txt != null)) {
244 txt = $(qpiece).data('solution');
245 should_be_changed = true;
247 if (!(txt != null)) return;
248 if (should_be_changed) all += 1;
249 if (txt !== $(qpiece).text()) {
250 return _this.piece_incorrect(qpiece);
252 if (should_be_changed) {
253 _this.piece_correct(qpiece);
258 return this.show_score([correct, all]);
261 Zastap.prototype.wrap_words = function(element, wrapper) {
262 var chld, i, ignore, insertWrapped, j, len, space, wordb, _ref, _results;
263 ignore = /^[ \t.,:;()]+/;
264 insertWrapped = function(txt, elem) {
266 nw = wrapper.clone();
267 return $(document.createTextNode(txt)).wrap(nw).parent().attr("data-original", txt).insertBefore(elem);
270 for (j = _ref = element.get(0).childNodes.length - 1; _ref <= 0 ? j <= 0 : j >= 0; _ref <= 0 ? j++ : j--) {
271 chld = element.get(0).childNodes[j];
272 if (chld.nodeType === document.TEXT_NODE) {
273 len = chld.textContent.length;
277 space = ignore.exec(chld.textContent.substr(i));
280 insertWrapped(chld.textContent.substr(wordb, i - wordb), chld);
282 $(document.createTextNode(space[0])).insertBefore(chld);
283 i += space[0].length;
289 if (wordb < len - 1) {
290 insertWrapped(chld.textContent.substr(wordb, len - 1 - wordb), chld);
292 _results.push($(chld).remove());
294 _results.push(void 0);
304 Przyporzadkuj = (function(_super) {
306 __extends(Przyporzadkuj, _super);
308 Przyporzadkuj.prototype.is_multiple = function() {
309 var qp, _i, _len, _ref;
310 _ref = $(".question-piece", this.element);
311 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
313 if ($(qp).data('solution').split(/[ ,]+/).length > 1) return true;
318 function Przyporzadkuj(element) {
320 Przyporzadkuj.__super__.constructor.call(this, element);
321 this.multiple = this.is_multiple();
322 $(".question", this.element).each(function(i, question) {
323 var draggable_opts, helper_opts;
327 if (_this.multiple) {
334 $(".draggable", question).draggable($.extend({}, draggable_opts, helper_opts));
335 $(".predicate .droppable", question).droppable({
336 accept: function(draggable) {
337 var $draggable, $predicate, added, _i, _len, _ref;
338 $draggable = $(draggable);
339 if (!$draggable.is(".draggable")) return false;
340 $predicate = $(this);
341 _ref = $predicate.find("li");
342 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
344 if ($(added).text() === $draggable.text()) return false;
348 drop: function(ev, ui) {
350 added = ui.draggable.clone();
351 added.attr('style', '');
352 $(ev.target).append(added);
353 added.draggable(draggable_opts);
354 if (!_this.multiple || ui.draggable.closest(".predicate").length > 0) {
355 return ui.draggable.remove();
359 return $(".subject", question).droppable({
360 accept: ".draggable",
361 drop: function(ev, ui) {
363 if ($(ui.draggable).closest(".subject").length > 0) return;
364 added = ui.draggable.clone();
365 added.attr('style', '');
366 if (!_this.multiple) {
367 $(ev.target).append(added);
368 added.draggable($.extend({}, draggable_opts, helper_opts));
370 return ui.draggable.remove();
376 Przyporzadkuj.prototype.check_question = function(question) {
377 var all, all_multiple, count, mandatory, optional, pn, pred, qp, v, _i, _j, _len, _len2, _ref, _ref2;
381 _ref = $(".predicate .question-piece", question);
382 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
384 pred = $(qp).closest("[data-predicate]");
385 v = this.get_value_optional_list(qp, 'solution');
388 all_multiple += mandatory.length + optional.length;
389 pn = pred.data('predicate');
390 if (mandatory.indexOf(pn) >= 0 || optional.indexOf(pn) >= 0) {
392 this.piece_correct(qp);
394 this.piece_incorrect(qp);
399 _ref2 = $(".subject .question-piece", question);
400 for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
402 v = this.get_value_optional_list(qp, 'solution');
405 all_multiple += mandatory.length + optional.length;
407 return [count, all_multiple];
413 return Przyporzadkuj;
417 excercise = function(ele) {
421 uporzadkuj: Uporzadkuj,
424 przyporzadkuj: Przyporzadkuj
426 cls = es[$(ele).attr('data-type')];
431 'EduModule': EduModule
434 $(document).ready(function() {
435 new EduModule($("#book-text"));
436 return $(".excercise").each(function(i, el) {
437 return excercise(this);