mumuki-laboratory 5.8.1 → 5.8.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87600d3445c8ae5dbea2faf628e69b2a638fcdd826e8e8aaa051fb2bd3926a18
4
- data.tar.gz: 10ba9a35ee5077f52af13797f42029f374d1495218708c8b55255a92ee3b886a
3
+ metadata.gz: 625ae660ff8299245d10e105830ddcf35e14a1700f36ecad6d338cbd0bee64bd
4
+ data.tar.gz: 43691be79aa7d382429e9443ed0727c19ded873284baab6c1ad8f8c9232d09b7
5
5
  SHA512:
6
- metadata.gz: 1e2051b926a10132b983dcc66382d7ee4615c3d88a1e30921bf25ab7283548428e5adc7833641aa413034db29f74fb3c7d64c4caaf69b2ab12441950f2d8e12b
7
- data.tar.gz: ef2059b7ebb09484296395183f2bf3b7b866a79ce794a776dd8b8e517db2da9545b4a3b92ca504682b5f38a9e66854cc76f21a9bb8b964748c7129889c841b03
6
+ metadata.gz: ca3b02948675b7bf146dac98f74ba891ecfb6feb979853b52d7bbce804a34b350278677beac6a782d79b8399a737e9243bfcca8cb0dde1128e7f966811ad1abe
7
+ data.tar.gz: bcb56b9bbac91d7600e69502432d6d176ffff4783a7c80c809a54606d8faceb56a49e232765fdd29fb18f9c52d6a1425ba73a64cf329210b2b188b0c029fc7f0
@@ -1,58 +1,47 @@
1
1
  mumuki.load(function () {
2
+ var $bubble = $('.mu-kids-character-speech-bubble').children('.mu-kids-character-speech-bubble-normal');
3
+ if(!$bubble.length) return;
2
4
 
3
- mumuki.resize(function () {
4
- var margin = 15;
5
- var fullMargin = margin * 2;
6
-
7
- var gbsBoard = $('.mu-kids-state');
8
-
9
- var dimension = gbsBoard.height() * 1.25 - fullMargin;
10
- gbsBoard.width(dimension);
11
-
12
- var $muKidsExercise = $('.mu-kids-exercise');
13
- var $muKidsExerciseDescription = $('.mu-kids-exercise-description');
14
-
15
- $muKidsExerciseDescription.width($muKidsExercise.width() - gbsBoard.width() - margin);
16
-
17
- gbsBoard.each(function (i) {
18
- gsBoardScale($(gbsBoard[i]));
19
- });
20
-
21
- var $muKidsBlocks = $('.mu-kids-blocks');
22
- var $blockArea = $muKidsBlocks.find('#blocklyDiv');
23
- var $blockSvg = $muKidsBlocks.find('.blocklySvg');
24
-
25
- $blockArea.width($muKidsBlocks.width());
26
- $blockArea.height($muKidsBlocks.height());
27
-
28
- $blockSvg.width($muKidsBlocks.width());
29
- $blockSvg.height($muKidsBlocks.height());
30
-
31
- function gsBoardScale($element) {
32
- var $table = $element.find('gs-board > table');
33
- $table.css('transform', 'scale(1)');
34
- var scaleX = ($element.width() - fullMargin * 2) / $table.width();
35
- var scaleY = ($element.height() - fullMargin * 2) / $table.height();
36
- $table.css('transform', 'scale(' + Math.min(scaleX, scaleY) + ')');
37
- }
38
-
39
- });
40
-
41
- var $speechParagraphs;
5
+ var availableTabs = ['.description', '.hint'];
6
+ var $speechParagraphs, paragraphHeight, scrollHeight;
42
7
  var currentParagraphIndex = 0;
8
+ var paragraphCount = 1;
9
+ var paragraphsLines = 2;
43
10
  var $prevSpeech = $('.mu-kids-character-speech-bubble-normal > .mu-kids-prev-speech').hide();
44
11
  var $nextSpeech = $('.mu-kids-character-speech-bubble-normal > .mu-kids-next-speech');
45
12
  var $speechTabs = $('.mu-kids-character-speech-bubble-tabs > li:not(.separator)');
46
13
  var $defaultSpeechTabName = 'description';
47
- var $bubble = $('.mu-kids-character-speech-bubble').children('.mu-kids-character-speech-bubble-normal');
48
- var $texts = $bubble.children('.description, .hint');
14
+ var $texts = $bubble.children(availableTabs.join(", "));
15
+
16
+ function floatFromPx(value) {
17
+ return parseFloat(value.substring(0, value.length - 2));
18
+ }
19
+
20
+ function resizeSpeechParagraphs(paragraphIndex) {
21
+ var previousParagraphCount = paragraphCount;
22
+ scrollHeight = $bubble[0].scrollHeight;
23
+ paragraphHeight = floatFromPx($speechParagraphs.css('line-height')) * paragraphsLines;
24
+ paragraphCount = Math.ceil(scrollHeight / paragraphHeight);
25
+ var newParagraphIndex = Math.floor((paragraphCount / previousParagraphCount) * currentParagraphIndex);
26
+ showParagraph(paragraphIndex || newParagraphIndex);
27
+ }
28
+
29
+ availableTabs.forEach(function (tabSelector) {
30
+ tabParagraphs(tabSelector).contents().unwrap().wrapAll('<p>');
31
+ });
32
+
33
+ function tabParagraphs(selector) {
34
+ return $('.mu-kids-character-speech-bubble > .mu-kids-character-speech-bubble-normal > div' + selector + ' > p');
35
+ }
49
36
 
50
37
  updateSpeechParagraphs();
51
38
  function updateSpeechParagraphs() {
52
- $speechParagraphs = $('.mu-kids-character-speech-bubble > .mu-kids-character-speech-bubble-normal > div.' + getSelectedTabName() + ' > p');
53
- showParagraph(0);
39
+ $speechParagraphs = tabParagraphs('.' + getSelectedTabName());
40
+ resizeSpeechParagraphs(0);
54
41
  }
55
42
 
43
+ resizeSpeechParagraphs();
44
+
56
45
  $speechTabs.each(function (i) {
57
46
  var $tab = $($speechTabs[i]);
58
47
  $tab.click(function () {
@@ -60,48 +49,75 @@ mumuki.load(function () {
60
49
  $tab.addClass('active');
61
50
  $texts.hide();
62
51
  $bubble.children('.' + $tab.data('target')).show();
63
- $bubble.scroll(0);
64
- hideCurrentParagraph();
65
52
  updateSpeechParagraphs();
66
53
  })
67
54
  });
68
55
 
69
56
  $nextSpeech.click(function () {
70
- hideCurrentParagraph();
71
- showNextParagraph();
57
+ showParagraph(currentParagraphIndex + 1);
72
58
  });
59
+
73
60
  $prevSpeech.click(function () {
74
- hideCurrentParagraph();
75
- showPrevParagraph();
61
+ showParagraph(currentParagraphIndex - 1);
76
62
  });
77
63
 
78
64
  function getSelectedTabName() {
79
65
  return $speechTabs.filter(".active").data('target') || $defaultSpeechTabName;
80
66
  }
81
67
 
82
- function hideCurrentParagraph() {
83
- $($speechParagraphs[currentParagraphIndex]).hide();
68
+ function showParagraph(index) {
69
+ $bubble[0].scrollTop = index * paragraphHeight;
70
+ currentParagraphIndex = index;
71
+ checkArrowsSpeechVisibility();
84
72
  }
85
73
 
86
- function showPrevParagraph() {
87
- showParagraph(currentParagraphIndex - 1);
74
+ function checkArrowsSpeechVisibility() {
75
+ setVisibility($prevSpeech, currentParagraphIndex !== 0);
76
+ setVisibility($nextSpeech, currentParagraphIndex !== paragraphCount - 1);
88
77
  }
89
78
 
90
- function showNextParagraph() {
91
- showParagraph(currentParagraphIndex + 1);
79
+ function setVisibility(element, isVisible) {
80
+ isVisible ? element.show() : element.hide();
92
81
  }
93
82
 
94
- function showParagraph(index) {
95
- $($speechParagraphs[index]).show();
96
- setVisibility($prevSpeech, index !== 0);
97
- setVisibility($nextSpeech, index !== $speechParagraphs.length - 1);
83
+ mumuki.resize(function () {
84
+ var margin = 15;
85
+ var fullMargin = margin * 2;
98
86
 
99
- currentParagraphIndex = index;
100
- }
87
+ var gbsBoard = $('.mu-kids-state');
101
88
 
102
- function setVisibility(element, isVisible) {
103
- if (isVisible) element.show(); else element.hide();
104
- }
89
+ var dimension = gbsBoard.height() * 1.25 - fullMargin;
90
+ gbsBoard.width(dimension);
91
+
92
+ var $muKidsExercise = $('.mu-kids-exercise');
93
+ var $muKidsExerciseDescription = $('.mu-kids-exercise-description');
94
+
95
+ $muKidsExerciseDescription.width($muKidsExercise.width() - gbsBoard.width() - margin);
96
+
97
+ gbsBoard.each(function (i) {
98
+ gsBoardScale($(gbsBoard[i]));
99
+ });
100
+
101
+ var $muKidsBlocks = $('.mu-kids-blocks');
102
+ var $blockArea = $muKidsBlocks.find('#blocklyDiv');
103
+ var $blockSvg = $muKidsBlocks.find('.blocklySvg');
104
+
105
+ $blockArea.width($muKidsBlocks.width());
106
+ $blockArea.height($muKidsBlocks.height());
107
+
108
+ $blockSvg.width($muKidsBlocks.width());
109
+ $blockSvg.height($muKidsBlocks.height());
110
+
111
+ function gsBoardScale($element) {
112
+ var $table = $element.find('gs-board > table');
113
+ $table.css('transform', 'scale(1)');
114
+ var scaleX = ($element.width() - fullMargin * 2) / $table.width();
115
+ var scaleY = ($element.height() - fullMargin * 2) / $table.height();
116
+ $table.css('transform', 'scale(' + Math.min(scaleX, scaleY) + ')');
117
+ }
118
+
119
+ resizeSpeechParagraphs();
120
+ });
105
121
 
106
122
  mumuki.kids = {
107
123
 
@@ -1,7 +1,7 @@
1
1
  module BreadcrumbsHelper
2
2
 
3
3
  def breadcrumbs(e, extra=nil)
4
- breadcrumbs0(e, extra, 'last')
4
+ breadcrumbs0(e.navigable_name, e, extra, 'last')
5
5
  end
6
6
 
7
7
  def home_breadcrumb
@@ -17,9 +17,7 @@ module BreadcrumbsHelper
17
17
  end
18
18
 
19
19
  def breadcrumb_item_class(last)
20
- <<HTML
21
- class='mu-breadcrumb-list-item #{last}'
22
- HTML
20
+ "class='mu-breadcrumb-list-item #{last}'"
23
21
  end
24
22
 
25
23
  def breadcrumb_list_item(last, item)
@@ -28,14 +26,17 @@ HTML
28
26
 
29
27
  private
30
28
 
31
- def breadcrumbs0(e, extra=nil, last='')
32
- return "#{breadcrumbs0(e)} #{breadcrumb_list_item(last, extra)}".html_safe if extra
29
+ def breadcrumbs_for_linkable(e, extra=nil, last='')
30
+ breadcrumbs0(link_to_path_element(e), e, extra, last)
31
+ end
32
+
33
+ def breadcrumbs0(base, e, extra, last)
34
+ return "#{breadcrumbs_for_linkable(e)} #{breadcrumb_list_item(last, extra)}".html_safe if extra
33
35
 
34
- base = link_to_path_element e
35
36
  if e.navigation_end?
36
37
  "#{home_breadcrumb} #{breadcrumb_list_item(last, base)}".html_safe
37
38
  else
38
- "#{breadcrumbs0(e.navigable_parent)} #{breadcrumb_list_item(last, base)}".html_safe
39
+ "#{breadcrumbs_for_linkable(e.navigable_parent)} #{breadcrumb_list_item(last, base)}".html_safe
39
40
  end
40
41
  end
41
42
  end
@@ -1,5 +1,5 @@
1
1
  <%= content_for :breadcrumbs do %>
2
- <%= breadcrumbs @chapter, link_to(t(:appendix), chapter_appendix_path(@chapter)) %>
2
+ <%= breadcrumbs @chapter, t(:appendix) %>
3
3
  <% end %>
4
4
 
5
5
  <h1><%= t :appendix %></h1>
@@ -1,5 +1,5 @@
1
1
  <%= content_for :breadcrumbs do %>
2
- <%= breadcrumbs0 @debatable, link_to(t(:discussions), item_discussions_path(@debatable))%>
2
+ <%= breadcrumbs_for_linkable @debatable, link_to(t(:discussions), item_discussions_path(@debatable))%>
3
3
  <%= breadcrumb_list_item('last', @discussion.friendly.truncate_words(4)) %>
4
4
  <% end %>
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Laboratory
3
- VERSION = '5.8.1'
3
+ VERSION = '5.8.3'
4
4
  end
5
5
  end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe BreadcrumbsHelper, organization_workspace: :test do
4
+
5
+ helper BreadcrumbsHelper
6
+ helper LinksHelper
7
+
8
+
9
+ context 'user' do
10
+ let(:user) { create(:user) }
11
+ let(:breadcrumb) { breadcrumbs(user) }
12
+
13
+ it { expect(breadcrumb).to include "<li class='mu-breadcrumb-list-item last'>#{user.name}</li>" }
14
+ end
15
+
16
+ context 'exercise' do
17
+ let(:breadcrumb) { breadcrumbs(exercise) }
18
+
19
+ context 'exercise in complement' do
20
+ let!(:complement) { create(:complement, name: 'my guide', exercises: [
21
+ create(:exercise, name: 'my exercise')
22
+ ]) }
23
+ let(:exercise) { complement.exercises.first }
24
+
25
+ before { reindex_current_organization! }
26
+
27
+ it { expect(breadcrumb).to include('my exercise') }
28
+ it { expect(breadcrumb).to include('my guide') }
29
+ it { expect(breadcrumb).to be_html_safe }
30
+
31
+ it { expect(breadcrumb).to include "<a href=\"/complements/#{complement.id}-my-guide\">my guide</a>" }
32
+ it { expect(breadcrumb).to include "<li class='mu-breadcrumb-list-item last'>1. my exercise</li>" }
33
+ end
34
+
35
+ context 'exercise in chapter' do
36
+ let!(:chapter) { create(:chapter, name: 'my chapter', lessons: [lesson]) }
37
+ let(:lesson) { create(:lesson, name: 'my lesson', exercises: [exercise]) }
38
+ let(:exercise) { create(:exercise, name: 'my exercise') }
39
+
40
+ before { reindex_current_organization! }
41
+
42
+ it { expect(breadcrumb).to include('my exercise') }
43
+ it { expect(breadcrumb).to include('my lesson') }
44
+ it { expect(breadcrumb).to include('my chapter') }
45
+ it { expect(breadcrumb).to be_html_safe }
46
+
47
+ it { expect(breadcrumb).to include "<a href=\"/chapters/#{chapter.id}-my-chapter\">my chapter</a>" }
48
+ it { expect(breadcrumb).to include "<a href=\"/lessons/#{lesson.id}-my-chapter-my-lesson\">1. my lesson</a>" }
49
+ it { expect(breadcrumb).to include "<li class='mu-breadcrumb-list-item last'>1. my exercise</li>" }
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumuki-laboratory
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.8.1
4
+ version: 5.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Bulgarelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-24 00:00:00.000000000 Z
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -962,11 +962,11 @@ files:
962
962
  - spec/features/progressive_tips_spec.rb
963
963
  - spec/features/standard_flow_spec.rb
964
964
  - spec/helpers/application_helper_spec.rb
965
+ - spec/helpers/breadcrumbs_helper_spec.rb
965
966
  - spec/helpers/email_helper_spec.rb
966
967
  - spec/helpers/exercise_input_helper_spec.rb
967
968
  - spec/helpers/icons_helper_spec.rb
968
969
  - spec/helpers/test_results_rendering_spec.rb
969
- - spec/helpers/with_breadcrumbs_spec.rb
970
970
  - spec/helpers/with_choices_spec.rb
971
971
  - spec/helpers/with_navigation_spec.rb
972
972
  - spec/mailers/previews/user_mailer_preview.rb
@@ -1147,11 +1147,11 @@ test_files:
1147
1147
  - spec/features/progressive_tips_spec.rb
1148
1148
  - spec/features/standard_flow_spec.rb
1149
1149
  - spec/helpers/application_helper_spec.rb
1150
+ - spec/helpers/breadcrumbs_helper_spec.rb
1150
1151
  - spec/helpers/email_helper_spec.rb
1151
1152
  - spec/helpers/exercise_input_helper_spec.rb
1152
1153
  - spec/helpers/icons_helper_spec.rb
1153
1154
  - spec/helpers/test_results_rendering_spec.rb
1154
- - spec/helpers/with_breadcrumbs_spec.rb
1155
1155
  - spec/helpers/with_choices_spec.rb
1156
1156
  - spec/helpers/with_navigation_spec.rb
1157
1157
  - spec/mailers/previews/user_mailer_preview.rb
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe BreadcrumbsHelper, organization_workspace: :test do
4
-
5
- helper BreadcrumbsHelper
6
- helper LinksHelper
7
-
8
- let(:breadcrumb) { breadcrumbs(exercise) }
9
-
10
- context 'exercise in complement' do
11
- let!(:complement) { create(:complement, name: 'my guide', exercises: [
12
- create(:exercise, name: 'my exercise')
13
- ]) }
14
- let(:exercise) { complement.exercises.first }
15
-
16
- before { reindex_current_organization! }
17
-
18
- it { expect(breadcrumb).to include('my exercise') }
19
- it { expect(breadcrumb).to include('my guide') }
20
- it { expect(breadcrumb).to be_html_safe }
21
- end
22
-
23
- context 'exercise in chapter' do
24
- let!(:chapter) { create(:chapter, name: 'my chapter', lessons: [
25
- create(:lesson, name: 'my lesson', exercises: [
26
- create(:exercise, name: 'my exercise')
27
- ])
28
- ]) }
29
- let(:exercise) { chapter.first_lesson.exercises.first }
30
-
31
- before { reindex_current_organization! }
32
-
33
- it { expect(breadcrumb).to include('my exercise') }
34
- it { expect(breadcrumb).to include('my lesson') }
35
- it { expect(breadcrumb).to include('my chapter') }
36
- it { expect(breadcrumb).to be_html_safe }
37
- end
38
- end