Skip to content
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

Feature/ms 447/scorer highlight plugin #101

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

AnastasiaArcadia
Copy link
Contributor

Pull request summary

Related to MS-447.

Scorer's Highlight plugin

How to test

On MS side:

  • Login as a scorer
  • Go to the task page
  • Click on the highlighter icon button
  • Select some text, click on the color button - text should be highlighted
  • Click on the eraser button - highlights should be cleared

views/js/previewer/plugins/content/highlighter.js Outdated Show resolved Hide resolved
views/js/previewer/plugins/content/highlighter.js Outdated Show resolved Hide resolved
views/js/previewer/plugins/content/highlighter.js Outdated Show resolved Hide resolved
function highlight(highlighter, selection) {
highlighter.highlightRanges(getAllRanges(selection));
//Sending the highlighIndex to parent so that it can be saved on MS side
parent.postMessage({ event: 'indexUpdated', payload: highlighter.getHighlightIndex() }, '*');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passing * is not a very good practice, as we know the target where we want the message to be sent we should use that, the only problem is we are not storing it in tao so IDK how and where we should store this info in tao. Failing to provide a specific target discloses the data you send to any interested malicious site.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Indeed, this might be a flaw.

suggestion: We use to have iframe by the past, and we have a legacy component to post message to a parent window: iframNotifier.
A property must be set by the parent to make the iframe elligible to communication.
However, I'm wondering if this module is not deprecated.
Even if you cannot control the parent window, couldn't you still declare a valid context from the config?

nitpick: Moreover, please always use window to namespace global context objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, seems like iframNotifier doesn't work with cross-origin, hasAccess doesn't pass
https://github.com/oat-sa/tao-core-libs-fe/blob/06905acf3ca51d67c54e474fc59806c4172264fc/src/iframeNotifier.js#L22

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. The iframeNotifier is meant to be used with fully controlled parents. If you use different domain names and servers it won't work. Moreover, I don't know if this module is still usable.

The overall idea is to secur the messaging, preventing the window to communicate with untrusted wrappers.

views/js/previewer/plugins/content/highlighter.js Outdated Show resolved Hide resolved
views/js/previewer/plugins/content/highlighter.js Outdated Show resolved Hide resolved
views/js/previewer/plugins/content/highlighter.js Outdated Show resolved Hide resolved
@@ -13,7 +13,7 @@
$previewFrameShadow: rgba(0, 0, 0, .7);

width: 100%;
height: 100%;
padding-top: 3rem;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to touch the scale plugin? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: Indeed, please be careful with the scale plugin, especially with its style. It might introduce regressions as it is very sensible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I have scroll bars for .devices-previewer - height: 100%; when the highlighter element is added to .content-wrapper 😔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add display: flex; flex-direction: column; to .content-wrapper or it will break something, WDYT?

Copy link
Contributor

@jsconan jsconan Oct 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is hard to tell. AFAIR the devicesPreviewer plugin was a pain to make working on every browsers.
But the isn't .content-wrapper used in other places? If you target it, you must ensure it will only apply for the previewer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like .item-previewer-scope -> .content-wrapper is used only here

Copy link
Contributor

@jsconan jsconan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review only.
A few remarks, but the overall look good. GJ!

@@ -13,7 +13,7 @@
$previewFrameShadow: rgba(0, 0, 0, .7);

width: 100%;
height: 100%;
padding-top: 3rem;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: Indeed, please be careful with the scale plugin, especially with its style. It might introduce regressions as it is very sensible.

views/js/previewer/component/qtiItem.js Outdated Show resolved Hide resolved
function highlight(highlighter, selection) {
highlighter.highlightRanges(getAllRanges(selection));
//Sending the highlighIndex to parent so that it can be saved on MS side
parent.postMessage({ event: 'indexUpdated', payload: highlighter.getHighlightIndex() }, '*');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Indeed, this might be a flaw.

suggestion: We use to have iframe by the past, and we have a legacy component to post message to a parent window: iframNotifier.
A property must be set by the parent to make the iframe elligible to communication.
However, I'm wondering if this module is not deprecated.
Even if you cannot control the parent window, couldn't you still declare a valid context from the config?

nitpick: Moreover, please always use window to namespace global context objects.

views/js/previewer/plugins/content/highlighter.js Outdated Show resolved Hide resolved
//hide highlighter menu by default
hider.hide(this.$highlighterTray);

testRunner.after('renderitem', function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: A namespace should be used here. So that you can unregister the handler upon destroy.

@AnastasiaArcadia AnastasiaArcadia changed the base branch from master to develop October 19, 2020 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants