mumuki-laboratory 7.12.0 → 8.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/mumuki_laboratory/application/characters.js +3 -1
  3. data/app/assets/javascripts/mumuki_laboratory/application/gamification.js +89 -11
  4. data/app/assets/javascripts/mumuki_laboratory/application/kids.js +171 -333
  5. data/app/assets/javascripts/mumuki_laboratory/application/kindergarten.js +144 -130
  6. data/app/assets/javascripts/mumuki_laboratory/application/mu-modal-carrousel.js +63 -0
  7. data/app/assets/javascripts/mumuki_laboratory/application/number-counter.js +18 -0
  8. data/app/assets/javascripts/mumuki_laboratory/application/primary.js +258 -0
  9. data/app/assets/javascripts/mumuki_laboratory/application/submission.js +1 -1
  10. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_kids_results.scss +117 -0
  11. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_kindergarten.scss +47 -113
  12. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_terms.scss +9 -12
  13. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_user_profile.scss +31 -3
  14. data/app/controllers/api/courses_controller.rb +1 -2
  15. data/app/controllers/api/organizations_controller.rb +2 -3
  16. data/app/controllers/api/users_controller.rb +2 -4
  17. data/app/controllers/application_controller.rb +41 -8
  18. data/app/controllers/assets_controller.rb +1 -0
  19. data/app/controllers/book_discussions_controller.rb +1 -1
  20. data/app/controllers/chapters_controller.rb +1 -0
  21. data/app/controllers/discussions_controller.rb +4 -0
  22. data/app/controllers/exercises_controller.rb +1 -0
  23. data/app/controllers/guides_controller.rb +2 -0
  24. data/app/controllers/invitations_controller.rb +2 -2
  25. data/app/controllers/lessons_controller.rb +1 -0
  26. data/app/controllers/login_controller.rb +1 -0
  27. data/app/controllers/users_controller.rb +9 -1
  28. data/app/helpers/assistance_box_helper.rb +7 -5
  29. data/app/helpers/contextualization_result_helper.rb +9 -1
  30. data/app/helpers/gamification_helper.rb +5 -0
  31. data/app/helpers/links_helper.rb +1 -1
  32. data/app/views/exercise_solutions/_assistant_rules_box.html.erb +13 -0
  33. data/app/views/exercise_solutions/_contextualization_results_container.html.erb +9 -0
  34. data/app/views/exercise_solutions/_kids_level_up.html.erb +11 -0
  35. data/app/views/exercise_solutions/_kids_results.html.erb +1 -1
  36. data/app/views/exercise_solutions/_results.html.erb +19 -19
  37. data/app/views/exercise_solutions/_results_title.html.erb +5 -0
  38. data/app/views/exercises/show.html.erb +4 -1
  39. data/app/views/layouts/_kindergarten.html.erb +4 -4
  40. data/app/views/layouts/_organizations_listing.html.erb +8 -12
  41. data/app/views/layouts/application.html.erb +8 -2
  42. data/app/views/layouts/modals/_guide_corollary.html.erb +1 -1
  43. data/app/views/layouts/modals/_kids_context.html.erb +1 -1
  44. data/app/views/layouts/modals/_kids_results.html.erb +16 -6
  45. data/app/views/layouts/modals/_kindergarten_context.html.erb +15 -15
  46. data/app/views/layouts/modals/_kindergarten_results.html.erb +20 -7
  47. data/app/views/layouts/modals/_kindergarten_results_aborted.html.erb +10 -7
  48. data/app/views/layouts/modals/_level_up.html.erb +27 -0
  49. data/app/views/users/_edit_user_form.html.erb +1 -1
  50. data/app/views/users/_user_form.html.erb +12 -2
  51. data/app/views/users/terms.html.erb +12 -0
  52. data/config/routes.rb +8 -8
  53. data/lib/mumuki/laboratory.rb +18 -5
  54. data/lib/mumuki/laboratory/controllers.rb +2 -0
  55. data/lib/mumuki/laboratory/controllers/action_redirector.rb +21 -0
  56. data/lib/mumuki/laboratory/controllers/immersive_navigation.rb +7 -0
  57. data/lib/mumuki/laboratory/controllers/results_rendering.rb +1 -0
  58. data/lib/mumuki/laboratory/events/events.rb +0 -33
  59. data/lib/mumuki/laboratory/locales/en.yml +11 -0
  60. data/lib/mumuki/laboratory/locales/es-CL.yml +5 -0
  61. data/lib/mumuki/laboratory/locales/es.yml +12 -1
  62. data/lib/mumuki/laboratory/locales/pt.yml +11 -0
  63. data/lib/mumuki/laboratory/version.rb +1 -1
  64. data/spec/capybara_helper.rb +5 -1
  65. data/spec/controllers/exercise_solutions_controller_spec.rb +1 -1
  66. data/spec/features/immersive_redirection_spec.rb +181 -0
  67. data/spec/features/profile_flow_spec.rb +35 -3
  68. data/spec/features/terms_flow_spec.rb +155 -0
  69. metadata +108 -98
  70. data/app/helpers/organization_list_helper.rb +0 -5
  71. data/spec/features/choose_organization_spec.rb +0 -74
@@ -1,145 +1,159 @@
1
1
  mumuki.load(() => {
2
- mumuki.kindergarten = {
2
+
3
+ mumuki.isKindergartenExercise = () => !!$('.mu-kindergarten').get(0);
4
+
5
+ class MumukiKindergarten extends mumuki.Kids {
6
+
7
+ constructor() {
8
+ super();
9
+ }
10
+
3
11
  initialize() {
12
+ super.initialize();
13
+ this.$contextModalButton = new mumuki.Button($('#mu-kids-context .mu-kids-modal-button.mu-close'));
14
+
15
+ this.resultActions.passed = this._showSuccessPopup.bind(this);
16
+ this.resultActions.passed_with_warnings = this._showSuccessPopup.bind(this);
17
+ this.resultActions.failed = this._showFailurePopup.bind(this);
18
+ this.resultActions.errored = this._showFailurePopup.bind(this);
19
+ this.resultActions.pending = this._showFailurePopup.bind(this);
20
+ this.resultActions.aborted = this.showAbortedPopup.bind(this);
21
+
4
22
  this.speech.verifyBrowserSupport();
5
23
  this.hint.showOrHideExpandHintButton();
6
24
  this.context.showNextOrCloseButton();
7
- this.result.configureCallbacks();
8
- },
9
- speech: {
10
- _isPlaying: false,
11
- click(selector, locale) {
12
- if (this._isPlaying) {
13
- this.stop();
14
- } else {
15
- this.play(selector, locale);
16
- }
17
- },
18
- play(selector, locale) {
19
- const msg = new SpeechSynthesisUtterance();
20
- msg.text = $(selector).text();
21
- msg.lang = locale.split('_')[0];
22
- msg.pitch = 0;
23
- msg.onend = () => this.stop();
24
- this._action('play', 'stop', true, (speech) => speech.speak(msg))
25
- },
26
- stop() {
27
- this._action('stop', 'play', false, (speech) => speech.cancel())
28
- },
29
- _action(add, remove, isPlaying, callback = () => {}) {
30
- callback(window.speechSynthesis);
31
- const $button = $('.mu-kindergarten-play-description')
32
- $button.find(`.mu-kindergarten-${add}`).addClass('hidden');
33
- $button.find(`.mu-kindergarten-${remove}`).removeClass('hidden');
34
- this._isPlaying = isPlaying;
35
- },
36
- verifyBrowserSupport() {
37
- if (!window.speechSynthesis) {
38
- const $button = $('.mu-kindergarten-play-description')
39
- $button.prop('disabled', true);
40
- $button.css('cursor', 'not-allowed');
41
- this._action('play', 'stop', false)
42
- }
43
- }
44
- },
45
- hint: {
46
- toggle() {
47
- $('.mu-kindergarten-light-speech-bubble').toggleClass('open');
48
- },
49
- toggleMedia() {
50
- const $hintMedia = $('.mu-kindergarten-hint-media');
51
- const $i = $('.expand-or-collapse-hint-media').children('i');
52
- $i.toggleClass('fa-caret-up').toggleClass('fa-caret-down');
53
- $hintMedia.toggleClass('closed');
54
- },
55
- showOrHideExpandHintButton() {
56
- const $button = $('.expand-or-collapse-hint-media');
57
- const $hintMedia = $('.mu-kindergarten-hint-media');
58
- if (!$hintMedia.get(0)) $button.addClass('hidden');
59
- },
60
- },
61
- context: {
62
- showContext() {
63
- mumuki.kids.showContext();
64
- this._showFirstSlideImage();
65
- },
66
- nextSlide() {
67
- this._clickButton('next');
68
- },
69
- prevSlide() {
70
- this._clickButton('prev');
71
- },
72
- _imageSlides() {
73
- return $('.mu-kindergarten-context-image-slides');
74
- },
75
- _activeSlideImage() {
76
- return this._imageSlides().find('.active');
77
- },
78
- _clickButton(prevOrNext) {
79
- this._activeSlideImage().removeClass('active')[prevOrNext]().addClass('active');
80
- this.showNextOrCloseButton();
81
- this._hidePreviousButtonIfFirstImage();
82
- },
83
- showNextOrCloseButton() {
84
- const $next = $('.mu-kindergarten-modal-button.mu-next');
85
- const $close = $('.mu-kindergarten-modal-button.mu-close');
86
- const isLastChild = this._activeSlideImage().is(':last-child');
87
- this._addClassIf($next, 'hidden', () => isLastChild);
88
- this._addClassIf($close, 'hidden', () => !isLastChild);
89
- },
90
- _hidePreviousButtonIfFirstImage() {
91
- const $prev = $('.mu-kindergarten-modal-button.mu-previous');
92
- this._addClassIf($prev, 'hidden', () => this._activeSlideImage().is(':first-child'))
93
- },
94
- _showFirstSlideImage() {
95
- this._imageSlides().find('img').each((i, el) => this._addClassIf($(el), 'active', () => i === 0))
96
- this.showNextOrCloseButton();
97
- this._hidePreviousButtonIfFirstImage();
98
- },
99
- _addClassIf(element, clazz, criteria) {
100
- if (criteria()) {
101
- element.addClass(clazz)
102
- } else {
103
- element.removeClass(clazz);
104
- }
105
- }
106
- },
107
- result: {
108
- configureCallbacks() {
109
- mumuki.kids.resultAction.passed = this._showOnSuccessPopup;
110
- mumuki.kids.resultAction.passed_with_warnings = this._showOnSuccessPopup;
111
-
112
- mumuki.kids.resultAction.failed = this._showOnFailurePopup;
113
- mumuki.kids.resultAction.errored = this._showOnFailurePopup;
114
- mumuki.kids.resultAction.pending = this._showOnFailurePopup;
115
- },
116
- _showOnSuccessPopup(data) {
117
- $('.submission-results').html(data.title_html);
118
- mumuki.kids._showOnSuccessPopup(data);
119
- $('#kids-results .modal-content').addClass(data.status);
120
- },
121
- _showOnFailurePopup(data) {
122
- mumuki.kids._getResultsAbortedModal().modal();
123
- $('#kids-results-aborted .modal-header').html(data.title_html);
124
- $('#kids-results-aborted .modal-content').addClass(data.status);
125
- mumuki.presenterCharacter.playAnimation('failure', mumuki.kids._getCharacterImage());
126
- }
127
25
  }
128
- };
129
26
 
130
- $(document).ready(() => {
27
+ // ================
28
+ // == Public API ==
29
+ // ================
30
+
31
+ showNonAbortedPopup(data, animation_name) {
32
+ this.$submissionResult.html(data.title_html);
33
+ this.$resultsModal.find('.modal-content').removeClass().addClass('modal-content kindergarten').addClass(data.status);
34
+ super.showNonAbortedPopup(data, animation_name);
35
+ }
36
+
37
+ showAbortedPopup(data) {
38
+ const $closeResultAbortedModalButton = new mumuki.Button(this.$resultsAbortedModal.find('.mu-close'));
39
+ $closeResultAbortedModalButton.setWaiting();
40
+ mumuki.presenterCharacter.playAnimation('failed', $('.mu-kids-character-result-aborted'));
41
+ super.showAbortedPopup(data);
42
+ setTimeout(() => $closeResultAbortedModalButton.enable(), 2500);
43
+ }
131
44
 
132
- if ($('.mu-kindergarten').get(0)) {
45
+ // ==================
46
+ // == Hook Methods ==
47
+ // ==================
133
48
 
134
- mumuki.resize(() => {
135
- mumuki.kids.scaleState($('.mu-kids-states'), 100);
136
- mumuki.kids.scaleBlocksArea($('.mu-kids-blocks'));
137
- })
49
+ _showSuccessPopup(data) {
50
+ this.showNonAbortedPopup(data, 'success2_l');
51
+ }
52
+
53
+ _showFailurePopup(data) {
54
+ this.showNonAbortedPopup(data, 'failure');
55
+ }
138
56
 
139
- mumuki.kindergarten.initialize()
57
+ // ====================
58
+ // == Event Callback ==
59
+ // ====================
140
60
 
61
+ onReady() {
62
+ mumuki.resize(this.onResize.bind(this));
141
63
  }
142
64
 
143
- })
65
+ onResize() {
66
+ this.scaleState(this.$states, 50);
67
+ this.scaleBlocksArea(this.$blocks);
68
+ }
69
+
70
+ // ==========================
71
+ // == Called by the runner ==
72
+ // ==========================
73
+
74
+ showResult(data) {
75
+ data.guide_finished_by_solution = false;
76
+ super.showResult(data);
77
+ }
78
+
79
+ restart() {
80
+ mumuki.presenterCharacter.playAnimation('talk', this.$bubbleCharacterAnimation);
81
+ }
82
+
83
+ // =======================
84
+ // == Specific Behavior ==
85
+ // =======================
86
+
87
+ get speech() {
88
+ return {
89
+ _isPlaying: false,
90
+ click(selector, locale) {
91
+ if (this._isPlaying) {
92
+ this.stop();
93
+ } else {
94
+ this.play(selector, locale);
95
+ }
96
+ },
97
+ play(selector, locale) {
98
+ const msg = new SpeechSynthesisUtterance();
99
+ msg.text = $(selector).text();
100
+ msg.lang = locale.split('_')[0];
101
+ msg.pitch = 0;
102
+ msg.onend = () => this.stop();
103
+ this._action('play', 'stop', true, (speech) => {
104
+ mumuki.presenterCharacter.playAnimation('talk', mumuki.kids.$bubbleCharacterAnimation);
105
+ speech.speak(msg);
106
+ })
107
+ },
108
+ stop() {
109
+ this._action('stop', 'play', false, (speech) => speech.cancel())
110
+ },
111
+ _action(add, remove, isPlaying, callback) {
112
+ callback(window.speechSynthesis);
113
+ const $button = $('.mu-kindergarten-play-description')
114
+ $button.find(`.mu-kindergarten-${add}`).addClass('hidden');
115
+ $button.find(`.mu-kindergarten-${remove}`).removeClass('hidden');
116
+ this._isPlaying = isPlaying;
117
+ },
118
+ verifyBrowserSupport() {
119
+ if (!window.speechSynthesis) {
120
+ const $button = $('.mu-kindergarten-play-description')
121
+ $button.prop('disabled', true);
122
+ $button.css('cursor', 'not-allowed');
123
+ this._action('play', 'stop', false)
124
+ }
125
+ }
126
+ }
127
+
128
+ }
129
+
130
+ get hint() {
131
+ return {
132
+ toggle() {
133
+ $('.mu-kindergarten-light-speech-bubble').toggleClass('open');
134
+ },
135
+ toggleMedia() {
136
+ const $hintMedia = $('.mu-kindergarten-hint-media');
137
+ const $i = $('.expand-or-collapse-hint-media').children('i');
138
+ $i.toggleClass('fa-caret-up').toggleClass('fa-caret-down');
139
+ $hintMedia.toggleClass('closed');
140
+ },
141
+ showOrHideExpandHintButton() {
142
+ const $button = $('.expand-or-collapse-hint-media');
143
+ const $hintMedia = $('.mu-kindergarten-hint-media');
144
+ if (!$hintMedia.get(0)) $button.addClass('hidden');
145
+ },
146
+ }
147
+ }
148
+
149
+ get context() {
150
+ return new mumuki.ModalCarrousel('.mu-kindergarten-context-image-slides', () => mumuki.kids.showContext());
151
+ }
152
+
153
+ }
154
+
155
+ if (mumuki.isKindergartenExercise()) {
156
+ mumuki.kids = new MumukiKindergarten();
157
+ }
144
158
 
145
159
  });
@@ -0,0 +1,63 @@
1
+ mumuki.ModalCarrousel = (() => {
2
+
3
+ class MuModalCarrousel {
4
+ constructor(containerSelector, onShow = () => {}) {
5
+ this.$container = $(containerSelector);
6
+ this.onShow = onShow;
7
+ }
8
+
9
+ show() {
10
+ this.onShow();
11
+ this._showFirstSlide();
12
+ }
13
+
14
+ nextSlide() {
15
+ this._clickButton('next');
16
+ }
17
+
18
+ prevSlide() {
19
+ this._clickButton('prev');
20
+ }
21
+
22
+ _activeSlide() {
23
+ return this.$container.find('.active');
24
+ }
25
+
26
+ _clickButton(prevOrNext) {
27
+ this._activeSlide().removeClass('active')[prevOrNext]().addClass('active');
28
+ this.showNextOrCloseButton();
29
+ this._hidePreviousButtonIfFirstSlide();
30
+ }
31
+
32
+ showNextOrCloseButton() {
33
+ const $next = $('.mu-kids-modal-button.mu-next');
34
+ const $close = $('.mu-kids-modal-button.mu-close');
35
+ const $footer = $('.modal-footer');
36
+ const isLastChild = this._activeSlide().is(':last-child');
37
+ this._addClassIf($next, 'hidden', () => isLastChild);
38
+ this._addClassIf($close, 'hidden', () => !isLastChild);
39
+ this._addClassIf($footer, 'hidden', () => !isLastChild);
40
+ }
41
+
42
+ _hidePreviousButtonIfFirstSlide() {
43
+ const $prev = $('.mu-kids-modal-button.mu-previous');
44
+ this._addClassIf($prev, 'hidden', () => this._activeSlide().is(':first-child'))
45
+ }
46
+
47
+ _showFirstSlide() {
48
+ this.$container.children().each((i, el) => this._addClassIf($(el), 'active', () => i === 0));
49
+ this.showNextOrCloseButton();
50
+ this._hidePreviousButtonIfFirstSlide();
51
+ }
52
+
53
+ _addClassIf(element, clazz, criteria) {
54
+ if (criteria()) {
55
+ element.addClass(clazz);
56
+ } else {
57
+ element.removeClass(clazz);
58
+ }
59
+ }
60
+ }
61
+
62
+ return MuModalCarrousel;
63
+ })();
@@ -0,0 +1,18 @@
1
+ mumuki.animateNumberCounter = (selector, valueTo, seconds = 1) => {
2
+ const $numberCounter = $(selector);
3
+
4
+ if ($numberCounter.text()) return;
5
+
6
+ const millis = seconds * 1000;
7
+ const incrementStep = valueTo / (millis / 10);
8
+
9
+ _increment();
10
+
11
+ function _increment(initValue = 0, delay = 10) {
12
+ if (initValue >= valueTo) return;
13
+ const nextValue = initValue + incrementStep;
14
+ // TODO: this one should be xp agnostic
15
+ $numberCounter.text(`+${Math.min(Math.round(nextValue), valueTo)}exp`);
16
+ setTimeout(() => _increment(nextValue), delay);
17
+ }
18
+ };
@@ -0,0 +1,258 @@
1
+ mumuki.load(() => {
2
+
3
+ mumuki.isPrimaryExercise = () => !!$('.mu-kids-exercise').get(0) && !$('.mu-kindergarten').get(0);
4
+
5
+ class MumukiPrimary extends mumuki.Kids {
6
+
7
+ constructor() {
8
+ super();
9
+ }
10
+
11
+ // ================
12
+ // == Public API ==
13
+ // ================
14
+
15
+ initialize() {
16
+ super.initialize();
17
+ this.$characterSpeechBubble = $('.mu-kids-character-speech-bubble');
18
+ this.$characterSpeechBubbleNormal = this.$characterSpeechBubble.children('.mu-kids-character-speech-bubble-normal');
19
+ this.$overlay = $('.mu-kids-overlay');
20
+ this.$contextModalButton = new mumuki.Button($('.mu-kids-context .modal-footer button'));
21
+
22
+ this._paragraphHeight = undefined;
23
+ this._currentParagraphIndex = 0;
24
+ this._paragraphCount = 1;
25
+ this._paragraphsLines = 2;
26
+ this._availableTabs = ['.description', '.hint'];
27
+ this._$speechParagraphs = undefined;
28
+ this._paragraphHeight = undefined;
29
+ this._scrollHeight = undefined;
30
+ this._nextSpeechBlinking = undefined;
31
+ this._$prevSpeech = $('.mu-kids-character-speech-bubble-normal > .mu-kids-prev-speech').hide();
32
+ this._$nextSpeech = $('.mu-kids-character-speech-bubble-normal > .mu-kids-next-speech');
33
+ this._$speechTabs = $('.mu-kids-character-speech-bubble-tabs > li:not(.separator)');
34
+ this._$texts = this.$characterSpeechBubbleNormal.children(this._availableTabs.join(", "));
35
+ this._$hint = $('.mu-kids-hint');
36
+ this._$description = $('.mu-kids-description');
37
+
38
+ this.resultActions.passed = this._showSuccessPopup.bind(this);
39
+ this.resultActions.passed_with_warnings = this._showOnCharacterBubble.bind(this);
40
+ this.resultActions.failed = this._showOnCharacterBubble.bind(this);
41
+ this.resultActions.errored = this._showOnCharacterBubble.bind(this);
42
+ this.resultActions.pending = this._showOnCharacterBubble.bind(this);
43
+ this.resultActions.aborted = this.showAbortedPopup.bind(this);
44
+
45
+ this.$contextModal.on('hidden.bs.modal', this.animateSpeech.bind(this));
46
+ }
47
+
48
+ showAbortedPopup(data) {
49
+ super.showAbortedPopup(data);
50
+ mumuki.submission.animateTimeoutError(this.submitButton);
51
+ }
52
+
53
+ // ==================
54
+ // == Hook Methods ==
55
+ // ==================
56
+
57
+ _showSuccessPopup(data) {
58
+ this.showNonAbortedPopup(data, 'success2_l', 4000);
59
+ }
60
+
61
+ _showFailurePopup(data) {
62
+ this._showOnCharacterBubble(data);
63
+ }
64
+
65
+ // ====================
66
+ // == Event Callback ==
67
+ // ====================
68
+
69
+ onReady() {
70
+ mumuki.resize(this.onResize.bind(this));
71
+
72
+ this._availableTabs.forEach((selector) => this._tabParagraphs(selector).contents().unwrap().wrapAll('<p>'));
73
+
74
+ this._updateSpeechParagraphs();
75
+ this._resizeSpeechParagraphs();
76
+
77
+ this._$speechTabs.each((i) => {
78
+ const $tab = $(this._$speechTabs[i]);
79
+ if ($tab.data('target')) {
80
+ $tab.click(() => {
81
+ this._$speechTabs.removeClass('active');
82
+ $tab.addClass('active');
83
+ this._$texts.hide();
84
+ this.$characterSpeechBubbleNormal.children('.' + $tab.data('target')).show();
85
+ this._updateSpeechParagraphs();
86
+ })
87
+ }
88
+ });
89
+
90
+ if (this._paragraphCount > 1) {
91
+ this._nextSpeechBlinking = mumuki.setInterval(() => this._$nextSpeech.fadeTo('slow', 0.1).fadeTo('slow', 1.0), 1000);
92
+ }
93
+
94
+ this._$nextSpeech.click(this._showNextParagraph.bind(this));
95
+ this._$prevSpeech.click(this._showPrevParagraph.bind(this));
96
+ this._$description.click(this.animateSpeech.bind(this));
97
+
98
+ this._$hint.click(() => {
99
+ this.animateHint();
100
+ this._$hint.removeClass('blink');
101
+ });
102
+ }
103
+
104
+ onResize() {
105
+ const FULL_MARGIN = 30;
106
+
107
+ distributeAreas(this.$stateImage, this.$states, this.$blocks, FULL_MARGIN);
108
+
109
+ if (!this.$exerciseDescription.hasClass('mu-kids-exercise-description-fixed')) {
110
+ this.$exerciseDescription.width(this.$exercise.width() - this.$states.width() - FULL_MARGIN / 2);
111
+ }
112
+
113
+ this.$state.each((_index, state) => this.scaleState($(state), FULL_MARGIN));
114
+ this.scaleBlocksArea(this.$blocks);
115
+
116
+ if (this._paragraphCount <= 1) clearInterval(this._nextSpeechBlinking);
117
+
118
+ this._updateSpeechParagraphs();
119
+ this._resizeSpeechParagraphs();
120
+ }
121
+
122
+ onNonAbortedPopupCall(data) {
123
+ this._showMessageOnCharacterBubble(data);
124
+ }
125
+
126
+ onSubmissionResultModalOpen(data) {
127
+ this._showCorollaryCharacter();
128
+ super.onSubmissionResultModalOpen(data);
129
+ }
130
+
131
+ // ==========================
132
+ // == Called by the runner ==
133
+ // ==========================
134
+
135
+ restart() {
136
+ this._hideMessageOnCharacterBubble();
137
+ const $bubble = this.$characterSpeechBubble;
138
+ Object.keys(this.resultActions).forEach($bubble.removeClass.bind($bubble));
139
+ mumuki.presenterCharacter.playAnimation('talk', this.$bubbleCharacterAnimation);
140
+ }
141
+
142
+ // =======================
143
+ // == Specific Behavior ==
144
+ // =======================
145
+
146
+ _hideMessageOnCharacterBubble() {
147
+ const $bubble = this.$characterSpeechBubble;
148
+ $bubble.find('.mu-kids-character-speech-bubble-tabs').show();
149
+ $bubble.find('.mu-kids-character-speech-bubble-normal').show();
150
+ $bubble.find('.mu-kids-character-speech-bubble-failed').hide();
151
+ $bubble.find('.mu-kids-discussion-link').remove();
152
+ Object.keys(this.resultActions).forEach($bubble.removeClass.bind($bubble));
153
+ this.$overlay.hide();
154
+ }
155
+
156
+ _showMessageOnCharacterBubble(data) {
157
+ const renderer = new mumuki.renderers.speechBubble.SpeechBubbleRenderer(this.$characterSpeechBubble);
158
+ renderer.setDiscussionsLinkHtml($('#mu-kids-discussion-link-html').html());
159
+ renderer.setResponseData(data);
160
+ renderer.render();
161
+ this.$overlay.show();
162
+ }
163
+
164
+ _showOnCharacterBubble(data) {
165
+ mumuki.presenterCharacter.playAnimation('failure', this.$bubbleCharacterAnimation);
166
+ this._showMessageOnCharacterBubble(data);
167
+ }
168
+
169
+ _showCorollaryCharacter() {
170
+ mumuki.characters.magnifying_glass.playAnimation('show', $('.mu-kids-corollary-animation'));
171
+ }
172
+
173
+ animateSpeech() {
174
+ mumuki.presenterCharacter.playAnimation('talk', this.$bubbleCharacterAnimation);
175
+ }
176
+
177
+ animateHint() {
178
+ mumuki.presenterCharacter.playAnimation('hint', this.$bubbleCharacterAnimation);
179
+ }
180
+
181
+ _showPrevParagraph() {
182
+ this.animateSpeech();
183
+ this._showParagraph(this._currentParagraphIndex - 1);
184
+ }
185
+
186
+ _showNextParagraph() {
187
+ this.animateSpeech();
188
+ this._showParagraph(this._currentParagraphIndex + 1);
189
+ clearInterval(this._nextSpeechBlinking);
190
+ }
191
+
192
+ _resizeSpeechParagraphs(paragraphIndex) {
193
+ const previousParagraphCount = this._paragraphCount;
194
+ this._scrollHeight = this.$characterSpeechBubbleNormal[0].scrollHeight;
195
+ this._paragraphHeight = floatFromPx(this._$speechParagraphs.css('line-height')) * this._paragraphsLines;
196
+ this._paragraphCount = Math.ceil(this._scrollHeight / this._paragraphHeight);
197
+ const newParagraphIndex = Math.floor((this._paragraphCount / previousParagraphCount) * this._currentParagraphIndex);
198
+ this._showParagraph(paragraphIndex || newParagraphIndex);
199
+ }
200
+
201
+ _showParagraph(index) {
202
+ this.$characterSpeechBubbleNormal[0].scrollTop = index * this._paragraphHeight;
203
+ this._currentParagraphIndex = index;
204
+ this._checkArrowsSpeechVisibility();
205
+ }
206
+
207
+ _checkArrowsSpeechVisibility() {
208
+ this._setVisibility(this._$prevSpeech, this._currentParagraphIndex !== 0);
209
+ this._setVisibility(this._$nextSpeech, this._currentParagraphIndex !== this._paragraphCount - 1);
210
+ }
211
+
212
+ _setVisibility(element, isVisible) {
213
+ isVisible ? element.show() : element.hide();
214
+ }
215
+
216
+ _tabParagraphs(selector) {
217
+ return $('.mu-kids-character-speech-bubble > .mu-kids-character-speech-bubble-normal > div' + selector + ' > p');
218
+ }
219
+
220
+ _updateSpeechParagraphs() {
221
+ this._$speechParagraphs = this._tabParagraphs('.' + this._getSelectedTabName());
222
+ this._resizeSpeechParagraphs(0);
223
+ }
224
+
225
+ _getSelectedTabName() {
226
+ return this._$speechTabs.filter('.active').data('target') || 'description';
227
+ }
228
+
229
+ }
230
+
231
+ /**
232
+ * Assigns propert widths to the states and blocks areas
233
+ * depending on the presence and type of available states
234
+ *
235
+ * @param {*} $muKidsStateImage
236
+ * @param {*} $muKidsStatesContainer
237
+ * @param {*} $muKidsBlocks
238
+ * @param {number} fullMargin
239
+ */
240
+ function distributeAreas($muKidsStateImage, $muKidsStatesContainer, $muKidsBlocks, fullMargin) {
241
+ if ($muKidsStateImage.children().length) {
242
+ const ratio = $muKidsStatesContainer.hasClass('mu-kids-single-state') ? 1 : 2;
243
+ $muKidsStatesContainer.width($muKidsStatesContainer.height() / ratio * 1.25 - fullMargin);
244
+ } else {
245
+ $muKidsStatesContainer.width(0);
246
+ $muKidsBlocks.width('100%');
247
+ }
248
+ }
249
+
250
+ function floatFromPx(value) {
251
+ return parseFloat(value.substring(0, value.length - 2));
252
+ }
253
+
254
+ if (mumuki.isPrimaryExercise()) {
255
+ mumuki.kids = new MumukiPrimary();
256
+ }
257
+
258
+ });