-
Notifications
You must be signed in to change notification settings - Fork 25
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
Fix in-video quiz question issues with display, sizing, and alignment #11
Fix in-video quiz question issues with display, sizing, and alignment #11
Conversation
@stvstnfrd @caesar2164 Let me know if any changes need to be made here. These changes solve the problem, but I'm aware they're inelegant/inefficient; I'll continue looking for an event I could listen for to detect a fullscreen change instead of checking every 200 milliseconds. |
Changes Unknown when pulling 438be6b on karandikar:fix-in-video-quiz into ** on Stanford-Online:master**. |
knownVideoPosition = $('.tc-wrapper', video).position().top; | ||
knownVideoHeight = $('.tc-wrapper', video).css('height'); | ||
knownVideoWidth = $('.tc-wrapper', video).css('width'); | ||
} |
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.
function getVideoDimensions() {
var videoPosition = $('.tc-wrapper', video).position().top;
var videoHeight = $('.tc-wrapper', video).css('height');
var videoWidth = $('.tc-wrapper', video).css('width');
return [videoPosition, videoHeight, videoWidth];
}
var knownVideoDimensions = getVideoDimensions();
// both our known size measurements and the size of the problem | ||
currentVideoPosition = $('.tc-wrapper', video).position().top; | ||
currentVideoHeight = $('.tc-wrapper', video).css('height'); | ||
currentVideoWidth = $('.tc-wrapper', video).css('width'); |
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.
define these with the function commented above!
@caesar2164 Fixed, let me know if anything else needs to change! |
@@ -25,6 +31,7 @@ function InVideoQuizXBlock(runtime, element) { | |||
|
|||
if (studentMode) { | |||
setUpStudentView(component); | |||
setUpVideoDimensions(); |
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.
let's just make this:
knownVideoDimensions = getVideoDimensions();
|
||
function setUpVideoDimensions() { | ||
knownVideoDimensions = getVideoDimensions(); | ||
} |
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.
let's delete this function
if ((currentVideoDimensions[0] !== knownVideoDimensions[0]) || | ||
(currentVideoDimensions[1] !== knownVideoDimensions[1]) || | ||
(currentVideoDimensions[2] !== knownVideoDimensions[2])) { | ||
resizeInVideoProblem(problemToDisplay, video); |
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.
let's pass currentVideoDimensions
as the third value to this function
ie:
resizeInVideoProblem(problemToDisplay, video, currentVideoDimensions);
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.
rewrite:
resizeInVideoProblem(problemToDisplay, currentVideoDimensions);
@@ -61,14 +79,22 @@ function InVideoQuizXBlock(runtime, element) { | |||
} | |||
}); | |||
} | |||
|
|||
function resizeInVideoProblem(currentProblem, currentVideo) { | |||
videoDimensions = getVideoDimensions(); |
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.
let's have this function take a third var for the videoDimensions
ie:
function resizeInVideoProblem(currentProblem, currentVideo, videoDimensions) {
and then we can just delete this line.
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.
Actually why do we even pass currentVideo
?
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.
better rewrite:
function resizeInVideoProblem(currentProblem, videoDimensions) {
|
||
function resizeInVideoProblem(currentProblem, currentVideo) { | ||
videoDimensions = getVideoDimensions(); | ||
currentProblem.css({top: videoDimensions[0], height: videoDimensions[1], width: videoDimensions[2]}); |
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.
just a quick readability cleanup:
currentProblem.css({
top: videoDimensions[0],
height: videoDimensions[1],
width: videoDimensions[2]
});
@@ -87,7 +113,9 @@ function InVideoQuizXBlock(runtime, element) { | |||
if (isProblemToDisplay) { | |||
problemToDisplay = $('.xblock-student_view', this) | |||
videoState.videoPlayer.pause(); | |||
resizeInVideoProblem(problemToDisplay, video); |
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.
as a consequence of changing the resizeInVideoProblem
function let's make this read:
resizeInVideoProblem(problemToDisplay, video, knownVideoDimensions);
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.
rewrite:
resizeInVideoProblem(problemToDisplay, knownVideoDimensions);
Changes Unknown when pulling d8c4310 on karandikar:fix-in-video-quiz into ** on Stanford-Online:master**. |
d8c4310
to
d191939
Compare
@caesar2164 Made the necessary edits! Let me know what you think |
Changes Unknown when pulling d191939 on karandikar:fix-in-video-quiz into ** on Stanford-Online:master**. |
videoWidth = $('.tc-wrapper', video).css('width'); | ||
return [videoPosition, videoHeight, videoWidth]; | ||
} | ||
|
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.
let's add a videoDimensionsDiffer()
function like so:
function videoDimensionsDiffer(currentVideoDimensions, knownVideoDimensions) {
if (currentVideoDimensions.length !== knownVideoDimensions.length) {
return true;
}
for (var i = 0, i < knownVideoDimensions.length, i++) {
if (knownVideoDimensions[i] !== currentVideoDimensions[i]) {
return true;
}
}
return false;
}
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.
@caesar2164 done!
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.
awesome
// both our known size measurements and the size of the problem | ||
currentVideoDimensions = getVideoDimensions(); | ||
|
||
if ((currentVideoDimensions[0] !== knownVideoDimensions[0]) || |
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.
this conditional can now be:
if (videoDimensionsDiffer(currentVideoDimensions, knownVideoDimensions)) {
...
}
Changes Unknown when pulling 55976e2 on karandikar:fix-in-video-quiz into ** on Stanford-Online:master**. |
// Interval at which to check if video size has changed size | ||
// and the displayed problems needs to do the same | ||
var resizeIntervalTime = 100; | ||
|
||
// Interval at which to check for problems to display | ||
// Checking every 0.5 seconds to make sure we check at least once per actual second of video | ||
var intervalTime = 500; |
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.
lets rename this variable, now that we have multiple intervals...
resizeIntervalObject = setInterval(function () { | ||
|
||
// check if the size has changed from the previous state; if so, update | ||
// both our known size measurements and the size of the problem |
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.
this comment can probably go away now that the code is easier to read...
Changes Unknown when pulling e95f268 on karandikar:fix-in-video-quiz into ** on Stanford-Online:master**. |
@@ -50,6 +57,25 @@ function InVideoQuizXBlock(runtime, element) { | |||
} |
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.
Doh, I missed this before, lets move this to here, so it only gets done once...
if (studentMode) {
knownVideoDimensions = getVideoDimensions();
}
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.
thanks!
|
||
$(function () { | ||
$('#seq_content .vert-mod .vert').each(function () { | ||
var component = $(this); | ||
|
||
if (studentMode) { | ||
setUpStudentView(component); | ||
knownVideoDimensions = getVideoDimensions(); |
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.
move down to location of other comment.
Changes Unknown when pulling 04fa075 on karandikar:fix-in-video-quiz into ** on Stanford-Online:master**. |
return [videoPosition, videoHeight, videoWidth]; | ||
} | ||
|
||
function videoDimensionsDiffer(newMeasurement, oldMeasurement) { |
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.
looks great!
@@ -31,6 +37,7 @@ function InVideoQuizXBlock(runtime, element) { | |||
}); | |||
|
|||
if (studentMode) { | |||
knownVideoDimensions = getVideoDimensions(); |
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.
awesomesauce
@@ -50,6 +57,25 @@ function InVideoQuizXBlock(runtime, element) { | |||
} | |||
} | |||
|
|||
function getVideoDimensions() { | |||
videoPosition = $('.tc-wrapper', video).position().top; |
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.
This variable needs declared first.
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.
yep!
@@ -50,6 +57,25 @@ function InVideoQuizXBlock(runtime, element) { | |||
} | |||
} | |||
|
|||
function getVideoDimensions() { | |||
videoPosition = $('.tc-wrapper', video).position().top; | |||
videoHeight = $('.tc-wrapper', video).css('height'); |
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.
This variable needs declared first.
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.
Yep!
function getVideoDimensions() { | ||
videoPosition = $('.tc-wrapper', video).position().top; | ||
videoHeight = $('.tc-wrapper', video).css('height'); | ||
videoWidth = $('.tc-wrapper', video).css('width'); |
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.
This variable needs declared first.
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.
Yep! My bad
videoPosition = $('.tc-wrapper', video).position().top; | ||
videoHeight = $('.tc-wrapper', video).css('height'); | ||
videoWidth = $('.tc-wrapper', video).css('width'); | ||
return [videoPosition, videoHeight, videoWidth]; |
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.
videoPosition
is an unexpected value to be returned from getVideoDimensions
;
is there a more apt name we can use?
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.
Also, looking at how this data is actually used, I suspect a dictionary/object may be a more apt data structure.
return {
'top': position,
'height': height,
'width': width
};
That means when we're modifying the CSS below, it's as easy as:
currentProblem.css(videoDimensions);
Of course, the for
loop will need updated, but that should be simple enough:
for (var key in knownVideoDimensions) {
if (knownVideoDimensions.hasOwnProperty(key)) {
if (knownVideoDimensions[key] !== currentVideoDimensions[key]) {
return true;
}
}
}
return false;
This makes the code more obvious, by avoiding directly indexing into the array arr[0]
, arr[1]
, etc., as that's opaque.
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.
This is a great idea, implemented it
} | ||
|
||
function videoDimensionsDiffer(newMeasurement, oldMeasurement) { | ||
if (newMeasurement.length !== oldMeasurement.length) { |
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.
When would this case occur?
Seems like only on the first run, because oldMeasurement
(via knownVideoDimensions
) is not initialized when being declared; does that seem right?
If so, could we just initialize it to some value above and drop this special handling here?
var knownVideoDimensions = [0, 0, 0];
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.
This case would never occur, since knownVideoDimensions is set right at the outset. Regardless, it's now unnecessary with the changes you've suggested since!
}); | ||
|
||
video.on('pause', function () { | ||
clearInterval(intervalObject); | ||
if (problemToDisplay) { | ||
resizeIntervalObject = setInterval(function () { | ||
currentVideoDimensions = getVideoDimensions(); |
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.
Should this be declared as a local variable?
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.
Done!
@@ -50,6 +57,25 @@ function InVideoQuizXBlock(runtime, element) { | |||
} | |||
} | |||
|
|||
function getVideoDimensions() { | |||
videoPosition = $('.tc-wrapper', video).position().top; |
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.
Nitpick: I tend to avoid prefixing variables if we're doing it for everything.
From the context of this function getVideoDimensions
, it's obvious that
any dimensions we list are for videos, unless otherwise noted.
Not only does it cut down on some verbosity, but it also makes it easier to grep the code: grepping for position
(case sensitive) won't find videoPosition
, but it will find position
.
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.
Yeah, this is fair. Made the requested changes
@stvstnfrd Made a bunch of changes based on your recommendations, let me know what you think! |
Changes Unknown when pulling e56e2aa on karandikar:fix-in-video-quiz into ** on Stanford-Online:master**. |
+1 lgtm, thanks for implementing those changes! |
@karandikar awesome, time to squash commits! |
If a video isn't the first component in the unit, the in-video-quiz questions appear incorrectly positioned on the page. We reposition the questions to properly cover the video while it's paused.
Previously, questions would sometimes fail to display in the in-video quiz xblocks. This was likely due to the "display" css property not changing from "none" to "block" for the problem component. This would also trigger issues with the videoState variable as well.
Previously, if the video transitioned from fullscreen to regular size with a question open, or if the window was resized with a question open, the question would not resize properly (the position, height, and/or width would be incorrect). This commit checks for changes to the video dimensions every 100ms when a question is open, and resizes the question if a change is detected.
- Rename ambiguous interval and timeout variables - Rename functions to reduce verbosity - Switch data structure for video dimension to be dictionary instead of list - Remove unnecessary comment
e56e2aa
to
8abbbd6
Compare
@caesar2164 @stvstnfrd Squashed, take a look and let me know if anything needs changing! |
Changes Unknown when pulling 8abbbd6 on karandikar:fix-in-video-quiz into ** on Stanford-Online:master**. |
Changes Unknown when pulling 20d2a26 on karandikar:fix-in-video-quiz into ** on Stanford-Online:master**. |
This set of commits fixes issues with the question alignment when the video isn't the first component, question sizing/alignment when a video is resized (window resize or un-fullscreening) with a question open, and questions displaying inconsistently because of a css issue.