+// Generated by CoffeeScript 1.4.0
+(function() {
+ var $, Binding, EduModule, Excercise, Wybor, excercise,
+ __hasProp = {}.hasOwnProperty,
+ __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; };
+
+ $ = jQuery;
+
+ Binding = (function() {
+
+ function Binding(handler, element) {
+ this.handler = handler;
+ this.element = element;
+ $(this.element).data(this.handler, this);
+ }
+
+ return Binding;
+
+ })();
+
+ EduModule = (function(_super) {
+
+ __extends(EduModule, _super);
+
+ function EduModule(element) {
+ var _this = this;
+ EduModule.__super__.constructor.call(this, 'edumodule', element);
+ $("[name=teacher-toggle]").change(function(ev) {
+ if ($(ev.target).is(":checked")) {
+ return $(".teacher", _this.element).addClass("show");
+ } else {
+ return $(".teacher", _this.element).removeClass("show");
+ }
+ });
+ }
+
+ return EduModule;
+
+ })(Binding);
+
+ Excercise = (function(_super) {
+
+ __extends(Excercise, _super);
+
+ function Excercise(element) {
+ var _this = this;
+ Excercise.__super__.constructor.call(this, 'excercise', element);
+ $(".check", this.element).click(function() {
+ return _this.check();
+ });
+ $('.solutions', this.element).click(function() {
+ return _this.show_solutions();
+ });
+ }
+
+ return Excercise;
+
+ })(Binding);
+
+ Wybor = (function(_super) {
+
+ __extends(Wybor, _super);
+
+ function Wybor(element) {
+ Wybor.__super__.constructor.call(this, element);
+ }
+
+ Wybor.prototype.check = function() {
+ var score, scores,
+ _this = this;
+ scores = [];
+ $(".question").each(function(i, question) {
+ return scores.push(_this.check_question(question));
+ });
+ score = [0, 0];
+ $.each(scores, function(i, s) {
+ score[0] += s[0];
+ return score[1] += s[1];
+ });
+ return this.show_score(score);
+ };
+
+ Wybor.prototype.check_question = function(question) {
+ var all, good, solution,
+ _this = this;
+ all = 0;
+ good = 0;
+ solution = $(question).attr('data-solution').split(',').map($.trim).map(function(x) {
+ return parseInt(x);
+ });
+ $(".question-piece", question).each(function(i, qpiece) {
+ var is_checked, piece_no, should_be_checked;
+ piece_no = parseInt($(qpiece).attr('data-no'));
+ should_be_checked = solution.indexOf(piece_no) >= 0;
+ is_checked = $("input", qpiece).is(":checked");
+ if (should_be_checked) {
+ all += 1;
+ }
+ if (is_checked) {
+ if (should_be_checked) {
+ good += 1;
+ return _this.piece_correct(qpiece);
+ } else {
+ return _this.piece_incorrect(qpiece);
+ }
+ } else {
+ return $(qpiece).removeClass("correct,incorrect");
+ }
+ });
+ return [good, all];
+ };
+
+ Wybor.prototype.piece_correct = function(qpiece) {
+ return $(qpiece).removeClass('incorrect').addClass('correct');
+ };
+
+ Wybor.prototype.piece_incorrect = function(qpiece) {
+ return $(qpiece).removeClass('correct').addClass('incorrect');
+ };
+
+ Wybor.prototype.show_solutions = function() {};
+
+ Wybor.prototype.show_score = function(score) {
+ return $(".message", this.element).text("Wynik: " + score[0] + " / " + score[1]);
+ };
+
+ return Wybor;
+
+ })(Excercise);
+
+ excercise = function(ele) {
+ var cls, es;
+ es = {
+ 'wybor': Wybor
+ };
+ cls = es[$(ele).attr('data-type')];
+ return new cls(ele);
+ };
+
+ window.edumed = {
+ 'EduModule': EduModule
+ };
+
+ $(document).ready(function() {
+ new EduModule($("#book-text"));
+ return $(".excercise").each(function(i, el) {
+ return excercise(this);
+ });
+ });
+
+}).call(this);