diff --git a/common/static/common/js/discussion/discussion_router.js b/common/static/common/js/discussion/discussion_router.js index 81905c3ff4..c490d575b9 100644 --- a/common/static/common/js/discussion/discussion_router.js +++ b/common/static/common/js/discussion/discussion_router.js @@ -93,20 +93,17 @@ DiscussionRouter.prototype.allThreads = function() { this.nav.updateSidebar(); - return this.nav.goHome(); + this.nav.goHome(); }; DiscussionRouter.prototype.setActiveThread = function() { if (this.thread) { - return this.nav.setActiveThread(this.thread.get("id")); - } else { - return this.nav.goHome(); + this.nav.setActiveThread(this.thread.get("id")); } }; DiscussionRouter.prototype.showThread = function(forum_name, thread_id) { - var self; - self = this; + var self = this; this.thread = this.discussion.get(thread_id); if (this.thread) { @@ -124,11 +121,13 @@ self.renderThreadView(); }).fail(function(xhr) { // otherwise display error message and navigate to all threads view - var errorMessage = (xhr.status === 404) ? - gettext("The thread you selected has been deleted. Please select another thread.") : - gettext("We had some trouble loading more responses. Please try again."); - - DiscussionUtil.discussionAlert(gettext("Sorry"), errorMessage); + var errorMsg; + if (xhr.status === 404) { + errorMsg = gettext("The thread you selected has been deleted. Please select another thread."); + } else { + errorMsg = gettext("We had some trouble loading more responses. Please try again."); + } + DiscussionUtil.discussionAlert(gettext("Sorry"), errorMsg); this.allThreads(); }); }; @@ -162,23 +161,23 @@ this.main.on("thread:responses:rendered", function() { return self.nav.updateSidebar(); }); - return this.thread.on("thread:thread_type_updated", this.showMain); + this.thread.on("thread:thread_type_updated", this.showMain); }; DiscussionRouter.prototype.navigateToThread = function(thread_id) { var thread, targetThreadRoute; thread = this.discussion.get(thread_id); targetThreadRoute = getSingleThreadRoute(thread.get("commentable_id"), thread_id); - this.navigate(targetThreadRoute, { trigger: true}); + this.navigate(targetThreadRoute, {trigger: true}); }; DiscussionRouter.prototype.navigateToAllThreads = function() { - this.navigate(allThreadsRoute, { trigger: true }); + this.navigate(allThreadsRoute, {trigger: true}); }; DiscussionRouter.prototype.showNewPost = function() { var self = this; - return $('.forum-content').fadeOut({ + $('.forum-content').fadeOut({ duration: 200, complete: function() { return self.newPost.fadeIn(200).focus(); @@ -187,7 +186,7 @@ }; DiscussionRouter.prototype.hideNewPost = function() { - return this.newPost.fadeOut({ + this.newPost.fadeOut({ duration: 200, complete: function() { return $('.forum-content').fadeIn(200).find('.thread-wrapper').focus(); diff --git a/common/static/common/js/discussion/utils.js b/common/static/common/js/discussion/utils.js index a0b1345ccb..e4f7b1cb8a 100644 --- a/common/static/common/js/discussion/utils.js +++ b/common/static/common/js/discussion/utils.js @@ -1,4 +1,4 @@ -/* globals $$course_id, Content, Markdown, URI */ +/* globals $$course_id, Content, Markdown, MathJax, URI */ (function() { 'use strict'; this.DiscussionUtil = (function() { @@ -65,7 +65,7 @@ DiscussionUtil.generateDiscussionLink = function(cls, txt, handler) { return $("") .addClass("discussion-link").attr("href", "#") - .addClass(cls).html(txt).click(function() {return handler(this);}); + .addClass(cls).text(txt).click(function() {return handler(this);}); }; DiscussionUtil.urlFor = function(name, param, param1, param2) { @@ -134,15 +134,17 @@ }; DiscussionUtil.showLoadingIndicator = function(element, takeFocus) { - this.$_loading = $( - "
" + - gettext("Loading content") + - "
" + var animElem = edx.HtmlUtils.joinHtml( + edx.HtmlUtils.HTML("
"), + gettext("Loading content"), + edx.HtmlUtils.HTML("
") ); - element.after(this.$_loading); + var $animElem = $(animElem.toString()); + element.after($animElem); + this.$_loading = $animElem; if (takeFocus) { this.makeFocusTrap(this.$_loading); - return this.$_loading.focus(); + this.$_loading.focus(); } }; @@ -151,40 +153,33 @@ }; DiscussionUtil.discussionAlert = function(header, body) { - var alertDiv, alertTrigger; + var $alertDiv, $alertTrigger; + // Prevents "text" is undefined in underscore.js in tests - looks like some tests use + // discussions somehow, but never append discussion fixtures or reset them; this causes + // entire test suite (lms, cms, common) to fail due to unhandled JS exception + var popupTemplate = $("#alert-popup").html() || ""; if ($("#discussion-alert").length === 0) { - alertDiv = $( - "