-
Notifications
You must be signed in to change notification settings - Fork 59
Implement tooltips/clarifications. #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
problem_builder/public/css/problem-builder-tinymce-content.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* Some styling to make clarifications stand out a bit in | ||
| studio HTML edit view. */ | ||
|
|
||
| .mce-content-body .pb-clarification { | ||
| color: #999; | ||
| font-size: 0.75em; | ||
| } | ||
|
|
||
| .mce-content-body .pb-clarification::before { | ||
| content: "(?)[" | ||
| } | ||
|
|
||
| .mce-content-body .pb-clarification::after { | ||
| content: "]" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| function QuestionnaireEdit(runtime, element) { | ||
| 'use strict'; | ||
| ProblemBuilderUtil.transformClarifications(element); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| window.ProblemBuilderUtil = { | ||
|
|
||
| transformClarifications: function(element) { | ||
| var $element = $(element); | ||
|
|
||
| var transformExisting = function(node) { | ||
| $('.pb-clarification', node).each(function() { | ||
| var item = $(this); | ||
| var content = item.html(); | ||
| var clarification = $( | ||
| '<span class="clarification" tabindex="0" role="note" aria-label="Clarification">' + | ||
| '<i data-tooltip-show-on-click="true" class="fa fa-info-circle" aria-hidden="true"></i>' + | ||
| '<span class="sr"></span>' + | ||
| '</span>' | ||
| ); | ||
| clarification.find('i').attr('data-tooltip', content); | ||
| clarification.find('span.sr').html(content); | ||
| item.empty().append(clarification); | ||
| }); | ||
| }; | ||
|
|
||
| // Transform all span.pb-clarifications already existing inside the element. | ||
| transformExisting($element); | ||
|
|
||
| // Transform all future span.pb-clarifications using mutation observer. | ||
| // It's only needed in the Studio when editing xblock children because the | ||
| // block's JS init function isn't called after edits in the Studio. | ||
| if (window.MutationObserver) { | ||
| var observer = new MutationObserver(function(mutations) { | ||
| mutations.forEach(function(mutation) { | ||
| Array.prototype.forEach.call(mutation.addedNodes, function(node) { | ||
| transformExisting(node); | ||
| }); | ||
| }) | ||
| }); | ||
| observer.observe($element[0], {childList: true, subtree: true}); | ||
| } | ||
| } | ||
|
|
||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| {% load i18n %} | ||
| <p>{{ question }}</p> | ||
| <p>{{ question|safe }}</p> | ||
|
|
||
| <h2>{% trans "Built-in choices:" %}</h2> | ||
|
|
||
| <ul> | ||
| <li>Choice (1): <strong>1 - {{ low }}</strong> ({{accepted_statuses.1}})</li> | ||
| <li>Choice (1): <strong>1 - {{ low|safe }}</strong> ({{accepted_statuses.1}})</li> | ||
| <li>Choice (2): <strong>2</strong> ({{accepted_statuses.2}})</li> | ||
| <li>Choice (3): <strong>3</strong> ({{accepted_statuses.3}})</li> | ||
| <li>Choice (4): <strong>4</strong> ({{accepted_statuses.4}})</li> | ||
| <li>Choice (5): <strong>5 - {{ high }}</strong> ({{accepted_statuses.5}})</li> | ||
| <li>Choice (5): <strong>5 - {{ high|safe }}</strong> ({{accepted_statuses.5}})</li> | ||
| </ul> | ||
|
|
||
| <h2>{% trans "Additional custom choices and tips:" %}</h2> |
110 changes: 110 additions & 0 deletions
110
problem_builder/tests/integration/test_clarifications.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (c) 2014-2015 Harvard, edX & OpenCraft | ||
| # | ||
| # This software's license gives you freedom; you can copy, convey, | ||
| # propagate, redistribute and/or modify this program under the terms of | ||
| # the GNU Affero General Public License (AGPL) as published by the Free | ||
| # Software Foundation (FSF), either version 3 of the License, or (at your | ||
| # option) any later version of the AGPL published by the FSF. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, but | ||
| # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero | ||
| # General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Affero General Public License | ||
| # along with this program in a file in the toplevel directory called | ||
| # "AGPLv3". If not, see <http://www.gnu.org/licenses/>. | ||
| # | ||
| """ | ||
| Test that <span class="pb-clarification"> elements are transformed into LMS-like tooltips. | ||
| """ | ||
|
|
||
| # Imports ########################################################### | ||
| import ddt | ||
| from cgi import escape | ||
| from xblockutils.base_test import SeleniumXBlockTest | ||
|
|
||
|
|
||
| # Classes ########################################################### | ||
|
|
||
|
|
||
| @ddt.ddt | ||
| class ClarificationTest(SeleniumXBlockTest): | ||
| """ | ||
| Test that the content of span.pb-clarification elements is transformed into | ||
| tooltip elements. | ||
| """ | ||
|
|
||
| clarification_text = 'Let me clarify...' | ||
|
|
||
| mcq_template = """ | ||
| <problem-builder> | ||
| <pb-mcq question="Who was your favorite character? {clarify_escaped}"> | ||
| <pb-choice value="gaius">Gaius Baltar</pb-choice> | ||
| <pb-choice value="adama">Admiral William Adama {clarify}</pb-choice> | ||
| <pb-choice value="starbuck">Starbuck</pb-choice> | ||
| </pb-mcq> | ||
| </problem-builder> | ||
| """ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want, you can put these templates into the |
||
|
|
||
| mrq_template = """ | ||
| <problem-builder> | ||
| <pb-mrq question="What makes a great {clarify_escaped} MRQ {clarify_escaped}?"> | ||
| <pb-choice value="1">Lots of choices</pb-choice> | ||
| <pb-choice value="2">Funny{clarify} choices</pb-choice> | ||
| <pb-choice value="3">Not sure {clarify}</pb-choice> | ||
| </pb-mrq> | ||
| </problem-builder> | ||
| """ | ||
|
|
||
| rating_template = """ | ||
| <problem-builder> | ||
| <pb-rating name="rating_1_1" question="How do you rate {clarify_escaped} Battlestar Galactica?"> | ||
| <pb-choice value="6">More than 5 stars {clarify}</pb-choice> | ||
| </pb-rating> | ||
| </problem-builder> | ||
| """ | ||
|
|
||
| long_answer_template = """ | ||
| <problem-builder> | ||
| <pb-answer question="What did you think {clarify_escaped} of the ending?" /> | ||
| </problem-builder> | ||
| """ | ||
|
|
||
| html_block_template = """ | ||
| <problem-builder> | ||
| <html_demo><p>This is some raw {clarify} HTML code.</p></html_demo> | ||
| </problem-builder> | ||
| """ | ||
|
|
||
| def prepare_xml_scenario(self, xml_template): | ||
| span = '<span class="pb-clarification">{}</span>'.format(self.clarification_text) | ||
| escaped_span = escape(span, quote=True) | ||
| return xml_template.format( | ||
| clarify=span, | ||
| clarify_escaped=escaped_span | ||
| ) | ||
|
|
||
| @ddt.data( | ||
| (mcq_template, 2), | ||
| (mrq_template, 4), | ||
| (rating_template, 2), | ||
| (long_answer_template, 1), | ||
| (html_block_template, 1), | ||
| ) | ||
| @ddt.unpack | ||
| def test_title(self, xml_template, tooltip_count): | ||
| self.set_scenario_xml(self.prepare_xml_scenario(xml_template)) | ||
| pb_element = self.go_to_view() | ||
| clarifications = pb_element.find_elements_by_css_selector('span.pb-clarification') | ||
|
|
||
| self.assertEqual(len(clarifications), tooltip_count) | ||
|
|
||
| for clarification in clarifications: | ||
| tooltip = clarification.find_element_by_css_selector('i[data-tooltip]') | ||
| self.assertEqual(tooltip.get_attribute('data-tooltip'), self.clarification_text) | ||
|
|
||
| sr = clarification.find_element_by_css_selector('span.sr') | ||
| self.assertEqual(sr.text, self.clarification_text) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be combined with
mentoring.css? Mentoring.css should really be renamed toproblem_builder.csssince it applies to the block as a whole. This would be a good opportunity to do so, and would reduce the number of separate CSS/JS files we are sending to the browser.Also nit: missing newline at EOF
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bradenmacdonald That's a good idea, I moved the CSS rules into
mentoring.cssand renamed it toproblem_builder.css.