Commit 2af1ddca by Jacek Bzdak

Removed special handling when hiding video blocks.

parent 5a0c5535
(function () {
/**
* Manager for HTML XBlocks. These blocks are hid by detaching and shown
* by re-attaching them to the DOM.This is only generic way to generically
* Manager for HTML XBlocks. These blocks are hidden by detaching and shown
* by re-attaching them to the DOM. This is only way to generically
* handle things like video players (they should stop playing when removed from DOM).
*
* @param html an html xblock
......@@ -20,27 +20,25 @@
/**
*
* Manager for HTML Video child. Videos are paused when hiding them, and re-sized when showing them.
* Manager for HTML Video child. Videos are re-sized when showing them.
* @param video an video xblock
*
*/
function VideoManager(video) {
this.show = function () {
if (typeof video.resizer === 'undefined'){
if (typeof video.resizer === 'undefined') {
// This one is tricky: but it looks like resizer is undefined only if the video is on the
// step that is initially visible (and then no resizing is necessary)
return;
}
video.resizer.align();
};
this.hide = function () {
if (typeof video.videoPlayer === 'undefined'){
// If video player is undefined this means that the video isn't loaded yet, so no need to
// pause it.
return;
}
video.videoPlayer.pause();
};
/**
* Videos should be paused when user leaves a step containing a video. There is was a proposed implementation
* but since it didn't work on every system we decided to drop it (it was out of scope for current task
* nevertheless). See OC-1441 for details.
*/
this.hide = function () {};
}
/**
......@@ -65,48 +63,48 @@
var children = runtime.children(xblock_element);
/**
* A list of managers for children than need special care when showing or hiding.
* A list of managers for children that need special care when showing or hiding.
*
* @type {show, hide}[]
*/
var managedChildren = [];
/***
* This is a workaround for issue where jquery.xblock.Runtime doesn't return HTML Xblocks when querying
* This is a workaround for issue where jquery.xblock.Runtime doesn't return HTML blocks when querying
* for children.
*
* This can be removed when:
*
* * We allow inclusion of Ooyala blocks inside ProblemBuilder and our clients migrate to Ooyala, in this case
* * We allow inclusion of Ooyala blocks inside StepBuilder and our clients migrate to Ooyala, in this case
* we may drop special handling of HTML blocks. See discussions in OC-1441.
* * We include HTML blocks in runtime.children for runtime of jquery.xblock, then just add
* `html: HtmlManager` to `Managers`, and remove this block.
*/
$("div.xblock.xblock-student_view.xmodule_HtmlModule", xblock_element).each(function (idx, element) {
managedChildren.push(new HtmlManager({element:element}));
$("div.xblock.xblock-student_view.xmodule_HtmlModule", xblock_element).each(function(idx, element) {
managedChildren.push(new HtmlManager({ element: element }));
});
for (var idx = 0; idx < children.length; idx++){
for (var idx = 0; idx < children.length; idx++) {
var child = children[idx];
// NOTE: While following assertion is true for e.g Video blocks:
// child.type == $(child.element).data('block-type') it is invalidated by for all sb-* blocks
// NOTE: While the following assertion is true for e.g Video blocks:
// child.type == $(child.element).data('block-type') it is invalid for all sb-* blocks
var type = $(child.element).data('block-type');
var constructor = Managers[type];
if (typeof constructor === 'undefined'){
if (typeof constructor === 'undefined') {
// This block does not requires special care, moving on
continue ;
continue;
}
managedChildren.push(new constructor(child));
}
this.show = function () {
for (var idx = 0; idx<managedChildren.length; idx++){
for (var idx = 0; idx < managedChildren.length; idx++) {
managedChildren[idx].show();
}
};
this.hide = function () {
for (var idx = 0; idx<managedChildren.length; idx++){
for (var idx = 0; idx < managedChildren.length; idx++) {
managedChildren[idx].hide();
}
};
......
......@@ -40,7 +40,7 @@ function MentoringWithStepsBlock(runtime, element) {
*
* @param func single arg function.
*/
function forEachStep(func){
function forEachStep(func) {
for (var idx=0; idx < steps.length; idx++) {
func(steps[idx]);
}
......@@ -51,15 +51,15 @@ function MentoringWithStepsBlock(runtime, element) {
*/
function showActiveStep() {
var step = getActiveStep();
step.show();
step.showStep();
}
/**
* Hides all steps
*/
function hideAllSteps() {
forEachStep(function(step){
step.hide();
forEachStep(function(step) {
step.hideStep();
});
}
......@@ -251,17 +251,19 @@ function MentoringWithStepsBlock(runtime, element) {
reviewButtonDOM.hide();
tryAgainDOM.show();
/**
* We detach review step from DOM, this is required to handle HTML
* blocks that can be added to the Review step.
*
* NOTE: This is handled differently than step js. As the html contents
* of review step are replaced with fresh contents in submit function.
*/
// reviewStepDOM is detached in hideReviewStep
reviewStepDOM.insertBefore(reviewStepAnchor);
reviewStepDOM.show();
}
/**
* We detach review step from DOM, this is required to handle HTML
* blocks with embedded videos, that can be added to that step.
*
* NOTE: Review steps are handled differently than "normal" steps:
* the HTML contents of a review step are replaced with fresh
* contents in submit function.
*/
function hideReviewStep() {
reviewStepDOM.hide();
reviewStepDOM.detach();
......@@ -312,7 +314,6 @@ function MentoringWithStepsBlock(runtime, element) {
} // Don't show attempts if unlimited attempts available (max_attempts === 0)
}
function onChange() {
// We do not allow users to modify answers belonging to a step after submitting them:
// Once an answer has been submitted ("Next Step" button is enabled),
......@@ -413,7 +414,7 @@ function MentoringWithStepsBlock(runtime, element) {
submitXHR = $.post(handlerUrl, JSON.stringify({})).success(handleTryAgain);
}
function notify(name, data){
function notify(name, data) {
// Notification interface does not exist in the workbench.
if (runtime.notify) {
runtime.notify(name, data);
......@@ -439,7 +440,7 @@ function MentoringWithStepsBlock(runtime, element) {
var itemFeedbackParentSelector = '.choice';
var itemFeedbackSelector = ".choice .choice-tips";
function clickedInside(selector, parent_selector){
function clickedInside(selector, parent_selector) {
return target.is(selector) || target.parents(parent_selector).length>0;
}
......
......@@ -105,12 +105,18 @@ function MentoringStepBlock(runtime, element) {
return $('.sb-step', element).data('has-question');
},
show: function () {
/**
* Shows a step, updating all children.
*/
showStep: function () {
$(element).show();
childManager.show();
},
hide: function () {
/**
* Hides a step, updating all children.
*/
hideStep: function () {
$(element).hide();
childManager.hide();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment