Commit 36e00867 by Brian Jacobel

Clean up generated javascript for display.js

parent 20290d2b
// Generated by CoffeeScript 1.6.1 /* eslint-disable no-underscore-dangle */
/* globals Logger, interpolate */
(function() { (function() {
var _this = this; 'use strict';
this.Sequence = (function() { this.Sequence = (function() {
function Sequence(element) { function Sequence(element) {
var _this = this; var self = this;
this.removeBookmarkIconFromActiveNavItem = function(event) { this.removeBookmarkIconFromActiveNavItem = function(event) {
return Sequence.prototype.removeBookmarkIconFromActiveNavItem.apply(_this, arguments); return Sequence.prototype.removeBookmarkIconFromActiveNavItem.apply(self, [event]);
}; };
this.addBookmarkIconToActiveNavItem = function(event) { this.addBookmarkIconToActiveNavItem = function(event) {
return Sequence.prototype.addBookmarkIconToActiveNavItem.apply(_this, arguments); return Sequence.prototype.addBookmarkIconToActiveNavItem.apply(self, [event]);
}; };
this._change_sequential = function(direction, event) { this._change_sequential = function(direction, event) {
return Sequence.prototype._change_sequential.apply(_this, arguments); return Sequence.prototype._change_sequential.apply(self, [direction, event]);
}; };
this.selectPrevious = function(event) { this.selectPrevious = function(event) {
return Sequence.prototype.selectPrevious.apply(_this, arguments); return Sequence.prototype.selectPrevious.apply(self, [event]);
}; };
this.selectNext = function(event) { this.selectNext = function(event) {
return Sequence.prototype.selectNext.apply(_this, arguments); return Sequence.prototype.selectNext.apply(self, [event]);
}; };
this.goto = function(event) { this.goto = function(event) {
return Sequence.prototype.goto.apply(_this, arguments); return Sequence.prototype.goto.apply(self, [event]);
}; };
this.toggleArrows = function() { this.toggleArrows = function() {
return Sequence.prototype.toggleArrows.apply(_this, arguments); return Sequence.prototype.toggleArrows.apply(self);
}; };
this.updateProgress = function() { this.addToUpdatedProblems = function(problemId, newContentState, newState) {
return Sequence.prototype.updateProgress.apply(_this, arguments); return Sequence.prototype.addToUpdatedProblems.apply(self, [problemId, newContentState, newState]);
};
this.addToUpdatedProblems = function(problem_id, new_content_state, new_state) {
return Sequence.prototype.addToUpdatedProblems.apply(_this, arguments);
}; };
this.hideTabTooltip = function(event) { this.hideTabTooltip = function(event) {
return Sequence.prototype.hideTabTooltip.apply(_this, arguments); return Sequence.prototype.hideTabTooltip.apply(self, [event]);
}; };
this.displayTabTooltip = function(event) { this.displayTabTooltip = function(event) {
return Sequence.prototype.displayTabTooltip.apply(_this, arguments); return Sequence.prototype.displayTabTooltip.apply(self, [event]);
}; };
this.updatedProblems = {}; this.updatedProblems = {};
this.requestToken = $(element).data('request-token'); this.requestToken = $(element).data('request-token');
this.el = $(element).find('.sequence'); this.el = $(element).find('.sequence');
...@@ -51,10 +51,9 @@ ...@@ -51,10 +51,9 @@
this.ajaxUrl = this.el.data('ajax-url'); this.ajaxUrl = this.el.data('ajax-url');
this.nextUrl = this.el.data('next-url'); this.nextUrl = this.el.data('next-url');
this.prevUrl = this.el.data('prev-url'); this.prevUrl = this.el.data('prev-url');
this.base_page_title = " | " + document.title; this.base_page_title = ' | ' + document.title;
this.initProgress();
this.bind(); this.bind();
this.render(parseInt(this.el.data('position'))); this.render(parseInt(this.el.data('position'), 10));
} }
Sequence.prototype.$ = function(selector) { Sequence.prototype.$ = function(selector) {
...@@ -66,398 +65,290 @@ ...@@ -66,398 +65,290 @@
this.el.on('bookmark:add', this.addBookmarkIconToActiveNavItem); this.el.on('bookmark:add', this.addBookmarkIconToActiveNavItem);
this.el.on('bookmark:remove', this.removeBookmarkIconFromActiveNavItem); this.el.on('bookmark:remove', this.removeBookmarkIconFromActiveNavItem);
this.$('#sequence-list .nav-item').on('focus mouseenter', this.displayTabTooltip); this.$('#sequence-list .nav-item').on('focus mouseenter', this.displayTabTooltip);
return this.$('#sequence-list .nav-item').on('blur mouseleave', this.hideTabTooltip); this.$('#sequence-list .nav-item').on('blur mouseleave', this.hideTabTooltip);
}; };
Sequence.prototype.displayTabTooltip = function(event) { Sequence.prototype.displayTabTooltip = function(event) {
return $(event.currentTarget).find('.sequence-tooltip').removeClass('sr'); $(event.currentTarget).find('.sequence-tooltip').removeClass('sr');
}; };
Sequence.prototype.hideTabTooltip = function(event) { Sequence.prototype.hideTabTooltip = function(event) {
return $(event.currentTarget).find('.sequence-tooltip').addClass('sr'); $(event.currentTarget).find('.sequence-tooltip').addClass('sr');
};
Sequence.prototype.initProgress = function() {
/*
"#problem_#{id}" -> progress
*/
return this.progressTable = {};
}; };
Sequence.prototype.updatePageTitle = function() { Sequence.prototype.updatePageTitle = function() {
/* // update the page title to include the current section
update the page title to include the current section var positionLink = this.link_for(this.position);
*/
var position_link; if (positionLink && positionLink.data('page-title')) {
position_link = this.link_for(this.position); document.title = positionLink.data('page-title') + this.base_page_title;
if (position_link && position_link.data('page-title')) {
return document.title = position_link.data('page-title') + this.base_page_title;
} }
}; };
Sequence.prototype.hookUpContentStateChangeEvent = function() { Sequence.prototype.hookUpContentStateChangeEvent = function() {
var _this = this; var self = this;
return $('.problems-wrapper').bind('contentChanged', function(event, problem_id, new_content_state, new_state) {
return _this.addToUpdatedProblems(problem_id, new_content_state, new_state); return $('.problems-wrapper').bind('contentChanged', function(event, problemId, newContentState, newState) {
return self.addToUpdatedProblems(problemId, newContentState, newState);
}); });
}; };
Sequence.prototype.addToUpdatedProblems = function(problem_id, new_content_state, new_state) { Sequence.prototype.addToUpdatedProblems = function(problemId, newContentState, newState) {
/* /**
Used to keep updated problem's state temporarily. * Used to keep updated problem's state temporarily.
* params:
* 'problem_id' is problem id.
* 'new_content_state' is the updated content of the problem.
* 'new_state' is the updated state of the problem.
* initialize for the current sequence if there isn't any updated problem
* for this position.
*/ */
/*
params:
*/
/*
'problem_id' is problem id.
*/
/*
'new_content_state' is the updated content of the problem.
*/
/*
'new_state' is the updated state of the problem.
*/
/*
initialize for the current sequence if there isn't any updated problem
*/
/*
for this position.
*/
if (!this.anyUpdatedProblems(this.position)) { if (!this.anyUpdatedProblems(this.position)) {
this.updatedProblems[this.position] = {}; this.updatedProblems[this.position] = {};
} }
/*
Now, put problem content and score against problem id for current active sequence.
*/
return this.updatedProblems[this.position][problem_id] = [new_content_state, new_state]; // Now, put problem content and score against problem id for current active sequence.
this.updatedProblems[this.position][problemId] = [newContentState, newState];
}; };
Sequence.prototype.anyUpdatedProblems = function(position) { Sequence.prototype.anyUpdatedProblems = function(position) {
/* /**
check for the updated problems for given sequence position. * check for the updated problems for given sequence position.
*/ * params:
* 'position' can be any sequence position.
/*
params:
*/
/*
'position' can be any sequence position.
*/ */
return this.updatedProblems[position] !== void 0; return typeof(this.updatedProblems[position]) !== 'undefined';
};
Sequence.prototype.hookUpProgressEvent = function() {
return $('.problems-wrapper').bind('progressChanged', this.updateProgress);
}; };
Sequence.prototype.mergeProgress = function(p1, p2) { Sequence.prototype.enableButton = function(buttonClass, buttonAction) {
/* this.$(buttonClass)
if either is "NA", return the other one .removeClass('disabled')
*/ .removeAttr('disabled')
.click(buttonAction);
var w1, w2;
if (p1 === "NA") {
return p2;
}
if (p2 === "NA") {
return p1;
}
/*
Both real progresses
*/
if (p1 === "done" && p2 === "done") {
return "done";
}
/*
not done, so if any progress on either, in_progress
*/
w1 = p1 === "done" || p1 === "in_progress";
w2 = p2 === "done" || p2 === "in_progress";
if (w1 || w2) {
return "in_progress";
}
return "none";
}; };
Sequence.prototype.updateProgress = function() { Sequence.prototype.disableButton = function(buttonClass) {
var new_progress; this.$(buttonClass).addClass('disabled').attr('disabled', true);
new_progress = "NA";
_this = this;
$('.problems-wrapper').each(function(index) {
var progress;
progress = $(this).data('progress_status');
return new_progress = _this.mergeProgress(progress, new_progress);
});
return this.progressTable[this.position] = new_progress;
}; };
Sequence.prototype.enableButton = function(button_class, button_action) { Sequence.prototype.setButtonLabel = function(buttonClass, buttonLabel) {
return this.$(button_class).removeClass('disabled').removeAttr('disabled').click(button_action); this.$(buttonClass + ' .sr').html(buttonLabel);
}; };
Sequence.prototype.disableButton = function(button_class) { Sequence.prototype.updateButtonState = function(
return this.$(button_class).addClass('disabled').attr('disabled', true); buttonClass, buttonAction, actionLabelPrefix, isAtBoundary, boundaryUrl
}; ) {
var buttonLabel;
Sequence.prototype.setButtonLabel = function(button_class, button_label) { if (isAtBoundary && boundaryUrl === 'None') {
return this.$(button_class + ' .sr').html(button_label); this.disableButton(buttonClass);
};
Sequence.prototype.updateButtonState = function(button_class, button_action, action_label_prefix, is_at_boundary, boundary_url) {
var button_label;
if (is_at_boundary && boundary_url === 'None') {
return this.disableButton(button_class);
} else { } else {
button_label = action_label_prefix + (is_at_boundary ? ' Subsection' : ' Unit'); buttonLabel = actionLabelPrefix + (isAtBoundary ? ' Subsection' : ' Unit');
this.setButtonLabel(button_class, button_label); this.setButtonLabel(buttonClass, buttonLabel);
return this.enableButton(button_class, button_action); this.enableButton(buttonClass, buttonAction);
} }
}; };
Sequence.prototype.toggleArrows = function() { Sequence.prototype.toggleArrows = function() {
var is_first_tab, is_last_tab, next_button_class, previous_button_class; var isFirstTab, isLastTab, nextButtonClass, previousButtonClass;
this.$('.sequence-nav-button').unbind('click');
/*
previous button
*/
is_first_tab = this.position === 1; this.$('.sequence-nav-button').unbind('click');
previous_button_class = '.sequence-nav-button.button-previous';
this.updateButtonState(previous_button_class, this.selectPrevious, 'Previous', is_first_tab, this.prevUrl);
/*
next button
*/
/* // previous button
use inequality in case contents.length is 0 and position is 1. isFirstTab = this.position === 1;
*/ previousButtonClass = '.sequence-nav-button.button-previous';
this.updateButtonState(previousButtonClass, this.selectPrevious, 'Previous', isFirstTab, this.prevUrl);
is_last_tab = this.position >= this.contents.length; // next button
next_button_class = '.sequence-nav-button.button-next'; // use inequality in case contents.length is 0 and position is 1.
return this.updateButtonState(next_button_class, this.selectNext, 'Next', is_last_tab, this.nextUrl); isLastTab = this.position >= this.contents.length;
nextButtonClass = '.sequence-nav-button.button-next';
this.updateButtonState(nextButtonClass, this.selectNext, 'Next', isLastTab, this.nextUrl);
}; };
Sequence.prototype.render = function(new_position) { Sequence.prototype.render = function(newPosition) {
var bookmarked, current_tab, modx_full_url, sequence_links, var bookmarked, currentTab, modxFullUrl, sequenceLinks,
_this = this; self = this;
if (this.position !== new_position) { if (this.position !== newPosition) {
if (this.position !== void 0) { if (this.position) {
this.mark_visited(this.position); this.mark_visited(this.position);
modx_full_url = "" + this.ajaxUrl + "/goto_position"; modxFullUrl = '' + this.ajaxUrl + '/goto_position';
$.postWithPrefix(modx_full_url, { $.postWithPrefix(modxFullUrl, {
position: new_position position: newPosition
}); });
} }
/*
On Sequence change, fire custom event "sequence:change" on element.
*/
/*
Added for aborting video bufferization, see ../video/10_main.js
*/
this.el.trigger("sequence:change");
this.mark_active(new_position);
current_tab = this.contents.eq(new_position - 1);
bookmarked = this.el.find('.active .bookmark-icon').hasClass('bookmarked') ? true : false;
this.content_container.html(current_tab.text()).attr("aria-labelledby", current_tab.attr("aria-labelledby")).data('bookmarked', bookmarked);
/*
update the data-attributes with latest contents only for updated problems.
*/
if (this.anyUpdatedProblems(new_position)) { // On Sequence change, fire custom event 'sequence:change' on element.
$.each(this.updatedProblems[new_position], function(problem_id, latest_data) { // Added for aborting video bufferization, see ../video/10_main.js
var latest_content, latest_response; this.el.trigger('sequence:change');
latest_content = latest_data[0]; this.mark_active(newPosition);
latest_response = latest_data[1]; currentTab = this.contents.eq(newPosition - 1);
return _this.content_container.find("[data-problem-id='" + problem_id + "']").data('content', latest_content).data('problem-score', latest_response.current_score).data('problem-total-possible', latest_response.total_possible).data('attempts-used', latest_response.attempts_used); bookmarked = this.el.find('.active .bookmark-icon').hasClass('bookmarked');
// update the data-attributes with latest contents only for updated problems.
this.content_container
.html(currentTab.text())
.attr('aria-labelledby', currentTab.attr('aria-labelledby'))
.data('bookmarked', bookmarked);
if (this.anyUpdatedProblems(newPosition)) {
$.each(this.updatedProblems[newPosition], function(problemId, latestData) {
var latestContent, latestResponse;
latestContent = latestData[0];
latestResponse = latestData[1];
self.content_container
.find("[data-problem-id='" + problemId + "']")
.data('content', latestContent)
.data('problem-score', latestResponse.current_score)
.data('problem-total-possible', latestResponse.total_possible)
.data('attempts-used', latestResponse.attempts_used);
}); });
} }
XBlock.initializeBlocks(this.content_container, this.requestToken); XBlock.initializeBlocks(this.content_container, this.requestToken);
/*
For embedded circuit simulator exercises in 6.002x
*/
// For embedded circuit simulator exercises in 6.002x
window.update_schematics(); window.update_schematics();
this.position = new_position; this.position = newPosition;
this.toggleArrows(); this.toggleArrows();
this.hookUpContentStateChangeEvent(); this.hookUpContentStateChangeEvent();
this.hookUpProgressEvent();
this.updatePageTitle(); this.updatePageTitle();
sequence_links = this.content_container.find('a.seqnav'); sequenceLinks = this.content_container.find('a.seqnav');
sequence_links.click(this.goto); sequenceLinks.click(this.goto);
this.path.text(this.el.find('.nav-item.active').data('path')); this.path.text(this.el.find('.nav-item.active').data('path'));
return this.sr_container.focus(); this.sr_container.focus();
} }
}; };
Sequence.prototype.goto = function(event) { Sequence.prototype.goto = function(event) {
var alert_template, alert_text, is_bottom_nav, new_position, widget_placement; var alertTemplate, alertText, isBottomNav, newPosition, widgetPlacement;
event.preventDefault(); event.preventDefault();
/*
Links from courseware <a class='seqnav' href='n'>...</a>, was .target
*/
// Links from courseware <a class='seqnav' href='n'>...</a>, was .target_tab
if ($(event.currentTarget).hasClass('seqnav')) { if ($(event.currentTarget).hasClass('seqnav')) {
new_position = $(event.currentTarget).attr('href'); newPosition = $(event.currentTarget).attr('href');
/* // Tab links generated by backend template
Tab links generated by backend template
*/
} else { } else {
new_position = $(event.currentTarget).data('element'); newPosition = $(event.currentTarget).data('element');
} }
if ((1 <= new_position) && (new_position <= this.num_contents)) {
is_bottom_nav = $(event.target).closest('nav[class="sequence-bottom"]').length > 0; if ((newPosition >= 1) && (newPosition <= this.num_contents)) {
if (is_bottom_nav) { isBottomNav = $(event.target).closest('nav[class="sequence-bottom"]').length > 0;
widget_placement = 'bottom';
if (isBottomNav) {
widgetPlacement = 'bottom';
} else { } else {
widget_placement = 'top'; widgetPlacement = 'top';
} }
/*
Formerly known as seq_goto
*/
Logger.log("edx.ui.lms.sequence.tab_selected", { // Formerly known as seq_goto
Logger.log('edx.ui.lms.sequence.tab_selected', {
current_tab: this.position, current_tab: this.position,
target_tab: new_position, target_tab: newPosition,
tab_count: this.num_contents, tab_count: this.num_contents,
id: this.id, id: this.id,
widget_placement: widget_placement widget_placement: widgetPlacement
}); });
/*
On Sequence change, destroy any existing polling thread
*/
/*
for queued submissions, see ../capa/display.js
*/
// On Sequence change, destroy any existing polling thread
// for queued submissions, see ../capa/display.js
if (window.queuePollerID) { if (window.queuePollerID) {
window.clearTimeout(window.queuePollerID); window.clearTimeout(window.queuePollerID);
delete window.queuePollerID; delete window.queuePollerID;
} }
return this.render(new_position); this.render(newPosition);
} else { } else {
alert_template = gettext("Sequence error! Cannot navigate to %(tab_name)s in the current SequenceModule. Please contact the course staff."); alertTemplate = gettext('Sequence error! Cannot navigate to %(tab_name)s in the current SequenceModule. Please contact the course staff.'); // eslint-disable-line max-len
alert_text = interpolate(alert_template, { alertText = interpolate(alertTemplate, {
tab_name: new_position tab_name: newPosition
}, true); }, true);
return alert(alert_text); alert(alertText); // eslint-disable-line no-alert
} }
}; };
Sequence.prototype.selectNext = function(event) { Sequence.prototype.selectNext = function(event) {
return this._change_sequential('next', event); this._change_sequential('next', event);
}; };
Sequence.prototype.selectPrevious = function(event) { Sequence.prototype.selectPrevious = function(event) {
return this._change_sequential('previous', event); this._change_sequential('previous', event);
}; };
/* // `direction` can be 'previous' or 'next'
`direction` can be 'previous' or 'next'
*/
Sequence.prototype._change_sequential = function(direction, event) { Sequence.prototype._change_sequential = function(direction, event) {
/* var analyticsEventName, isBottomNav, newPosition, offset, widgetPlacement;
silently abort if direction is invalid.
*/
var analytics_event_name, is_bottom_nav, new_position, offset, widget_placement; // silently abort if direction is invalid.
if (direction !== 'previous' && direction !== 'next') { if (direction !== 'previous' && direction !== 'next') {
return; return;
} }
event.preventDefault(); event.preventDefault();
analytics_event_name = "edx.ui.lms.sequence." + direction + "_selected"; analyticsEventName = 'edx.ui.lms.sequence.' + direction + '_selected';
is_bottom_nav = $(event.target).closest('nav[class="sequence-bottom"]').length > 0; isBottomNav = $(event.target).closest('nav[class="sequence-bottom"]').length > 0;
if (is_bottom_nav) {
widget_placement = 'bottom'; if (isBottomNav) {
widgetPlacement = 'bottom';
} else { } else {
widget_placement = 'top'; widgetPlacement = 'top';
} }
/*
Formerly known as seq_next and seq_prev
*/
Logger.log(analytics_event_name, { // Formerly known as seq_next and seq_prev
Logger.log(analyticsEventName, {
id: this.id, id: this.id,
current_tab: this.position, current_tab: this.position,
tab_count: this.num_contents, tab_count: this.num_contents,
widget_placement: widget_placement widget_placement: widgetPlacement
}); });
if ((direction === 'next') && (this.position >= this.contents.length)) { if ((direction === 'next') && (this.position >= this.contents.length)) {
return window.location.href = this.nextUrl; window.location.href = this.nextUrl;
} else if ((direction === 'previous') && (this.position === 1)) { } else if ((direction === 'previous') && (this.position === 1)) {
return window.location.href = this.prevUrl; window.location.href = this.prevUrl;
} else { } else {
/* // If the bottom nav is used, scroll to the top of the page on change.
If the bottom nav is used, scroll to the top of the page on change. if (isBottomNav) {
*/
if (is_bottom_nav) {
$.scrollTo(0, 150); $.scrollTo(0, 150);
} }
offset = { offset = {
next: 1, next: 1,
previous: -1 previous: -1
}; };
new_position = this.position + offset[direction];
return this.render(new_position); newPosition = this.position + offset[direction];
this.render(newPosition);
} }
}; };
Sequence.prototype.link_for = function(position) { Sequence.prototype.link_for = function(position) {
return this.$("#sequence-list .nav-item[data-element=" + position + "]"); return this.$('#sequence-list .nav-item[data-element=' + position + ']');
}; };
Sequence.prototype.mark_visited = function(position) { Sequence.prototype.mark_visited = function(position) {
/* // Don't overwrite class attribute to avoid changing Progress class
Don't overwrite class attribute to avoid changing Progress class var element = this.link_for(position);
*/ element.removeClass('inactive').removeClass('active').addClass('visited');
var element;
element = this.link_for(position);
return element.removeClass("inactive").removeClass("active").addClass("visited");
}; };
Sequence.prototype.mark_active = function(position) { Sequence.prototype.mark_active = function(position) {
/* // Don't overwrite class attribute to avoid changing Progress class
Don't overwrite class attribute to avoid changing Progress class var element = this.link_for(position);
*/ element.removeClass('inactive').removeClass('visited').addClass('active');
var element;
element = this.link_for(position);
return element.removeClass("inactive").removeClass("visited").addClass("active");
}; };
Sequence.prototype.addBookmarkIconToActiveNavItem = function(event) { Sequence.prototype.addBookmarkIconToActiveNavItem = function(event) {
event.preventDefault(); event.preventDefault();
this.el.find('.nav-item.active .bookmark-icon').removeClass('is-hidden').addClass('bookmarked'); this.el.find('.nav-item.active .bookmark-icon').removeClass('is-hidden').addClass('bookmarked');
return this.el.find('.nav-item.active .bookmark-icon-sr').text(gettext('Bookmarked')); this.el.find('.nav-item.active .bookmark-icon-sr').text(gettext('Bookmarked'));
}; };
Sequence.prototype.removeBookmarkIconFromActiveNavItem = function(event) { Sequence.prototype.removeBookmarkIconFromActiveNavItem = function(event) {
event.preventDefault(); event.preventDefault();
this.el.find('.nav-item.active .bookmark-icon').removeClass('bookmarked').addClass('is-hidden'); this.el.find('.nav-item.active .bookmark-icon').removeClass('bookmarked').addClass('is-hidden');
return this.el.find('.nav-item.active .bookmark-icon-sr').text(''); this.el.find('.nav-item.active .bookmark-icon-sr').text('');
}; };
return Sequence; return Sequence;
}());
})();
}).call(this); }).call(this);
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