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").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) {
79 return $(elem).data(data_key).split(',').map($.trim).map(function(x) {
84 Excercise.prototype.show_score = function(score) {
85 return $(".message", this.element).text("Wynik: " + score[0] + " / " + score[1]);
92 Wybor = (function(_super) {
94 __extends(Wybor, _super);
96 function Wybor(element) {
97 Wybor.__super__.constructor.call(this, element);
100 Wybor.prototype.check_question = function(question) {
101 var all, good, solution,
105 solution = this.get_value_list(question, 'solution');
106 $(".question-piece", question).each(function(i, qpiece) {
107 var is_checked, piece_no, should_be_checked;
108 piece_no = parseInt($(qpiece).attr('data-no'));
109 should_be_checked = solution.indexOf(piece_no) >= 0;
110 is_checked = $("input", qpiece).is(":checked");
111 if (should_be_checked) all += 1;
113 if (should_be_checked) {
115 return _this.piece_correct(qpiece);
117 return _this.piece_incorrect(qpiece);
120 return $(qpiece).removeClass("correct,incorrect");
126 Wybor.prototype.show_solutions = function() {};
132 Uporzadkuj = (function(_super) {
134 __extends(Uporzadkuj, _super);
136 function Uporzadkuj(element) {
137 Uporzadkuj.__super__.constructor.call(this, element);
138 $('ol, ul', this.element).sortable({
143 Uporzadkuj.prototype.check_question = function(question) {
144 var all, correct, pkt, pkts, positions, sorted, _ref;
145 positions = this.get_value_list(question, 'original');
146 sorted = positions.sort();
147 pkts = $('.question-piece', question);
150 for (pkt = 0, _ref = pkts.length; 0 <= _ref ? pkt < _ref : pkt > _ref; 0 <= _ref ? pkt++ : pkt--) {
152 if (pkts.eq(pkt).data('pos') === sorted[pkt]) {
154 this.piece_correct(pkts.eq(pkt));
156 this.piece_incorrect(pkts.eq(pkt));
159 return [correct, all];
166 Luki = (function(_super) {
168 __extends(Luki, _super);
170 function Luki(element) {
171 Luki.__super__.constructor.call(this, element);
174 Luki.prototype.check = function() {
179 $(".question-piece", this.element).each(function(i, qpiece) {
180 if ($(qpiece).data('solution') === $(qpiece).val()) {
181 _this.piece_correct(qpiece);
184 _this.piece_incorrect(qpiece);
188 return this.show_score([correct, all]);
195 Zastap = (function(_super) {
197 __extends(Zastap, _super);
199 function Zastap(element) {
201 Zastap.__super__.constructor.call(this, element);
202 $(".paragraph", this.element).each(function(i, par) {
204 _this.wrap_words($(par), $('<span class="zastap question-piece"/>'));
205 spans = $("> span", par).attr("contenteditable", "true");
206 return spans.click(function(ev) {
207 spans.filter(':not(:empty)').removeClass('editing');
208 return $(ev.target).addClass('editing');
213 Zastap.prototype.check = function() {
218 $(".question-piece", this.element).each(function(i, qpiece) {
219 var should_be_changed, txt;
220 txt = $(qpiece).data('original');
221 should_be_changed = false;
222 if (!(txt != null)) {
223 txt = $(qpiece).data('solution');
224 should_be_changed = true;
226 if (!(txt != null)) return;
227 if (should_be_changed) all += 1;
228 if (txt !== $(qpiece).text()) {
229 return _this.piece_incorrect(qpiece);
231 if (should_be_changed) {
232 _this.piece_correct(qpiece);
237 return this.show_score([correct, all]);
240 Zastap.prototype.wrap_words = function(element, wrapper) {
241 var chld, i, ignore, insertWrapped, j, len, space, wordb, _ref, _results;
242 ignore = /^[ \t.,:;()]+/;
243 insertWrapped = function(txt, elem) {
245 nw = wrapper.clone();
246 return $(document.createTextNode(txt)).wrap(nw).parent().attr("data-original", txt).insertBefore(elem);
249 for (j = _ref = element.get(0).childNodes.length - 1; _ref <= 0 ? j <= 0 : j >= 0; _ref <= 0 ? j++ : j--) {
250 chld = element.get(0).childNodes[j];
251 if (chld.nodeType === document.TEXT_NODE) {
252 len = chld.textContent.length;
256 space = ignore.exec(chld.textContent.substr(i));
259 insertWrapped(chld.textContent.substr(wordb, i - wordb), chld);
261 $(document.createTextNode(space[0])).insertBefore(chld);
262 i += space[0].length;
268 if (wordb < len - 1) {
269 insertWrapped(chld.textContent.substr(wordb, len - 1 - wordb), chld);
271 _results.push($(chld).remove());
273 _results.push(void 0);
283 Przyporzadkuj = (function(_super) {
285 __extends(Przyporzadkuj, _super);
287 function Przyporzadkuj(element) {
289 Przyporzadkuj.__super__.constructor.call(this, element);
290 if (this.element.attr('multiple') != null) {
291 this.multiple = true;
293 this.multiple = false;
295 $(".question", this.element).each(function(i, question) {
299 helper: _this.multiple ? "clone" : null
301 $(".draggable", question).draggable(draggable_opts).droppable({
304 $(".predicate .droppable", question).droppable({
305 accept: ".draggable",
306 drop: function(ev, ui) {
307 var added, is_multiple;
308 is_multiple = ui.draggable.is(".multiple");
309 added = ui.draggable.clone();
310 added.attr('style', '');
311 $(this).append(added);
312 added.draggable(draggable_opts);
313 if (!is_multiple) return ui.draggable.remove();
316 return $(".subject", question).droppable({
317 accept: ".draggable",
318 drop: function(ev, ui) {
319 var added, is_multiple;
320 is_multiple = ui.draggable.is(".multiple");
321 added = ui.draggable.clone();
322 added.attr('style', '');
324 $(this).append(added);
325 added.draggable(draggable_opts);
327 return ui.draggable.remove();
333 return Przyporzadkuj;
337 excercise = function(ele) {
341 uporzadkuj: Uporzadkuj,
344 przyporzadkuj: Przyporzadkuj
346 cls = es[$(ele).attr('data-type')];
351 'EduModule': EduModule
354 $(document).ready(function() {
355 new EduModule($("#book-text"));
356 return $(".excercise").each(function(i, el) {
357 return excercise(this);